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
|
signature PARSER = sig
structure P: PPC
structure D: DYNARRAY
type ctx
type nid = int
datatype ctype =
unknown_t |
void_t |
char_t |
uchar_t |
short_t |
ushort_t |
int_t |
uint_t |
long_t |
ulong_t |
longlong_t |
ulonglong_t |
pointer_t of int * ctype |
function_t of ctype * ctype list * bool |
array_t of Word64.word * ctype |
struct_t of
{ name: nid, size: word, alignment: word,
fields: (nid * word * ctype) list } |
union_t of
{ name: nid, size: word, alignment: word,
fields: (nid * word * ctype) list } |
enum_t of nid * bool | (* is complete? *)
remote_t of int
datatype unop =
UnopPreInc |
UnopPreDec |
UnopAddr |
UnopDeref |
UnopPos |
UnopNeg |
UnopComp |
UnopLogNeg |
UnopSizeof |
UnopCast |
UnopPostInc |
UnopPostDec
and binopReg =
BrSubscript |
BrMul |
BrDiv |
BrMod |
BrSum |
BrSub |
BrShiftLeft |
BrShiftRight |
BrGreater |
BrLess |
BrLessEqual |
BrGreaterEqual |
BrEqual |
BrNotEqual |
BrBitAnd |
BrBitXor |
BrBitOr |
BrLogAnd |
BrLogOr |
BrAssign |
BrMulAssign |
BrDivAssign |
BrModAssign |
BrSumAssign |
BrSubAssign |
BrLeftShiftAssign |
BrRightShiftAssign |
BrBitAndAssign |
BrBitXorAssign |
BrBitOrAssign |
BrComma
and cnum =
Ninteger of Word64.word
| Nfloat of Real32.real
| Ndouble of Real64.real
and id = Lid of int | Gid of int
and expr =
Eid of int * id option |
Econst of int * cnum |
Estrlit of int |
EmemberByV of exprAug * int |
EmemberByP of exprAug * int |
EfuncCall of exprAug * exprAug list |
Eternary of exprAug * exprAug * exprAug |
EsizeofType of ctype |
Eunop of unop * exprAug |
Ebinop of binop * exprAug * exprAug
and exprAug = EA of expr * P.tkPos * bool * ctype
and binop = BR of binopReg | BinopTernaryIncomplete of exprAug
datatype linkage = LinkInternal | LinkExternal
val iniLayouts:
(bool * word * { offset: word, t: ctype, value: word } list) D.t
datatype cini = CiniExpr of exprAug | CiniLayout of int
type objDef = int * P.tkPos * ctype * cini * linkage
datatype stmt =
StmtExpr of exprAug |
StmtCompound of (int * cini option) list * stmt list |
StmtIf of exprAug * stmt * stmt option |
StmtFor of exprAug option * exprAug option * exprAug option * stmt |
StmtWhile of exprAug * stmt |
StmtDoWhile of stmt * exprAug |
StmtReturn of exprAug option |
StmtBreak |
StmtNone |
StmtContinue
type funcInfo = {
name: int,
pos: P.tkPos,
t: ctype,
paramNum: int,
localVars: { name: nid, pos: P.tkPos, onStack: bool, t: ctype } vector,
stmt: stmt
}
datatype declClass = DeclRegular | DeclTentative | DeclDefined
type decl = P.tkPos * declClass * ctype * linkage
(* Objects are in reverse order *)
datatype def = Objects of objDef list | Definition of funcInfo
val createCtx: string -> string list -> string option -> ctx
val parseDef: ctx -> bool * ctx
val printDef: def -> unit
val alignOfType: ctype -> word
val sizeOfType: ctype -> word
val isFunc: ctype -> bool
val isSigned: ctype -> bool
val isPointer: ctype -> bool
val pointsTo: ctype -> ctype
val isArray: ctype -> bool
val elementType: ctype -> ctype
val typeRank: ctype -> int
val resolveType: ctype -> ctype
val commonType: ctype -> ctype -> ctype
val getLayoutSize: int -> word
val extz: word -> word -> word
val exts: word -> word -> word
val getT: exprAug -> ctype
val funcParts: ctype -> ctype * ctype list
val Pctype: (ctype, 'a, 'b, 'c) a1printer
val getFieldInfo: ctype -> nid -> (word * ctype) option
val finalize: ctx -> ctx
type progInfo = {
ext: nid list,
glob: nid list,
objsZI: objDef list,
objs: objDef list,
funcs: funcInfo list,
strlits: int list
}
val explode: ctx -> progInfo
end
|