]> git.mdlowis.com Git - proto/obnc.git/commitdiff
attempted to flesh out ssa backend. Considering scrapping it and moving to a tree...
authormike lowis <mike@mdlowis.com>
Thu, 10 Jun 2021 11:44:50 +0000 (07:44 -0400)
committermike lowis <mike@mdlowis.com>
Thu, 10 Jun 2021 11:44:50 +0000 (07:44 -0400)
cerise/backend/ssa/codegen.c
cerise/tests/Module.m

index 7d67b17a027294ba8a53b24f18c1a55ddba19726..1ddc6db8e18ebe5138282a07d7233b83d1699fff 100644 (file)
@@ -26,6 +26,11 @@ Type StringType = {
 static size_t MaxBlocks = 0;
 static size_t NumBlocks = 0;
 static Block* Blocks = NULL;
+static size_t Level = 0;
+static struct {
+    size_t curr;
+    size_t join;
+} Levels[32] = {0};
 
 static size_t block_new(void)
 {
@@ -39,10 +44,9 @@ static size_t block_new(void)
     return (NumBlocks-1);
 }
 
-static void put_op(size_t blkid, Operation* op)
+static void put_op(Operation* op)
 {
-    assert(blkid < NumBlocks);
-    Block* block = &Blocks[blkid];
+    Block* block = &Blocks[Levels[Level].curr];
     if (block->nops == block->mops)
     {
         block->mops = (block->mops ? 4u : (block->mops << 1u));
@@ -51,6 +55,52 @@ static void put_op(size_t blkid, Operation* op)
     block->ops[block->nops++] = *op;
 }
 
+static void load_var(Parser* p, Item* item)
+{
+    if (!item->reg)
+    {
+        switch (item->mode)
+        {
+            case ITEM_CONST:
+                /* TODO: range check the constant */
+                item->reg = p->curr_reg++;
+                printf("    $%d = %lld;\n", item->reg, item->imm.i);
+                break;
+
+//            case ITEM_VAR:
+//                item->reg = declare_temp(p, item->type, isref);
+//                if (item->type->form == FORM_RECORD)
+//                {
+//                    printf(" = (Byte*)&%s[0];\n", item->imm.s);
+//                }
+//                else
+//                {
+//                    printf(" = %c%s;\n", (isref ? '&' : ' '), item->imm.s);
+//                }
+//                item->imm.i = 0;
+//                break;
+//
+//            case ITEM_MVAR:
+//                item->reg = declare_temp(p, item->type, isref);
+//                if (item->type->form == FORM_RECORD)
+//                {
+//                    printf(" = &%s_%s[0];\n", p->name, item->imm.s);
+//                }
+//                else
+//                {
+//                    printf(" = %c%s_%s;\n", (isref ? '&' : ' '), p->name, item->imm.s);
+//                }
+//                item->imm.i = 0;
+//                break;
+
+            default:
+                assert(!"bad load_var()");
+        }
+    }
+}
+
+
+
 
 void codegen_startmod(Parser* p)
 {
@@ -127,6 +177,7 @@ void codegen_binop(Parser* p, int op, Item* a, Item* b)
 void codegen_store(Parser* p, Item* a, Item* b)
 {
     (void)p, (void)a, (void)b;
+    load_var(p, b);
 }
 
 void codegen_if(Parser* p, Item* item)
index 723c8183769f9071bcb4b2cfba2f441adc0ae733..e0679860d29dd919aa9525074c293086e8c76c73 100644 (file)
@@ -136,5 +136,6 @@ begin
 #    c = Bar(42);
 
     c = 42;
+    c = 24;
 
 end