Skip to content

Commit 2414419

Browse files
gretay-jspoechsel
authored andcommitted
Replace tuple with record in Cextcall (#10)
1 parent 2912fd7 commit 2414419

File tree

9 files changed

+71
-44
lines changed

9 files changed

+71
-44
lines changed

backend/afl_instrument.ml

Lines changed: 2 additions & 1 deletion
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),
106+
(Cop (Cextcall { name = "caml_setup_afl";
107+
ret = typ_int; alloc = false; ty_args = []; },
107108
[Cconst_int (0, dbg ())],
108109
dbg ()),
109110
c))

backend/amd64/selection.ml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ method is_immediate_test _cmp n = is_immediate n
142142

143143
method! is_simple_expr e =
144144
match e with
145-
| Cop(Cextcall (fn, _, _, _), args, _)
145+
| Cop(Cextcall { name = fn; }, args, _)
146146
when List.mem fn inline_ops ->
147147
(* inlined ops are simple if their arguments are *)
148148
List.for_all self#is_simple_expr args
@@ -151,7 +151,7 @@ method! is_simple_expr e =
151151

152152
method! effects_of e =
153153
match e with
154-
| Cop(Cextcall(fn, _, _, _), args, _)
154+
| Cop(Cextcall { name = fn; }, args, _)
155155
when List.mem fn inline_ops ->
156156
Selectgen.Effect_and_coeffect.join_list_map args self#effects_of
157157
| _ ->
@@ -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
(* Recognize sign extension *)
232232
| Casr ->

backend/cmm.ml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,12 @@ type memory_chunk =
150150

151151
and operation =
152152
Capply of machtype
153-
| Cextcall of string * machtype * exttype list * bool
153+
| Cextcall of
154+
{ name : string;
155+
ret : machtype;
156+
ty_args : exttype list;
157+
alloc : bool;
158+
}
154159
| Cload of memory_chunk * Asttypes.mutable_flag
155160
| Calloc
156161
| Cstore of memory_chunk * Lambda.initialization_or_assignment

backend/cmm.mli

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,15 @@ type memory_chunk =
140140

141141
and operation =
142142
Capply of machtype
143-
| Cextcall of string * machtype * exttype list * bool
144-
(** The [machtype] is the machine type of the result.
145-
The [exttype list] describes the unboxing types of the arguments.
146-
An empty list means "all arguments are machine words [XInt]". *)
143+
| Cextcall of
144+
{ name : string;
145+
ret : machtype;
146+
ty_args : exttype list;
147+
alloc : bool;
148+
}
149+
(** The [machtype] is the machine type of the result.
150+
The [exttype list] describes the unboxing types of the arguments.
151+
An empty list means "all arguments are machine words [XInt]". *)
147152
| Cload of memory_chunk * Asttypes.mutable_flag
148153
| Calloc
149154
| Cstore of memory_chunk * Lambda.initialization_or_assignment

backend/cmm_helpers.ml

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,8 @@ let rec remove_unit = function
611611
Clet(id, c1, remove_unit c2)
612612
| Cop(Capply _mty, args, dbg) ->
613613
Cop(Capply typ_void, args, dbg)
614-
| Cop(Cextcall(proc, _ty_res, ty_args, alloc), args, dbg) ->
615-
Cop(Cextcall(proc, typ_void, ty_args, alloc), args, dbg)
614+
| Cop(Cextcall c, args, dbg) ->
615+
Cop(Cextcall {c with ret = typ_void; }, args, dbg)
616616
| Cexit (_,_) as c -> c
617617
| Ctuple [] as c -> c
618618
| c -> Csequence(c, Ctuple [])
@@ -734,10 +734,12 @@ let float_array_ref arr ofs dbg =
734734
box_float dbg (unboxed_float_array_ref arr ofs dbg)
735735

