aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/ssa.cpp
diff options
context:
space:
mode:
authorgingerBill <ginger.bill.22@gmail.com>2016-08-16 11:43:21 +0100
committergingerBill <ginger.bill.22@gmail.com>2016-08-16 11:43:21 +0100
commit6f7f82d87766d4d60165ea54f2ee760f9ad12bc0 (patch)
tree4bcb75d44fc9520b3b90d97e8dc24309dbc1e6b3 /src/codegen/ssa.cpp
parent74e02760ca5f3df36200cf4bb21d7bf123b14eb1 (diff)
parent50fd9548b95f3929295be632619c20732094c93c (diff)
Merge branch 'master' of http://git.handmadedev.org/gingerbill/Odin
# Conflicts: # examples/main.ll # examples/main.odin # examples/win32.odin # src/codegen/print_llvm.cpp
Diffstat (limited to 'src/codegen/ssa.cpp')
-rw-r--r--src/codegen/ssa.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/codegen/ssa.cpp b/src/codegen/ssa.cpp
index 3df8cbd81..7a0c587c5 100644
--- a/src/codegen/ssa.cpp
+++ b/src/codegen/ssa.cpp
@@ -53,6 +53,7 @@ struct ssaProcedure {
ssaTargetList * target_list;
};
+#define SSA_STARTUP_RUNTIME_PROC_NAME "__$startup_runtime"
#define SSA_INSTR_KINDS \
@@ -73,6 +74,7 @@ struct ssaProcedure {
SSA_INSTR_KIND(ExtractElement), \
SSA_INSTR_KIND(InsertElement), \
SSA_INSTR_KIND(ShuffleVector), \
+ SSA_INSTR_KIND(StartupRuntime), \
SSA_INSTR_KIND(Count),
enum ssaInstrKind {
@@ -192,6 +194,8 @@ struct ssaInstr {
ssaValue *elem;
ssaValue *index;
} insert_element;
+
+ struct {} startup_runtime;
};
};
@@ -890,6 +894,7 @@ void ssa_end_procedure_body(ssaProcedure *proc) {
case ssaInstr_Ret:
case ssaInstr_Unreachable:
case ssaInstr_CopyMemory:
+ case ssaInstr_StartupRuntime:
continue;
case ssaInstr_Call:
if (instr->call.type == NULL) {
@@ -2340,6 +2345,26 @@ void ssa_build_stmt(ssaProcedure *proc, AstNode *node) {
}
}
+
+void ssa_emit_startup_runtime(ssaProcedure *proc) {
+ GB_ASSERT(proc->parent == NULL && are_strings_equal(proc->name, make_string("main")));
+
+ ssaValue *v = ssa_alloc_instr(proc->module->allocator, ssaInstr_StartupRuntime);
+ if (proc->curr_block) {
+ gb_array_append(proc->curr_block->values, v);
+ }
+ ssa_emit(proc, v);
+}
+
+void ssa_insert_code_before_proc(ssaProcedure* proc, ssaProcedure *parent) {
+ if (parent == NULL) {
+ if (are_strings_equal(proc->name, make_string("main"))) {
+ ssa_emit_startup_runtime(proc);
+ }
+ }
+}
+
+
void ssa_build_proc(ssaValue *value, ssaProcedure *parent) {
ssaProcedure *proc = &value->proc;
@@ -2347,6 +2372,7 @@ void ssa_build_proc(ssaValue *value, ssaProcedure *parent) {
if (proc->body != NULL) {
ssa_begin_procedure_body(proc);
+ ssa_insert_code_before_proc(proc, parent);
ssa_build_stmt(proc, proc->body);
ssa_end_procedure_body(proc);
}