From a76ba1b33e397638c4209dd77e6073e423ac07a8 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 22 Apr 2019 02:34:30 +0200 Subject: Start on bytecode. Commit before os switch --- include/ssa/ssa.h | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'include/ssa') diff --git a/include/ssa/ssa.h b/include/ssa/ssa.h index 16ceb25..32d1ba6 100644 --- a/include/ssa/ssa.h +++ b/include/ssa/ssa.h @@ -20,7 +20,7 @@ typedef enum { SSA_FUNC_END, SSA_PUSH, SSA_CALL -} SsaInstructionType; +} SsaInstruction; typedef enum { SSA_NUMBER_TYPE_INTEGER, @@ -42,7 +42,8 @@ typedef usize SsaFuncIndex; typedef struct { Buffer/*instruction data*/ instructions; - HashMap/**/ intermediates; + HashMap/**/ intermediates_map; + Buffer/*SsaNumber*/ intermediates; HashMap/**/ strings; SsaIntermediateIndex intermediate_counter; SsaStringIndex string_counter; @@ -50,28 +51,51 @@ typedef struct { SsaFuncIndex func_counter; } Ssa; +typedef struct { + SsaRegister lhs; + u16 rhs; +} SsaInsForm1; + +typedef struct { + SsaRegister result; + SsaRegister lhs; + SsaRegister rhs; +} SsaInsForm2; + +typedef struct { + SsaFuncIndex func_index; + u8 num_args; +} SsaInsFuncStart; + +typedef struct { + SsaRegister result; + FunctionDecl *func_decl; +} SsaInsFuncCall; + /* None of these functions are thread-safe */ SsaNumber create_ssa_integer(i64 value); SsaNumber create_ssa_float(f64 value); +SsaNumber ssa_get_intermediate(Ssa *self, SsaIntermediateIndex index); + CHECK_RESULT int ssa_init(Ssa *self, ScopedAllocator *allocator); CHECK_RESULT int ssa_get_unique_reg(Ssa *self, SsaRegister *result); CHECK_RESULT int ssa_ins_assign_inter(Ssa *self, SsaRegister dest, SsaNumber number); CHECK_RESULT int ssa_ins_assign_string(Ssa *self, SsaRegister dest, BufferView str); CHECK_RESULT int ssa_ins_assign_reg(Ssa *self, SsaRegister dest, SsaRegister src); -CHECK_RESULT int ssa_ins_binop(Ssa *self, SsaInstructionType binop_type, SsaRegister lhs, SsaRegister rhs, SsaRegister *result); +CHECK_RESULT int ssa_ins_binop(Ssa *self, SsaInstruction binop_type, SsaRegister lhs, SsaRegister rhs, SsaRegister *result); CHECK_RESULT int ssa_ins_func_start(Ssa *self, u8 num_args, SsaFuncIndex *result); CHECK_RESULT int ssa_ins_func_end(Ssa *self); CHECK_RESULT int ssa_ins_push(Ssa *self, SsaRegister reg); -CHECK_RESULT int ssa_ins_call(Ssa *self, void *func, SsaRegister *result); +CHECK_RESULT int ssa_ins_call(Ssa *self, FunctionDecl *func_decl, SsaRegister *result); typedef struct { jmp_buf env; - Ssa ssa; + Ssa *ssa; } SsaCompilerContext; -/* longjump to compiler env on failure */ +/* longjump to context->env on failure */ void scope_generate_ssa(Scope *self, SsaCompilerContext *context); #endif -- cgit v1.2.3