Skip to content

Commit cee886c

Browse files
jyasskingraydon
authored andcommitted
---
yaml --- r: 339 b: refs/heads/master c: c99f027 h: refs/heads/master i: 337: 6ceca6b 335: dcc7ce4 v: v3
1 parent 1588946 commit cee886c

File tree

2 files changed

+48
-20
lines changed

2 files changed

+48
-20
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: 215060b72b71db9c7ca5810fcf6ebce3d4b04ea3
2+
refs/heads/master: c99f0273e37708bb708709dce49c8b4f726a4453

trunk/src/boot/llvm/lltrans.ml

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ let log cx = Session.log "trans"
1010
cx.Semant.ctxt_sess.Session.sess_log_out
1111
;;
1212

13+
(* Returns a new LLVM IRBuilder positioned at the end of llblock. If
14+
debug_loc isn't None, the IRBuilder's debug location is set to its
15+
contents, which should be a DILocation mdnode. (See
16+
http://llvm.org/docs/SourceLevelDebugging.html, or get it from an existing
17+
llbuilder with Llvm.current_debug_location.) *)
18+
let llbuilder_at_end_with_debug_loc
19+
(llctx:Llvm.llcontext) (llblock:Llvm.llbasicblock)
20+
(debug_loc:Llvm.llvalue option) =
21+
let llbuilder = Llvm.builder_at_end llctx llblock in
22+
may (Llvm.set_current_debug_location llbuilder) debug_loc;
23+
llbuilder
24+
1325
let trans_crate
1426
(sem_cx:Semant.ctxt)
1527
(llctx:Llvm.llcontext)
@@ -93,17 +105,22 @@ let trans_crate
93105
md_node [| const_i32 line; const_i32 col; scope; const_i32 0 |]
94106
in
95107

108+
let di_location_from_id (scope:Llvm.llvalue) (id:node_id)
109+
: Llvm.llvalue option =
110+
match Session.get_span sess id with
111+
None -> None
112+
| Some {lo=(_, line, col)} ->
113+
Some (di_location line col scope)
114+
in
115+
96116
(* Sets the 'llbuilder's current location (which it attaches to all
97117
instructions) to the location of the start of the 'id' node within
98118
'scope', usually a subprogram or lexical block. *)
99119
let set_debug_location
100120
(llbuilder:Llvm.llbuilder) (scope:Llvm.llvalue) (id:node_id)
101121
: unit =
102-
match Session.get_span sess id with
103-
None -> ()
104-
| Some {lo=(_, line, col)} ->
105-
Llvm.set_current_debug_location llbuilder
106-
(di_location line col scope)
122+
may (Llvm.set_current_debug_location llbuilder)
123+
(di_location_from_id scope id)
107124
in
108125

109126
(* Translation of our node_ids into LLVM identifiers, which are strings. *)
@@ -445,9 +462,10 @@ let trans_crate
445462
let llty = trans_slot None slot in
446463
let ty = Semant.slot_ty slot in
447464

448-
let new_block klass =
465+
let new_block klass debug_loc =
449466
let llblock = Llvm.append_block llctx (anon_llid klass) llfn in
450-
let llbuilder = Llvm.builder_at_end llctx llblock in
467+
let llbuilder =
468+
llbuilder_at_end_with_debug_loc llctx llblock debug_loc in
451469
(llblock, llbuilder)
452470
in
453471

@@ -460,8 +478,9 @@ let trans_crate
460478
let test =
461479
Llvm.build_icmp Llvm.Icmp.Ne null ptr (anon_llid "nullp") llbuilder
462480
in
463-
let (llthen, llthen_builder) = new_block "then" in
464-
let (llnext, llnext_builder) = new_block "next" in
481+
let debug_loc = Llvm.current_debug_location llbuilder in
482+
let (llthen, llthen_builder) = new_block "then" debug_loc in
483+
let (llnext, llnext_builder) = new_block "next" debug_loc in
465484
ignore (Llvm.build_cond_br test llthen llnext llbuilder);
466485
let llthen_builder = inner ptr llthen_builder in
467486
ignore (Llvm.build_br llnext llthen_builder);
@@ -483,8 +502,9 @@ let trans_crate
483502
Llvm.build_icmp Llvm.Icmp.Eq
484503
rc (imm 0L) (anon_llid "zerop") llbuilder
485504
in
486-
let (llthen, llthen_builder) = new_block "then" in
487-
let (llnext, llnext_builder) = new_block "next" in
505+
let debug_loc = Llvm.current_debug_location llbuilder in
506+
let (llthen, llthen_builder) = new_block "then" debug_loc in
507+
let (llnext, llnext_builder) = new_block "next" debug_loc in
488508
ignore (Llvm.build_cond_br test llthen llnext llbuilder);
489509
let llthen_builder = inner ptr llthen_builder in
490510
ignore (Llvm.build_br llnext llthen_builder);
@@ -588,16 +608,18 @@ let trans_crate
588608
* a little trickery here to wrangle the statement sequence into LLVM's
589609
* format. *)
590610

591-
let new_block id_opt klass =
611+
let new_block id_opt klass debug_loc =
592612
let llblock = Llvm.append_block llctx (node_llid id_opt klass) llfn in
593-
let llbuilder = Llvm.builder_at_end llctx llblock in
594-
(llblock, llbuilder)
613+
let llbuilder =
614+
llbuilder_at_end_with_debug_loc llctx llblock debug_loc in
615+
(llblock, llbuilder)
595616
in
596617

597618
(* Build up the slot-to-llvalue mapping, allocating space along the
598619
* way. *)
599620
let slot_to_llvalue = Hashtbl.create 0 in
600-
let (_, llinitbuilder) = new_block None "init" in
621+
let (_, llinitbuilder) =
622+
new_block None "init" (di_location_from_id llsubprogram fn_id) in
601623

602624
(* Allocate space for arguments (needed because arguments are lvalues in
603625
* Rust), and store them in the slot-to-llvalue mapping. *)
@@ -885,7 +907,9 @@ let trans_crate
885907

886908
| Ast.STMT_if sif ->
887909
let llexpr = trans_expr sif.Ast.if_test in
888-
let (llnext, llnextbuilder) = new_block None "next" in
910+
let (llnext, llnextbuilder) =
911+
new_block None "next"
912+
(Llvm.current_debug_location llbuilder) in
889913
let branch_to_next llbuilder' _ =
890914
ignore (Llvm.build_br llnext llbuilder')
891915
in
@@ -931,10 +955,13 @@ let trans_crate
931955

932956
| Ast.STMT_check_expr expr ->
933957
let llexpr = trans_expr expr in
934-
let (llfail, llfailbuilder) = new_block None "fail" in
958+
let debug_loc = Llvm.current_debug_location llbuilder in
959+
let (llfail, llfailbuilder) =
960+
new_block None "fail" debug_loc in
935961
let reason = Fmt.fmt_to_str Ast.fmt_expr expr in
936962
trans_fail llfailbuilder lltask reason head.id;
937-
let (llok, llokbuilder) = new_block None "ok" in
963+
let (llok, llokbuilder) =
964+
new_block None "ok" debug_loc in
938965
ignore (Llvm.build_cond_br llexpr llok llfail llbuilder);
939966
trans_tail_with_builder llokbuilder
940967

@@ -966,7 +993,8 @@ let trans_crate
966993
({ node = (stmts:Ast.stmt array); id = id }:Ast.block)
967994
(terminate:Llvm.llbuilder -> node_id -> unit)
968995
: Llvm.llbasicblock =
969-
let (llblock, llbuilder) = new_block (Some id) "bb" in
996+
let (llblock, llbuilder) =
997+
new_block (Some id) "bb" (di_location_from_id llsubprogram id) in
970998
trans_stmts id llbuilder (Array.to_list stmts) terminate;
971999
llblock
9721000
in

0 commit comments

Comments
 (0)