-
Notifications
You must be signed in to change notification settings - Fork 38
/
Example.hs
56 lines (45 loc) · 1.11 KB
/
Example.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
47
48
49
50
51
52
53
54
55
56
{-# LANGUAGE OverloadedStrings #-}
module Example where
-- Pretty Printer
import LLVM.Pretty (ppllvm, ppll)
-- AST
import LLVM.AST
import qualified LLVM.AST as AST
import LLVM.AST.Global
import Data.Text.Lazy.IO as TIO
int :: Type
int = IntegerType 32
defAdd :: Definition
defAdd = GlobalDefinition functionDefaults
{ name = Name "add"
, parameters =
( [ Parameter int (Name "a") []
, Parameter int (Name "b") [] ]
, False )
, returnType = int
, basicBlocks = [block]
}
where
block :: BasicBlock
block = BasicBlock
(Name "entry")
[ Name "result" :=
Add False
False
(LocalReference int (Name "a"))
(LocalReference int (Name "b"))
[] ]
(Do $ Ret (Just (LocalReference int (Name "result"))) [])
astModule :: AST.Module
astModule = defaultModule
{ moduleName = "llvm-pp"
, moduleDefinitions = [defAdd]
}
main :: IO ()
main = do
TIO.putStrLn "=== Module ==="
TIO.putStrLn (ppllvm astModule)
TIO.putStrLn "=== Definition ==="
TIO.putStrLn (ppll defAdd)
TIO.putStrLn "=== Basic Block ==="
TIO.putStrLn (ppll block)