Refactor mcg.h as it's getting a bit big; keep track of register variables.
authorDavid Given <dg@cowlark.com>
Sat, 1 Oct 2016 22:30:33 +0000 (00:30 +0200)
committerDavid Given <dg@cowlark.com>
Sat, 1 Oct 2016 22:30:33 +0000 (00:30 +0200)
mach/proto/mcg/mcg.h
mach/proto/mcg/parse_em.c
mach/proto/mcg/procedure.h [new file with mode: 0644]
mach/proto/mcg/treebuilder.c

index 3db29b8..7856049 100644 (file)
 #include "em_flag.h"
 #include "em_ptyp.h"
 #include "array.h"
+#include "imap.h"
 #include "pmap.h"
 #include "diagnostics.h"
 #include "astring.h"
 #include "ir.h"
 #include "mcgg.h"
 #include "hop.h"
+#include "procedure.h"
 
 extern char em_pseu[][4];
 extern char em_mnem[][4];
@@ -71,14 +73,6 @@ struct em
     } u;
 };
     
-struct procedure
-{
-    const char* name;
-    struct basicblock* root_bb;
-    size_t nlocals;
-    ARRAYOF(struct basicblock) blocks;
-};
-
 struct basicblock
 {
     const char* name;
@@ -118,7 +112,7 @@ extern void bb_print(char k, struct basicblock* block);
 extern void tb_filestart(void);
 extern void tb_fileend(void);
 extern void tb_procedure(struct procedure* proc);
-extern void tb_regvar(arith offset, int size, int type, int priority);
+extern void tb_regvar(struct procedure* proc, arith offset, int size, int type, int priority);
 
 extern void pass_convert_stack_ops(struct procedure* proc);
 extern void pass_remove_dead_blocks(struct procedure* proc);
@@ -127,8 +121,6 @@ extern void pass_instruction_selector(struct procedure* proc);
 extern void pass_promote_float_ops(struct procedure* proc);
 extern void pass_group_irs(struct procedure* proc);
 
-extern void procedure_compile(struct procedure* proc);
-
 #endif
 
 /* vim: set sw=4 ts=4 expandtab : */
index 4508d59..12ea255 100644 (file)
@@ -338,7 +338,7 @@ static void parse_mes(void)
                 int size = mes_get_cst();
                 int type = mes_get_cst();
                 int priority = mes_get_cst();
-                tb_regvar(offset, size, type, priority);
+                tb_regvar(current_proc, offset, size, type, priority);
             }
             break;
         }
diff --git a/mach/proto/mcg/procedure.h b/mach/proto/mcg/procedure.h
new file mode 100644 (file)
index 0000000..de11c54
--- /dev/null
@@ -0,0 +1,22 @@
+#ifndef PROCEDURE_H
+#define PROCEDURE_H
+
+struct local
+{
+    bool is_register;
+};
+
+struct procedure
+{
+    const char* name;
+    struct basicblock* root_bb;
+    size_t nlocals;
+    ARRAYOF(struct basicblock) blocks;
+    IMAPOF(struct local) locals;
+};
+
+extern void procedure_compile(struct procedure* proc);
+
+#endif
+
+/* vim: set sw=4 ts=4 expandtab : */
index 8835c0b..f4c4814 100644 (file)
@@ -107,9 +107,12 @@ void tb_fileend(void)
 {
 }
 
-void tb_regvar(arith offset, int size, int type, int priority)
+void tb_regvar(struct procedure* procedure, arith offset, int size, int type, int priority)
 {
-    /* ignored */
+    struct local* local = calloc(1, sizeof(*local));
+    local->size = size;
+    local->is_register = true;
+    imap_put(&procedure->locals, offset, local);
 }
 
 static struct ir* address_of_external(const char* label, arith offset)