13
13
(* *)
14
14
(* *************************************************************************)
15
15
16
- type machtype_component =
16
+ type machtype_component = Cmx_format .machtype_component =
17
17
| Val
18
18
| Addr
19
19
| Int
@@ -173,6 +173,12 @@ and operation =
173
173
| Copaque
174
174
| Cbeginregion | Cendregion
175
175
176
+ type value_kind =
177
+ | Vval of Lambda .value_kind (* Valid OCaml values *)
178
+ | Vint (* Untagged integers and off-heap pointers *)
179
+ | Vaddr (* Derived pointers *)
180
+ | Vfloat (* Unboxed floating-point numbers *)
181
+
176
182
type expression =
177
183
Cconst_int of int * Debuginfo .t
178
184
| Cconst_natint of nativeint * Debuginfo .t
@@ -189,17 +195,17 @@ type expression =
189
195
| Cop of operation * expression list * Debuginfo .t
190
196
| Csequence of expression * expression
191
197
| Cifthenelse of expression * Debuginfo .t * expression
192
- * Debuginfo .t * expression * Debuginfo .t
198
+ * Debuginfo .t * expression * Debuginfo .t * value_kind
193
199
| Cswitch of expression * int array * (expression * Debuginfo .t ) array
194
- * Debuginfo .t
200
+ * Debuginfo .t * value_kind
195
201
| Ccatch of
196
202
rec_flag
197
203
* (int * (Backend_var.With_provenance .t * machtype ) list
198
204
* expression * Debuginfo .t ) list
199
- * expression
205
+ * expression * value_kind
200
206
| Cexit of int * expression list
201
207
| Ctrywith of expression * Backend_var.With_provenance .t * expression
202
- * Debuginfo .t
208
+ * Debuginfo .t * value_kind
203
209
| Cregion of expression
204
210
| Ctail of expression
205
211
@@ -234,8 +240,8 @@ type phrase =
234
240
Cfunction of fundecl
235
241
| Cdata of data_item list
236
242
237
- let ccatch (i , ids , e1 , e2 , dbg ) =
238
- Ccatch (Nonrecursive , [i, ids, e2, dbg], e1)
243
+ let ccatch (i , ids , e1 , e2 , dbg , kind ) =
244
+ Ccatch (Nonrecursive , [i, ids, e2, dbg], e1, kind )
239
245
240
246
let reset () =
241
247
label_counter := init_label
@@ -244,21 +250,21 @@ let iter_shallow_tail f = function
244
250
| Clet (_ , _ , body ) | Cphantom_let (_ , _ , body ) | Clet_mut (_ , _ , _ , body ) ->
245
251
f body;
246
252
true
247
- | Cifthenelse (_cond , _ifso_dbg , ifso , _ifnot_dbg , ifnot , _dbg ) ->
253
+ | Cifthenelse (_cond , _ifso_dbg , ifso , _ifnot_dbg , ifnot , _dbg , _value_kind ) ->
248
254
f ifso;
249
255
f ifnot;
250
256
true
251
257
| Csequence (_e1 , e2 ) ->
252
258
f e2;
253
259
true
254
- | Cswitch (_e , _tbl , el , _dbg' ) ->
260
+ | Cswitch (_e , _tbl , el , _dbg' , _value_kind ) ->
255
261
Array. iter (fun (e , _dbg ) -> f e) el;
256
262
true
257
- | Ccatch (_rec_flag , handlers , body ) ->
263
+ | Ccatch (_rec_flag , handlers , body , _value_kind ) ->
258
264
List. iter (fun (_ , _ , h , _dbg ) -> f h) handlers;
259
265
f body;
260
266
true
261
- | Ctrywith (e1 , _id , e2 , _dbg ) ->
267
+ | Ctrywith (e1 , _id , e2 , _dbg , _value_kind ) ->
262
268
f e1;
263
269
f e2;
264
270
true
@@ -280,30 +286,34 @@ let iter_shallow_tail f = function
280
286
| Cop _ ->
281
287
false
282
288
283
- let map_shallow_tail f = function
289
+ let map_shallow_tail ? kind f = function
284
290
| Clet (id , exp , body ) ->
285
291
Clet (id, exp, f body)
286
292
| Clet_mut (id , kind , exp , body ) ->
287
293
Clet_mut (id, kind, exp, f body)
288
294
| Cphantom_let (id , exp , body ) ->
289
295
Cphantom_let (id, exp, f body)
290
- | Cifthenelse (cond , ifso_dbg , ifso , ifnot_dbg , ifnot , dbg ) ->
296
+ | Cifthenelse (cond , ifso_dbg , ifso , ifnot_dbg , ifnot , dbg , kind_before ) ->
291
297
Cifthenelse
292
298
(
293
299
cond,
294
300
ifso_dbg, f ifso,
295
301
ifnot_dbg, f ifnot,
296
- dbg
302
+ dbg,
303
+ Option. value kind ~default: kind_before
297
304
)
298
305
| Csequence (e1 , e2 ) ->
299
306
Csequence (e1, f e2)
300
- | Cswitch (e , tbl , el , dbg' ) ->
301
- Cswitch (e, tbl, Array. map (fun (e , dbg ) -> f e, dbg) el, dbg')
302
- | Ccatch (rec_flag , handlers , body ) ->
307
+ | Cswitch (e , tbl , el , dbg' , kind_before ) ->
308
+ Cswitch (e, tbl, Array. map (fun (e , dbg ) -> f e, dbg) el, dbg',
309
+ Option. value kind ~default: kind_before)
310
+ | Ccatch (rec_flag , handlers , body , kind_before ) ->
303
311
let map_h (n , ids , handler , dbg ) = (n, ids, f handler, dbg) in
304
- Ccatch (rec_flag, List. map map_h handlers, f body)
305
- | Ctrywith (e1 , id , e2 , dbg ) ->
306
- Ctrywith (f e1, id, f e2, dbg)
312
+ Ccatch (rec_flag, List. map map_h handlers, f body,
313
+ Option. value kind ~default: kind_before)
314
+ | Ctrywith (e1 , id , e2 , dbg , kind_before ) ->
315
+ Ctrywith (f e1, id, f e2, dbg,
316
+ Option. value kind ~default: kind_before)
307
317
| Cregion e ->
308
318
Cregion (f e)
309
319
| Ctail e ->
@@ -319,7 +329,7 @@ let map_shallow_tail f = function
319
329
| Ctuple _
320
330
| Cop _ as cmm -> cmm
321
331
322
- let map_tail f =
332
+ let map_tail ? kind f =
323
333
let rec loop = function
324
334
| Cconst_int _
325
335
| Cconst_natint _
@@ -330,7 +340,7 @@ let map_tail f =
330
340
| Ctuple _
331
341
| Cop _ as c ->
332
342
f c
333
- | cmm -> map_shallow_tail loop cmm
343
+ | cmm -> map_shallow_tail ?kind loop cmm
334
344
in
335
345
loop
336
346
@@ -349,16 +359,16 @@ let iter_shallow f = function
349
359
List. iter f el
350
360
| Csequence (e1 , e2 ) ->
351
361
f e1; f e2
352
- | Cifthenelse (cond , _ifso_dbg , ifso , _ifnot_dbg , ifnot , _dbg ) ->
362
+ | Cifthenelse (cond , _ifso_dbg , ifso , _ifnot_dbg , ifnot , _dbg , _value_kind ) ->
353
363
f cond; f ifso; f ifnot
354
- | Cswitch (_e , _ia , ea , _dbg ) ->
364
+ | Cswitch (_e , _ia , ea , _dbg , _value_kind ) ->
355
365
Array. iter (fun (e , _ ) -> f e) ea
356
- | Ccatch (_rf , hl , body ) ->
366
+ | Ccatch (_rf , hl , body , _value_kind ) ->
357
367
let iter_h (_n , _ids , handler , _dbg ) = f handler in
358
368
List. iter iter_h hl; f body
359
369
| Cexit (_n , el ) ->
360
370
List. iter f el
361
- | Ctrywith (e1 , _id , e2 , _dbg ) ->
371
+ | Ctrywith (e1 , _id , e2 , _dbg , _value_kind ) ->
362
372
f e1; f e2
363
373
| Cregion e ->
364
374
f e
@@ -386,17 +396,17 @@ let map_shallow f = function
386
396
Cop (op, List. map f el, dbg)
387
397
| Csequence (e1 , e2 ) ->
388
398
Csequence (f e1, f e2)
389
- | Cifthenelse (cond , ifso_dbg , ifso , ifnot_dbg , ifnot , dbg ) ->
390
- Cifthenelse (f cond, ifso_dbg, f ifso, ifnot_dbg, f ifnot, dbg)
391
- | Cswitch (e , ia , ea , dbg ) ->
392
- Cswitch (e, ia, Array. map (fun (e , dbg ) -> f e, dbg) ea, dbg)
393
- | Ccatch (rf , hl , body ) ->
399
+ | Cifthenelse (cond , ifso_dbg , ifso , ifnot_dbg , ifnot , dbg , kind ) ->
400
+ Cifthenelse (f cond, ifso_dbg, f ifso, ifnot_dbg, f ifnot, dbg, kind )
401
+ | Cswitch (e , ia , ea , dbg , kind ) ->
402
+ Cswitch (e, ia, Array. map (fun (e , dbg ) -> f e, dbg) ea, dbg, kind )
403
+ | Ccatch (rf , hl , body , kind ) ->
394
404
let map_h (n , ids , handler , dbg ) = (n, ids, f handler, dbg) in
395
- Ccatch (rf, List. map map_h hl, f body)
405
+ Ccatch (rf, List. map map_h hl, f body, kind )
396
406
| Cexit (n , el ) ->
397
407
Cexit (n, List. map f el)
398
- | Ctrywith (e1 , id , e2 , dbg ) ->
399
- Ctrywith (f e1, id, f e2, dbg)
408
+ | Ctrywith (e1 , id , e2 , dbg , value_kind ) ->
409
+ Ctrywith (f e1, id, f e2, dbg, value_kind )
400
410
| Cregion e ->
401
411
Cregion (f e)
402
412
| Ctail e ->
0 commit comments