Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to llvm-hs(-pure) 5.1 #4

Merged
merged 3 commits into from
Dec 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/Codegen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
-------------------------------------------------------------------------------
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 []
Expand Down
6 changes: 2 additions & 4 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down