From 329e6cf5ea15adae208aef5a93dec6bdb9721b59 Mon Sep 17 00:00:00 2001 From: Akuli Date: Fri, 10 Jan 2025 15:52:29 +0200 Subject: [PATCH] simplify even more --- compiler/build_cf_graph.jou | 7 ++++--- compiler/cf_graph.jou | 14 +++----------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/compiler/build_cf_graph.jou b/compiler/build_cf_graph.jou index 671b1a2c..abb9da5e 100644 --- a/compiler/build_cf_graph.jou +++ b/compiler/build_cf_graph.jou @@ -114,7 +114,7 @@ def add_unary_op( target: LocalVariable*, ) -> None: ins = CfInstruction{location = location, kind = op, destvar = target} - ins.set_1_operand(arg) + ins.add_operand(arg) add_instruction(st, ins) @@ -128,7 +128,8 @@ def add_binary_op( target: LocalVariable*, ) -> None: ins = CfInstruction{location = location, kind = op, destvar = target} - ins.set_2_operands(lhs, rhs) + ins.add_operand(lhs) + ins.add_operand(rhs) add_instruction(st, ins) @@ -325,7 +326,7 @@ def build_class_field_pointer( kind = CfInstructionKind::PtrClassField, destvar = result, } - ins.set_1_operand(instance) + ins.add_operand(instance) assert sizeof(ins.fieldname) == sizeof(f->name) strcpy(ins.fieldname, f->name) diff --git a/compiler/cf_graph.jou b/compiler/cf_graph.jou index 36031183..fed7cc6e 100644 --- a/compiler/cf_graph.jou +++ b/compiler/cf_graph.jou @@ -202,18 +202,10 @@ class CfInstruction: free_signature(&self->signature) free(self->operands) - def set_1_operand(self, operand: LocalVariable*) -> None: - self->noperands = 1 - self->operands = malloc(sizeof(self->operands[0])) + def add_operand(self, operand: LocalVariable*) -> None: + self->operands = realloc(self->operands, sizeof(self->operands[0]) * (self->noperands + 1)) assert self->operands != NULL - self->operands[0] = operand - - def set_2_operands(self, operand1: LocalVariable*, operand2: LocalVariable*) -> None: - self->noperands = 2 - self->operands = malloc(2 * sizeof(self->operands[0])) - assert self->operands != NULL - self->operands[0] = operand1 - self->operands[1] = operand2 + self->operands[self->noperands++] = operand class CfBlock: