blob: f052e03cde81d5768b6e4719a157ab4e1712ebef (
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
|
(************************************************************************)
(* * The Coq Proof Assistant / The Coq Development Team *)
(* v * Copyright INRIA, CNRS and contributors *)
(* <O___,, * (see version control and CREDITS file for authors & dates) *)
(* \VV/ **************************************************************)
(* // * This file is distributed under the terms of the *)
(* * GNU Lesser General Public License Version 2.1 *)
(* * (see LICENSE file for the text of the license) *)
(************************************************************************)
(** List of opcodes.
It is used to generate the [coq_instruct.h], [coq_jumptbl.h] and
[vmopcodes.ml] files.
If adding an instruction, DON'T FORGET TO UPDATE coq_fix_code.c
with the arity of the instruction and maybe coq_tcode_of_code.
*)
let opcodes =
[|
"ACC0";
"ACC1";
"ACC2";
"ACC3";
"ACC4";
"ACC5";
"ACC6";
"ACC7";
"ACC";
"PUSH";
"PUSHACC0";
"PUSHACC1";
"PUSHACC2";
"PUSHACC3";
"PUSHACC4";
"PUSHACC5";
"PUSHACC6";
"PUSHACC7";
"PUSHACC";
"POP";
"ENVACC0";
"ENVACC1";
"ENVACC2";
"ENVACC3";
"ENVACC";
"PUSHENVACC0";
"PUSHENVACC1";
"PUSHENVACC2";
"PUSHENVACC3";
"PUSHENVACC";
"PUSH_RETADDR";
"APPLY";
"APPLY1";
"APPLY2";
"APPLY3";
"APPLY4";
"APPTERM";
"APPTERM1";
"APPTERM2";
"APPTERM3";
"RETURN";
"RESTART";
"GRAB";
"GRABREC";
"CLOSURE";
"CLOSUREREC";
"CLOSURECOFIX";
"OFFSETCLOSURE0";
"OFFSETCLOSURE1";
"OFFSETCLOSURE";
"PUSHOFFSETCLOSURE0";
"PUSHOFFSETCLOSURE1";
"PUSHOFFSETCLOSURE";
"GETGLOBAL";
"PUSHGETGLOBAL";
"MAKEBLOCK";
"MAKEBLOCK1";
"MAKEBLOCK2";
"MAKEBLOCK3";
"MAKEBLOCK4";
"SWITCH";
"PUSHFIELDS";
"GETFIELD0";
"GETFIELD1";
"GETFIELD";
"SETFIELD0";
"SETFIELD1";
"SETFIELD";
"PROJ";
"ENSURESTACKCAPACITY";
"CONST0";
"CONST1";
"CONST2";
"CONST3";
"CONSTINT";
"PUSHCONST0";
"PUSHCONST1";
"PUSHCONST2";
"PUSHCONST3";
"PUSHCONSTINT";
"ACCUMULATE";
"MAKESWITCHBLOCK";
"MAKEACCU";
"MAKEPROD";
"BRANCH";
"CHECKADDINT63";
"ADDINT63";
"CHECKADDCINT63";
"CHECKADDCARRYCINT63";
"CHECKSUBINT63";
"SUBINT63";
"CHECKSUBCINT63";
"CHECKSUBCARRYCINT63";
"CHECKMULINT63";
"CHECKMULCINT63";
"CHECKDIVINT63";
"CHECKMODINT63";
"CHECKDIVEUCLINT63";
"CHECKDIV21INT63";
"CHECKLXORINT63";
"CHECKLORINT63";
"CHECKLANDINT63";
"CHECKLSLINT63";
"CHECKLSRINT63";
"CHECKADDMULDIVINT63";
"CHECKLSLINT63CONST1";
"CHECKLSRINT63CONST1";
"CHECKEQINT63";
"CHECKLTINT63";
"LTINT63";
"CHECKLEINT63";
"LEINT63";
"CHECKCOMPAREINT63";
"CHECKHEAD0INT63";
"CHECKTAIL0INT63";
"ISINT";
"AREINT2";
"CHECKOPPFLOAT";
"CHECKABSFLOAT";
"CHECKEQFLOAT";
"CHECKLTFLOAT";
"LTFLOAT";
"CHECKLEFLOAT";
"LEFLOAT";
"CHECKCOMPAREFLOAT";
"CHECKCLASSIFYFLOAT";
"CHECKADDFLOAT";
"CHECKSUBFLOAT";
"CHECKMULFLOAT";
"CHECKDIVFLOAT";
"CHECKSQRTFLOAT";
"CHECKFLOATOFINT63";
"CHECKFLOATNORMFRMANTISSA";
"CHECKFRSHIFTEXP";
"CHECKLDSHIFTEXP";
"CHECKNEXTUPFLOAT";
"CHECKNEXTDOWNFLOAT";
"ISINT_CAML_CALL2";
"ISARRAY_CAML_CALL1";
"ISARRAY_INT_CAML_CALL2";
"ISARRAY_INT_CAML_CALL3";
"STOP"
|]
let pp_c_comment fmt =
Format.fprintf fmt "/* %a */"
let pp_ocaml_comment fmt =
Format.fprintf fmt "(* %a *)"
let pp_header isOcaml fmt =
Format.fprintf fmt "%a"
(fun fmt ->
(if isOcaml then pp_ocaml_comment else pp_c_comment) fmt
Format.pp_print_string)
"DO NOT EDIT: automatically generated by kernel/genOpcodeFiles.ml"
let pp_with_commas fmt k =
Array.iteri (fun n s ->
Format.fprintf fmt " %a%s@."
k s
(if n + 1 < Array.length opcodes
then "," else "")
) opcodes
let pp_coq_instruct_h fmt =
let line = Format.fprintf fmt "%s@." in
pp_header false fmt;
line "#pragma once";
line "enum instructions {";
pp_with_commas fmt Format.pp_print_string;
line "};"
let pp_coq_jumptbl_h fmt =
pp_with_commas fmt (fun fmt -> Format.fprintf fmt "&&coq_lbl_%s")
let pp_vmopcodes_ml fmt =
pp_header true fmt;
Array.iteri (fun n s ->
Format.fprintf fmt "let op%s = %d@.@." s n
) opcodes
let usage () =
Format.eprintf "usage: %s [enum|jump|copml]@." Sys.argv.(0);
exit 1
let main () =
match Sys.argv.(1) with
| "enum" -> pp_coq_instruct_h Format.std_formatter
| "jump" -> pp_coq_jumptbl_h Format.std_formatter
| "copml" -> pp_vmopcodes_ml Format.std_formatter
| _ -> usage ()
| exception Invalid_argument _ -> usage ()
let () = main ()
|