~laumann/hadb

333070a8ae4e115de313b176e1ec7f1a76e06202 — Thomas Bracht Laumann Jespersen 1 year, 12 days ago 8b3599d
format/dwarf: fix for latest hare stdlib

The strio module was removed, replaced in parts by the memio module.
1 files changed, 16 insertions(+), 17 deletions(-)

M format/dwarf/decode.ha
M format/dwarf/decode.ha => format/dwarf/decode.ha +16 -17
@@ 1,8 1,8 @@
use io;
use bufio;
use memio;
use endian;
use strings;
use strio;

// unsigned LEB128
export type uleb128 = uint;


@@ 55,7 55,7 @@ export fn new(is_stmt: bool) registers = {
	};
};

fn scanbyte(f: io::handle) (u8 | error) = match (bufio::scanbyte(f)?) {
fn scanbyte(f: io::handle) (u8 | error) = match (bufio::read_byte(f)?) {
	case let b: u8 => return b;
	case io::EOF => return unexpectedeof;
};


@@ 119,7 119,7 @@ fn decodesleb128(dec: *decoder) (sleb128 | error) = {
	];
	for (let i = 0z; i < len(cases); i += 1) {
		const (input, expected) = cases[i];
		const src = bufio::fixed(input, io::mode::READ);
		const src = memio::fixed(input);
		const dec = newdecoder(&src, 10, 1, -1, 4, true, []);

		const decoded = decodeuleb128(&dec);


@@ 142,7 142,7 @@ fn decodesleb128(dec: *decoder) (sleb128 | error) = {
	];
	for (let i = 0z; i < len(cases); i += 1) {
		const (input, expected) = cases[i];
		const src = bufio::fixed(input, io::mode::READ);
		const src = memio::fixed(input);
		const dec = newdecoder(&src, 10, 1, -1, 4, true, []);

		const decoded = decodesleb128(&dec);


@@ 197,7 197,7 @@ fn readexact(h: io::handle, buf: []u8) (void | error) = {

// FIXME: better API
export fn decode_lineprogramheader(input: []u8) (lineprogramheader | error) = {
	const src = bufio::fixed(input, io::mode::READ);
	const src = memio::fixed(input);
	let buf: [8]u8 = [0...];

	readexact(&src, buf[..4])?;


@@ 218,7 218,7 @@ export fn decode_lineprogramheader(input: []u8) (lineprogramheader | error) = {
	let standard_opcode_lengths = alloc([0u8...], opcode_base - 1);
	for (let i = 0z; i < opcode_base - 1; i += 1)
		standard_opcode_lengths[i] = scanbyte(&src)?;
	

	// sequence of include directories
	let include_dirs: []str = [];
	for (true) {


@@ 226,11 226,11 @@ export fn decode_lineprogramheader(input: []u8) (lineprogramheader | error) = {
		if (b == 0)
			break;

		let dirname = strio::dynamic();
		defer io::close(&dirname)!;
		let d: []u8 = [];

		for (b != 0; b = scanbyte(&src)?)
			strio::appendrune(&dirname, b : u32 : rune)?;
			append(d, b);
		append(include_dirs, strings::fromutf8(d)!);
	};

	let file_names: []fileentry = [];


@@ 239,18 239,17 @@ export fn decode_lineprogramheader(input: []u8) (lineprogramheader | error) = {
		if (b == 0)
			break;

		let name = strio::dynamic();
		defer io::close(&name)!;
		let name: []u8 = [];

		for (b != 0; b = scanbyte(&src)?)
			strio::appendrune(&name, b : u32 : rune)?;
			append(name, b);

		const dir_index = decodeuleb128_fromstream(&src)?;
		const mtime = decodeuleb128_fromstream(&src)?;
		const length = decodeuleb128_fromstream(&src)?;

		append(file_names, fileentry {
			name = strings::dup(strio::string(&name)),
			name = strings::fromutf8(name)!,
			dir_index = dir_index,
			mtime = mtime,
			length = length,


@@ 291,7 290,7 @@ fn newline(regs: *registers) line = line {
};

export fn decode_op(dec: *decoder) (op | io::EOF | error) = {
	const bop = match (bufio::scanbyte(dec.src)?) {
	const bop = match (bufio::read_byte(dec.src)?) {
	case let b: u8 => yield b;
	case io::EOF => return io::EOF;
	};


@@ 470,7 469,7 @@ export fn decode_lines(dec: *decoder) ([]line | error) = {
		(0x24d, 7, true, false, true),
	];

	const src = bufio::fixed(bytestream, io::mode::READ);
	const src = memio::fixed(bytestream);
	const dec = newdecoder(&src, opcode_base,
		minimum_instruction_length, line_base, line_range, true, []);



@@ 566,7 565,7 @@ export fn decode_lines(dec: *decoder) ([]line | error) = {
		(0x0000000000001168, 11,  1, true, false, true),
	];

	const src = bufio::fixed(lnp, io::mode::READ);
	const src = memio::fixed(lnp);
	const dec = newdecoder(&src, opcode_base,
		min_instr_length, line_base, line_range, default_is_stmt, []);



@@ 614,7 613,7 @@ export fn decode_lines(dec: *decoder) ([]line | error) = {
	assert(len(lph.file_names) == 1);

	const lineprogram = debugline[4 + 2 + 4 + lph.headerlen..];
	const src = bufio::fixed(lineprogram, io::mode::READ);
	const src = memio::fixed(lineprogram);
	const dec = newdecoder(&src,
		lph.opcode_base,
		lph.min_instr_length,