Skip to content

Commit 2cd07e6

Browse files
gretay-jsmshinwell
authored andcommitted
Replace tuple with record in Cextcall (#10)
1 parent 2fca196 commit 2cd07e6

File tree

10 files changed

+74
-40
lines changed

10 files changed

+74
-40
lines changed

backend/afl_instrument.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ let instrument_initialiser c dbg =
103103
calls *)
104104
with_afl_logging
105105
(Csequence
106-
(Cop (Cextcall ("caml_setup_afl", typ_int, false, None),
106+
(Cop (Cextcall { name = "caml_setup_afl";
107+
ret = typ_int; alloc = false; label_after = None; },
107108
[Cconst_int (0, dbg ())],
108109
dbg ()),
109110
c))

backend/amd64/selection.ml

+7-7
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ method is_immediate_natint n = n <= 0x7FFFFFFFn && n >= -0x80000000n
135135

136136
method! is_simple_expr e =
137137
match e with
138-
| Cop(Cextcall (fn, _, _, _), args, _)
138+
| Cop(Cextcall { name = fn; }, args, _)
139139
when List.mem fn inline_ops ->
140140
(* inlined ops are simple if their arguments are *)
141141
List.for_all self#is_simple_expr args
@@ -144,7 +144,7 @@ method! is_simple_expr e =
144144

145145
method! effects_of e =
146146
match e with
147-
| Cop(Cextcall(fn, _, _, _), args, _)
147+
| Cop(Cextcall { name = fn; }, args, _)
148148
when List.mem fn inline_ops ->
149149
Selectgen.Effect_and_coeffect.join_list_map args self#effects_of
150150
| _ ->
@@ -201,7 +201,7 @@ method! select_operation op args dbg =
201201
self#select_floatarith true Imulf Ifloatmul args
202202
| Cdivf ->
203203
self#select_floatarith false Idivf Ifloatdiv args
204-
| Cextcall("sqrt", _, false, _) ->
204+
| Cextcall { name = "sqrt"; alloc = false; } ->
205205
begin match args with
206206
[Cop(Cload ((Double|Double_u as chunk), _), [loc], _dbg)] ->
207207
let (addr, arg) = self#select_addressing chunk loc in
@@ -221,12 +221,12 @@ method! select_operation op args dbg =
221221
| _ ->
222222
super#select_operation op args dbg
223223
end
224-
| Cextcall("caml_bswap16_direct", _, _, _) ->
224+
| Cextcall { name = "caml_bswap16_direct"; } ->
225225
(Ispecific (Ibswap 16), args)
226-
| Cextcall("caml_int32_direct_bswap", _, _, _) ->
226+
| Cextcall { name = "caml_int32_direct_bswap"; } ->
227227
(Ispecific (Ibswap 32), args)
228-
| Cextcall("caml_int64_direct_bswap", _, _, _)
229-
| Cextcall("caml_nativeint_direct_bswap", _, _, _) ->
228+
| Cextcall { name = "caml_int64_direct_bswap"; }
229+
| Cextcall { name = "caml_nativeint_direct_bswap"; } ->
230230
(Ispecific (Ibswap 64), args)
231231
(* AMD64 does not support immediate operands for multiply high signed *)
232232
| Cmulhi ->

backend/cmm.ml

+8-3
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,14 @@ type memory_chunk =
135135

136136
and operation =
137137
Capply of machtype
138-
| Cextcall of string * machtype * bool * label option
139-
(** If specified, the given label will be placed immediately after the
140-
call (at the same place as any frame descriptor would reference). *)
138+
| Cextcall of
139+
{ name: string;
140+
ret: machtype;
141+
alloc: bool;
142+
label_after: label option;
143+
(** If specified, the given label will be placed immediately after the
144+
call (at the same place as any frame descriptor would reference). *)
145+
}
141146
| Cload of memory_chunk * Asttypes.mutable_flag
142147
| Calloc
143148
| Cstore of memory_chunk * Lambda.initialization_or_assignment

backend/cmm.mli

+8-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,14 @@ type memory_chunk =
129129

130130
and operation =
131131
Capply of machtype
132-
| Cextcall of string * machtype * bool * label option
132+
| Cextcall of
133+
{ name: string;
134+
ret: machtype;
135+
alloc: bool;
136+
label_after: label option;
137+
(** If specified, the given label will be placed immediately after the
138+
call (at the same place as any frame descriptor would reference). *)
139+
}
133140
| Cload of memory_chunk * Asttypes.mutable_flag
134141
| Calloc
135142
| Cstore of memory_chunk * Lambda.initialization_or_assignment

backend/cmm_helpers.ml

+22-12
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,8 @@ let rec remove_unit = function
604604
Clet(id, c1, remove_unit c2)
605605
| Cop(Capply _mty, args, dbg) ->
606606
Cop(Capply typ_void, args, dbg)
607-
| Cop(Cextcall(proc, _mty, alloc, label_after), args, dbg) ->
608-
Cop(Cextcall(proc, typ_void, alloc, label_after), args, dbg)
607+
| Cop(Cextcall c, args, dbg) ->
608+
Cop(Cextcall {c with ret = typ_void}, args, dbg)
609609
| Cexit (_,_) as c -> c
610610
| Ctuple [] as c -> c
611611
| c -> Csequence(c, Ctuple [])
@@ -727,10 +727,12 @@ let float_array_ref arr ofs dbg =
727727
box_float dbg (unboxed_float_array_ref arr ofs dbg)
728728

729729
let addr_array_set arr ofs newval dbg =
730-
Cop(Cextcall("caml_modify", typ_void, false, None),
730+
Cop(Cextcall { name = "caml_modify"; ret = typ_void; alloc = false;
731+
label_after = None},
731732
[array_indexing log2_size_addr arr ofs dbg; newval], dbg)
732733
let addr_array_initialize arr ofs newval dbg =
733-
Cop(Cextcall("caml_initialize", typ_void, false, None),
734+
Cop(Cextcall { name = "caml_initialize";
735+
ret = typ_void; alloc = false; label_after = None},
734736
[array_indexing log2_size_addr arr ofs dbg; newval], dbg)
735737
let int_array_set arr ofs newval dbg =
736738
Cop(Cstore (Word_int, Lambda.Assignment),
@@ -766,7 +768,8 @@ let bigstring_length ba dbg =
766768

767769
let lookup_tag obj tag dbg =
768770
bind "tag" tag (fun tag ->
769-
Cop(Cextcall("caml_get_public_method", typ_val, false, None),
771+
Cop(Cextcall { name = "caml_get_public_method"; ret = typ_val;
772+
alloc = false; label_after = None },
770773
[obj; tag],
771774
dbg))
772775

@@ -796,14 +799,16 @@ let make_alloc_generic set_fn dbg tag wordsize args =
796799
| e1::el -> Csequence(set_fn (Cvar id) (Cconst_int (idx, dbg)) e1 dbg,
797800
fill_fields (idx + 2) el) in
798801
Clet(VP.create id,
799-
Cop(Cextcall("caml_alloc", typ_val, true, None),
802+
Cop(Cextcall { name = "caml_alloc"; ret = typ_val; alloc = true;
803+
label_after = None },
800804
[Cconst_int (wordsize, dbg); Cconst_int (tag, dbg)], dbg),
801805
fill_fields 1 args)
802806
end
803807

804808
let make_alloc dbg tag args =
805809
let addr_array_init arr ofs newval dbg =
806-
Cop(Cextcall("caml_initialize", typ_void, false, None),
810+
Cop(Cextcall { name = "caml_initialize"; ret = typ_void; alloc = false;
811+
label_after = None },
807812
[array_indexing log2_size_addr arr ofs dbg; newval], dbg)
808813
in
809814
make_alloc_generic addr_array_init dbg tag (List.length args) args
@@ -2141,13 +2146,14 @@ let bbswap bi arg dbg =
21412146
| Pint32 -> "int32"
21422147
| Pint64 -> "int64"
21432148
in
2144-
Cop(Cextcall(Printf.sprintf "caml_%s_direct_bswap" prim,
2145-
typ_int, false, None),
2149+
Cop(Cextcall { name = Printf.sprintf "caml_%s_direct_bswap" prim;
2150+
ret = typ_int; alloc = false; label_after = None; },
21462151
[arg],
21472152
dbg)
21482153

21492154
let bswap16 arg dbg =
2150-
(Cop(Cextcall("caml_bswap16_direct", typ_int, false, None),
2155+
(Cop(Cextcall { name = "caml_bswap16_direct";
2156+
ret = typ_int; alloc = false; label_after = None; },
21512157
[arg],
21522158
dbg))
21532159

@@ -2172,12 +2178,16 @@ let assignment_kind
21722178
let setfield n ptr init arg1 arg2 dbg =
21732179
match assignment_kind ptr init with
21742180
| Caml_modify ->
2175-
return_unit dbg (Cop(Cextcall("caml_modify", typ_void, false, None),
2181+
return_unit dbg (Cop(Cextcall { name = "caml_modify";
2182+
ret = typ_void; alloc = false;
2183+
label_after = None },
21762184
[field_address arg1 n dbg;
21772185
arg2],
21782186
dbg))
21792187
| Caml_initialize ->
2180-
return_unit dbg (Cop(Cextcall("caml_initialize", typ_void, false, None),
2188+
return_unit dbg (Cop(Cextcall { name = "caml_initialize";
2189+
ret = typ_void; alloc = false;
2190+
label_after = None },
21812191
[field_address arg1 n dbg;
21822192
arg2],
21832193
dbg))

backend/cmmgen.ml

+11-5
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,8 @@ and transl_catch env nfail ids body handler dbg =
735735
and transl_make_array dbg env kind args =
736736
match kind with
737737
| Pgenarray ->
738-
Cop(Cextcall("caml_make_array", typ_val, true, None),
738+
Cop(Cextcall { name = "caml_make_array";
739+
ret = typ_val; alloc = true; label_after = None},
739740
[make_alloc dbg 0 (List.map (transl env) args)], dbg)
740741
| Paddrarray | Pintarray ->
741742
make_alloc dbg 0 (List.map (transl env) args)
@@ -772,8 +773,10 @@ and transl_ccall env prim args dbg =
772773
in
773774
let args = transl_args prim.prim_native_repr_args args in
774775
wrap_result
775-
(Cop(Cextcall(Primitive.native_name prim,
776-
typ_res, prim.prim_alloc, None), args, dbg))
776+
(Cop(Cextcall { name = Primitive.native_name prim;
777+
ret = typ_res; alloc = prim.prim_alloc;
778+
label_after = None },
779+
args, dbg))
777780

778781
and transl_prim_1 env p arg dbg =
779782
match p with
@@ -1315,7 +1318,9 @@ and transl_letrec env bindings cont =
13151318
bindings
13161319
in
13171320
let op_alloc prim args =
1318-
Cop(Cextcall(prim, typ_val, true, None), args, dbg) in
1321+
Cop(Cextcall { name = prim; ret = typ_val; alloc = true;
1322+
label_after = None },
1323+
args, dbg) in
13191324
let rec init_blocks = function
13201325
| [] -> fill_nonrec bsz
13211326
| (id, _exp, RHS_block sz) :: rem ->
@@ -1341,7 +1346,8 @@ and transl_letrec env bindings cont =
13411346
| [] -> cont
13421347
| (id, exp, (RHS_block _ | RHS_infix _ | RHS_floatblock _)) :: rem ->
13431348
let op =
1344-
Cop(Cextcall("caml_update_dummy", typ_void, false, None),
1349+
Cop(Cextcall { name = "caml_update_dummy"; ret = typ_void;
1350+
alloc = false; label_after = None },
13451351
[Cvar (VP.var id); transl env exp], dbg) in
13461352
Csequence(op, fill_blocks rem)
13471353
| (_id, _exp, RHS_nonrec) :: rem ->

backend/printcmm.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ let location d =
101101

102102
let operation d = function
103103
| Capply _ty -> "app" ^ location d
104-
| Cextcall(lbl, _ty, _alloc, _) ->
104+
| Cextcall { name = lbl; _ } ->
105105
Printf.sprintf "extcall \"%s\"%s" lbl (location d)
106106
| Cload (c, Asttypes.Immutable) -> Printf.sprintf "load %s" (chunk c)
107107
| Cload (c, Asttypes.Mutable) -> Printf.sprintf "load_mut %s" (chunk c)
@@ -212,7 +212,7 @@ let rec expr ppf = function
212212
List.iter (fun e -> fprintf ppf "@ %a" expr e) el;
213213
begin match op with
214214
| Capply mty -> fprintf ppf "@ %a" machtype mty
215-
| Cextcall(_, mty, _, _) -> fprintf ppf "@ %a" machtype mty
215+
| Cextcall { ret=mty } -> fprintf ppf "@ %a" machtype mty
216216
| _ -> ()
217217
end;
218218
fprintf ppf ")@]"

backend/selectgen.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ let env_empty = {
6666

6767
let oper_result_type = function
6868
Capply ty -> ty
69-
| Cextcall(_s, ty, _alloc, _) -> ty
69+
| Cextcall { ret = ty; } -> ty
7070
| Cload (c, _) ->
7171
begin match c with
7272
| Word_val -> typ_val
@@ -451,7 +451,7 @@ method select_operation op args _dbg =
451451
| (Capply _, _) ->
452452
let label_after = Cmm.new_label () in
453453
(Icall_ind { label_after; }, args)
454-
| (Cextcall(func, _ty, alloc, label_after), _) ->
454+
| (Cextcall { name = func; alloc; label_after; }, _) ->
455455
let label_after =
456456
match label_after with
457457
| None -> Cmm.new_label ()

backend/spacetime_profiling.ml

+9-6
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,10 @@ let code_for_function_prologue ~function_name ~fun_dbg:dbg ~node_hole =
110110
dbg,
111111
Clet (VP.create is_new_node,
112112
Clet (VP.create pc, cconst_symbol function_name,
113-
Cop (Cextcall ("caml_spacetime_allocate_node",
114-
[| Int |], false, None),
113+
Cop (Cextcall { name = "caml_spacetime_allocate_node";
114+
ret = [| Int |];
115+
alloc = false;
116+
label_after = None},
115117
[cconst_int (1 (* header *) + !index_within_node);
116118
Cvar pc;
117119
Cvar node_hole;
@@ -151,8 +153,9 @@ let code_for_blockheader ~value's_header ~node ~dbg =
151153
the latter table to be used for resolving a program counter at such
152154
a point to a location.
153155
*)
154-
Cop (Cextcall ("caml_spacetime_generate_profinfo", [| Int |],
155-
false, Some label),
156+
Cop (Cextcall { name = "caml_spacetime_generate_profinfo";
157+
ret = [| Int |];
158+
alloc = false; label_after = Some label },
156159
[Cvar address_of_profinfo;
157160
cconst_int (index_within_node + 1)],
158161
dbg)
@@ -271,8 +274,8 @@ let code_for_call ~node ~callee ~is_tail ~label dbg =
271274
if is_tail then node
272275
else cconst_int 1 (* [Val_unit] *)
273276
in
274-
Cop (Cextcall ("caml_spacetime_indirect_node_hole_ptr",
275-
[| Int |], false, None),
277+
Cop (Cextcall { name = "caml_spacetime_indirect_node_hole_ptr";
278+
ret = [| Int |]; alloc = false; label_after = None },
276279
[callee; Cvar place_within_node; caller_node],
277280
dbg))
278281

ocaml/testsuite/tools/parsecmm.mly

+3-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,9 @@ expr:
220220
| LPAREN APPLY location expr exprlist machtype RPAREN
221221
{ Cop(Capply $6, $4 :: List.rev $5, debuginfo ?loc:$3 ()) }
222222
| LPAREN EXTCALL STRING exprlist machtype RPAREN
223-
{Cop(Cextcall($3, $5, false, None), List.rev $4, debuginfo ())}
223+
{Cop(Cextcall {name=$3; ret=$5; alloc=false;
224+
label_after=None},
225+
List.rev $4, debuginfo ())}
224226
| LPAREN ALLOC exprlist RPAREN { Cop(Calloc, List.rev $3, debuginfo ()) }
225227
| LPAREN SUBF expr RPAREN { Cop(Cnegf, [$3], debuginfo ()) }
226228
| LPAREN SUBF expr expr RPAREN { Cop(Csubf, [$3; $4], debuginfo ()) }

0 commit comments

Comments
 (0)