diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-01-30 08:44:54 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-01-30 08:45:07 +0100 |
commit | 1cb1af774cdf0bd8c3f8da257c789184d349bc8c (patch) | |
tree | cad1d1cdab1ae88633a490cf8a50290798ac4c02 | |
parent | 462be93d0eb03e48b92e41a3e653c955f639bb0b (diff) |
Fix loading global string literals
-rw-r--r-- | codegen.hs | 8 | ||||
-rw-r--r-- | puts.nl | 9 |
2 files changed, 14 insertions, 3 deletions
@@ -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 @@ -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 |