From b095aedd386e076d1f5a56b7384b836e653387d1 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 17 Sep 2019 01:28:55 +0200 Subject: Add support for r8-r15 registers, pass args to registers directly (sys-v) --- src/bytecode/bytecode.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'src/bytecode') diff --git a/src/bytecode/bytecode.c b/src/bytecode/bytecode.c index 3b6d980..7dbc305 100644 --- a/src/bytecode/bytecode.c +++ b/src/bytecode/bytecode.c @@ -432,19 +432,6 @@ static void add_ins6(BytecodeCompilerContext *self, AmalOpcode opcode, i8 dst_re fputc('\n', stderr); } -static void add_ins7(BytecodeCompilerContext *self, AmalOpcode opcode, u8 import_index, u16 func_index, i8 num_args, const char *fmt) { - Buffer *instructions = &self->bytecode->data; - size_t index = instructions->size; - - throw_if_error(buffer_append_empty(instructions, sizeof(AmalOpcodeType) + sizeof(import_index) + sizeof(func_index) + sizeof(num_args))); - instructions->data[index] = opcode; - memcpy(instructions->data + index + sizeof(AmalOpcodeType), &import_index, sizeof(import_index)); - memcpy(instructions->data + index + sizeof(AmalOpcodeType) + sizeof(import_index), &func_index, sizeof(func_index)); - memcpy(instructions->data + index + sizeof(AmalOpcodeType) + sizeof(import_index) + sizeof(func_index), &num_args, sizeof(num_args)); - fprintf(stderr, fmt, import_index, func_index, num_args); - fputc('\n', stderr); -} - static void add_instructions(BytecodeCompilerContext *self) { /*doc(Bytecode instructions) # Instructions layout @@ -459,6 +446,7 @@ static void add_instructions(BytecodeCompilerContext *self) { SsaInsFuncStart ssa_ins_func_start; SsaInsFuncCall ssa_ins_func_call; SsaInsFuncCallExtern ssa_ins_func_call_extern; + SsaInsCallStart ssa_ins_call_start; SsaInsJumpZero ssa_ins_jump_zero; SsaInsJump ssa_ins_jump; @@ -547,14 +535,19 @@ static void add_instructions(BytecodeCompilerContext *self) { add_ins2(self, AMAL_OP_PUSH_RET, reg, "push_ret r%d"); break; } + case SSA_CALL_START: { + instruction += ssa_extract_data(instruction, &ssa_ins_call_start, sizeof(ssa_ins_call_start)); + add_ins2(self, AMAL_OP_CALL_START, ssa_ins_call_start.num_args, "call_start %d"); + break; + } case SSA_CALL: { instruction += ssa_extract_data(instruction, &ssa_ins_func_call, sizeof(ssa_ins_func_call)); - add_ins7(self, AMAL_OP_CALL, ssa_ins_func_call.import_index, ssa_ins_func_call.func_decl->ssa_func_index, ssa_ins_func_call.num_args, "call f(%d,%d), %d"); + add_ins6(self, AMAL_OP_CALL, ssa_ins_func_call.import_index, ssa_ins_func_call.func_decl->ssa_func_index, "call f(%d,%d)"); break; } case SSA_CALL_EXTERN: { instruction += ssa_extract_data(instruction, &ssa_ins_func_call_extern, sizeof(ssa_ins_func_call_extern)); - add_ins7(self, AMAL_OP_CALLE, ssa_ins_func_call_extern.import_index, ssa_ins_func_call_extern.func_decl_lhs->extern_index, ssa_ins_func_call_extern.num_args, "calle ef(%d,%d), %d"); + add_ins6(self, AMAL_OP_CALLE, ssa_ins_func_call_extern.import_index, ssa_ins_func_call_extern.func_decl_lhs->extern_index, "calle ef(%d,%d)"); break; } case SSA_JUMP_ZERO: { -- cgit v1.2.3