From f2297c20b69d942fd1e8fdcdd8f4d142c71de662 Mon Sep 17 00:00:00 2001 From: Matthew Sotoudeh Date: Sun, 30 Jul 2023 18:09:52 -0700 Subject: bad line numbers support --- codegen.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'codegen.c') diff --git a/codegen.c b/codegen.c index 5111c76..7acd2c9 100644 --- a/codegen.c +++ b/codegen.c @@ -60,6 +60,11 @@ static int count(void) { return i++; } +static void emit_line(struct Token *tok) { + if (opt_line_numbers && tok && tok->line_no && tok->filename) + println("#line %d \"%s\"", tok->line_no, tok->filename); +} + static int RETURN_TMP; void print_label(char *label) { @@ -305,8 +310,7 @@ static void gen_addr(Node *node, int to_tmp) { // Generate code for a given node. static void gen_expr(Node *node, int to_tmp) { - // println(" .loc %d %d", node->tok->file->file_no, node->tok->line_no); - + emit_line(node->tok); switch (node->kind) { case ND_NULL_EXPR: return; @@ -560,6 +564,7 @@ static void gen_expr(Node *node, int to_tmp) { } static void gen_stmt(Node *node) { + emit_line(node->tok); switch (node->kind) { case ND_IF: { int cond = count(), condfalse = count(), c = count(); @@ -838,6 +843,8 @@ static void emit_text(Obj *prog) { if (!fn->is_function || !fn->is_definition) continue; + emit_line(fn->body->tok); + // No code is emitted for "static inline" functions // if no one is referencing them. if (!fn->is_live) -- cgit v1.2.3