From: Michael D. Lowis Date: Wed, 2 Mar 2022 22:08:31 +0000 (-0500) Subject: more implementation of binary operations X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=f67be4f18764b1825b25025ac58cb4d539798739;p=proto%2Fobnc.git more implementation of binary operations --- diff --git a/cerise/backend/ssa/codegen.c b/cerise/backend/ssa/codegen.c index 24ee686..0a0bf5b 100644 --- a/cerise/backend/ssa/codegen.c +++ b/cerise/backend/ssa/codegen.c @@ -291,7 +291,13 @@ void print_op(Parser* p, SsaNode* expr) case MODE_BINOP: printf(" "); print_ident(p, &(expr->dest)); - printf(" = \n"); + printf(" = %s ", binop_name(expr)); + emit_type(expr->type); + printf(" "); + print_ident(p, &(expr->left.var)); + printf(", "); + print_ident(p, &(expr->right.var)); + printf("\n"); break; case MODE_BINOP_LC: @@ -318,18 +324,8 @@ void print_op(Parser* p, SsaNode* expr) printf("\n"); break; - case MODE_CONST: - printf(" "); - print_ident(p, &(expr->dest)); - printf(" = \n"); - break; - case MODE_VAR: - printf(" "); - print_ident(p, &(expr->dest)); - printf(" = \n"); - break; - + case MODE_CONST: default: printf("OP ????\n"); assert(!"not implemented"); @@ -337,7 +333,6 @@ void print_op(Parser* p, SsaNode* expr) } } - void codegen_block(Parser* p, SsaBlock* block) { /* perform a topological sort of the nodes */ diff --git a/cerise/tests/Module.m b/cerise/tests/Module.m index 0bd2020..9b4b1cf 100644 --- a/cerise/tests/Module.m +++ b/cerise/tests/Module.m @@ -114,14 +114,23 @@ begin # Arithmetic ops c = b + 1; c = 1 + b; + c = b + b; + c = b - 1; c = 1 - b; + c = b - b; + c = b * 1; c = 1 * b; + c = b * b; + c = b / 1; c = 1 / b; + c = b / b; + c = b % 1; c = 1 % b; + c = b % b; # # Comparison ops # c = b == 1;