-
Notifications
You must be signed in to change notification settings - Fork 1
/
annotated.ml
141 lines (116 loc) · 2.32 KB
/
annotated.ml
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
(* First IR, where each block is annotated with the local
* variables modified in the block (and any sub-blocks).
*
* Also strips out positional information (hurrah!)
*
* Used for generating efficient SSA. *)
open Libwasm.Types
type var = int32
type literal = Libwasm.Values.value
type name = int list
type block_info = {
block_stack_ty: stack_type;
block_mutated_locals: var list;
block_instrs: instr list
}
and conditional_info = {
conditional_stack_ty: stack_type;
conditional_mutated_locals: var list;
conditional_true_instrs: instr list;
conditional_false_instrs: instr list
}
and instr =
| Unreachable
| Nop
| Drop
| Select
| Block of block_info
| Loop of block_info
| If of conditional_info
| Br of var
| BrIf of var
| BrTable of var list * var
| Return
| Call of var
| CallIndirect of var
| GetLocal of var
| SetLocal of var
| TeeLocal of var
| GetGlobal of var
| SetGlobal of var
| Load of Libwasm.Ast.loadop
| Store of Libwasm.Ast.storeop
| MemorySize
| MemoryGrow
| Const of literal
| Test of Libwasm.Ast.testop
| Compare of Libwasm.Ast.relop
| Unary of Libwasm.Ast.unop
| Binary of Libwasm.Ast.binop
| Convert of Libwasm.Ast.cvtop
(* Globals & Functions *)
type const = instr list
and global =
{
gtype : global_type;
value : const;
}
and func =
{
ftype : var;
locals : value_type list;
body : instr list;
}
(* Tables & Memories *)
type table =
{
ttype : table_type;
}
type memory =
{
mtype : memory_type;
}
type 'data segment =
{
index : var;
offset : const;
init : 'data;
}
type table_segment = var list segment
type memory_segment = string segment
(* Modules *)
type type_ = func_type
type export_desc =
| FuncExport of var
| TableExport of var
| MemoryExport of var
| GlobalExport of var
type export =
{
name : name;
edesc : export_desc;
}
type import_desc =
| FuncImport of var
| TableImport of table_type
| MemoryImport of memory_type
| GlobalImport of global_type
type import =
{
module_name : name;
item_name : name;
idesc : import_desc;
}
type module_ =
{
types : type_ list;
globals : global list;
tables : table list;
memories : memory list;
funcs : func list;
start : var option;
elems : var list segment list;
data : string segment list;
imports : import list;
exports : export list;
}