diff options
author | Matthew Sotoudeh <matthew@masot.net> | 2023-07-30 18:09:52 -0700 |
---|---|---|
committer | Matthew Sotoudeh <matthew@masot.net> | 2023-07-30 18:09:52 -0700 |
commit | f2297c20b69d942fd1e8fdcdd8f4d142c71de662 (patch) | |
tree | 5072f8f11eea2d8265e48d6c3bce533e124f016f /codegen.c | |
parent | c84bbdc2a296f4b818fa8ec05a6dbe2dd46fc4f1 (diff) |
bad line numbers support
Diffstat (limited to 'codegen.c')
-rw-r--r-- | codegen.c | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -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) |