Skip to content

Commit 15a0cae

Browse files
committed
---
yaml --- r: 471 b: refs/heads/master c: 982dcc2 h: refs/heads/master i: 469: 2cc8874 467: 9db76a3 463: f37766c v: v3
1 parent a8bef8b commit 15a0cae

File tree

8 files changed

+140
-81
lines changed

8 files changed

+140
-81
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 76e03be459e0ad0defc6c6855e4ccfde85782a53
2+
refs/heads/master: 982dcc29bf6cd41e967a0befe0c6195811cd6a55

trunk/src/boot/be/abi.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ type abi =
121121
-> Common.size (* callsz *)
122122
-> Common.nabi
123123
-> Common.fixup (* grow_task *)
124-
-> unit);
124+
-> bool (* is_obj_fn *)
125+
-> unit);
125126

126127
abi_emit_fn_epilogue: (Il.emitter -> unit);
127128

trunk/src/boot/be/il.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,13 @@ let get_element_ptr
901901
(string_of_cell fmt mem_cell)
902902
;;
903903

904+
let ptr_cast (cell:cell) (rty:referent_ty) : cell =
905+
match cell with
906+
Mem (mem, _) -> Mem (mem, rty)
907+
| Reg (reg, AddrTy _) -> Reg (reg, AddrTy rty)
908+
| _ -> bug () "expected address cell in Il.ptr_cast"
909+
;;
910+
904911
(*
905912
* Local Variables:
906913
* fill-column: 78;

trunk/src/boot/be/x86.ml

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ let restore_frame_base (e:Il.emitter) (base:Il.reg) (retpc:Il.reg) : unit =
593593
*
594594
* *ebp+20+(4*N) = [argN ]
595595
* ...
596+
* *ebp+28 = [arg2 ] = obj/closure ptr
596597
* *ebp+24 = [arg1 ] = task ptr
597598
* *ebp+20 = [arg0 ] = out ptr
598599
* *ebp+16 = [retpc ]
@@ -1033,7 +1034,7 @@ let unwind_glue
10331034

10341035

10351036
(* Puts result in eax; clobbers ecx, edx in the process. *)
1036-
let rec calculate_sz (e:Il.emitter) (size:size) : unit =
1037+
let rec calculate_sz (e:Il.emitter) (size:size) (in_obj:bool) : unit =
10371038
let emit = Il.emit e in
10381039
let mov dst src = emit (Il.umov dst src) in
10391040
let push x = emit (Il.Push x) in
@@ -1045,11 +1046,48 @@ let rec calculate_sz (e:Il.emitter) (size:size) : unit =
10451046
let mul x y = emit (Il.binary Il.UMUL (rc x) (ro x) (ro y)) in
10461047
let subi x y = emit (Il.binary Il.SUB (rc x) (ro x) (immi y)) in
10471048
let eax_gets_a_and_ecx_gets_b a b =
1048-
calculate_sz e b;
1049+
calculate_sz e b in_obj;
10491050
push (ro eax);
1050-
calculate_sz e a;
1051+
calculate_sz e a in_obj;
10511052
pop (rc ecx);
10521053
in
1054+
1055+
let ty_param_n_in_obj_fn i =
1056+
(*
1057+
* Here we are trying to immitate the obj-fn branch of
1058+
* Trans.get_ty_params_of_current_frame while using
1059+
* eax as our only register.
1060+
*)
1061+
1062+
(* Bind all the referent types we'll need... *)
1063+
1064+
let obj_body_rty = Semant.obj_closure_rty word_bits in
1065+
let tydesc_rty = Semant.tydesc_rty word_bits in
1066+
(* Note that we cheat here and pretend only to have i+1 tydescs (because
1067+
we GEP to the i'th while still in this function, so no one outside
1068+
finds out about the lie. *)
1069+
let tydesc_tys = Array.init (i + 1) (fun _ -> Ast.TY_type) in
1070+
let ty_params_ty = Ast.TY_tup tydesc_tys in
1071+
let ty_params_rty = Semant.referent_type word_bits ty_params_ty in
1072+
1073+
(* ... and fetch! *)
1074+
1075+
mov (rc eax) (Il.Cell closure_ptr);
1076+
let obj_body = word_n (h eax) Abi.box_rc_field_body in
1077+
let obj_body = Il.ptr_cast obj_body obj_body_rty in
1078+
let tydesc_ptr = get_element_ptr obj_body Abi.obj_body_elt_tydesc in
1079+
1080+
mov (rc eax) (Il.Cell tydesc_ptr);
1081+
let tydesc = Il.ptr_cast (word_at (h eax)) tydesc_rty in
1082+
let ty_params_ptr =
1083+
get_element_ptr tydesc Abi.tydesc_field_first_param
1084+
in
1085+
1086+
mov (rc eax) (Il.Cell ty_params_ptr);
1087+
let ty_params = Il.ptr_cast (word_at (h eax)) ty_params_rty in
1088+
get_element_ptr ty_params i
1089+
in
1090+
10531091
match size with
10541092
SIZE_fixed i ->
10551093
mov (rc eax) (immi i)
@@ -1061,15 +1099,23 @@ let rec calculate_sz (e:Il.emitter) (size:size) : unit =
10611099
mov (rc eax) (imm (Asm.M_POS f))
10621100

10631101
| SIZE_param_size i ->
1064-
mov (rc eax) (Il.Cell (ty_param_n i));
1102+
if in_obj
1103+
then
1104+
mov (rc eax) (Il.Cell (ty_param_n_in_obj_fn i))
1105+
else
1106+
mov (rc eax) (Il.Cell (ty_param_n i));
10651107
mov (rc eax) (Il.Cell (word_n (h eax) Abi.tydesc_field_size))
10661108

10671109
| SIZE_param_align i ->
1068-
mov (rc eax) (Il.Cell (ty_param_n i));
1110+
if in_obj
1111+
then
1112+
mov (rc eax) (Il.Cell (ty_param_n_in_obj_fn i))
1113+
else
1114+
mov (rc eax) (Il.Cell (ty_param_n i));
10691115
mov (rc eax) (Il.Cell (word_n (h eax) Abi.tydesc_field_align))
10701116

10711117
| SIZE_rt_neg a ->
1072-
calculate_sz e a;
1118+
calculate_sz e a in_obj;
10731119
neg eax
10741120

10751121
| SIZE_rt_add (a, b) ->
@@ -1185,6 +1231,7 @@ let fn_prologue
11851231
(callsz:size)
11861232
(nabi:nabi)
11871233
(grow_task_fixup:fixup)
1234+
(is_obj_fn:bool)
11881235
: unit =
11891236

11901237
let esi_n = word_n (h esi) in
@@ -1314,7 +1361,7 @@ let fn_prologue
13141361
emit (Il.jmp Il.JA Il.CodeNone);
13151362

13161363
(* Calculate dynamic frame size. *)
1317-
calculate_sz e call_and_frame_sz;
1364+
calculate_sz e call_and_frame_sz is_obj_fn;
13181365
((ro eax), Some primordial_underflow_jmp_pc)
13191366
end
13201367
| Some e -> ((imm e), None)

trunk/src/boot/me/dwarf.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,7 @@ let dwarf_visitor
16771677
in
16781678

16791679
let record trec =
1680-
let rty = referent_type abi (Ast.TY_rec trec) in
1680+
let rty = referent_type word_bits (Ast.TY_rec trec) in
16811681
let rty_sz = Il.referent_ty_size abi.Abi.abi_word_bits in
16821682
let fix = new_fixup "record type DIE" in
16831683
let die = DEF (fix, SEQ [|
@@ -1926,7 +1926,7 @@ let dwarf_visitor
19261926
* I'm a bit surprised by that!
19271927
*)
19281928

1929-
let rty = referent_type abi (Ast.TY_tag ttag) in
1929+
let rty = referent_type word_bits (Ast.TY_tag ttag) in
19301930
let rty_sz = Il.referent_ty_size abi.Abi.abi_word_bits in
19311931
let rtys =
19321932
match rty with

trunk/src/boot/me/layout.ml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ let layout_visitor
113113
| Il.CodeTy -> true
114114
| Il.NilTy -> false
115115
in
116-
rt_in_mem (slot_referent_type cx.ctxt_abi slot)
116+
rt_in_mem (slot_referent_type cx.ctxt_abi.Abi.abi_word_bits slot)
117117
in
118118

119119
let rty_sz rty = Il.referent_ty_size cx.ctxt_abi.Abi.abi_word_bits rty in
@@ -142,7 +142,7 @@ let layout_visitor
142142
: unit =
143143
let accum (off,align) id : (size * size) =
144144
let slot = get_slot cx id in
145-
let rt = slot_referent_type cx.ctxt_abi slot in
145+
let rt = slot_referent_type cx.ctxt_abi.Abi.abi_word_bits slot in
146146
let (elt_size, elt_align) = rty_layout rt in
147147
if vregs_ok
148148
&& (is_subword_size elt_size)
@@ -170,7 +170,9 @@ let layout_visitor
170170
then elt_off
171171
else neg_sz (add_sz elt_off elt_size)
172172
in
173-
Stack.push (slot_referent_type cx.ctxt_abi slot) slot_accum;
173+
Stack.push
174+
(slot_referent_type cx.ctxt_abi.Abi.abi_word_bits slot)
175+
slot_accum;
174176
iflog
175177
begin
176178
fun _ ->

trunk/src/boot/me/semant.ml

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,24 +1822,24 @@ let run_passes
18221822

18231823
(* Rust type -> IL type conversion. *)
18241824

1825-
let word_sty (abi:Abi.abi) : Il.scalar_ty =
1826-
Il.ValTy abi.Abi.abi_word_bits
1825+
let word_sty (word_bits:Il.bits) : Il.scalar_ty =
1826+
Il.ValTy word_bits
18271827
;;
18281828

1829-
let word_rty (abi:Abi.abi) : Il.referent_ty =
1830-
Il.ScalarTy (word_sty abi)
1829+
let word_rty (word_bits:Il.bits) : Il.referent_ty =
1830+
Il.ScalarTy (word_sty word_bits)
18311831
;;
18321832

1833-
let tydesc_rty (abi:Abi.abi) : Il.referent_ty =
1833+
let tydesc_rty (word_bits:Il.bits) : Il.referent_ty =
18341834
(*
18351835
* NB: must match corresponding tydesc structure
18361836
* in trans and offsets in ABI exactly.
18371837
*)
18381838
Il.StructTy
18391839
[|
1840-
word_rty abi; (* Abi.tydesc_field_first_param *)
1841-
word_rty abi; (* Abi.tydesc_field_size *)
1842-
word_rty abi; (* Abi.tydesc_field_align *)
1840+
word_rty word_bits; (* Abi.tydesc_field_first_param *)
1841+
word_rty word_bits; (* Abi.tydesc_field_size *)
1842+
word_rty word_bits; (* Abi.tydesc_field_align *)
18431843
Il.ScalarTy (Il.AddrTy Il.CodeTy); (* Abi.tydesc_field_copy_glue *)
18441844
Il.ScalarTy (Il.AddrTy Il.CodeTy); (* Abi.tydesc_field_drop_glue *)
18451845
Il.ScalarTy (Il.AddrTy Il.CodeTy); (* Abi.tydesc_field_free_glue *)
@@ -1849,29 +1849,29 @@ let tydesc_rty (abi:Abi.abi) : Il.referent_ty =
18491849
|]
18501850
;;
18511851

1852-
let obj_closure_rty (abi:Abi.abi) : Il.referent_ty =
1852+
let obj_closure_rty (word_bits:Il.bits) : Il.referent_ty =
18531853
Il.StructTy [|
1854-
word_rty abi;
1854+
word_rty word_bits;
18551855
Il.StructTy [|
1856-
Il.ScalarTy (Il.AddrTy (tydesc_rty abi));
1857-
word_rty abi (* A lie: it's opaque, but this permits
1858-
* GEP'ing to it. *)
1856+
Il.ScalarTy (Il.AddrTy (tydesc_rty word_bits));
1857+
word_rty word_bits (* A lie: it's opaque, but this permits
1858+
* GEP'ing to it. *)
18591859
|]
18601860
|]
18611861
;;
18621862

1863-
let rec referent_type (abi:Abi.abi) (t:Ast.ty) : Il.referent_ty =
1863+
let rec referent_type (word_bits:Il.bits) (t:Ast.ty) : Il.referent_ty =
18641864
let s t = Il.ScalarTy t in
18651865
let v b = Il.ValTy b in
18661866
let p t = Il.AddrTy t in
18671867
let sv b = s (v b) in
18681868
let sp t = s (p t) in
18691869

1870-
let word = word_rty abi in
1870+
let word = word_rty word_bits in
18711871
let ptr = sp Il.OpaqueTy in
18721872
let rc_ptr = sp (Il.StructTy [| word; Il.OpaqueTy |]) in
18731873
let codeptr = sp Il.CodeTy in
1874-
let tup ttup = Il.StructTy (Array.map (referent_type abi) ttup) in
1874+
let tup ttup = Il.StructTy (Array.map (referent_type word_bits) ttup) in
18751875
let tag ttag =
18761876
let union =
18771877
Il.UnionTy
@@ -1916,7 +1916,7 @@ let rec referent_type (abi:Abi.abi) (t:Ast.ty) : Il.referent_ty =
19161916
Il.StructTy [| codeptr; fn_closure_ptr |]
19171917

19181918
| Ast.TY_obj _ ->
1919-
let obj_closure_ptr = sp (obj_closure_rty abi) in
1919+
let obj_closure_ptr = sp (obj_closure_rty word_bits) in
19201920
Il.StructTy [| ptr; obj_closure_ptr |]
19211921

19221922
| Ast.TY_tag ttag -> tag ttag
@@ -1928,26 +1928,26 @@ let rec referent_type (abi:Abi.abi) (t:Ast.ty) : Il.referent_ty =
19281928
| Ast.TY_port _
19291929
| Ast.TY_task -> rc_ptr
19301930

1931-
| Ast.TY_type -> sp (tydesc_rty abi)
1931+
| Ast.TY_type -> sp (tydesc_rty word_bits)
19321932

19331933
| Ast.TY_native _ -> ptr
19341934

19351935
| Ast.TY_box t ->
1936-
sp (Il.StructTy [| word; referent_type abi t |])
1936+
sp (Il.StructTy [| word; referent_type word_bits t |])
19371937

1938-
| Ast.TY_mutable t -> referent_type abi t
1938+
| Ast.TY_mutable t -> referent_type word_bits t
19391939

19401940
| Ast.TY_param (i, _) -> Il.ParamTy i
19411941

19421942
| Ast.TY_named _ -> bug () "named type in referent_type"
1943-
| Ast.TY_constrained (t, _) -> referent_type abi t
1943+
| Ast.TY_constrained (t, _) -> referent_type word_bits t
19441944

1945-
and slot_referent_type (abi:Abi.abi) (sl:Ast.slot) : Il.referent_ty =
1945+
and slot_referent_type (word_bits:Il.bits) (sl:Ast.slot) : Il.referent_ty =
19461946
let s t = Il.ScalarTy t in
19471947
let p t = Il.AddrTy t in
19481948
let sp t = s (p t) in
19491949

1950-
let rty = referent_type abi (slot_ty sl) in
1950+
let rty = referent_type word_bits (slot_ty sl) in
19511951
match sl.Ast.slot_mode with
19521952
| Ast.MODE_local -> rty
19531953
| Ast.MODE_alias -> sp rty
@@ -1958,7 +1958,7 @@ let task_rty (abi:Abi.abi) : Il.referent_ty =
19581958
begin
19591959
Array.init
19601960
Abi.n_visible_task_fields
1961-
(fun _ -> word_rty abi)
1961+
(fun _ -> word_rty abi.Abi.abi_word_bits)
19621962
end
19631963
;;
19641964

@@ -1970,14 +1970,17 @@ let call_args_referent_type_full
19701970
(iterator_arg_rtys:Il.referent_ty array)
19711971
(indirect_arg_rtys:Il.referent_ty array)
19721972
: Il.referent_ty =
1973-
let out_slot_rty = slot_referent_type abi out_slot in
1973+
let out_slot_rty = slot_referent_type abi.Abi.abi_word_bits out_slot in
19741974
let out_ptr_rty = Il.ScalarTy (Il.AddrTy out_slot_rty) in
19751975
let task_ptr_rty = Il.ScalarTy (Il.AddrTy (task_rty abi)) in
19761976
let ty_param_rtys =
1977-
let td = Il.ScalarTy (Il.AddrTy (tydesc_rty abi)) in
1977+
let td = Il.ScalarTy (Il.AddrTy (tydesc_rty abi.Abi.abi_word_bits)) in
19781978
Il.StructTy (Array.init n_ty_params (fun _ -> td))
19791979
in
1980-
let arg_rtys = Il.StructTy (Array.map (slot_referent_type abi) in_slots) in
1980+
let arg_rtys =
1981+
Il.StructTy
1982+
(Array.map (slot_referent_type abi.Abi.abi_word_bits) in_slots)
1983+
in
19811984
(*
19821985
* NB: must match corresponding calltup structure in trans and
19831986
* member indices in ABI exactly.
@@ -2003,7 +2006,7 @@ let call_args_referent_type
20032006
(* Abi.indirect_args_elt_closure *)
20042007
match closure with
20052008
None ->
2006-
[| word_rty cx.ctxt_abi |]
2009+
[| word_rty cx.ctxt_abi.Abi.abi_word_bits |]
20072010
| Some c ->
20082011
[| Il.ScalarTy (Il.AddrTy c) |]
20092012
in
@@ -2057,16 +2060,18 @@ let direct_call_args_referent_type
20572060
;;
20582061

20592062
let ty_sz (abi:Abi.abi) (t:Ast.ty) : int64 =
2060-
force_sz (Il.referent_ty_size abi.Abi.abi_word_bits (referent_type abi t))
2063+
let wb = abi.Abi.abi_word_bits in
2064+
force_sz (Il.referent_ty_size wb (referent_type wb t))
20612065
;;
20622066

20632067
let ty_align (abi:Abi.abi) (t:Ast.ty) : int64 =
2064-
force_sz (Il.referent_ty_align abi.Abi.abi_word_bits (referent_type abi t))
2068+
let wb = abi.Abi.abi_word_bits in
2069+
force_sz (Il.referent_ty_align wb (referent_type wb t))
20652070
;;
20662071

20672072
let slot_sz (abi:Abi.abi) (s:Ast.slot) : int64 =
2068-
force_sz (Il.referent_ty_size abi.Abi.abi_word_bits
2069-
(slot_referent_type abi s))
2073+
let wb = abi.Abi.abi_word_bits in
2074+
force_sz (Il.referent_ty_size wb (slot_referent_type wb s))
20702075
;;
20712076

20722077
let word_slot (abi:Abi.abi) : Ast.slot =

0 commit comments

Comments
 (0)