summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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