summary refs log tree commit diff
path: root/parse.c
diff options
context:
space:
mode:
authorThomas Bracht Laumann Jespersen <t@laumann.xyz>2023-01-26 12:09:44 +0100
committerQuentin Carbonneaux <quentin@c9x.me>2023-06-06 18:44:51 +0200
commit0d929287d77ccc3fb52ca8bd072678b5ae2c81c8 (patch)
tree72cf91ec66052797059734c9d089a49a69b47122 /parse.c
parente493a7f23352f51acc0a1e12284ab19d7894488a (diff)
downloadroux-0d929287d77ccc3fb52ca8bd072678b5ae2c81c8.tar.gz
implement line number info tracking
Support "file" and "loc" directives. "file" takes a string (a file name)
assigns it a number, sets the current file to that number and records
the string for later. "loc" takes a single number and outputs location
information with a reference to the current file.
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/parse.c b/parse.c
index c54448f..5b9f60e 100644
--- a/parse.c
+++ b/parse.c
@@ -53,6 +53,7 @@ enum Token {
 	Tdata,
 	Tsection,
 	Talign,
+	Tfile,
 	Tl,
 	Tw,
 	Tsh,
@@ -110,6 +111,7 @@ static char *kwmap[Ntok] = {
 	[Tdata] = "data",
 	[Tsection] = "section",
 	[Talign] = "align",
+	[Tfile] = "file",
 	[Tsb] = "sb",
 	[Tub] = "ub",
 	[Tsh] = "sh",
@@ -130,7 +132,7 @@ enum {
 	TMask = 16383, /* for temps hash */
 	BMask = 8191, /* for blocks hash */
 
-	K = 9583425, /* found using tools/lexh.c */
+	K = 10525445, /* found using tools/lexh.c */
 	M = 23,
 };
 
@@ -655,6 +657,16 @@ parseline(PState ps)
 		expect(Tnl);
 		closeblk();
 		return PLbl;
+	case Oloc:
+		expect(Tint);
+		op = Oloc;
+		k = Kw;
+		r = R;
+		arg[0] = INT(tokval.num);
+		if (arg[0].val != tokval.num)
+			err("line number too big");
+		arg[1] = R;
+		goto Ins;
 	}
 	r = tmpref(tokval.str);
 	expect(Teq);
@@ -1160,7 +1172,7 @@ parselnk(Lnk *lnk)
 }
 
 void
-parse(FILE *f, char *path, void data(Dat *), void func(Fn *))
+parse(FILE *f, char *path, void dbgfile(char *), void data(Dat *), void func(Fn *))
 {
 	Lnk lnk;
 	uint n;
@@ -1177,6 +1189,10 @@ parse(FILE *f, char *path, void data(Dat *), void func(Fn *))
 		switch (parselnk(&lnk)) {
 		default:
 			err("top-level definition expected");
+		case Tfile:
+			expect(Tstr);
+			dbgfile(tokval.str);
+			break;
 		case Tfunc:
 			func(parsefn(&lnk));
 			break;