From 825c8fb36e687ab624507044ce160bdb061b1445 Mon Sep 17 00:00:00 2001 From: Ondrej Slamecka Date: Sun, 24 Dec 2017 12:50:35 +0100 Subject: [PATCH 1/3] Do not name `store` instruction --- src/Codegen.hs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Codegen.hs b/src/Codegen.hs index 08e1b64..402715a 100644 --- a/src/Codegen.hs +++ b/src/Codegen.hs @@ -159,6 +159,12 @@ instr ty ins = do modifyBlock (blk { stack = (ref := ins) : i } ) return $ local ty ref +unnminstr :: Instruction -> Codegen () +unnminstr ins = do + blk <- current + let i = stack blk + modifyBlock (blk { stack = (Do ins) : i } ) + terminator :: Named Terminator -> Codegen (Named Terminator) terminator trm = do blk <- current @@ -266,8 +272,8 @@ call fn args = instr float $ Call Nothing CC.C [] (Right fn) (toArgs args) [] [] alloca :: Type -> Codegen Operand alloca ty = instr float $ Alloca ty Nothing 0 [] -store :: Operand -> Operand -> Codegen Operand -store ptr val = instr float $ Store False ptr val Nothing 0 [] +store :: Operand -> Operand -> Codegen () +store ptr val = unnminstr $ Store False ptr val Nothing 0 [] load :: Operand -> Codegen Operand load ptr = instr float $ Load False ptr Nothing 0 [] From cc60b61639cf85054512c39b36d46685642c3e2e Mon Sep 17 00:00:00 2001 From: Ondrej Slamecka Date: Mon, 25 Dec 2017 18:04:54 +0100 Subject: [PATCH 2/3] Provide a function for getting pointers to functions --- src/Codegen.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Codegen.hs b/src/Codegen.hs index 402715a..219aa83 100644 --- a/src/Codegen.hs +++ b/src/Codegen.hs @@ -15,6 +15,8 @@ import Control.Applicative import Control.Monad.State import LLVM.AST +import LLVM.AST.Typed (typeOf) +import LLVM.AST.AddrSpace import LLVM.AST.Type import LLVM.AST.Global import qualified LLVM.AST as AST @@ -67,6 +69,18 @@ external retty label argtys = addDefn $ , basicBlocks = [] } +fnPtr :: Name -> LLVM Type +fnPtr nm = findType <$> gets moduleDefinitions + where + findType defs = + case fnDefByName of + [] -> error $ "Undefined function: " ++ show nm + [fn] -> PointerType (typeOf fn) (AddrSpace 0) + _ -> error $ "Ambiguous function name: " ++ show nm + where + globalDefs = [g | GlobalDefinition g <- defs] + fnDefByName = [f | f@(Function { name = nm }) <- globalDefs] + --------------------------------------------------------------------------------- -- Types ------------------------------------------------------------------------------- From d56bc0690787293d69855d24eb3b03a4bab7cc78 Mon Sep 17 00:00:00 2001 From: Ondrej Slamecka Date: Mon, 25 Dec 2017 18:08:26 +0100 Subject: [PATCH 3/3] Use Stack LTS 10 --- stack.yaml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/stack.yaml b/stack.yaml index 88a59a3..b3f084d 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,9 +1,7 @@ -resolver: lts-9.3 +resolver: lts-10.0 packages: - '.' -extra-deps: -- llvm-hs-pure-5.0.0 -- llvm-hs-5.0.0 +extra-deps: [] flags: llvm-hs: