~ecs/public-inbox

add dbgfile, dbgloc v1 PROPOSED

Evan Johnston: 1
 add dbgfile, dbgloc

 5 files changed, 35 insertions(+), 3 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~ecs/public-inbox/patches/51649/mbox | git am -3
Learn more about email & git

[PATCH] add dbgfile, dbgloc Export this patch

---
 qbe/ast.ha     |  4 +++-
 qbe/inst.ha    |  4 +++-
 qbe/parse.ha   | 14 +++++++++++++-
 qbe/token.ha   |  8 ++++++++
 qbe/unparse.ha |  8 ++++++++
 5 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/qbe/ast.ha b/qbe/ast.ha
index 94b4be2..8b62acd 100644
--- a/qbe/ast.ha
+++ b/qbe/ast.ha
@@ -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;
diff --git a/qbe/inst.ha b/qbe/inst.ha
index d5f387b..e9da2bd 100644
--- a/qbe/inst.ha
+++ b/qbe/inst.ha
@@ -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 =>
diff --git a/qbe/parse.ha b/qbe/parse.ha
index 62e17dd..b87d938 100644
--- a/qbe/parse.ha
+++ b/qbe/parse.ha
@@ -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
	};
};
diff --git a/qbe/token.ha b/qbe/token.ha
index 02b4fa2..6ce3393 100644
--- a/qbe/token.ha
+++ b/qbe/token.ha
@@ -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";
diff --git a/qbe/unparse.ha b/qbe/unparse.ha
index bd2fca5..2f2104d 100644
--- a/qbe/unparse.ha
+++ b/qbe/unparse.ha
@@ -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, "dbgloc {}, {}", 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)?;
};
-- 
2.44.0