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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
module GSA.Types where
import Data.IntMap.Strict (IntMap)
import Data.Text (Text)
data Typ
= Tint
| Tfloat
| Tlong
| Tsingle
| Tany32
| Tany64
deriving (Eq, Show)
data RetTyp
= Tret Typ
| Tint8signed
| Tint8unsigned
| Tint16signed
| Tint16unsigned
| Tvoid
deriving (Eq, Show)
data Signature = Signature
{ sigArgs :: [Typ],
sigRes :: RetTyp
}
deriving (Eq, Show)
data Chunk
= Mint8signed
| Mint8unsigned
| Mint16signed
| Mint16unsigned
| Mint32
| Mint64
| Mfloat32
| Mfloat64
| Many32
| Many64
signatureMain :: Signature
signatureMain = Signature {sigArgs = [], sigRes = Tret Tint}
newtype Node = Node {getNode :: Int} deriving (Eq, Show)
newtype Reg = Reg {getReg :: Int} deriving (Eq, Show)
newtype Ident = Ident {getIdent :: Int} deriving (Eq, Show)
newtype Addressing = Addressing {getAddressing :: Int} deriving (Eq, Show)
newtype Operation = Operation {getOperation :: Int} deriving (Eq, Show)
type Condition = Int
data Pred a
= Ptrue
| Pfalse
| Plit (Bool, a)
| Pand (Pred a) (Pred a)
| Por (Pred a) (Pred a)
deriving (Eq, Show)
type Predicate = Pred Condition
data MergeInstruction
= Imu Reg Reg Reg
| Igamma [(Predicate, Reg)] Reg
| Ieta Predicate Reg Reg
deriving (Eq, Show)
data Instruction
= Inop Node
| Iop Operation [Reg] Reg Node
| Iload Chunk Addressing [Reg] Reg Node
| Istore Chunk Addressing [Reg] Reg Node
| Icall Signature (Either Reg Ident)
| Icond Condition [Reg] Node Node
| Ijumptable Reg [Node]
| Ireturn (Maybe Reg)
| Imfunc [MergeInstruction]
deriving (Eq, Show)
newtype MergeBlock = MergeBlock {getMergeBlock :: [MergeInstruction]} deriving (Eq, Show)
newtype Code = Code {getCode :: IntMap Instruction} deriving (Eq, Show)
data Function = Function
{ fnSig :: Signature,
fnParams :: [Reg],
fnStackSize :: Int,
fnCode :: Code,
fnEntrypoint :: Node,
fnExtParams :: [Reg]
}
deriving (Eq, Show)
newtype Program = Program {getProgram :: [Function]} deriving (Eq, Show)
|