summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-01-30 08:44:54 +0100
committertomsmeding <tom.smeding@gmail.com>2017-01-30 08:45:07 +0100
commit1cb1af774cdf0bd8c3f8da257c789184d349bc8c (patch)
treecad1d1cdab1ae88633a490cf8a50290798ac4c02
parent462be93d0eb03e48b92e41a3e653c955f639bb0b (diff)
Fix loading global string literals
-rw-r--r--codegen.hs8
-rw-r--r--puts.nl9
2 files changed, 14 insertions, 3 deletions
diff --git a/codegen.hs b/codegen.hs
index 23db784..bf620e4 100644
--- a/codegen.hs
+++ b/codegen.hs
@@ -477,9 +477,7 @@ literalToOperand (LitVar n) t = do
return oper'
literalToOperand (LitString s) (TypePtr (TypeInt 8)) = do
name <- addStringLiteral s
- let loadoper = A.ConstantOperand $ A.C.GlobalReference (A.ptr A.i8) (A.Name name)
- label <- addInstr $ A.Load False loadoper Nothing 0 []
- return $ A.LocalReference (A.ptr A.i8) (A.Name label)
+ return $ A.ConstantOperand $ A.C.GlobalReference (A.ptr A.i8) (A.Name name)
literalToOperand (LitString _) _ = undefined
literalToOperand (LitCall n args) _ = do
((TypeFunc rt ats), lname) <- lookupGlobalFunction n
@@ -526,6 +524,10 @@ castOperand orig@(A.LocalReference (A.PointerType t1 _) _) (TypePtr t2)
| toLLVMType t2 == t1 = return orig
| otherwise = throwError $ "Cannot implicitly cast between pointer to '" ++ show t1
++ "' and '" ++ pshow t2 ++ "'"
+castOperand orig@(A.ConstantOperand (A.C.GlobalReference (A.PointerType t1 _) _)) (TypePtr t2)
+ | toLLVMType t2 == t1 = return orig
+ | otherwise = throwError $ "Cannot implicitly cast between pointer to '" ++ show t1
+ ++ "' and '" ++ pshow t2 ++ "'"
castOperand orig t2 = throwError $ "Cast from '" ++ show orig ++ "' to type '" ++ pshow t2 ++ "' not implemented"
castToBool :: A.Operand -> CGMonad A.Operand
diff --git a/puts.nl b/puts.nl
new file mode 100644
index 0000000..4379916
--- /dev/null
+++ b/puts.nl
@@ -0,0 +1,9 @@
+type int = i32;
+type char = i8;
+
+extern func int(ptr(char)) puts;
+
+int main(){
+ puts("kaas!");
+ return 0;
+} \ No newline at end of file