Skip to content

Commit 9d0d350

Browse files
jyasskingraydon
authored andcommitted
Make the LLVM compiler crash when it hits a source construct it doesn't know
what to do with, rather than silently omitting it from the output.
1 parent fe78e33 commit 9d0d350

File tree

4 files changed

+41
-17
lines changed

4 files changed

+41
-17
lines changed

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ TEST_XFAILS_LLVM := $(addprefix test/run-pass/, \
373373
acyclic-unwind.rs \
374374
alt-pattern-simple.rs \
375375
alt-tag.rs \
376+
argv.rs \
376377
basic.rs \
377378
bind-obj-ctor.rs \
378379
bind-thunk.rs \

src/boot/fe/ast.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,8 @@ let sprintf_effect = sprintf_fmt fmt_effect;;
13891389
let sprintf_tag = sprintf_fmt fmt_tag;;
13901390
let sprintf_carg = sprintf_fmt fmt_carg;;
13911391
let sprintf_constr = sprintf_fmt fmt_constr;;
1392+
let sprintf_mod_item =
1393+
sprintf_fmt (fun ff (id,item) -> fmt_mod_item ff id item);;
13921394
let sprintf_mod_items = sprintf_fmt fmt_mod_items;;
13931395
let sprintf_decl_param = sprintf_fmt fmt_decl_param;;
13941396
let sprintf_decl_params = sprintf_fmt fmt_decl_params;;

src/boot/llvm/lltrans.ml

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,6 @@ let trans_crate
120120
| Some (Node num) -> num_llid num
121121
in
122122

123-
(*
124-
* Returns a bogus value for use in stub code that hasn't been implemented
125-
* yet.
126-
*
127-
* TODO: On some joyous day, remove me.
128-
*)
129-
let bogus = Llvm.const_null (Llvm.i32_type llctx) in
130-
let bogus_ptr = Llvm.const_null (Llvm.pointer_type (Llvm.i32_type llctx)) in
131-
132123
let llnilty = Llvm.array_type (Llvm.i1_type llctx) 0 in
133124
let llnil = Llvm.const_array (Llvm.i1_type llctx) [| |] in
134125

@@ -338,7 +329,9 @@ let trans_crate
338329
word_ty
339330

340331
| Ast.TY_tag _ | Ast.TY_iso _ | Ast.TY_idx _
341-
| Ast.TY_obj _ | Ast.TY_type -> (opaque()) (* TODO *)
332+
| Ast.TY_obj _ | Ast.TY_type ->
333+
raise (Not_implemented
334+
("trans_ty_full " ^ (Ast.sprintf_ty() ty)))
342335

343336
| Ast.TY_param _ | Ast.TY_named _ ->
344337
bug () "unresolved type in lltrans"
@@ -543,8 +536,10 @@ let trans_crate
543536
let (dbg_llscopes:(node_id, Llvm.llvalue) Hashtbl.t) = Hashtbl.create 0 in
544537
let declare_mod_item
545538
(name:Ast.ident)
546-
{ node = { Ast.decl_item = (item:Ast.mod_item') }; id = id }
539+
mod_item
547540
: unit =
541+
let { node = { Ast.decl_item = (item:Ast.mod_item') }; id = id } =
542+
mod_item in
548543
let full_name = Semant.item_str sem_cx id in
549544
let (filename, line_num) =
550545
match Session.get_span sess id with
@@ -564,7 +559,16 @@ let trans_crate
564559
Hashtbl.add llitems id llfn;
565560
Hashtbl.add dbg_llscopes id meta
566561

567-
| _ -> () (* TODO *)
562+
| Ast.MOD_ITEM_type _ ->
563+
() (* Types get translated with their terms. *)
564+
565+
| Ast.MOD_ITEM_mod _ ->
566+
() (* Modules simply contain other items that are translated
567+
on their own. *)
568+
569+
| _ -> raise (Not_implemented
570+
("declare_mod_item " ^
571+
(Ast.sprintf_mod_item() (name,mod_item))))
568572
in
569573

570574
let trans_fn
@@ -711,9 +715,12 @@ let trans_crate
711715
match referent with
712716
Semant.DEFN_slot _ -> Hashtbl.find slot_to_llvalue id
713717
| Semant.DEFN_item _ -> Hashtbl.find llitems id
714-
| _ -> bogus_ptr (* TODO *)
718+
| _ -> raise
719+
(Not_implemented
720+
("referent of " ^ (Ast.sprintf_lval() lval)))
715721
end
716-
| Ast.LVAL_ext _ -> bogus_ptr (* TODO *)
722+
| Ast.LVAL_ext _ -> raise
723+
(Not_implemented ("trans_lval " ^ (Ast.sprintf_lval() lval)))
717724
in
718725

719726
let trans_atom (atom:Ast.atom) : Llvm.llvalue =
@@ -754,10 +761,16 @@ let trans_crate
754761
| Ast.BINOP_div -> Llvm.build_sdiv lllhs llrhs llid llbuilder
755762
| Ast.BINOP_mod -> Llvm.build_srem lllhs llrhs llid llbuilder
756763

757-
| _ -> bogus (* TODO *)
764+
| _ -> raise
765+
(Not_implemented
766+
("trans_binary_expr " ^
767+
(Ast.sprintf_expr() (Ast.EXPR_binary (op,lhs,rhs)))))
758768
in
759769

760-
let trans_unary_expr _ = bogus in (* TODO *)
770+
let trans_unary_expr e = raise
771+
(Not_implemented ("trans_unary_expr " ^
772+
(Ast.sprintf_expr() (Ast.EXPR_unary e))))
773+
in
761774

762775
let trans_expr (expr:Ast.expr) : Llvm.llvalue =
763776
iflog (fun _ -> log sem_cx "trans_expr: %a" Ast.sprintf_expr expr);
@@ -915,7 +928,11 @@ let trans_crate
915928
(Some d) [| s; len |];
916929
trans_tail ()
917930

918-
| _ -> trans_stmts block_id llbuilder tail terminate
931+
| Ast.STMT_decl _ ->
932+
trans_tail ()
933+
934+
| _ -> raise (Not_implemented
935+
("trans_stmts " ^ (Ast.sprintf_stmt() head)))
919936

920937
(*
921938
* Translates an AST block to one or more LLVM basic blocks and returns

src/boot/util/common.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ let bug _ =
2525
in Printf.ksprintf k
2626
;;
2727

28+
(* TODO: On some joyous day, remove me. *)
29+
exception Not_implemented of string
30+
;;
31+
2832
exception Semant_err of ((node_id option) * string)
2933
;;
3034

0 commit comments

Comments
 (0)