From 922b99fca915a6e58a6b48ce82262db8e46abf6d Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 20 Sep 2022 12:23:53 -0400 Subject: [PATCH] renamed type field --- cerise/backend/ssa/codegen.c | 18 +++++++++--------- cerise/inc/cerise.h | 3 ++- cerise/src/ssa.c | 27 ++++++++++++++------------- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/cerise/backend/ssa/codegen.c b/cerise/backend/ssa/codegen.c index 508f531..7173caa 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->arg_type->form == FORM_INT) + if (node->left_type->form == FORM_INT) { switch(node->code) { @@ -219,7 +219,7 @@ char* binop_name(SsaNode* node) default: assert(!"unknown"); break; } } - else if (node->arg_type->form == FORM_REAL) + else if (node->left_type->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->arg_type, value); + print_const(expr->left_type, value); } else { @@ -288,7 +288,7 @@ void print_op(Parser* p, SsaNode* expr) else if (expr->code == STORE) { printf(" store "); - emit_type(expr->arg_type); + emit_type(expr->left_type); print_operand(p, expr, expr->lconst, &(expr->left)); printf(", "); emit_type(expr->ret_type); @@ -301,15 +301,15 @@ void print_op(Parser* p, SsaNode* expr) printf(" "); print_ident(p, &(expr->dest)); printf(" = getelementptr "); - emit_type(expr->arg_type); + emit_type(expr->left_type); printf(", "); - emit_type(expr->arg_type); + emit_type(expr->left_type); printf("* "); print_ident(p, &(expr->left.var)); printf(", "); - emit_type(expr->arg_type->base); + emit_type(expr->left_type->base); printf(" 0, "); - emit_type(expr->arg_type->base); + emit_type(expr->left_type->base); printf(" "); print_operand(p, expr, expr->rconst, &(expr->right)); puts(""); @@ -365,7 +365,7 @@ void print_op(Parser* p, SsaNode* expr) printf(" "); print_ident(p, &(expr->dest)); printf(" = %s ", binop_name(expr)); - emit_type(expr->arg_type); + emit_type(expr->left_type); printf(" "); print_operand(p, expr, expr->lconst, &(expr->left)); printf(", "); diff --git a/cerise/inc/cerise.h b/cerise/inc/cerise.h index 41354c6..61353db 100644 --- a/cerise/inc/cerise.h +++ b/cerise/inc/cerise.h @@ -135,7 +135,8 @@ typedef struct SsaNode { unsigned int lconst : 1; unsigned int rconst : 1; Type* ret_type; - Type* arg_type; + Type* left_type; + Type* right_type; SsaVar dest; SsaValue left; SsaValue right; diff --git a/cerise/src/ssa.c b/cerise/src/ssa.c index 87b68f4..13689b8 100644 --- a/cerise/src/ssa.c +++ b/cerise/src/ssa.c @@ -119,7 +119,7 @@ static SsaNode* ssa_node(int code, int mode) node->code = code; node->mode = mode; node->dest.symid = 0; - node->dest.symver = 0; /* TODO: increment temp ver */ + node->dest.symver = 0; return node; } @@ -137,7 +137,8 @@ SsaNode* ssa_ident(Parser* p, long long index) { node = ssa_node(IDENT, MODE_VAR); node->ret_type = sym->type; - node->arg_type = sym->type; + node->left_type = sym->type; + node->right_type = sym->type; node->loaded = !sym->global; node->dest.symid = index; node->dest.symver = sym->version; @@ -152,7 +153,7 @@ SsaNode* ssa_bool(Parser* p, bool val) (void)p; SsaNode* node = ssa_node(BOOL, MODE_CONST); node->ret_type = &BoolType; - node->arg_type = &BoolType; + node->left_type = &BoolType; node->left.val.i = val; return node; } @@ -162,7 +163,7 @@ SsaNode* ssa_int(Parser* p, long long val) (void)p; SsaNode* node = ssa_node(INT, MODE_CONST); node->ret_type = &IntType; - node->arg_type = &IntType; + node->left_type = &IntType; node->left.val.i = val; return node; } @@ -172,7 +173,7 @@ SsaNode* ssa_real(Parser* p, double val) (void)p; SsaNode* node = ssa_node(REAL, MODE_CONST); node->ret_type = &RealType; - node->arg_type = &RealType; + node->left_type = &RealType; node->left.val.f = val; return node; } @@ -189,7 +190,7 @@ 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->arg_type = dest->ret_type; + node->left_type = dest->ret_type; node->dest = dest->left.var; if (value->mode == MODE_CONST) @@ -224,7 +225,7 @@ SsaNode* ssa_index(Parser* p, SsaNode* array, SsaNode* index) load(p, index); SsaNode* node = ssa_node('[', MODE_MEMORY); node->ret_type = array->ret_type->base; - node->arg_type = array->ret_type; + node->left_type = array->ret_type; node->left = array->left; // if (index->mode == MODE_CONST) @@ -266,7 +267,7 @@ 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->arg_type = &BoolType; + node->left_type = &BoolType; node->left.block = br1; node->right.block = br2; node = load(p, node); @@ -289,14 +290,14 @@ SsaNode* ssa_return(Parser* p, SsaNode* expr) load(p, expr); } node->ret_type = expr->ret_type; - node->arg_type = expr->ret_type; + node->left_type = expr->ret_type; node = load(p, node); node->dest = expr->dest; } else { node->ret_type = &VoidType; - node->arg_type = &VoidType; + node->left_type = &VoidType; node = load(p, node); } return node; @@ -348,7 +349,7 @@ static SsaNode* binop(Parser* p, int op, SsaNode* left, SsaNode* right) /* set the result type appropriately */ node->ret_type = left->ret_type; - node->arg_type = left->ret_type; + node->left_type = left->ret_type; /* comparison ops are handled specially */ switch (op) @@ -378,7 +379,7 @@ 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->arg_type = operand->ret_type; + node->left_type = operand->ret_type; node->left.var = operand->dest; } return node; @@ -483,7 +484,7 @@ static SsaNode* const_binop(int op, SsaNode* a, SsaNode* b) assert(!"not a left.valid form"); } - a->arg_type = a->ret_type; + a->left_type = a->ret_type; return a; } -- 2.49.0