aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/ast.h8
-rw-r--r--include/bytecode/bytecode.h2
-rw-r--r--include/ir/ir.h165
-rw-r--r--include/parser.h2
-rw-r--r--include/ssa/ssa.h165
5 files changed, 171 insertions, 171 deletions
diff --git a/include/ast.h b/include/ast.h
index f62d31f..eaaf93e 100644
--- a/include/ast.h
+++ b/include/ast.h
@@ -11,7 +11,7 @@
#include "std/hash_map.h"
#include "number.h"
#include "binop_type.h"
-#include "ssa/ssa.h"
+#include "ir/ir.h"
#include <setjmp.h>
@@ -75,7 +75,7 @@ typedef enum {
AST_NOT_RESOLVED,
AST_RESOLVING,
AST_RESOLVED,
- AST_SSA_RESOLVED
+ AST_IR_RESOLVED
} AstResolveStatus;
typedef enum {
@@ -96,7 +96,7 @@ typedef struct {
typedef struct {
AstResolvedType type;
AstResolveStatus status;
- SsaRegister ssa_reg;
+ IrRegister ir_reg;
} AstResolveData;
typedef enum {
@@ -192,7 +192,7 @@ struct FunctionDecl {
LhsExpr *lhs_expr; /* Borrowed from the LhsExpr that owns this FunctionDecl if it exists, otherwise NULL */
FunctionSignature *signature; /* TODO: Make this a non-pointer type? */
Scope body;
- SsaFuncIndex ssa_func_index;
+ IrFuncIndex ir_func_index;
};
struct FunctionCall {
diff --git a/include/bytecode/bytecode.h b/include/bytecode/bytecode.h
index f649368..a70bb6f 100644
--- a/include/bytecode/bytecode.h
+++ b/include/bytecode/bytecode.h
@@ -173,6 +173,6 @@ CHECK_RESULT int bytecode_init(Bytecode *self, ArenaAllocator *allocator);
CHECK_RESULT int buffer_append_header(Buffer *program_data);
/* longjump to self->env on failure */
-void generate_bytecode_from_ssa(BytecodeCompilerContext *self);
+void generate_bytecode_from_ir(BytecodeCompilerContext *self);
#endif
diff --git a/include/ir/ir.h b/include/ir/ir.h
new file mode 100644
index 0000000..f7aa4a7
--- /dev/null
+++ b/include/ir/ir.h
@@ -0,0 +1,165 @@
+#ifndef AMALGAM_IR_H
+#define AMALGAM_IR_H
+
+#include "../std/buffer.h"
+#include "../std/hash_map.h"
+#include "../std/defs.h"
+#include "../defs.h"
+
+#include <setjmp.h>
+
+#define IR_ERR_EXTERN_FUNC_SIG_MISMATCH -20
+
+/* Important: The number of fields in this enum can't exceed 255 */
+typedef enum {
+ IR_ASSIGN_INTER,
+ IR_ASSIGN_STRING,
+ IR_ASSIGN_REG,
+ IR_ADD,
+ IR_SUB,
+ IR_IMUL,
+ IR_MUL,
+ IR_IDIV,
+ IR_DIV,
+ IR_EQUALS,
+ IR_NOT_EQUAL,
+ IR_AND,
+ IR_ILT,
+ IR_ILE,
+ IR_IGT,
+ IR_IGE,
+ IR_LT,
+ IR_LE,
+ IR_GT,
+ IR_GE,
+ IR_FUNC_START,
+ IR_FUNC_END,
+ IR_PUSH,
+ IR_PUSH_RET,
+ IR_CALL_START,
+ IR_CALL,
+ IR_CALL_EXTERN,
+ IR_JUMP_ZERO,
+ IR_JUMP,
+ IR_RET,
+ IR_LABEL
+} IrInstruction;
+
+typedef enum {
+ IR_NUMBER_TYPE_INTEGER,
+ IR_NUMBER_TYPE_FLOAT
+} IrNumberType;
+
+typedef struct {
+ union {
+ i64 integer;
+ f64 floating;
+ } value;
+ IrNumberType type;
+} IrNumber;
+
+typedef struct {
+ FunctionSignature *func_sig;
+ BufferView name;
+} IrExternFunc;
+
+typedef struct {
+ FunctionSignature *func_sig;
+ BufferView name;
+} IrExportFunc;
+
+typedef struct {
+ FunctionSignature *func_sig;
+} IrFunc;
+
+typedef i16 JumpOffset;
+typedef i16 IrRegister;
+typedef u16 IrIntermediateIndex;
+typedef u16 IrStringIndex;
+typedef u16 IrExternFuncIndex;
+typedef u16 IrExportFuncIndex;
+typedef u16 IrFuncIndex;
+typedef u16 IrLabelIndex;
+
+typedef struct {
+ Buffer/*instruction data*/ instructions;
+ HashMapType(IrNumber, IrIntermediateIndex) intermediates_map;
+ Buffer/*IrNumber*/ intermediates;
+ HashMapType(BufferView, IrStringIndex) strings_map;
+ Buffer/*BufferView*/ strings;
+ HashMapType(BufferView, IrExternFuncIndex) extern_funcs_map;
+ Buffer/*IrExternFunc*/ extern_funcs;
+ Buffer/*IrExportFunc*/ export_funcs;
+ Buffer/*IrFunc*/ funcs;
+
+ IrIntermediateIndex intermediate_counter;
+ IrStringIndex string_counter;
+ IrExternFuncIndex extern_func_counter;
+ IrExportFuncIndex export_func_counter;
+ IrFuncIndex func_counter;
+ IrRegister reg_counter;
+ IrRegister param_counter;
+ IrLabelIndex label_counter;
+ Parser *parser; /* Borrowed */
+} Ir;
+
+typedef struct {
+ IrRegister lhs;
+ u16 rhs;
+} IrInsForm1;
+
+typedef struct {
+ IrRegister result;
+ IrRegister lhs;
+ IrRegister rhs;
+} IrInsForm2;
+
+typedef struct {
+ u8 flags;
+ u16 num_local_vars_regs;
+} IrInsFuncStart;
+
+typedef struct {
+ FunctionDecl *func_decl;
+ u8 import_index;
+} IrInsFuncCall;
+
+typedef struct {
+ LhsExpr *func_decl_lhs;
+ int import_index;
+} IrInsFuncCallExtern;
+
+typedef struct {
+ u8 num_args;
+} IrInsCallStart;
+
+typedef struct {
+ IrRegister condition_reg;
+ IrLabelIndex target_label;
+} IrInsJumpZero;
+
+typedef struct {
+ IrLabelIndex target_label;
+} IrInsJump;
+
+/* None of these functions are thread-safe */
+IrNumber create_ir_integer(i64 value);
+IrNumber create_ir_float(f64 value);
+
+IrNumber ir_get_intermediate(Ir *self, IrIntermediateIndex index);
+BufferView ir_get_string(Ir *self, IrStringIndex index);
+
+CHECK_RESULT int ir_init(Ir *self, Parser *parser);
+
+typedef struct {
+ jmp_buf env;
+ Ir *ir;
+ amal_compiler *compiler;
+ /* 0 if the current scope belongs to the file, otherwise ParserFileScopeReference's import_index (the import file that contains the scope) */
+ u8 import_index;
+} IrCompilerContext;
+
+/* longjump to context->env on failure */
+void scope_generate_ir(Scope *self, IrCompilerContext *context);
+
+#endif
diff --git a/include/parser.h b/include/parser.h
index 88bed93..b9a09b2 100644
--- a/include/parser.h
+++ b/include/parser.h
@@ -29,7 +29,7 @@ struct Parser {
bool has_func_parent;
ArenaAllocator *allocator; /* Owned */
amal_compiler *compiler;
- Ssa *ssa;
+ Ir *ir;
bool started;
TokenizerError error;
ErrorContext error_context;
diff --git a/include/ssa/ssa.h b/include/ssa/ssa.h
deleted file mode 100644
index e8e68c3..0000000
--- a/include/ssa/ssa.h
+++ /dev/null
@@ -1,165 +0,0 @@
-#ifndef AMALGAM_SSA_H
-#define AMALGAM_SSA_H
-
-#include "../std/buffer.h"
-#include "../std/hash_map.h"
-#include "../std/defs.h"
-#include "../defs.h"
-
-#include <setjmp.h>
-
-#define SSA_ERR_EXTERN_FUNC_SIG_MISMATCH -20
-
-/* Important: The number of fields in this enum can't exceed 255 */
-typedef enum {
- SSA_ASSIGN_INTER,
- SSA_ASSIGN_STRING,
- SSA_ASSIGN_REG,
- SSA_ADD,
- SSA_SUB,
- SSA_IMUL,
- SSA_MUL,
- SSA_IDIV,
- SSA_DIV,
- SSA_EQUALS,
- SSA_NOT_EQUAL,
- SSA_AND,
- SSA_ILT,
- SSA_ILE,
- SSA_IGT,
- SSA_IGE,
- SSA_LT,
- SSA_LE,
- SSA_GT,
- SSA_GE,
- SSA_FUNC_START,
- SSA_FUNC_END,
- SSA_PUSH,
- SSA_PUSH_RET,
- SSA_CALL_START,
- SSA_CALL,
- SSA_CALL_EXTERN,
- SSA_JUMP_ZERO,
- SSA_JUMP,
- SSA_RET,
- SSA_LABEL
-} SsaInstruction;
-
-typedef enum {
- SSA_NUMBER_TYPE_INTEGER,
- SSA_NUMBER_TYPE_FLOAT
-} SsaNumberType;
-
-typedef struct {
- union {
- i64 integer;
- f64 floating;
- } value;
- SsaNumberType type;
-} SsaNumber;
-
-typedef struct {
- FunctionSignature *func_sig;
- BufferView name;
-} SsaExternFunc;
-
-typedef struct {
- FunctionSignature *func_sig;
- BufferView name;
-} SsaExportFunc;
-
-typedef struct {
- FunctionSignature *func_sig;
-} SsaFunc;
-
-typedef i16 JumpOffset;
-typedef i16 SsaRegister;
-typedef u16 SsaIntermediateIndex;
-typedef u16 SsaStringIndex;
-typedef u16 SsaExternFuncIndex;
-typedef u16 SsaExportFuncIndex;
-typedef u16 SsaFuncIndex;
-typedef u16 SsaLabelIndex;
-
-typedef struct {
- Buffer/*instruction data*/ instructions;
- HashMapType(SsaNumber, SsaIntermediateIndex) intermediates_map;
- Buffer/*SsaNumber*/ intermediates;
- HashMapType(BufferView, SsaStringIndex) strings_map;
- Buffer/*BufferView*/ strings;
- HashMapType(BufferView, SsaExternFuncIndex) extern_funcs_map;
- Buffer/*SsaExternFunc*/ extern_funcs;
- Buffer/*SsaExportFunc*/ export_funcs;
- Buffer/*SsaFunc*/ funcs;
-
- SsaIntermediateIndex intermediate_counter;
- SsaStringIndex string_counter;
- SsaExternFuncIndex extern_func_counter;
- SsaExportFuncIndex export_func_counter;
- SsaFuncIndex func_counter;
- SsaRegister reg_counter;
- SsaRegister param_counter;
- SsaLabelIndex label_counter;
- Parser *parser; /* Borrowed */
-} Ssa;
-
-typedef struct {
- SsaRegister lhs;
- u16 rhs;
-} SsaInsForm1;
-
-typedef struct {
- SsaRegister result;
- SsaRegister lhs;
- SsaRegister rhs;
-} SsaInsForm2;
-
-typedef struct {
- u8 flags;
- u16 num_local_vars_regs;
-} SsaInsFuncStart;
-
-typedef struct {
- FunctionDecl *func_decl;
- u8 import_index;
-} SsaInsFuncCall;
-
-typedef struct {
- LhsExpr *func_decl_lhs;
- int import_index;
-} SsaInsFuncCallExtern;
-
-typedef struct {
- u8 num_args;
-} SsaInsCallStart;
-
-typedef struct {
- SsaRegister condition_reg;
- SsaLabelIndex target_label;
-} SsaInsJumpZero;
-
-typedef struct {
- SsaLabelIndex target_label;
-} SsaInsJump;
-
-/* 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);
-BufferView ssa_get_string(Ssa *self, SsaStringIndex index);
-
-CHECK_RESULT int ssa_init(Ssa *self, Parser *parser);
-
-typedef struct {
- jmp_buf env;
- Ssa *ssa;
- amal_compiler *compiler;
- /* 0 if the current scope belongs to the file, otherwise ParserFileScopeReference's import_index (the import file that contains the scope) */
- u8 import_index;
-} SsaCompilerContext;
-
-/* longjump to context->env on failure */
-void scope_generate_ssa(Scope *self, SsaCompilerContext *context);
-
-#endif