-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathExample3.hs
46 lines (40 loc) · 1.33 KB
/
Example3.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE RecursiveDo #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
module Main where
import GHC.TypeLits
import LLVM.Prelude
import LLVM.AST.Tagged.Operand
import qualified LLVM.AST.Tagged.Constant as TC
import LLVM.AST.Tagged.Global
import LLVM.AST.Tagged.Tag
import LLVM.AST.TypeLevel.Type
import qualified LLVM.AST as AST
import qualified LLVM.AST.Type as AST
import qualified LLVM.AST.Float as F
import qualified LLVM.AST.Constant as C
import qualified LLVM.AST.IntegerPredicate as P
import LLVM.AST.Tagged.IRBuilder as TBuilder
import qualified LLVM.IRBuilder as Builder
import Data.HVect
simple :: AST.Module
simple = Builder.buildModule "exampleModule" $ mdo
TBuilder.function @(IntegerType' 32) @'[ '(IntegerType' 32, 'ParameterName' "a")] "f" $ \(a :&: HNil) -> mdo
entry <- block `named` "entry"
cond <- icmp P.EQ a (constantOperand (TC.int 0))
condBr cond ifThen ifElse
ifThen <- block
trVal <- add a (constantOperand (TC.int 0))
br ifExit
ifElse <- block `named` "if.else"
flVal <- add a (constantOperand (TC.int 0))
br ifExit
ifExit <- block `named` "if.exit"
r <- phi [(trVal, ifThen), (flVal, ifElse)]
ret r
main :: IO ()
main = print simple