aboutsummaryrefslogtreecommitdiff
path: root/include/ssa
diff options
context:
space:
mode:
Diffstat (limited to 'include/ssa')
-rw-r--r--include/ssa/ssa.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/include/ssa/ssa.h b/include/ssa/ssa.h
new file mode 100644
index 0000000..e5bd86b
--- /dev/null
+++ b/include/ssa/ssa.h
@@ -0,0 +1,56 @@
+#ifndef AMALGAM_SSA_H
+#define AMALGAM_SSA_H
+
+#include "../std/buffer.h"
+#include "../std/hash_map.h"
+#include "../std/defs.h"
+
+typedef enum {
+ SSA_ASSIGN_INTER,
+ SSA_ASSIGN_REG,
+ SSA_ADD,
+ SSA_SUB,
+ SSA_MUL,
+ SSA_DIV,
+ SSA_FUNC_START,
+ SSA_FUNC_END,
+ SSA_PUSH,
+ SSA_CALL
+} SsaInstructionType;
+
+typedef enum {
+ SSA_NUMBER_TYPE_INTEGER,
+ SSA_NUMBER_TYPE_FLOAT
+} SsaNumberType;
+
+typedef struct {
+ i64 value;
+ SsaNumberType type;
+} SsaNumber;
+
+typedef u16 SsaRegister;
+typedef u16 SsaIntermediateIndex;
+typedef u32 SsaFuncIndex;
+
+typedef struct {
+ Buffer/*instruction data*/ instructions;
+ HashMap/*<SsaNumberType, IntermediateIndex>*/ intermediates;
+ SsaIntermediateIndex intermediate_counter;
+ SsaRegister reg_counter;
+ SsaFuncIndex func_counter;
+} Ssa;
+
+/* None of these functions are thread-safe */
+SsaNumber create_ssa_number(i64 value, SsaNumberType type);
+
+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_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_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, SsaFuncIndex func, SsaRegister *result);
+
+#endif