~ecs/hare-qbe

cf27d02aa2d4e7e8cce9893a5d4f2b68817c668d — Evan Johnston 2 months ago e928f8b
add dbgfile, dbgloc
6 files changed, 37 insertions(+), 3 deletions(-)

M qbe/ast.ha
M qbe/free.ha
M qbe/inst.ha
M qbe/parse.ha
M qbe/token.ha
M qbe/unparse.ha
M qbe/ast.ha => qbe/ast.ha +3 -1
@@ 90,6 90,8 @@ export type funcdef = struct {
	blocks: []block,
};

export type definition = (typedef | datadef | funcdef);
export type dbgfile = str;

export type definition = (typedef | datadef | funcdef | dbgfile);

export type definitions = []definition;

M qbe/free.ha => qbe/free.ha +2 -0
@@ 123,6 123,7 @@ fn free_funcdef(f: funcdef) void = {
			free_val(b.dst);
			free_val(b.sz);
		case hlt => void;
		case dbgloc => void;
		};
		free(b.insts);
		match (b.jump) {


@@ 146,6 147,7 @@ export fn free_definition(d: definition) void = match (d) {
case let t: typedef => free_typedef(t);
case let d: datadef => free_datadef(d);
case let f: funcdef => free_funcdef(f);
case let d: dbgfile => free(d);
};

export fn free_definitions(d: definitions) void = {

M qbe/inst.ha => qbe/inst.ha +3 -1
@@ 217,7 217,9 @@ export type blit = struct {

export type hlt = void;

export type inst = (onearg | twoarg | _vastart | call | blit | hlt);
export type dbgloc = (uint, uint);

export type inst = (onearg | twoarg | _vastart | call | blit | hlt | dbgloc);

export fn strinst(i: (itype1 | itype2)) str = match (i) {
case let o: itype1 =>

M qbe/parse.ha => qbe/parse.ha +13 -1
@@ 268,6 268,16 @@ fn parse_val(in: *lexer) (val | error) = {
};

fn parse_statement(in: *lexer) (inst | phi | void | error) = {
	match (try(in, ltok::DBGLOC)?) {
	case let t: token =>
		let out: dbgloc = (0, 0);
		out.0 = want(in, ltok::LIT_U64)?.1 as u64: uint;
		want(in, ltok::COMMA)?;
		out.1 = want(in, ltok::LIT_U64)?.1 as u64: uint;
		parse_nl(in)?;
		return out;
	case void => void;
	};
	let out = match (try(in, ltok::LIT_TEMP)?) {
	case let t: token =>
		want(in, ltok::EQ)?;


@@ 481,7 491,7 @@ fn parse_funcdef(in: *lexer, linkage: linkage) (funcdef | error) = {
fn parse_definition(in: *lexer) (definition | void | error) = {
	if (try(in, ltok::EOF)? is token) return void;
	let linkage = parse_linkage(in)?;
	switch (want(in, ltok::DATA, ltok::FUNCTION, ltok::TYPE)?.0) {
	switch (want(in, ltok::DATA, ltok::FUNCTION, ltok::TYPE, ltok::DBGFILE)?.0) {
	case ltok::DATA =>
		return parse_datadef(in, linkage)?;
	case ltok::FUNCTION =>


@@ 490,6 500,8 @@ fn parse_definition(in: *lexer) (definition | void | error) = {
		if (linkage.exported) return ltok::EXPORT: unexpected;
		if (linkage.secname != "") return ltok::SECTION: unexpected;
		return parse_typedef(in)?;
	case ltok::DBGFILE =>
		return want(in, ltok::LIT_STR)?.1 as str: dbgfile: definition;
	case => abort(); // unreachable i think
	};
};

M qbe/token.ha => qbe/token.ha +8 -0
@@ 62,6 62,8 @@ export type ltok = enum {
	CUOS,
	D,
	DATA,
	DBGFILE,
	DBGLOC,
	DIV,
	DTOSI,
	DTOUI,


@@ 146,6 148,8 @@ export type ltok = enum {
	LIT_TEMP,
	LIT_TYPE,
	LIT_U64,

	
	EOF,
};



@@ 213,6 217,8 @@ const bmap: [_]str = [
	"cuos",
	"d",
	"data",
	"dbgfile",
	"dbgloc",
	"div",
	"dtosi",
	"dtoui",


@@ 363,6 369,8 @@ case ltok::CUOD => return "CUOD";
case ltok::CUOS => return "CUOS";
case ltok::D => return "D";
case ltok::DATA => return "DATA";
case ltok::DBGFILE => return "DBGFILE";
case ltok::DBGLOC => return "DBGLOC";
case ltok::DIV => return "DIV";
case ltok::DTOSI => return "DTOSI";
case ltok::DTOUI => return "DTOUI";

M qbe/unparse.ha => qbe/unparse.ha +8 -0
@@ 207,6 207,8 @@ case _vastart =>
	fmt::fprintln(out, "\tvastart")?;
case let c: call =>
	unparse_call(out, c)?;
case let d: dbgloc =>
	fmt::fprintfln(out, "\tdbgloc {}, {}", d.0, d.1)?;
};

fn unparse_jump(out: io::handle, j: jump) (io::error | void) = match (j) {


@@ 265,6 267,10 @@ fn unparse_funcdef(out: io::handle, f: funcdef) (io::error | void) = {
	fmt::fprintln(out, "}")?;
};

fn unparse_dbgfile(out: io::handle, f: dbgfile) (io::error | void) = {
	fmt::fprintfln(out, "dbgfile \"{}\"", f)?;
};

export fn unparse_definition(out: io::handle, _def: definition) (io::error | void) = {
	match (_def) {
	case let t: typedef =>


@@ 273,6 279,8 @@ export fn unparse_definition(out: io::handle, _def: definition) (io::error | voi
		unparse_datadef(out, d)?;
	case let f: funcdef =>
		unparse_funcdef(out, f)?;
	case let d: dbgfile =>
		unparse_dbgfile(out, d)?;
	};
	fmt::fprintln(out)?;
};