Add -minimal mode to rustboot that skips emitting code that's broken or unneeded for rustc. Shrink rustc by 300kb. Back under 1mb.

This commit is contained in:
Graydon Hoare 2010-10-05 18:44:39 -07:00
parent d1e59d6910
commit 8ecbe49a8f
6 changed files with 38 additions and 16 deletions

View File

@ -368,7 +368,8 @@ endif
$(CFG_COMPILER): $(COMPILER_INPUTS) $(CFG_BOOT) $(CFG_RUNTIME) $(CFG_STDLIB)
@$(call CFG_ECHO, compile: $<)
$(CFG_QUIET)OCAMLRUNPARAM="b1" $(CFG_BOOT) $(CFG_BOOT_FLAGS) -o $@ $<
$(CFG_QUIET)OCAMLRUNPARAM="b1" $(CFG_BOOT) $(CFG_BOOT_FLAGS) \
-minimal -o $@ $<
$(CFG_QUIET)chmod 0755 $@
self: $(CFG_COMPILER)

View File

@ -126,7 +126,8 @@ type abi =
-> Common.nabi
-> Common.fixup (* grow_task *)
-> bool (* is_obj_fn *)
-> unit);
-> bool (* minimal *)
-> unit);
abi_emit_fn_epilogue: (Il.emitter -> unit);

View File

@ -1236,6 +1236,7 @@ let fn_prologue
(nabi:nabi)
(grow_task_fixup:fixup)
(is_obj_fn:bool)
(minimal:bool)
: unit =
let esi_n = word_n (h esi) in
@ -1372,8 +1373,11 @@ let fn_prologue
in
(* "Full" frame size-check. *)
stack_growth_check e nabi grow_task_fixup
dynamic_frame_sz dynamic_grow_jmp restart_pc (h esi) (h edi);
match dynamic_grow_jmp with
None when minimal -> ()
| _ ->
stack_growth_check e nabi grow_task_fixup
dynamic_frame_sz dynamic_grow_jmp restart_pc (h esi) (h edi);
(* Establish a frame, wherever we landed. *)

View File

@ -24,6 +24,7 @@ let (sess:Session.sess) =
Session.sess_out = None;
Session.sess_library_mode = false;
Session.sess_alt_backend = false;
Session.sess_minimal = false;
Session.sess_use_pexps = false;
(* FIXME (issue #69): need something fancier here for unix
* sub-flavours.
@ -229,6 +230,10 @@ let argspecs =
(flag (fun _ -> sess.Session.sess_use_pexps <- true)
"-pexp" "use pexp portion of AST");
(flag (fun _ -> sess.Session.sess_minimal <- true)
"-minimal" ("reduce code size by disabling various features"
^ " (use at own risk)"));
("-zc", Arg.Int (fun i -> sess.Session.sess_fuzz_item_count <- i),
"count of items to generate when fuzzing");

View File

@ -13,6 +13,7 @@ type sess =
mutable sess_out: filename option;
mutable sess_library_mode: bool;
mutable sess_alt_backend: bool;
mutable sess_minimal: bool;
mutable sess_use_pexps: bool;
mutable sess_targ: target;
mutable sess_log_lex: bool;

View File

@ -1488,6 +1488,7 @@ let trans_visitor
let frame_fns =
match fnid with
None -> zero
| Some _ when cx.ctxt_sess.Session.sess_minimal -> zero
| Some fnid -> get_frame_glue_fns fnid
in
let crate_ptr_reg = next_vreg () in
@ -1499,14 +1500,19 @@ let trans_visitor
mov (word_at (fp_imm frame_fns_disp)) frame_fns
and check_interrupt_flag _ =
let dom = next_vreg_cell wordptr_ty in
let flag = next_vreg_cell word_sty in
mov dom (Il.Cell (tp_imm (word_n Abi.task_field_dom)));
mov flag (Il.Cell (deref_imm dom
(word_n Abi.dom_field_interrupt_flag)));
let null_jmp = null_check flag in
trans_yield ();
patch null_jmp
if cx.ctxt_sess.Session.sess_minimal
then ()
else
begin
let dom = next_vreg_cell wordptr_ty in
let flag = next_vreg_cell word_sty in
mov dom (Il.Cell (tp_imm (word_n Abi.task_field_dom)));
mov flag (Il.Cell (deref_imm dom
(word_n Abi.dom_field_interrupt_flag)));
let null_jmp = null_check flag in
trans_yield ();
patch null_jmp
end
and trans_glue_frame_entry
(callsz:size)
@ -1534,7 +1540,8 @@ let trans_visitor
push_new_emitter_with_vregs None;
iflog (fun _ -> annotate "prologue");
abi.Abi.abi_emit_fn_prologue (emitter())
framesz callsz nabi_rust (upcall_fixup "upcall_grow_task") false;
framesz callsz nabi_rust (upcall_fixup "upcall_grow_task")
false cx.ctxt_sess.Session.sess_minimal;
write_frame_info_ptrs None;
(* FIXME: not clear why, but checking interrupt in glue context
* causes many.rs to crash when run on a sufficiently large number
@ -4766,7 +4773,8 @@ let trans_visitor
push_new_emitter_with_vregs (Some id);
iflog (fun _ -> annotate "prologue");
abi.Abi.abi_emit_fn_prologue (emitter())
framesz callsz nabi_rust (upcall_fixup "upcall_grow_task") false;
framesz callsz nabi_rust (upcall_fixup "upcall_grow_task")
false cx.ctxt_sess.Session.sess_minimal;
write_frame_info_ptrs None;
iflog (fun _ -> annotate "finished prologue");
trans_block fe.Ast.for_each_body;
@ -5371,7 +5379,8 @@ let trans_visitor
(string_of_size callsz)));
abi.Abi.abi_emit_fn_prologue
(emitter()) framesz callsz nabi_rust
(upcall_fixup "upcall_grow_task") obj_fn;
(upcall_fixup "upcall_grow_task") obj_fn
cx.ctxt_sess.Session.sess_minimal;
write_frame_info_ptrs (Some fnid);
if yield_check
@ -5765,7 +5774,8 @@ let trans_visitor
push_new_emitter_with_vregs (Some b.id);
iflog (fun _ -> annotate "prologue");
abi.Abi.abi_emit_fn_prologue (emitter())
framesz callsz nabi_rust (upcall_fixup "upcall_grow_task") true;
framesz callsz nabi_rust (upcall_fixup "upcall_grow_task")
true cx.ctxt_sess.Session.sess_minimal;
write_frame_info_ptrs None;
iflog (fun _ -> annotate "finished prologue");
trans_block b;