From 0d929287d77ccc3fb52ca8bd072678b5ae2c81c8 Mon Sep 17 00:00:00 2001 From: Thomas Bracht Laumann Jespersen Date: Thu, 26 Jan 2023 12:09:44 +0100 Subject: 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. --- all.h | 4 +++- amd64/emit.c | 3 +++ amd64/isel.c | 1 + arm64/emit.c | 3 +++ emit.c | 32 ++++++++++++++++++++++++++++++++ main.c | 8 +++++++- ops.h | 2 ++ parse.c | 20 ++++++++++++++++++-- rv64/emit.c | 3 +++ tools/lexh.c | 6 +++--- 10 files changed, 75 insertions(+), 7 deletions(-) diff --git a/all.h b/all.h index b6591f0..4d36314 100644 --- a/all.h +++ b/all.h @@ -502,7 +502,7 @@ bshas(BSet *bs, uint elt) /* parse.c */ extern Op optab[NOp]; -void parse(FILE *, char *, void (Dat *), void (Fn *)); +void parse(FILE *, char *, void (char *), void (Dat *), void (Fn *)); void printfn(Fn *, FILE *); void printref(Ref, Fn *, FILE *); void err(char *, ...) __attribute__((noreturn)); @@ -568,6 +568,8 @@ void rega(Fn *); /* emit.c */ void emitfnlnk(char *, Lnk *, FILE *); void emitdat(Dat *, FILE *); +void emitdbgfile(char *, FILE *); +void emitdbgloc(uint, FILE *); int stashbits(void *, int); void elf_emitfnfin(char *, FILE *); void elf_emitfin(FILE *); diff --git a/amd64/emit.c b/amd64/emit.c index 46de3d9..2290d2d 100644 --- a/amd64/emit.c +++ b/amd64/emit.c @@ -547,6 +547,9 @@ emitins(Ins i, Fn *fn, FILE *f) emitcopy(i.arg[0], i.arg[1], i.cls, fn, f); emitcopy(i.arg[1], TMP(XMM0+15), i.cls, fn, f); break; + case Oloc: + emitdbgloc(i.arg[0].val, f); + break; } } diff --git a/amd64/isel.c b/amd64/isel.c index 3d5d5a9..277063f 100644 --- a/amd64/isel.c +++ b/amd64/isel.c @@ -392,6 +392,7 @@ sel(Ins i, ANum *an, Fn *fn) case_Oload: seladdr(&i.arg[0], an, fn); goto Emit; + case Oloc: case Ocall: case Osalloc: case Ocopy: diff --git a/arm64/emit.c b/arm64/emit.c index ee1593f..5ca6e79 100644 --- a/arm64/emit.c +++ b/arm64/emit.c @@ -446,6 +446,9 @@ emitins(Ins *i, E *e) if (!req(i->to, R)) emitf("mov %=, sp", i, e); break; + case Oloc: + emitdbgloc(i->arg[0].val, e->f); + break; } } diff --git a/emit.c b/emit.c index 017c461..b880d67 100644 --- a/emit.c +++ b/emit.c @@ -207,3 +207,35 @@ macho_emitfin(FILE *f) emitfin(f, sec); } + +static uint32_t *file; +static uint nfile; +static uint curfile; + +void +emitdbgfile(char *fn, FILE *f) +{ + uint32_t id; + uint n; + + id = intern(fn); + for (n=0; nto, R)) emitf("mv %=, sp", i, fn, f); break; + case Oloc: + emitdbgloc(i->arg[0].val, f); + break; } } diff --git a/tools/lexh.c b/tools/lexh.c index 5ceb4ee..8883976 100644 --- a/tools/lexh.c +++ b/tools/lexh.c @@ -23,11 +23,11 @@ char *tok[] = { "ceql", "cnel", "cles", "clts", "cgts", "cges", "cnes", "ceqs", "cos", "cuos", "cled", "cltd", "cgtd", "cged", "cned", "ceqd", "cod", "cuod", - "vaarg", "vastart", "...", "env", + "vaarg", "vastart", "...", "env", "loc", "call", "phi", "jmp", "jnz", "ret", "hlt", "export", - "function", "type", "data", "section", "align", "blit", - "l", "w", "sh", "uh", "h", "sb", "ub", "b", + "function", "type", "data", "section", "align", "file", + "blit", "l", "w", "sh", "uh", "h", "sb", "ub", "b", "d", "s", "z", "loadw", "loadl", "loads", "loadd", "alloc1", "alloc2", -- cgit v1.2.3