diff --git a/src/Codegen.hs b/src/Codegen.hs index 08e1b64..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 ------------------------------------------------------------------------------- @@ -159,6 +173,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 +286,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 [] 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: