Skip to content

Commit 8925349

Browse files
jyasskingraydon
authored andcommitted
---
yaml --- r: 342 b: refs/heads/master c: 09885b5 h: refs/heads/master v: v3
1 parent 25004e3 commit 8925349

File tree

3 files changed

+78
-22
lines changed

3 files changed

+78
-22
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: c070c1124883e400cc9fba1b97c6cfef60189575
2+
refs/heads/master: 09885b5b878730f266d3450b95d2f91b46183654

trunk/src/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,6 @@ TEST_XFAILS_LLVM := $(addprefix test/run-pass/, \
477477
task-comm-4.rs \
478478
task-comm-5.rs \
479479
threads.rs \
480-
tup.rs \
481480
type-sizes.rs \
482481
unit.rs \
483482
use-import-export.rs \

trunk/src/boot/llvm/lltrans.ml

Lines changed: 77 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*)
44

55
open Common;;
6+
open Semant;;
67
open Transutil;;
78

89
let log cx = Session.log "trans"
@@ -549,6 +550,37 @@ let trans_crate
549550
end
550551
in
551552

553+
(* Dereferences the box referred to by ptr, whose type is ty. Looks
554+
straight through all mutable and constrained-type boxes, and loads
555+
pointers per dctrl. Returns the dereferenced value and its type. *)
556+
let rec deref_ty
557+
(llbuilder:Llvm.llbuilder) (dctrl:deref_ctrl)
558+
(ptr:Llvm.llvalue) (ty:Ast.ty)
559+
: (Llvm.llvalue * Ast.ty) =
560+
match (ty, dctrl) with
561+
562+
| (Ast.TY_mutable ty, _)
563+
| (Ast.TY_constrained (ty, _), _) ->
564+
deref_ty llbuilder dctrl ptr ty
565+
566+
| (Ast.TY_box ty', DEREF_one_box)
567+
| (Ast.TY_box ty', DEREF_all_boxes) ->
568+
let content =
569+
Llvm.build_load
570+
(get_element_ptr llbuilder ptr (Abi.box_rc_field_body))
571+
(anon_llid "deref") llbuilder
572+
in
573+
let inner_dctrl =
574+
if dctrl = DEREF_one_box
575+
then DEREF_none
576+
else DEREF_all_boxes
577+
in
578+
(* Possibly deref recursively. *)
579+
deref_ty llbuilder inner_dctrl content ty'
580+
581+
| _ -> (ptr, ty)
582+
in
583+
552584
let (llitems:(node_id, Llvm.llvalue) Hashtbl.t) = Hashtbl.create 0 in
553585
(* Maps a fn's or block's id to an LLVM metadata node (subprogram or
554586
lexical block) representing it. *)
@@ -724,36 +756,61 @@ let trans_crate
724756

725757
(* Translates an lval by reference into the appropriate pointer
726758
* value. *)
727-
let trans_lval (lval:Ast.lval) : Llvm.llvalue =
759+
let rec trans_lval (lval:Ast.lval) : (Llvm.llvalue * Ast.ty) =
728760
iflog (fun _ -> log sem_cx "trans_lval: %a" Ast.sprintf_lval lval);
729761
match lval with
730762
Ast.LVAL_base { id = base_id } ->
731763
set_debug_loc base_id;
732-
let id =
733-
Hashtbl.find sem_cx.Semant.ctxt_lval_to_referent base_id
734-
in
735-
let referent = Hashtbl.find sem_cx.Semant.ctxt_all_defns id in
764+
let referent = lval_to_referent sem_cx base_id in
736765
begin
737-
match referent with
738-
Semant.DEFN_slot _ -> Hashtbl.find slot_to_llvalue id
739-
| Semant.DEFN_item _ -> Hashtbl.find llitems id
766+
match resolve_lval_id sem_cx base_id with
767+
Semant.DEFN_slot slot ->
768+
(Hashtbl.find slot_to_llvalue referent, slot_ty slot)
769+
| Semant.DEFN_item _ ->
770+
(Hashtbl.find llitems referent, lval_ty sem_cx lval)
740771
| _ ->
741-
Common.unimpl (Some id)
772+
Common.unimpl (Some referent)
742773
"LLVM base-referent translation of: %a"
743774
Ast.sprintf_lval lval
744775
end
745-
| Ast.LVAL_ext _ ->
746-
Common.unimpl (Some (Semant.lval_base_id lval))
747-
"LLVM lval translation of: %a"
748-
Ast.sprintf_lval lval
776+
| Ast.LVAL_ext (base, component) ->
777+
let (llbase, base_ty) = trans_lval base in
778+
let base_ty = strip_mutable_or_constrained_ty base_ty in
779+
(*
780+
* All lval components aside from explicit-deref just
781+
* auto-deref through all boxes to find their indexable
782+
* referent.
783+
*)
784+
let (llbase, base_ty) =
785+
if component = Ast.COMP_deref
786+
then (llbase, base_ty)
787+
else deref_ty llbuilder DEREF_all_boxes llbase base_ty
788+
in
789+
match (base_ty, component) with
790+
(Ast.TY_rec entries,
791+
Ast.COMP_named (Ast.COMP_ident id)) ->
792+
let i = arr_idx (Array.map fst entries) id in
793+
(get_element_ptr llbuilder llbase i, snd entries.(i))
794+
795+
| (Ast.TY_tup entries,
796+
Ast.COMP_named (Ast.COMP_idx i)) ->
797+
(get_element_ptr llbuilder llbase i, entries.(i))
798+
799+
| (Ast.TY_box _, Ast.COMP_deref) ->
800+
deref_ty llbuilder DEREF_one_box llbase base_ty
801+
802+
| _ -> (Common.unimpl (Some (Semant.lval_base_id lval))
803+
"LLVM lval translation of: %a"
804+
Ast.sprintf_lval lval)
749805
in
750806

751807
let trans_atom (atom:Ast.atom) : Llvm.llvalue =
752808
iflog (fun _ -> log sem_cx "trans_atom: %a" Ast.sprintf_atom atom);
753809
match atom with
754810
Ast.ATOM_literal { node = lit } -> trans_literal lit
755811
| Ast.ATOM_lval lval ->
756-
Llvm.build_load (trans_lval lval) (anon_llid "tmp") llbuilder
812+
Llvm.build_load (fst (trans_lval lval)) (anon_llid "tmp")
813+
llbuilder
757814
in
758815

759816
let build_binop (op:Ast.binop) (lllhs:Llvm.llvalue) (llrhs:Llvm.llvalue)
@@ -867,7 +924,7 @@ let trans_crate
867924
match head.node with
868925
Ast.STMT_init_tup (dest, elems) ->
869926
let zero = const_i32 0 in
870-
let lldest = trans_lval dest in
927+
let (lldest, _) = trans_lval dest in
871928
let trans_tup_elem idx (_, atom) =
872929
let indices = [| zero; const_i32 idx |] in
873930
let gep_id = anon_llid "init_tup_gep" in
@@ -881,12 +938,12 @@ let trans_crate
881938

882939
| Ast.STMT_copy (dest, src) ->
883940
let llsrc = trans_expr src in
884-
let lldest = trans_lval dest in
941+
let (lldest, _) = trans_lval dest in
885942
ignore (Llvm.build_store llsrc lldest llbuilder);
886943
trans_tail ()
887944

888945
| Ast.STMT_copy_binop (dest, op, src) ->
889-
let lldest = trans_lval dest in
946+
let (lldest, _) = trans_lval dest in
890947
let llsrc = trans_atom src in
891948
(* FIXME: Handle vecs and strs. *)
892949
let lldest_deref =
@@ -898,8 +955,8 @@ let trans_crate
898955

899956
| Ast.STMT_call (dest, fn, args) ->
900957
let llargs = Array.map trans_atom args in
901-
let lldest = trans_lval dest in
902-
let llfn = trans_lval fn in
958+
let (lldest, _) = trans_lval dest in
959+
let (llfn, _) = trans_lval fn in
903960
let llallargs = Array.append [| lldest; lltask |] llargs in
904961
let llrv = build_call llfn llallargs "" llbuilder in
905962
Llvm.set_instruction_call_conv Llvm.CallConv.c llrv;
@@ -966,7 +1023,7 @@ let trans_crate
9661023
trans_tail_with_builder llokbuilder
9671024

9681025
| Ast.STMT_init_str (dst, str) ->
969-
let d = trans_lval dst in
1026+
let (d, _) = trans_lval dst in
9701027
let s = static_str str in
9711028
let len =
9721029
Llvm.const_int word_ty ((String.length str) + 1)

0 commit comments

Comments
 (0)