From: David Given Date: Thu, 27 Oct 2016 21:17:16 +0000 (+0200) Subject: Mangle label names (turns out that the ACK assembler can't really cope with X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=658db4ba719582f4b9dfbdd6c79f32e431f9b5ca;p=ack.git Mangle label names (turns out that the ACK assembler can't really cope with labels that are the same name as instructions...). --- diff --git a/mach/powerpc/mcg/platform.c b/mach/powerpc/mcg/platform.c index 7d8499e0b..4a77118ca 100644 --- a/mach/powerpc/mcg/platform.c +++ b/mach/powerpc/mcg/platform.c @@ -290,5 +290,17 @@ struct hop* platform_swap(struct basicblock* bb, struct hreg* src, struct hreg* return hop; } +const char* platform_label(const char* label) +{ + /* Labels starting with . are internal, not exported, and don't need mangling. */ + + if (label[0] == '.') + return label; + + /* Otherwise, mangle. */ + + return aprintf("_%s", label); +} + /* vim: set sw=4 ts=4 expandtab : */ diff --git a/mach/proto/mcg/basicblock.c b/mach/proto/mcg/basicblock.c index 5a30d9a90..aa0a729e0 100644 --- a/mach/proto/mcg/basicblock.c +++ b/mach/proto/mcg/basicblock.c @@ -20,7 +20,7 @@ struct basicblock* bb_get(const char* name) struct idf* p; if (!name) - name = aprintf("___anon_bb_%d", next_id++); + name = aprintf(".anon_bb_%d", next_id++); p = str2idf((char*) name, 0); if (!p->block) { diff --git a/mach/proto/mcg/data.c b/mach/proto/mcg/data.c index 6b6fc084f..2e6fde9b2 100644 --- a/mach/proto/mcg/data.c +++ b/mach/proto/mcg/data.c @@ -44,7 +44,7 @@ static void emit_header(int desired_section) fatal("label '%s' can't change sections", pending->name); fprintf(outputfile, "\n.sect %s\n", section_to_str(pending->section)); - fprintf(outputfile, "%s:\n", pending->name); + fprintf(outputfile, "%s:\n", platform_label(pending->name)); pending = NULL; } } diff --git a/mach/proto/mcg/hop.c b/mach/proto/mcg/hop.c index 02f6b2930..1afa04c50 100644 --- a/mach/proto/mcg/hop.c +++ b/mach/proto/mcg/hop.c @@ -265,11 +265,11 @@ char* hop_render(struct hop* hop) switch (ir->opcode) { case IR_BLOCK: - appendf("%s", ir->u.bvalue->name); + appendf("%s", platform_label(ir->u.bvalue->name)); break; case IR_LABEL: - appendf("%s", ir->u.lvalue); + appendf("%s", platform_label(ir->u.lvalue)); break; case IR_LOCAL: diff --git a/mach/proto/mcg/mcg.h b/mach/proto/mcg/mcg.h index 13a3d236e..08f6828bf 100644 --- a/mach/proto/mcg/mcg.h +++ b/mach/proto/mcg/mcg.h @@ -124,6 +124,7 @@ extern struct hop* platform_prologue(void); extern struct hop* platform_epilogue(void); extern struct hop* platform_move(struct basicblock* bb, struct hreg* src, struct hreg* dest); extern struct hop* platform_swap(struct basicblock* bb, struct hreg* src, struct hreg* dest); +extern const char* platform_label(const char* label); extern FILE* outputfile; extern FILE* dominance_dot_file; diff --git a/mach/proto/mcg/pass_instructionselection.c b/mach/proto/mcg/pass_instructionselection.c index 525846878..2bf5e5b59 100644 --- a/mach/proto/mcg/pass_instructionselection.c +++ b/mach/proto/mcg/pass_instructionselection.c @@ -220,6 +220,7 @@ static struct insn* walk_instructions(struct burm_node* node, int goal) { case ir_to_esn(IR_REG, 0): current_hop->output = node->ir->result; + assert(current_hop->output != NULL); break; case ir_to_esn(IR_NOP, 'I'): @@ -227,6 +228,7 @@ static struct insn* walk_instructions(struct burm_node* node, int goal) case ir_to_esn(IR_NOP, 'L'): case ir_to_esn(IR_NOP, 'D'): current_hop->output = node->left->ir->result; + assert(current_hop->output != NULL); break; } } @@ -314,9 +316,9 @@ void pass_instruction_selector(void) { int i; - for (i=0; iname); + fprintf(outputfile, "%s:\n", platform_label(bb->name)); for (j=0; jhops.count; j++) { struct hop* hop = bb->hops.item[j]; @@ -128,12 +128,12 @@ static void write_cfg_graph(const char* name) { int i; - fprintf(cfg_dot_file, "subgraph %s {\n", name); - fprintf(cfg_dot_file, "\t%s [color=red];\n", cfg.entry->name); + fprintf(cfg_dot_file, "subgraph \"%s\" {\n", name); + fprintf(cfg_dot_file, "\t\"%s\" [color=red];\n", cfg.entry->name); for (i=0; i %s;\n", + fprintf(cfg_dot_file, "\t\"%s\" -> \"%s\";\n", cfg.graph.item[i].left->name, cfg.graph.item[i].right->name); } @@ -145,12 +145,12 @@ static void write_dominance_graph(const char* name) { int i; - fprintf(dominance_dot_file, "subgraph %s {\n", name); - fprintf(dominance_dot_file, "\t%s [color=green];\n", cfg.entry->name); + fprintf(dominance_dot_file, "subgraph \"%s\" {\n", name); + fprintf(dominance_dot_file, "\t\"%s\" [color=green];\n", cfg.entry->name); for (i=0; i %s;\n", + fprintf(dominance_dot_file, "\t\"%s\" -> \"%s\";\n", dominance.graph.item[i].right->name, dominance.graph.item[i].left->name); }