From baa3b5067df77b75e27539bf9a5b7ad5ae15d610 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 20 Sep 2022 16:29:53 -0400 Subject: [PATCH] refactores SSA nodes. almost back to functional... --- cerise/backend/ssa/codegen.c | 62 +++++----- cerise/inc/cerise.h | 45 +++++-- cerise/src/grammar.c | 10 +- cerise/src/ssa.c | 223 ++++++++++++++--------------------- cerise/src/type_checks.c | 24 ++-- cerise/tests/Module.m | 30 ++--- 6 files changed, 186 insertions(+), 208 deletions(-) diff --git a/cerise/backend/ssa/codegen.c b/cerise/backend/ssa/codegen.c index 7173caa..4c58fef 100644 --- a/cerise/backend/ssa/codegen.c +++ b/cerise/backend/ssa/codegen.c @@ -199,7 +199,7 @@ static void print_const(Type* type, SsaValue* val) char* binop_name(SsaNode* node) { char* name = NULL; - if (node->left_type->form == FORM_INT) + if (SSA_LTYPE(node)->form == FORM_INT) { switch(node->code) { @@ -219,7 +219,7 @@ char* binop_name(SsaNode* node) default: assert(!"unknown"); break; } } - else if (node->left_type->form == FORM_REAL) + else if (SSA_LTYPE(node)->form == FORM_REAL) { switch(node->code) { @@ -252,7 +252,7 @@ void print_operand(Parser* p, SsaNode* expr, int is_const, SsaValue* value) { if (is_const) { - print_const(expr->left_type, value); + print_const(SSA_LTYPE(expr), value); } else { @@ -276,42 +276,42 @@ void print_op(Parser* p, SsaNode* expr) if (expr->code == LOAD) { printf(" "); - print_ident(p, &(expr->dest)); + print_ident(p, &(SSA_VAR(expr))); printf(" = load "); - emit_type(expr->ret_type); + emit_type(SSA_TYPE(expr)); printf(", "); - emit_type(expr->ret_type); + emit_type(SSA_TYPE(expr)); printf("* "); - print_ident(p, &(expr->left.var)); + print_ident(p, &(SSA_LVAR(expr))); puts(""); } else if (expr->code == STORE) { printf(" store "); - emit_type(expr->left_type); - print_operand(p, expr, expr->lconst, &(expr->left)); + emit_type(SSA_LTYPE(expr)); + print_operand(p, expr, SSA_LCONST(expr), &(expr->left->value)); printf(", "); - emit_type(expr->ret_type); + emit_type(SSA_TYPE(expr)); printf("* "); - print_ident(p, &(expr->dest)); + print_ident(p, &(SSA_VAR(expr))); puts(""); } else if (expr->code == '[') { printf(" "); - print_ident(p, &(expr->dest)); + print_ident(p, &(SSA_VAR(expr))); printf(" = getelementptr "); - emit_type(expr->left_type); + emit_type(SSA_LTYPE(expr)); printf(", "); - emit_type(expr->left_type); + emit_type(SSA_LTYPE(expr)); printf("* "); - print_ident(p, &(expr->left.var)); + print_ident(p, &(SSA_LVAR(expr))); printf(", "); - emit_type(expr->left_type->base); + emit_type(SSA_LTYPE(expr)->base); printf(" 0, "); - emit_type(expr->left_type->base); + emit_type(SSA_LTYPE(expr)->base); printf(" "); - print_operand(p, expr, expr->rconst, &(expr->right)); + print_operand(p, expr, SSA_RCONST(expr), &(expr->right->value)); puts(""); } else @@ -325,17 +325,17 @@ void print_op(Parser* p, SsaNode* expr) if (expr->code == RETURN) { printf(" ret "); - emit_type(expr->ret_type); - if (expr->ret_type->form != FORM_VOID) + emit_type(SSA_TYPE(expr)); + if (SSA_TYPE(expr)->form != FORM_VOID) { printf(" "); if (expr->mode == MODE_CTRL) { - print_ident(p, &(expr->dest)); + print_ident(p, &(SSA_VAR(expr))); } else { - print_const(expr->ret_type, &(expr->left)); + print_const(SSA_TYPE(expr), &(expr->value)); } } puts(""); @@ -343,33 +343,33 @@ void print_op(Parser* p, SsaNode* expr) else if (expr->code == IF) { printf(" br %%Bool "); - print_ident(p, &(expr->dest)); + print_ident(p, &(SSA_VAR(expr))); printf(", label %%L%ld, label %%L%ld\n", - expr->left.block->id, - expr->right.block->id + SSA_LBLK(expr)->id, + SSA_RBLK(expr)->id ); } else if (expr->code == BRANCH) { - printf(" br label %%L%ld\n", expr->left.block->id); + printf(" br label %%L%ld\n", SSA_LBLK(expr)->id); } break; case MODE_UNOP: printf(" "); - print_ident(p, &(expr->dest)); + print_ident(p, &(SSA_VAR(expr))); printf(" = \n"); break; case MODE_BINOP: printf(" "); - print_ident(p, &(expr->dest)); + print_ident(p, &(SSA_VAR(expr))); printf(" = %s ", binop_name(expr)); - emit_type(expr->left_type); + emit_type(SSA_LTYPE(expr)); printf(" "); - print_operand(p, expr, expr->lconst, &(expr->left)); + print_operand(p, expr, SSA_LCONST(expr), &(expr->left->value)); printf(", "); - print_operand(p, expr, expr->rconst, &(expr->right)); + print_operand(p, expr, SSA_RCONST(expr), &(expr->right->value)); printf("\n"); break; diff --git a/cerise/inc/cerise.h b/cerise/inc/cerise.h index 61353db..797146d 100644 --- a/cerise/inc/cerise.h +++ b/cerise/inc/cerise.h @@ -127,21 +127,50 @@ typedef union { struct SsaBlock* block; } SsaValue; +//typedef struct SsaNode { +// struct SsaNode* next; +// unsigned int code : 25; +// unsigned int mode : 4; +// unsigned int loaded : 1; +// unsigned int lconst : 1; +// unsigned int rconst : 1; +// Type* ret_type; +// Type* left_type; +// Type* right_type; +// SsaVar dest; +// SsaValue left; +// SsaValue right; +//} SsaNode; + typedef struct SsaNode { struct SsaNode* next; unsigned int code : 25; unsigned int mode : 4; unsigned int loaded : 1; - unsigned int lconst : 1; - unsigned int rconst : 1; - Type* ret_type; - Type* left_type; - Type* right_type; - SsaVar dest; - SsaValue left; - SsaValue right; + Type* type; + SsaValue value; + struct SsaNode* left; + struct SsaNode* right; } SsaNode; +#define SSA_TYPE(a) ((a)->type) +#define SSA_LTYPE(a) ((a)->left->type) +#define SSA_RTYPE(a) ((a)->right->type) + +#define SSA_VAL(a) ((a)->value.val) +#define SSA_LVAL(a) ((a)->left->value.val) +#define SSA_RVAL(a) ((a)->right->value.val) + +#define SSA_VAR(a) ((a)->value.var) +#define SSA_LVAR(a) ((a)->left->value.var) +#define SSA_RVAR(a) ((a)->right->value.var) + +#define SSA_LBLK(a) ((a)->left->value.block) +#define SSA_RBLK(a) ((a)->right->value.block) + +#define SSA_LCONST(a) ((a)->left->mode == MODE_CONST) +#define SSA_RCONST(a) ((a)->right->mode == MODE_CONST) + typedef struct SsaPhiVar { struct SsaPhiVar* next; size_t block; diff --git a/cerise/src/grammar.c b/cerise/src/grammar.c index e646d30..cf680eb 100644 --- a/cerise/src/grammar.c +++ b/cerise/src/grammar.c @@ -92,7 +92,7 @@ static SsaNode* designator(Parser* p) case '.': { expect(p, '.'); - if (expr->ret_type->form != FORM_RECORD) + if (expr->type->form != FORM_RECORD) { error(p, "attempting to access field of non-array object"); } @@ -104,7 +104,7 @@ static SsaNode* designator(Parser* p) case '[': { expect(p, '['); - if (expr->ret_type->form != FORM_ARRAY) + if (expr->type->form != FORM_ARRAY) { error(p, "attempting to index non-array value"); } @@ -431,8 +431,8 @@ static SsaBlock* statement_seq(Parser* p) block->links[1] = p->curr_join; } - if_node->left.block = block->links[0]; - if_node->right.block = block->links[1]; + SSA_LBLK(if_node) = block->links[0]; + SSA_RBLK(if_node) = block->links[1]; ssa_join(p); expect(p, END); @@ -515,7 +515,7 @@ static void const_decl(Parser* p) sym = symbol_new(p, 0, name, SYM_CONST, export); expect(p, '='); sym->value = expression(p); - sym->type = sym->value->ret_type; + sym->type = sym->value->type; if (sym->value->mode != MODE_CONST) { error(p, "constant defined with non-constant expression"); diff --git a/cerise/src/ssa.c b/cerise/src/ssa.c index 13689b8..53f497a 100644 --- a/cerise/src/ssa.c +++ b/cerise/src/ssa.c @@ -10,19 +10,19 @@ static SsaNode* load(Parser* p, SsaNode* node); bool ssa_asbool(SsaNode* node) { assert(node->code == BOOL); - return (bool)(node->left.val.i); + return (bool)(SSA_VAL(node).i); } long long ssa_asint(SsaNode* node) { assert(node->code == INT); - return (node->left.val.i); + return (SSA_VAL(node).i); } double ssa_asreal(SsaNode* node) { assert(node->code == REAL); - return (node->left.val.f); + return (SSA_VAL(node).f); } /* @@ -118,8 +118,8 @@ static SsaNode* ssa_node(int code, int mode) SsaNode* node = calloc(1, sizeof(SsaNode)); node->code = code; node->mode = mode; - node->dest.symid = 0; - node->dest.symver = 0; + SSA_VAR(node).symid = 0; + SSA_VAR(node).symver = 0; return node; } @@ -136,14 +136,10 @@ SsaNode* ssa_ident(Parser* p, long long index) else { node = ssa_node(IDENT, MODE_VAR); - node->ret_type = sym->type; - node->left_type = sym->type; - node->right_type = sym->type; + node->type = sym->type; node->loaded = !sym->global; - node->dest.symid = index; - node->dest.symver = sym->version; - node->left.var.symid = index; - node->left.var.symver = sym->version; + SSA_VAR(node).symid = index; + SSA_VAR(node).symver = sym->version; } return node; } @@ -152,9 +148,8 @@ SsaNode* ssa_bool(Parser* p, bool val) { (void)p; SsaNode* node = ssa_node(BOOL, MODE_CONST); - node->ret_type = &BoolType; - node->left_type = &BoolType; - node->left.val.i = val; + node->type = &BoolType; + SSA_VAL(node).i = val; return node; } @@ -162,9 +157,8 @@ SsaNode* ssa_int(Parser* p, long long val) { (void)p; SsaNode* node = ssa_node(INT, MODE_CONST); - node->ret_type = &IntType; - node->left_type = &IntType; - node->left.val.i = val; + node->type = &IntType; + SSA_VAL(node).i = val; return node; } @@ -172,9 +166,8 @@ SsaNode* ssa_real(Parser* p, double val) { (void)p; SsaNode* node = ssa_node(REAL, MODE_CONST); - node->ret_type = &RealType; - node->left_type = &RealType; - node->left.val.f = val; + node->type = &RealType; + SSA_VAL(node).f = val; return node; } @@ -189,23 +182,13 @@ SsaNode* ssa_store(Parser* p, SsaNode* dest, SsaNode* value) { load(p, value); SsaNode* node = ssa_node(STORE, MODE_MEMORY); - node->ret_type = dest->ret_type; - node->left_type = dest->ret_type; - node->dest = dest->left.var; + node->type = dest->type; + node->left = value; + SSA_VAR(node) = SSA_VAR(dest); - if (value->mode == MODE_CONST) + if (!symbol_getbyid(p, SSA_VAR(node).symid)->global) { - node->lconst = 1; - node->left = value->left; - } - else - { - node->left.var = value->dest; - } - - if (!symbol_getbyid(p, node->dest.symid)->global) - { - node->dest.symver = phi_add(p, node->dest); + SSA_VAR(node).symver = phi_add(p, SSA_VAR(node)); } ssa_block_add(p->curr_block, node); node->loaded = 1; @@ -221,23 +204,11 @@ SsaNode* ssa_fieldref(Parser* p, SsaNode* record, char* fname) SsaNode* ssa_index(Parser* p, SsaNode* array, SsaNode* index) { -// load(p, array); load(p, index); SsaNode* node = ssa_node('[', MODE_MEMORY); - node->ret_type = array->ret_type->base; - node->left_type = array->ret_type; - node->left = array->left; - -// if (index->mode == MODE_CONST) -// { -// node->rconst = 1; -// node->right = index->left; -// } -// else - { - node->right.var = index->dest; - } - + node->type = array->type->base; + node->left = array; + node->right = index; return node; } @@ -266,12 +237,11 @@ SsaNode* ssa_if(Parser* p, SsaNode* cond, SsaBlock* br1, SsaBlock* br2) { cond = load(p, cond); SsaNode* node = ssa_node(IF, MODE_CTRL); - node->ret_type = &VoidType; - node->left_type = &BoolType; - node->left.block = br1; - node->right.block = br2; + node->left = cond; + SSA_LBLK(node) = br1; + SSA_RBLK(node) = br2; node = load(p, node); - node->dest = cond->dest; + SSA_VAR(node) = SSA_VAR(cond); // TODO: unnecessary? return node; } @@ -289,15 +259,13 @@ SsaNode* ssa_return(Parser* p, SsaNode* expr) { load(p, expr); } - node->ret_type = expr->ret_type; - node->left_type = expr->ret_type; + node->type = expr->type; node = load(p, node); - node->dest = expr->dest; + SSA_VAR(node) = SSA_VAR(expr); } else { - node->ret_type = &VoidType; - node->left_type = &VoidType; + node->type = &VoidType; node = load(p, node); } return node; @@ -306,7 +274,7 @@ SsaNode* ssa_return(Parser* p, SsaNode* expr) SsaNode* ssa_branch(Parser* p, SsaBlock* br) { SsaNode* node = ssa_node(BRANCH, MODE_CTRL); - node->left.block = br; + SSA_LBLK(node) = br; ssa_block_add(p->curr_block, node); node->loaded = 1; return node; @@ -328,28 +296,11 @@ static SsaNode* binop(Parser* p, int op, SsaNode* left, SsaNode* right) left = load(p, left); right = load(p, right); node = ssa_node(op, MODE_BINOP); - - if (left->mode == MODE_CONST) - { - node->lconst = 1; - node->left = left->left; - node->right.var = right->dest; - } - else if (right->mode == MODE_CONST) - { - node->rconst = 1; - node->left.var = left->dest; - node->right = right->left; - } - else - { - node->left.var = left->dest; - node->right.var = right->dest; - } + node->left = load(p, left); + node->right = load(p, right); /* set the result type appropriately */ - node->ret_type = left->ret_type; - node->left_type = left->ret_type; + node->type = left->type; /* comparison ops are handled specially */ switch (op) @@ -360,7 +311,7 @@ static SsaNode* binop(Parser* p, int op, SsaNode* left, SsaNode* right) case LTEQ: case '>': case GTEQ: - node->ret_type = &BoolType; + node->type = &BoolType; break; } } @@ -378,56 +329,55 @@ static SsaNode* unop(Parser* p, int op, SsaNode* operand) { operand = load(p, operand); node = ssa_node(op, MODE_UNOP); - node->ret_type = operand->ret_type; - node->left_type = operand->ret_type; - node->left.var = operand->dest; + node->type = operand->type; + node->left = operand; } return node; } static SsaNode* const_binop(int op, SsaNode* a, SsaNode* b) { - if (a->ret_type->form == FORM_INT || a->ret_type->form == FORM_BOOL) + if (a->type->form == FORM_INT || a->type->form == FORM_BOOL) { switch (op) { - case '+': a->left.val.i = a->left.val.i + b->left.val.i; break; - case '-': a->left.val.i = a->left.val.i - b->left.val.i; break; - case '*': a->left.val.i = a->left.val.i * b->left.val.i; break; - case '/': a->left.val.i = a->left.val.i / b->left.val.i; break; - case '%': a->left.val.i = a->left.val.i % b->left.val.i; break; - case AND: a->left.val.i = a->left.val.i && b->left.val.i; break; - case OR: a->left.val.i = a->left.val.i || b->left.val.i; break; + case '+': SSA_LVAL(a).i = SSA_LVAL(a).i + SSA_LVAL(b).i; break; + case '-': SSA_LVAL(a).i = SSA_LVAL(a).i - SSA_LVAL(b).i; break; + case '*': SSA_LVAL(a).i = SSA_LVAL(a).i * SSA_LVAL(b).i; break; + case '/': SSA_LVAL(a).i = SSA_LVAL(a).i / SSA_LVAL(b).i; break; + case '%': SSA_LVAL(a).i = SSA_LVAL(a).i % SSA_LVAL(b).i; break; + case AND: SSA_LVAL(a).i = SSA_LVAL(a).i && SSA_LVAL(b).i; break; + case OR: SSA_LVAL(a).i = SSA_LVAL(a).i || SSA_LVAL(b).i; break; case EQ: puts("EQ"); - a->left.val.i = a->left.val.i == b->left.val.i; - a->ret_type = &BoolType; + SSA_LVAL(a).i = SSA_LVAL(a).i == SSA_LVAL(b).i; + a->type = &BoolType; break; case NEQ: - a->left.val.i = a->left.val.i != b->left.val.i; - a->ret_type = &BoolType; + SSA_LVAL(a).i = SSA_LVAL(a).i != SSA_LVAL(b).i; + a->type = &BoolType; break; case '<': - a->left.val.i = a->left.val.i < b->left.val.i; - a->ret_type = &BoolType; + SSA_LVAL(a).i = SSA_LVAL(a).i < SSA_LVAL(b).i; + a->type = &BoolType; break; case LTEQ: - a->left.val.i = a->left.val.i <= b->left.val.i; - a->ret_type = &BoolType; + SSA_LVAL(a).i = SSA_LVAL(a).i <= SSA_LVAL(b).i; + a->type = &BoolType; break; case '>': - a->left.val.i = a->left.val.i > b->left.val.i; - a->ret_type = &BoolType; + SSA_LVAL(a).i = SSA_LVAL(a).i > SSA_LVAL(b).i; + a->type = &BoolType; break; case GTEQ: - a->left.val.i = a->left.val.i >= b->left.val.i; - a->ret_type = &BoolType; + SSA_LVAL(a).i = SSA_LVAL(a).i >= SSA_LVAL(b).i; + a->type = &BoolType; break; default: @@ -435,43 +385,43 @@ static SsaNode* const_binop(int op, SsaNode* a, SsaNode* b) break; } } - else if (a->ret_type->form == FORM_REAL) + else if (a->type->form == FORM_REAL) { switch (op) { - case '+': a->left.val.f = a->left.val.f + b->left.val.f; break; - case '-': a->left.val.f = a->left.val.f - b->left.val.f; break; - case '*': a->left.val.f = a->left.val.f * b->left.val.f; break; - case '/': a->left.val.f = a->left.val.f / b->left.val.f; break; + case '+': SSA_LVAL(a).f = SSA_LVAL(a).f + SSA_LVAL(b).f; break; + case '-': SSA_LVAL(a).f = SSA_LVAL(a).f - SSA_LVAL(b).f; break; + case '*': SSA_LVAL(a).f = SSA_LVAL(a).f * SSA_LVAL(b).f; break; + case '/': SSA_LVAL(a).f = SSA_LVAL(a).f / SSA_LVAL(b).f; break; case EQ: - a->left.val.f = a->left.val.f == b->left.val.f; - a->ret_type = &BoolType; + SSA_LVAL(a).f = SSA_LVAL(a).f == SSA_LVAL(b).f; + a->type = &BoolType; break; case NEQ: - a->left.val.f = a->left.val.f != b->left.val.f; - a->ret_type = &BoolType; + SSA_LVAL(a).f = SSA_LVAL(a).f != SSA_LVAL(b).f; + a->type = &BoolType; break; case '<': - a->left.val.f = a->left.val.f < b->left.val.f; - a->ret_type = &BoolType; + SSA_LVAL(a).f = SSA_LVAL(a).f < SSA_LVAL(b).f; + a->type = &BoolType; break; case LTEQ: - a->left.val.f = a->left.val.f <= b->left.val.f; - a->ret_type = &BoolType; + SSA_LVAL(a).f = SSA_LVAL(a).f <= SSA_LVAL(b).f; + a->type = &BoolType; break; case '>': - a->left.val.f = a->left.val.f > b->left.val.f; - a->ret_type = &BoolType; + SSA_LVAL(a).f = SSA_LVAL(a).f > SSA_LVAL(b).f; + a->type = &BoolType; break; case GTEQ: - a->left.val.f = a->left.val.f >= b->left.val.f; - a->ret_type = &BoolType; + SSA_LVAL(a).f = SSA_LVAL(a).f >= SSA_LVAL(b).f; + a->type = &BoolType; break; default: @@ -483,36 +433,34 @@ static SsaNode* const_binop(int op, SsaNode* a, SsaNode* b) { assert(!"not a left.valid form"); } - - a->left_type = a->ret_type; return a; } static SsaNode* const_unop(int op, SsaNode* a) { - if (a->ret_type->form == FORM_INT) + if (a->type->form == FORM_INT) { switch (op) { - case '+': a->left.val.i = +a->left.val.i; break; - case '-': a->left.val.i = -a->left.val.i; break; + case '+': SSA_LVAL(a).i = +SSA_LVAL(a).i; break; + case '-': SSA_LVAL(a).i = -SSA_LVAL(a).i; break; default: assert(!"not a valid op"); break; } } - else if (a->ret_type->form == FORM_REAL) + else if (a->type->form == FORM_REAL) { switch (op) { - case '+': a->left.val.f = +a->left.val.f; break; - case '-': a->left.val.f = -a->left.val.f; break; + case '+': SSA_LVAL(a).f = +SSA_LVAL(a).f; break; + case '-': SSA_LVAL(a).f = -SSA_LVAL(a).f; break; default: assert(!"not a valid op"); break; } } - else if (a->ret_type->form == FORM_BOOL) + else if (a->type->form == FORM_BOOL) { switch (op) { - case NOT: a->left.val.i = !a->left.val.i; break; + case NOT: SSA_LVAL(a).i = !SSA_LVAL(a).i; break; default: assert(!"not a valid op"); break; } } @@ -535,17 +483,18 @@ static SsaNode* load(Parser* p, SsaNode* node) // else if (node->mode == MODE_VAR) { - node->left.var = node->dest; - node->dest.symid = 0; + node->left = ssa_ident(p, 0); + SSA_LVAR(node) = SSA_VAR(node); + SSA_VAR(node).symid = 0; node->mode = MODE_MEMORY; node->code = LOAD; } - if (node->dest.symid == 0) + if (SSA_VAR(node).symid == 0) { Symbol* sym = symbol_getbyid(p, 0); sym->version++; - node->dest.symver = sym->version; + SSA_VAR(node).symver = sym->version; } ssa_block_add(p->curr_block, node); node->loaded = 1; diff --git a/cerise/src/type_checks.c b/cerise/src/type_checks.c index 8abc5fc..603ab82 100644 --- a/cerise/src/type_checks.c +++ b/cerise/src/type_checks.c @@ -2,7 +2,7 @@ void check_int(Parser* p, SsaNode* a) { - if (a->ret_type->form != FORM_INT) + if (a->type->form != FORM_INT) { error(p, "not an int"); } @@ -16,7 +16,7 @@ void check_ints(Parser* p, SsaNode* a, SsaNode* b) void check_real(Parser* p, SsaNode* a) { - if (a->ret_type->form != FORM_REAL) + if (a->type->form != FORM_REAL) { error(p, "not a real"); } @@ -30,11 +30,11 @@ void check_reals(Parser* p, SsaNode* a, SsaNode* b) void check_num(Parser* p, SsaNode* a) { - if (a->ret_type->form == FORM_REAL) + if (a->type->form == FORM_REAL) { check_real(p, a); } - else if (a->ret_type->form == FORM_INT) + else if (a->type->form == FORM_INT) { check_int(p, a); } @@ -46,7 +46,7 @@ void check_num(Parser* p, SsaNode* a) void check_nums(Parser* p, SsaNode* a, SsaNode* b) { - if (a->ret_type->form == FORM_REAL) + if (a->type->form == FORM_REAL) { check_reals(p, a, b); } @@ -58,7 +58,7 @@ void check_nums(Parser* p, SsaNode* a, SsaNode* b) void check_bool(Parser* p, SsaNode* a) { - if (a->ret_type->form != FORM_BOOL) + if (a->type->form != FORM_BOOL) { error(p, "not an bool"); } @@ -84,7 +84,7 @@ void check_type(Parser* p, Type* type, SsaNode* a) { check_bool(p, a); } -// else if (a->ret_type->form == FORM_ARRAY) +// else if (a->type->form == FORM_ARRAY) // { // } else @@ -95,20 +95,20 @@ void check_type(Parser* p, Type* type, SsaNode* a) void check_types(Parser* p, SsaNode* a, SsaNode* b) { -// printf("%d %d\n", a->ret_type->form, b->ret_type->form); - if (a->ret_type->form == FORM_REAL) +// printf("%d %d\n", a->type->form, b->type->form); + if (a->type->form == FORM_REAL) { check_reals(p, a, b); } - else if (a->ret_type->form == FORM_INT) + else if (a->type->form == FORM_INT) { check_ints(p, a, b); } - else if (a->ret_type->form == FORM_BOOL) + else if (a->type->form == FORM_BOOL) { check_bools(p, a, b); } -// else if (a->ret_type->form == FORM_ARRAY) +// else if (a->type->form == FORM_ARRAY) // { // } else diff --git a/cerise/tests/Module.m b/cerise/tests/Module.m index 3f9054d..b97a6da 100644 --- a/cerise/tests/Module.m +++ b/cerise/tests/Module.m @@ -132,24 +132,24 @@ var # 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 TestIfStatements() begin - vIntArray[0] = vIntArray[1] + vIntArray[2]; + if vInt == 1 then + vInt = 42; + end + + if vInt == 1 then + vInt = 42; + else + vInt = 24; + end end +#procedure TestArrayAccess() +#begin +# vIntArray[0] = vIntArray[1] + vIntArray[2]; +#end + #procedure TestRecordAccess() #begin #end -- 2.49.0