From c45e7fe603f3080edb5bf6d5378943017568b5ba Mon Sep 17 00:00:00 2001 From: Victorious3 Date: Fri, 8 Oct 2021 13:27:18 +0200 Subject: [PATCH] Give string literals an alloca --- princess.h | 5 ----- src/compiler.pr | 21 +++++++++++++++++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/princess.h b/princess.h index e6def21b..1c880fc5 100644 --- a/princess.h +++ b/princess.h @@ -3,15 +3,10 @@ #include #include -#include #include #include -#include -#include #include -#include #include -#include #ifndef _WIN32 #include diff --git a/src/compiler.pr b/src/compiler.pr index b2ad13ca..24d72a71 100644 --- a/src/compiler.pr +++ b/src/compiler.pr @@ -807,6 +807,14 @@ def walk_String(node: *parser::Node, state: *State) -> Value { } !Value let global = make_global_value(strtpe, "str", str_value, state) + + let alloca_ret = make_local_value(tpe, null, state) + let alloca = make_insn_dbg(InsnKind::ALLOCA, loc) + alloca.value.alloca = { + ret = alloca_ret + } !InsnAlloca + push_insn(alloca, state) + alloca_ret.tpe = typechecking::pointer(tpe) let index = allocate(Value, 2) index[0] = make_int_value(0) @@ -823,8 +831,10 @@ def walk_String(node: *parser::Node, state: *State) -> Value { index = index } !InsnGetElementPtr push_insn(gep, state) - - let ret = make_local_value(tpe, null, state) + + let alloca_retp = allocate(Value) + @alloca_retp = alloca_ret + let ret = make_local_value(tpe, alloca_retp, state) let values = allocate(Value, 2) values[0] = { @@ -854,6 +864,13 @@ def walk_String(node: *parser::Node, state: *State) -> Value { } !InsnInsertValue push_insn(insert, state) + let store = make_insn_dbg(InsnKind::STORE, loc) + store.value.store = { + value = ret, + loc = alloca_ret + } !InsnStore + push_insn(store, state) + return ret }