aboutsummaryrefslogtreecommitdiffstats
path: root/src/GSA/Types.hs
blob: ff6bb153af3a8d586b0b94d81ca493a5e50a2fe6 (plain)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
module GSA.Types where

import Data.IntMap.Strict (IntMap)
import Data.Map.Strict (Map)
import Data.Text (Text)
import Data.Int (Int64)

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
  deriving (Eq, Show)

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 Ptrofs = Ptrofs { getPtrofs :: Int } deriving (Eq, Show)

data Comparison =
  Ceq
  | Cne
  | Clt
  | Cle
  | Cgt
  | Cge
  deriving (Eq, Show)

negateComparison Ceq = Cne
negateComparison Cne = Ceq
negateComparison Clt = Cge
negateComparison Cle = Cgt
negateComparison Cgt = Cle
negateComparison Cge = Clt

swapComparison Ceq = Ceq
swapComparison Cne = Cne
swapComparison Clt = Cgt
swapComparison Cle = Cge
swapComparison Cgt = Clt
swapComparison Cge = Cle

data Condition =
  Ccomp Comparison
  | Ccompu Comparison
  | Ccompimm Comparison Int
  | Ccompuimm Comparison Int
  | Ccompl Comparison
  | Ccomplu Comparison
  | Ccomplimm Comparison Int64
  | Ccompluimm Comparison Int64
  | Ccompf Comparison
  | Cnotcompf Comparison
  | Ccompfs Comparison
  | Cnotcompfs Comparison
  | Cmaskzero Int
  | Cmasknotzero Int
  deriving (Eq, Show)

data Addressing =
  Aindexed Integer
  | Aindexed2 Integer
  | Ascaled Integer Integer
  | Aindexed2scaled Integer Integer
  | Aglobal Ident Ptrofs
  | Abased Ident Ptrofs
  | Abasedscaled Integer Ident Ptrofs
  | Ainstack Ptrofs
  deriving (Eq, Show)

data Operation = Omove
  | Ointconst Int
  | Olongconst Int64
  | Ofloatconst Double
  | Osingleconst Float
  | Oindirectsymbol Ident
  | Ocast8signed
  | Ocast8unsigned
  | Ocast16signed
  | Ocast16unsigned
  | Oneg
  | Osub
  | Omul
  | Omulimm Int
  | Omulhs
  | Omulhu
  | Odiv
  | Odivu
  | Omod
  | Omodu
  | Oand
  | Oandimm Int
  | Oor
  | Oorimm Int
  | Oxor
  | Oxorimm Int
  | Onot
  | Oshl
  | Oshlimm Int
  | Oshr
  | Oshrimm Int
  | Oshrximm Int
  | Oshru
  | Oshruimm Int
  | Ororimm Int
  | Oshldimm Int
  | Olea Addressing
  | Omakelong
  | Olowlong
  | Ohighlong
  | Ocast32signed
  | Ocast32unsigned
  | Onegl
  | Oaddlimm Int64
  | Osubl
  | Omull
  | Omullimm Int64
  | Omullhs
  | Omullhu
  | Odivl
  | Odivlu
  | Omodl
  | Omodlu
  | Oandl
  | Oandlimm Int64
  | Oorl
  | Oorlimm Int64
  | Oxorl
  | Oxorlimm Int64
  | Onotl
  | Oshll
  | Oshllimm Int
  | Oshrl
  | Oshrlimm Int
  | Oshrxlimm Int
  | Oshrlu
  | Oshrluimm Int
  | Ororlimm Int
  | Oleal Addressing
  | Onegf
  | Oabsf
  | Oaddf
  | Osubf
  | Omulf
  | Odivf
  | Onegfs
  | Oabsfs
  | Oaddfs
  | Osubfs
  | Omulfs
  | Odivfs
  | Osingleoffloat
  | Ofloatofsingle
  | Ointoffloat
  | Ofloatofint
  | Ointofsingle
  | Osingleofint
  | Olongoffloat
  | Ofloatoflong
  | Olongofsingle
  | Osingleoflong
  | Ocmp Condition
  | Osel Condition Typ
  deriving (Eq, Show)

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 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 :: Map Text Function} deriving (Eq, Show)