From 311a353fea97e74eb049180da51b5395561975cc Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Thu, 26 Jan 2017 22:04:17 +0100 Subject: Also fix stores... See HEAD^ --- codegen.hs | 10 ++-------- simple.nl | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/codegen.hs b/codegen.hs index cda6239..59adb0b 100644 --- a/codegen.hs +++ b/codegen.hs @@ -114,12 +114,12 @@ variableStoreOperand :: Name -> CGMonad A.Operand variableStoreOperand name = get >>= (maybe getGlobal getLocal . Map.lookup name . variables) where getLocal :: (Type, LLName) -> CGMonad A.Operand - getLocal (t, nm) = return $ A.LocalReference (toLLVMType t) (A.Name nm) + getLocal (t, nm) = return $ A.LocalReference (A.ptr (toLLVMType t)) (A.Name nm) getGlobal :: CGMonad A.Operand getGlobal = do (t, nm) <- lookupGlobalVar name - return $ A.ConstantOperand $ A.C.GlobalReference (toLLVMType t) (A.Name nm) + return $ A.ConstantOperand $ A.C.GlobalReference (A.ptr (toLLVMType t)) (A.Name nm) variableOperand :: Name -> CGMonad A.Operand variableOperand name = get >>= (maybe getGlobal getLocal . Map.lookup name . variables) @@ -258,12 +258,6 @@ genSingle _ _ = undefined genExpression :: Expression -> CGMonad A.Operand genExpression (ExLit lit (Just t)) = literalToOperand lit t --- genExpression (ExLit (LitInt i) (Just t@(TypeInt sz))) = do --- aname <- getNewName "t" --- void $ addNamedInstr $ A.Name aname A.:= A.Alloca (toLLVMType t) Nothing 0 [] --- void $ addInstr $ A.Store False (A.LocalReference (toLLVMType t) (A.Name aname)) --- (A.ConstantOperand (A.C.Int (fromIntegral sz) i)) Nothing 0 [] --- return aname genExpression (ExBinOp bo e1 e2 (Just t)) = do e1op <- genExprArgument e1 e2op <- genExprArgument e2 diff --git a/simple.nl b/simple.nl index 2accc6a..8a8180a 100644 --- a/simple.nl +++ b/simple.nl @@ -5,7 +5,7 @@ int g_var; int main(i32 argc, ptr(ptr(i8)) argv) { //int i = g_var; - int i; + int i = 40; //i = g_var + 2 + 3; int a = i + 2; return a; -- cgit v1.2.3-54-g00ecf