summaryrefslogtreecommitdiff
path: root/codegen.c
diff options
context:
space:
mode:
Diffstat (limited to 'codegen.c')
-rw-r--r--codegen.c11
1 files changed, 9 insertions, 2 deletions
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)
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback