Skip to content

Commit 5e42620

Browse files
author
Hongbo Zhang
committed
instrument field information
1 parent dafcaf0 commit 5e42620

File tree

16 files changed

+101
-85
lines changed

16 files changed

+101
-85
lines changed

asmcomp/closure.ml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ let rec split_list n l =
3939
let rec build_closure_env env_param pos = function
4040
[] -> Tbl.empty
4141
| id :: rem ->
42-
Tbl.add id (Uprim(Pfield pos, [Uvar env_param], Debuginfo.none))
42+
Tbl.add id (Uprim(Pfield (pos, Fld_na), [Uvar env_param], Debuginfo.none))
4343
(build_closure_env env_param (pos+1) rem)
4444

4545
(* Auxiliary for accessing globals. We change the name of the global
@@ -148,9 +148,9 @@ let prim_size prim args =
148148
| Pgetglobal id -> 1
149149
| Psetglobal id -> 1
150150
| Pmakeblock(tag, _, mut) -> 5 + List.length args
151-
| Pfield f -> 1
151+
| Pfield _ -> 1
152152
| Psetfield(f, isptr) -> if isptr then 4 else 1
153-
| Pfloatfield f -> 1
153+
| Pfloatfield _ -> 1
154154
| Psetfloatfield f -> 1
155155
| Pduprecord _ -> 10 + List.length args
156156
| Pccall p -> (if p.prim_alloc then 10 else 4) + List.length args
@@ -469,10 +469,10 @@ let simplif_prim_pure fpc p (args, approxs) dbg =
469469
(Uprim(p, args, dbg), Value_tuple (Array.of_list approxs))
470470
end
471471
(* Field access *)
472-
| Pfield n, _, [ Value_const(Uconst_ref(_, Uconst_block(_, l))) ]
472+
| Pfield (n,_), _, [ Value_const(Uconst_ref(_, Uconst_block(_, l))) ]
473473
when n < List.length l ->
474474
make_const (List.nth l n)
475-
| Pfield n, [ Uprim(Pmakeblock _, ul, _) ], [approx]
475+
| Pfield (n,_), [ Uprim(Pmakeblock _, ul, _) ], [approx]
476476
when n < List.length ul ->
477477
(List.nth ul n, field_approx n approx)
478478
(* Strings *)
@@ -715,7 +715,7 @@ let check_constant_result lam ulam approx =
715715
let glb =
716716
Uprim(Pgetglobal (Ident.create_persistent id), [], Debuginfo.none)
717717
in
718-
Uprim(Pfield i, [glb], Debuginfo.none), approx
718+
Uprim(Pfield (i, Fld_na), [glb], Debuginfo.none), approx
719719
end
720720
| _ -> (ulam, approx)
721721

@@ -920,9 +920,9 @@ let rec close fenv cenv = function
920920
check_constant_result lam
921921
(getglobal id)
922922
(Compilenv.global_approx id)
923-
| Lprim(Pfield n, [lam]) ->
923+
| Lprim((Pfield (n, _) as field), [lam]) ->
924924
let (ulam, approx) = close fenv cenv lam in
925-
check_constant_result lam (Uprim(Pfield n, [ulam], Debuginfo.none))
925+
check_constant_result lam (Uprim(field, [ulam], Debuginfo.none))
926926
(field_approx n approx)
927927
| Lprim(Psetfield(n, _), [Lprim(Pgetglobal id, []); lam]) ->
928928
let (ulam, approx) = close fenv cenv lam in

asmcomp/cmmgen.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,9 +1560,9 @@ and transl_prim_1 p arg dbg =
15601560
| Pignore ->
15611561
return_unit(remove_unit (transl arg))
15621562
(* Heap operations *)
1563-
| Pfield n ->
1563+
| Pfield (n,_) ->
15641564
get_field (transl arg) n
1565-
| Pfloatfield n ->
1565+
| Pfloatfield (n,_) ->
15661566
let ptr = transl arg in
15671567
box_float(
15681568
Cop(Cload Double_u,

boot/ocamlc

2.48 KB
Binary file not shown.

boot/ocamldep

-105 Bytes
Binary file not shown.

boot/ocamllex

46 Bytes
Binary file not shown.

bytecomp/bytegen.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,9 @@ let comp_primitive p args =
301301
| Psetglobal id -> Ksetglobal id
302302
| Pintcomp cmp -> Kintcomp cmp
303303
| Pmakeblock(tag, _, mut) -> Kmakeblock(List.length args, tag)
304-
| Pfield n -> Kgetfield n
304+
| Pfield (n, _) -> Kgetfield n
305305
| Psetfield(n, ptr) -> Ksetfield n
306-
| Pfloatfield n -> Kgetfloatfield n
306+
| Pfloatfield (n,_) -> Kgetfloatfield n
307307
| Psetfloatfield n -> Ksetfloatfield n
308308
| Pduprecord _ -> Kccall("caml_obj_dup", 1)
309309
| Pccall p -> Kccall(p.prim_name, p.prim_arity)

bytecomp/lambda.ml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,17 @@ type tag_info =
3333
| Tuple
3434
| Array
3535
| Variant of string
36-
| Record
36+
| Record of string array (* when its empty means we dont get such information *)
37+
| Module of string list option
3738
| NA
3839

3940
let default_tag_info : tag_info = NA
4041

42+
type field_dbg_info =
43+
| Fld_na
44+
| Fld_record of string
45+
| Fld_module of string
46+
4147
type primitive =
4248
| Pidentity
4349
| Pbytes_to_string
@@ -54,9 +60,9 @@ type primitive =
5460
| Psetglobal of Ident.t
5561
(* Operations on heap blocks *)
5662
| Pmakeblock of int * tag_info * mutable_flag
57-
| Pfield of int
63+
| Pfield of int * field_dbg_info
5864
| Psetfield of int * bool
59-
| Pfloatfield of int
65+
| Pfloatfield of int * field_dbg_info
6066
| Psetfloatfield of int
6167
| Pduprecord of Types.record_representation * int
6268
(* Force lazy values *)
@@ -485,7 +491,7 @@ let rec transl_normal_path = function
485491
Pident id ->
486492
if Ident.global id then Lprim(Pgetglobal id, []) else Lvar id
487493
| Pdot(p, s, pos) ->
488-
Lprim(Pfield pos, [transl_normal_path p])
494+
Lprim(Pfield (pos, Fld_na (* TODO *)), [transl_normal_path p])
489495
| Papply(p1, p2) ->
490496
fatal_error "Lambda.transl_path"
491497

bytecomp/lambda.mli

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,17 @@ type tag_info =
3535
| Tuple
3636
| Array
3737
| Variant of string
38-
| Record
38+
| Record of string array
39+
| Module of string list option
3940
| NA
4041

4142
val default_tag_info : tag_info
4243

44+
type field_dbg_info =
45+
| Fld_na
46+
| Fld_record of string
47+
| Fld_module of string
48+
4349
type pointer_info =
4450
| NullConstructor of string
4551
| NullVariant of string
@@ -63,9 +69,9 @@ type primitive =
6369
| Psetglobal of Ident.t
6470
(* Operations on heap blocks *)
6571
| Pmakeblock of int * tag_info * mutable_flag
66-
| Pfield of int
67-
| Psetfield of int * bool
68-
| Pfloatfield of int
72+
| Pfield of int * field_dbg_info
73+
| Psetfield of int * bool (* could have field info at least for record *)
74+
| Pfloatfield of int * field_dbg_info
6975
| Psetfloatfield of int
7076
| Pduprecord of Types.record_representation * int
7177
(* Force lazy values *)

bytecomp/matching.ml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ let make_field_args binding_kind arg first_pos last_pos argl =
12881288
let rec make_args pos =
12891289
if pos > last_pos
12901290
then argl
1291-
else (Lprim(Pfield pos, [arg]), binding_kind) :: make_args (pos + 1)
1291+
else (Lprim(Pfield (pos, Fld_na (* TODO*) ), [arg]), binding_kind) :: make_args (pos + 1)
12921292
in make_args first_pos
12931293

12941294
let get_key_constr = function
@@ -1403,7 +1403,7 @@ let make_variant_matching_nonconst p lab def ctx = function
14031403
let def = make_default (matcher_variant_nonconst lab) def
14041404
and ctx = filter_ctx p ctx in
14051405
{pm=
1406-
{cases = []; args = (Lprim(Pfield 1, [arg]), Alias) :: argl;
1406+
{cases = []; args = (Lprim(Pfield (1, Fld_na (* TODO*)), [arg]), Alias) :: argl;
14071407
default=def} ;
14081408
ctx=ctx ;
14091409
pat = normalize_pat p}
@@ -1490,7 +1490,8 @@ let get_mod_field modname field =
14901490
with Not_found ->
14911491
fatal_error ("Primitive "^modname^"."^field^" not found.")
14921492
in
1493-
Lprim(Pfield p, [Lprim(Pgetglobal mod_ident, [])])
1493+
Lprim(Pfield (p, Fld_na (* TODO - then we dont need query any more*)),
1494+
[Lprim(Pgetglobal mod_ident, [])])
14941495
with Not_found -> fatal_error ("Module "^modname^" unavailable.")
14951496
)
14961497

@@ -1519,7 +1520,7 @@ let inline_lazy_force_cond arg loc =
15191520
(* if (tag == Obj.forward_tag) then varg.(0) else ... *)
15201521
Lprim(Pintcomp Ceq,
15211522
[Lvar tag; Lconst(Const_base(Const_int Obj.forward_tag))]),
1522-
Lprim(Pfield 0, [varg]),
1523+
Lprim(Pfield (0, Fld_na (* TODO: lazy *)), [varg]),
15231524
Lifthenelse(
15241525
(* ... if (tag == Obj.lazy_tag) then Lazy.force varg else ... *)
15251526
Lprim(Pintcomp Ceq,
@@ -1540,7 +1541,7 @@ let inline_lazy_force_switch arg loc =
15401541
{ sw_numconsts = 0; sw_consts = [];
15411542
sw_numblocks = 256; (* PR#6033 - tag ranges from 0 to 255 *)
15421543
sw_blocks =
1543-
[ (Obj.forward_tag, Lprim(Pfield 0, [varg]));
1544+
[ (Obj.forward_tag, Lprim(Pfield (0, Fld_na (* TODO: lazy *)), [varg]));
15441545
(Obj.lazy_tag,
15451546
Lapply(force_fun, [varg], loc)) ];
15461547
sw_failaction = Some varg } ))))
@@ -1589,7 +1590,7 @@ let make_tuple_matching arity def = function
15891590
let rec make_args pos =
15901591
if pos >= arity
15911592
then argl
1592-
else (Lprim(Pfield pos, [arg]), Alias) :: make_args (pos + 1) in
1593+
else (Lprim(Pfield (pos, Fld_na (* TODO: tuple*)) , [arg]), Alias) :: make_args (pos + 1) in
15931594
{cases = []; args = make_args 0 ;
15941595
default=make_default (matcher_tuple arity) def}
15951596

@@ -1628,8 +1629,8 @@ let make_record_matching all_labels def = function
16281629
let lbl = all_labels.(pos) in
16291630
let access =
16301631
match lbl.lbl_repres with
1631-
Record_regular -> Pfield lbl.lbl_pos
1632-
| Record_float -> Pfloatfield lbl.lbl_pos in
1632+
Record_regular -> Pfield (lbl.lbl_pos, Fld_record lbl.lbl_name)
1633+
| Record_float -> Pfloatfield (lbl.lbl_pos, Fld_record lbl.lbl_name) in
16331634
let str =
16341635
match lbl.lbl_mut with
16351636
Immutable -> Alias
@@ -2404,7 +2405,7 @@ let combine_constructor arg ex_pat cstr partial ctx def
24042405
nonconsts
24052406
default
24062407
in
2407-
Llet(Alias, tag, Lprim(Pfield 0, [arg]), tests)
2408+
Llet(Alias, tag, Lprim(Pfield (0, Fld_na), [arg]), tests)
24082409
in
24092410
List.fold_right
24102411
(fun (path, act) rem ->
@@ -2470,7 +2471,7 @@ let call_switcher_variant_constant fail arg int_lambda_list =
24702471

24712472
let call_switcher_variant_constr fail arg int_lambda_list =
24722473
let v = Ident.create "variant" in
2473-
Llet(Alias, v, Lprim(Pfield 0, [arg]),
2474+
Llet(Alias, v, Lprim(Pfield (0, Fld_na), [arg]),
24742475
call_switcher
24752476
fail (Lvar v) min_int max_int int_lambda_list)
24762477

bytecomp/printlambda.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ let primitive ppf = function
109109
| Psetglobal id -> fprintf ppf "setglobal %a" Ident.print id
110110
| Pmakeblock(tag, _, Immutable) -> fprintf ppf "makeblock %i" tag
111111
| Pmakeblock(tag, _, Mutable) -> fprintf ppf "makemutable %i" tag
112-
| Pfield n -> fprintf ppf "field %i" n
112+
| Pfield (n,_) -> fprintf ppf "field %i" n
113113
| Psetfield(n, ptr) ->
114114
let instr = if ptr then "setfield_ptr " else "setfield_imm " in
115115
fprintf ppf "%s%i" instr n
116-
| Pfloatfield n -> fprintf ppf "floatfield %i" n
116+
| Pfloatfield (n,_) -> fprintf ppf "floatfield %i" n
117117
| Psetfloatfield n -> fprintf ppf "setfloatfield %i" n
118118
| Pduprecord (rep, size) -> fprintf ppf "duprecord %a %i" record_rep rep size
119119
| Plazyforce -> fprintf ppf "force"
@@ -369,7 +369,7 @@ let lambda use_env env ppf v =
369369
fprintf ppf
370370
"@[<2>(let@ (@[<hv 1>%a@]" bindings (List.rev args);
371371
fprintf ppf ")@ %a)@]" lam body
372-
| Lprim(Pfield n, [ Lprim(Pgetglobal id,[])]) when use_env ->
372+
| Lprim(Pfield (n,_), [ Lprim(Pgetglobal id,[])]) when use_env ->
373373
fprintf ppf "%s.%s/%d" id.name (get_string (id,n) env) n
374374

375375
| Lprim(Psetfield (n,_), [ Lprim(Pgetglobal id,[]) ; e ]) when use_env ->

0 commit comments

Comments
 (0)