Skip to content

Commit fd09d4e

Browse files
committed
Emit jump labels with node id
1 parent ae518db commit fd09d4e

2 files changed

Lines changed: 13 additions & 19 deletions

File tree

codegen.c

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -279,17 +279,9 @@ static int64_t count(void) {
279279
return i++;
280280
}
281281

282-
static const char *goto_label(Node *node) {
283-
if (node->lbl.unique_label)
284-
return node->lbl.unique_label;
285-
if (node->lbl.node)
286-
return node->lbl.node->lbl.unique_label;
287-
internal_error();
288-
}
289-
290282
static void name_labels(Node *n) {
291283
for (; n; n = n->lbl.next)
292-
n->lbl.unique_label = new_unique_name();
284+
n->lbl.label_id = count();
293285
}
294286

295287
static const char *tmpbuf(int sz) {
@@ -2545,7 +2537,7 @@ static void gen_expr2(Node *node, bool is_void) {
25452537
}
25462538
return;
25472539
case ND_LABEL_VAL: {
2548-
Printftn("lea %s(%%rip), %%rax", goto_label(node));
2540+
Printftn("lea .L.jmp.%" PRIi64 "(%%rip), %%rax", node->lbl.node->lbl.label_id);
25492541
return;
25502542
}
25512543
case ND_CAS: {
@@ -2829,7 +2821,7 @@ static void gen_stmt(Node *node) {
28292821
return;
28302822
case ND_GOTO:
28312823
gen_defr(node);
2832-
Printftn("jmp %s", goto_label(node));
2824+
Printftn("jmp .L.jmp.%" PRIi64, node->lbl.node->lbl.label_id);
28332825
return;
28342826
case ND_GOTO_EXPR:
28352827
gen_expr(node->m.lhs);
@@ -2843,8 +2835,8 @@ static void gen_stmt(Node *node) {
28432835
node->lbl.label_id);
28442836
return;
28452837
case ND_LABEL: {
2846-
if (node->lbl.unique_label)
2847-
Printfsn("%s:", node->lbl.unique_label);
2838+
if (node->lbl.label_id)
2839+
Printfsn(".L.jmp.%" PRIi64 ":", node->lbl.label_id);
28482840
return;
28492841
}
28502842
case ND_RETURN: {
@@ -4699,7 +4691,7 @@ static void asm_body(Node *node) {
46994691
if (node->gasm.outputs)
47004692
Printf("%df", ap->label_id);
47014693
else
4702-
Printf("%s", goto_label(ap->arg));
4694+
Printf(".L.jmp.%" PRIi64, ap->arg->lbl.node->lbl.label_id);
47034695
continue;
47044696
}
47054697

@@ -4843,7 +4835,7 @@ static void gen_asm(Node *node) {
48434835
Printftn("lea %df(%%rip), %s; jmp %df", fallthrough_label, tmp_gp, meet_label);
48444836
for (AsmParam *ap = node->gasm.labels; ap; ap = ap->next) {
48454837
Printftn("%d:", ap->label_id);
4846-
Printftn("lea %s(%%rip), %s", goto_label(ap->arg), tmp_gp);
4838+
Printftn("lea .L.jmp.%" PRIi64 "(%%rip), %s", ap->arg->lbl.node->lbl.label_id, tmp_gp);
48474839
Printftn("jmp %df", meet_label);
48484840
}
48494841
Printftn("%d:", meet_label);
@@ -5034,9 +5026,11 @@ static void emit_data(Obj *var) {
50345026
if (!rel)
50355027
break;
50365028

5037-
const char *str = rel->var ? get_symbol(rel->var)
5038-
: rel->label->lbl.node->lbl.unique_label;
5039-
Printftn(".quad \"%s\"%+ld", str, rel->addend);
5029+
if (rel->var)
5030+
Printftn(".quad \"%s\"+%" PRIi64, get_symbol(rel->var), rel->addend);
5031+
else
5032+
Printftn(".quad .L.jmp.%" PRIi64 "+%" PRIi64, rel->label->lbl.node->lbl.label_id, rel->addend);
5033+
50405034
pos += 8;
50415035
rel = rel->next;
50425036
}

slimcc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ struct Relocation {
405405
int offset;
406406
Node *label;
407407
Obj *var;
408-
long addend;
408+
int64_t addend;
409409
};
410410

411411
typedef enum {

0 commit comments

Comments
 (0)