From: Michael D. Lowis Date: Wed, 21 Sep 2022 18:18:22 +0000 (-0400) Subject: flat array indexing is functioning. nested arrays are broken. this is...progress X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=73af153d5307ef693ca87231261139b8b04f88ca;p=proto%2Fobnc.git flat array indexing is functioning. nested arrays are broken. this is...progress --- diff --git a/cerise/src/ssa.c b/cerise/src/ssa.c index 50eaa95..b9cbec4 100644 --- a/cerise/src/ssa.c +++ b/cerise/src/ssa.c @@ -6,6 +6,7 @@ static SsaNode* unop(Parser* p, int op, SsaNode* operand); static SsaNode* const_binop(int op, SsaNode* left, SsaNode* right); static SsaNode* const_unop(int op, SsaNode* operand); static SsaNode* load(Parser* p, SsaNode* node); +static SsaNode* loadmem(Parser* p, SsaNode* node); bool ssa_asbool(SsaNode* node) { @@ -180,7 +181,12 @@ SsaNode* ssa_op(Parser* p, int op, SsaNode* left, SsaNode* right) SsaNode* ssa_store(Parser* p, SsaNode* dest, SsaNode* value) { - load(p, value); + value = load(p, value); + if (dest->mode == MODE_MEMORY && dest->code == '[') + { + dest = load(p, dest); + } + SsaNode* node = ssa_node(STORE, MODE_MEMORY); node->type = dest->type; node->left = value; @@ -188,7 +194,8 @@ SsaNode* ssa_store(Parser* p, SsaNode* dest, SsaNode* value) if (!symbol_getbyid(p, SSA_VAR(node).symid)->global) { - SSA_VAR(node).symver = phi_add(p, SSA_VAR(node)); +// SSA_VAR(node).symver = phi_add(p, SSA_VAR(node)); + (void)phi_add(p, SSA_VAR(node)); } ssa_block_add(p->curr_block, node); node->loaded = 1; @@ -204,7 +211,8 @@ SsaNode* ssa_fieldref(Parser* p, SsaNode* record, char* fname) SsaNode* ssa_index(Parser* p, SsaNode* array, SsaNode* index) { - load(p, index); +// array = load(p, array); + index = load(p, index); SsaNode* node = ssa_node('[', MODE_MEMORY); node->type = array->type->base; node->left = array; @@ -299,8 +307,8 @@ static SsaNode* binop(Parser* p, int op, SsaNode* left, SsaNode* right) } else { - left = load(p, left); - right = load(p, right); + left = loadmem(p, left); + right = loadmem(p, right); node = ssa_node(op, MODE_BINOP); node->left = load(p, left); node->right = load(p, right); @@ -482,11 +490,6 @@ static SsaNode* load(Parser* p, SsaNode* node) { if (!node->loaded && (node->mode != MODE_CONST)) { -// if (node->mode == MODE_MEMORY && node->code == '[') -// { -//// puts ("array!"); -// } -// else if (node->mode == MODE_VAR) { node->left = ssa_ident(p, 0); @@ -507,3 +510,16 @@ static SsaNode* load(Parser* p, SsaNode* node) } return node; } + +static SsaNode* loadmem(Parser* p, SsaNode* node) +{ + node = load(p, node); + if (node->mode == MODE_MEMORY && node->code == '[') + { + SsaNode* load_op = ssa_node(LOAD, MODE_MEMORY); + load_op->left = node; + load_op->type = node->type; + node = load(p, load_op); + } + return node; +} diff --git a/cerise/tests/Module.m b/cerise/tests/Module.m index 431fba0..322000b 100644 --- a/cerise/tests/Module.m +++ b/cerise/tests/Module.m @@ -5,6 +5,7 @@ var vInt* : Int vReal : Real vIntArray : array 42 of Int + vIntArray2 : array 5 of array 5 of Int procedure TestReturnVoid() begin @@ -54,102 +55,107 @@ begin vInt = 1 % vInt; vInt = vInt % vInt; end -# -#procedure TestIntCompOps() -#begin -# vBool = vInt == 1; -# vBool = 1 == vInt; -# vBool = vInt == vInt; -# -# vBool = vInt != 1; -# vBool = 1 != vInt; -# vBool = vInt != vInt; -# -# vBool = vInt < 1; -# vBool = 1 < vInt; -# vBool = vInt < vInt; -# -# vBool = vInt > 1; -# vBool = 1 > vInt; -# vBool = vInt > vInt; -# -# vBool = vInt <= 1; -# vBool = 1 <= vInt; -# vBool = vInt <= vInt; -# -# vBool = vInt >= 1; -# vBool = 1 >= vInt; -# vBool = vInt >= vInt; -#end -# -#procedure TestRealArithOps() -#begin -# vReal = vReal + 1.0; -# vReal = 1.0 + vReal; -# vReal = vReal + vReal; -# -# vReal = vReal - 1.0; -# vReal = 1.0 - vReal; -# vReal = vReal - vReal; -# -# vReal = vReal * 1.0; -# vReal = 1.0 * vReal; -# vReal = vReal * vReal; -# -# vReal = vReal / 1.0; -# vReal = 1.0 / vReal; -# vReal = vReal / vReal; -# -# vReal = vReal % 1.0; -# vReal = 1.0 % vReal; -# vReal = vReal % vReal; -#end -# -#procedure TestRealCompOps() -#begin -# vBool = vReal == 1.0; -# vBool = 1.0 == vReal; -# vBool = vReal == vReal; -# -# vBool = vReal != 1.0; -# vBool = 1.0 != vReal; -# vBool = vReal != vReal; -# -# vBool = vReal < 1.0; -# vBool = 1.0 < vReal; -# vBool = vReal < vReal; -# -# vBool = vReal > 1.0; -# vBool = 1.0 > vReal; -# vBool = vReal > vReal; -# -# vBool = vReal <= 1.0; -# vBool = 1.0 <= vReal; -# vBool = vReal <= vReal; -# -# vBool = vReal >= 1.0; -# vBool = 1.0 >= vReal; -# vBool = vReal >= vReal; -#end -# -#procedure TestIfStatements() -#begin -# if vInt == 1 then -# vInt = 42; -# end -# -# if vInt == 1 then -# vInt = 42; -# else -# vInt = 24; -# end -#end -procedure TestArrayAccess() +procedure TestIntCompOps() +begin + vBool = vInt == 1; + vBool = 1 == vInt; + vBool = vInt == vInt; + + vBool = vInt != 1; + vBool = 1 != vInt; + vBool = vInt != vInt; + + vBool = vInt < 1; + vBool = 1 < vInt; + vBool = vInt < vInt; + + vBool = vInt > 1; + vBool = 1 > vInt; + vBool = vInt > vInt; + + vBool = vInt <= 1; + vBool = 1 <= vInt; + vBool = vInt <= vInt; + + vBool = vInt >= 1; + vBool = 1 >= vInt; + vBool = vInt >= vInt; +end + +procedure TestRealArithOps() +begin + vReal = vReal + 1.0; + vReal = 1.0 + vReal; + vReal = vReal + vReal; + + vReal = vReal - 1.0; + vReal = 1.0 - vReal; + vReal = vReal - vReal; + + vReal = vReal * 1.0; + vReal = 1.0 * vReal; + vReal = vReal * vReal; + + vReal = vReal / 1.0; + vReal = 1.0 / vReal; + vReal = vReal / vReal; + + vReal = vReal % 1.0; + vReal = 1.0 % vReal; + vReal = vReal % vReal; +end + +procedure TestRealCompOps() +begin + vBool = vReal == 1.0; + vBool = 1.0 == vReal; + vBool = vReal == vReal; + + vBool = vReal != 1.0; + vBool = 1.0 != vReal; + vBool = vReal != vReal; + + vBool = vReal < 1.0; + vBool = 1.0 < vReal; + vBool = vReal < vReal; + + vBool = vReal > 1.0; + vBool = 1.0 > vReal; + vBool = vReal > vReal; + + vBool = vReal <= 1.0; + vBool = 1.0 <= vReal; + vBool = vReal <= vReal; + + vBool = vReal >= 1.0; + vBool = 1.0 >= vReal; + vBool = vReal >= vReal; +end + +procedure TestIfStatements() +begin + if vInt == 1 then + vInt = 42; + end + + if vInt == 1 then + vInt = 42; + else + vInt = 24; + end +end + +procedure TestFlatArrayAccess() begin vIntArray[0] = vIntArray[1] + vIntArray[2]; end +procedure TestNestedArrayAccess() +begin + vIntArray2[0][1] = vIntArray2[1][1] + vIntArray2[2][1]; +end + #procedure TestRecordAccess() #begin #end