Mangle label names (turns out that the ACK assembler can't really cope with
authorDavid Given <dg@cowlark.com>
Thu, 27 Oct 2016 21:17:16 +0000 (23:17 +0200)
committerDavid Given <dg@cowlark.com>
Thu, 27 Oct 2016 21:17:16 +0000 (23:17 +0200)
labels that are the same name as instructions...).

mach/powerpc/mcg/platform.c
mach/proto/mcg/basicblock.c
mach/proto/mcg/data.c
mach/proto/mcg/hop.c
mach/proto/mcg/mcg.h
mach/proto/mcg/pass_instructionselection.c
mach/proto/mcg/procedure.c

index 7d8499e..4a77118 100644 (file)
@@ -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 : */
 
index 5a30d9a..aa0a729 100644 (file)
@@ -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)
        {
index 6b6fc08..2e6fde9 100644 (file)
@@ -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;
     }
 }
index 02f6b29..1afa04c 100644 (file)
@@ -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:
index 13a3d23..08f6828 100644 (file)
@@ -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;
index 5258468..2bf5e5b 100644 (file)
@@ -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; i<cfg.preorder.count; i++)
+    for (i=0; i<dominance.preorder.count; i++)
     {
-        current_bb = cfg.preorder.item[i];
+        current_bb = dominance.preorder.item[i];
         select_instructions();
     }
 }
index a41dac4..d09d30c 100644 (file)
@@ -115,7 +115,7 @@ static void emit_procedure(struct procedure* proc)
     {
         struct basicblock* bb = dominance.preorder.item[i];
         
-        fprintf(outputfile, "%s:\n", bb->name);
+        fprintf(outputfile, "%s:\n", platform_label(bb->name));
         for (j=0; j<bb->hops.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<cfg.graph.count; i++)
     {
-        fprintf(cfg_dot_file, "\t%s -> %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<dominance.graph.count; i++)
     {
-        fprintf(dominance_dot_file, "\t%s -> %s;\n",
+        fprintf(dominance_dot_file, "\t\"%s\" -> \"%s\";\n",
             dominance.graph.item[i].right->name,
             dominance.graph.item[i].left->name);
     }