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)
{
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));
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)
{
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)