736736
let addr_array_set arr ofs newval dbg =
737-
Cop(Cextcall("caml_modify", typ_void, [], false),
737+
Cop(Cextcall { name = "caml_modify"; ret = typ_void; alloc = false;
738+
ty_args = []},
738739
[array_indexing log2_size_addr arr ofs dbg; newval], dbg)
739740
let addr_array_initialize arr ofs newval dbg =
740-
Cop(Cextcall("caml_initialize", typ_void, [], false),
741+
Cop(Cextcall { name = "caml_initialize";
742+
ret = typ_void; alloc = false; ty_args = []},
741743
[array_indexing log2_size_addr arr ofs dbg; newval], dbg)
742744
let int_array_set arr ofs newval dbg =
743745
Cop(Cstore (Word_int, Lambda.Assignment),
@@ -773,7 +775,8 @@ let bigstring_length ba dbg =
773775

774776
let lookup_tag obj tag dbg =
775777
bind "tag" tag (fun tag ->
776-
Cop(Cextcall("caml_get_public_method", typ_val, [], false),
778+
Cop(Cextcall { name = "caml_get_public_method"; ret = typ_val;
779+
alloc = false; ty_args = [] },
777780
[obj; tag],
778781
dbg))
779782

@@ -803,14 +806,16 @@ let make_alloc_generic set_fn dbg tag wordsize args =
803806
| e1::el -> Csequence(set_fn (Cvar id) (Cconst_int (idx, dbg)) e1 dbg,
804807
fill_fields (idx + 2) el) in
805808
Clet(VP.create id,
806-
Cop(Cextcall("caml_alloc", typ_val, [], true),
809+
Cop(Cextcall { name = "caml_alloc"; ret = typ_val; alloc = true;
810+
ty_args = [] },
807811
[Cconst_int (wordsize, dbg); Cconst_int (tag, dbg)], dbg),
808812
fill_fields 1 args)
809813
end
810814

811815
let make_alloc dbg tag args =
812816
let addr_array_init arr ofs newval dbg =
813-
Cop(Cextcall("caml_initialize", typ_void, [], false),
817+
Cop(Cextcall { name = "caml_initialize"; ret = typ_void; alloc = false;
818+
ty_args = [] },
814819
[array_indexing log2_size_addr arr ofs dbg; newval], dbg)
815820
in
816821
make_alloc_generic addr_array_init dbg tag (List.length args) args
@@ -2152,13 +2157,14 @@ let bbswap bi arg dbg =
21522157
| Pint32 -> "int32", XInt32
21532158
| Pint64 -> "int64", XInt64
21542159
in
2155-
Cop(Cextcall(Printf.sprintf "caml_%s_direct_bswap" prim,
2156-
typ_int, [tyarg], false),
2160+
Cop(Cextcall { name = Printf.sprintf "caml_%s_direct_bswap" prim;
2161+
ret = typ_int; alloc = false; ty_args = [tyarg]; },
21572162
[arg],
21582163
dbg)
21592164

21602165
let bswap16 arg dbg =
2161-
(Cop(Cextcall("caml_bswap16_direct", typ_int, [], false),
2166+
(Cop(Cextcall { name = "caml_bswap16_direct";
2167+
ret = typ_int; alloc = false; ty_args = []; },
21622168
[arg],
21632169
dbg))
21642170

@@ -2183,15 +2189,19 @@ let assignment_kind
21832189
let setfield n ptr init arg1 arg2 dbg =
21842190
match assignment_kind ptr init with
21852191
| Caml_modify ->
2186-
return_unit dbg
2187-
(Cop(Cextcall("caml_modify", typ_void, [], false),
2188-
[field_address arg1 n dbg; arg2],
2189-
dbg))
2192+
return_unit dbg (Cop(Cextcall { name = "caml_modify";
2193+
ret = typ_void; alloc = false;
2194+
ty_args = [] },
2195+
[field_address arg1 n dbg;
2196+
arg2],
2197+
dbg))
21902198
| Caml_initialize ->
2191-
return_unit dbg
2192-
(Cop(Cextcall("caml_initialize", typ_void, [], false),
2193-
[field_address arg1 n dbg; arg2],
2194-
dbg))
2199+
return_unit dbg (Cop(Cextcall { name = "caml_initialize";
2200+
ret = typ_void; alloc = false;
2201+
ty_args = [] },
2202+
[field_address arg1 n dbg;
2203+
arg2],
2204+
dbg))
21952205
| Simple ->
21962206
return_unit dbg (set_field arg1 n arg2 init dbg)
21972207

backend/cmmgen.ml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,8 @@ and transl_catch env nfail ids body handler dbg =
736736
and transl_make_array dbg env kind args =
737737
match kind with
738738
| Pgenarray ->
739-
Cop(Cextcall("caml_make_array", typ_val, [], true),
739+
Cop(Cextcall { name = "caml_make_array";
740+
ret = typ_val; alloc = true; ty_args = []},
740741
[make_alloc dbg 0 (List.map (transl env) args)], dbg)
741742
| Paddrarray | Pintarray ->
742743
make_alloc dbg 0 (List.map (transl env) args)
@@ -785,8 +786,10 @@ and transl_ccall env prim args dbg =
785786
in
786787
let typ_args, args = transl_args prim.prim_native_repr_args args in
787788
wrap_result
788-
(Cop(Cextcall(Primitive.native_name prim,
789-
typ_res, typ_args, prim.prim_alloc), args, dbg))
789+
(Cop(Cextcall { name = Primitive.native_name prim;
790+
ret = typ_res; alloc = prim.prim_alloc;
791+
ty_args = typ_args },
792+
args, dbg))
790793

791794
and transl_prim_1 env p arg dbg =
792795
match p with
@@ -1328,7 +1331,9 @@ and transl_letrec env bindings cont =
13281331
bindings
13291332
in
13301333
let op_alloc prim args =
1331-
Cop(Cextcall(prim, typ_val, [], true), args, dbg) in
1334+
Cop(Cextcall { name = prim; ret = typ_val; alloc = true;
1335+
ty_args = [] },
1336+
args, dbg) in
13321337
let rec init_blocks = function
13331338
| [] -> fill_nonrec bsz
13341339
| (id, _exp, RHS_block sz) :: rem ->
@@ -1354,7 +1359,8 @@ and transl_letrec env bindings cont =
13541359
| [] -> cont
13551360
| (id, exp, (RHS_block _ | RHS_infix _ | RHS_floatblock _)) :: rem ->
13561361
let op =
1357-
Cop(Cextcall("caml_update_dummy", typ_void, [], false),
1362+
Cop(Cextcall { name = "caml_update_dummy"; ret = typ_void;
1363+
alloc = false; ty_args = [] },
13581364
[Cvar (VP.var id); transl env exp], dbg) in
13591365
Csequence(op, fill_blocks rem)
13601366
| (_id, _exp, RHS_nonrec) :: rem ->

backend/printcmm.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ let location d =
116116

117117
let operation d = function
118118
| Capply _ty -> "app" ^ location d
119-
| Cextcall(lbl, _ty_res, _ty_args, _alloc) ->
119+
| Cextcall { name = lbl; _ } ->
120120
Printf.sprintf "extcall \"%s\"%s" lbl (location d)
121121
| Cload (c, Asttypes.Immutable) -> Printf.sprintf "load %s" (chunk c)
122122
| Cload (c, Asttypes.Mutable) -> Printf.sprintf "load_mut %s" (chunk c)
@@ -222,8 +222,8 @@ let rec expr ppf = function
222222
List.iter (fun e -> fprintf ppf "@ %a" expr e) el;
223223
begin match op with
224224
| Capply mty -> fprintf ppf "@ %a" machtype mty
225-
| Cextcall(_, ty_res, ty_args, _) ->
226-
fprintf ppf "@ %a" extcall_signature (ty_res, ty_args)
225+
| Cextcall { ret; ty_args; alloc = _; name = _; } ->
226+
fprintf ppf "@ %a" extcall_signature (ret, ty_args)
227227
| _ -> ()
228228
end;
229229
fprintf ppf ")@]"

backend/selectgen.ml

Lines changed: 3 additions & 3 deletions
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_res, _ty_args, _alloc) -> ty_res
69+
| Cextcall { ret = ty; ty_args = _; alloc = _; name = _; } -> ty
7070
| Cload (c, _) ->
7171
begin match c with
7272
| Word_val -> typ_val
@@ -444,8 +444,8 @@ method select_operation op args _dbg =
444444
(Icall_imm { func; }, rem)
445445
| (Capply _, _) ->
446446
(Icall_ind, args)
447-
| (Cextcall(func, ty_res, ty_args, alloc), _) ->
448-
Iextcall { func; ty_res; ty_args; alloc; }, args
447+
| (Cextcall { name = func; alloc; ret; ty_args }, _) ->
448+
Iextcall { func; alloc; ty_res = ret; ty_args }, args
449449
| (Cload (chunk, _mut), [arg]) ->
450450
let (addr, eloc) = self#select_addressing chunk arg in
451451
(Iload(chunk, addr), [eloc])

ocaml/testsuite/tools/parsecmm.mly

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ expr:
218218
| LPAREN APPLY location expr exprlist machtype RPAREN
219219
{ Cop(Capply $6, $4 :: List.rev $5, debuginfo ?loc:$3 ()) }
220220
| LPAREN EXTCALL STRING exprlist machtype RPAREN
221-
{Cop(Cextcall($3, $5, [], false),
222-
List.rev $4, debuginfo ())}
221+
{Cop(Cextcall {name=$3; ret=$5; alloc=false; ty_args=[];},
222+
List.rev $4, debuginfo ())}
223223
| LPAREN ALLOC exprlist RPAREN { Cop(Calloc, List.rev $3, debuginfo ()) }
224224
| LPAREN SUBF expr RPAREN { Cop(Cnegf, [$3], debuginfo ()) }
225225
| LPAREN SUBF expr expr RPAREN { Cop(Csubf, [$3; $4], debuginfo ()) }

0 commit comments

Comments
 (0)