From 1cb1af774cdf0bd8c3f8da257c789184d349bc8c Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Mon, 30 Jan 2017 08:44:54 +0100 Subject: Fix loading global string literals --- codegen.hs | 8 +++++--- puts.nl | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 puts.nl 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 -- cgit v1.2.3-70-g09d2