Add a -O option and change the Makefile to use it.

上级 ddf96ac3
......@@ -14,7 +14,7 @@ CFG_INFO := $(info cfg: building on $(CFG_OSTYPE) $(CFG_CPUTYPE))
CFG_GCC_CFLAGS :=
CFG_GCC_LINK_FLAGS :=
CFG_BOOT_FLAGS := $(BOOT_FLAGS)
CFG_RUSTC_FLAGS := -nowarn
CFG_RUSTC_FLAGS := -nowarn -O
# On Darwin, we need to run dsymutil so the debugging information ends
# up in the right place. On other platforms, it automatically gets
......
......@@ -58,6 +58,7 @@ fn default_environment(session.session sess,
eval.env env,
str input, str output,
bool shared,
bool optimize,
vec[str] library_search_paths) {
auto def = tup(0, 0);
auto p = parser.new_parser(sess, env, def, input);
......@@ -69,7 +70,7 @@ fn default_environment(session.session sess,
auto type_cache = typeck_result._1;
// FIXME: uncomment once typestate_check works
// crate = typestate_check.check_crate(crate);
trans.trans_crate(sess, crate, type_cache, output, shared);
trans.trans_crate(sess, crate, type_cache, output, shared, optimize);
}
impure fn pretty_print_input(session.session sess,
......@@ -131,6 +132,9 @@ fn get_os() -> session.os {
let bool pretty = false;
let bool glue = false;
// FIXME: Maybe we should support -O0, -O1, -Os, etc
let bool optimize = false;
auto i = 1u;
auto len = _vec.len[str](args);
......@@ -140,6 +144,8 @@ fn get_os() -> session.os {
if (_str.byte_len(arg) > 0u && arg.(0) == '-' as u8) {
if (_str.eq(arg, "-nowarn")) {
do_warn = false;
} else if (_str.eq(arg, "-O")) {
optimize = true;
} else if (_str.eq(arg, "-glue")) {
glue = true;
} else if (_str.eq(arg, "-shared")) {
......@@ -189,10 +195,10 @@ fn get_os() -> session.os {
if (glue) {
alt (output_file) {
case (none[str]) {
middle.trans.make_common_glue("glue.bc");
middle.trans.make_common_glue("glue.bc", optimize);
}
case (some[str](?s)) {
middle.trans.make_common_glue(s);
middle.trans.make_common_glue(s, optimize);
}
}
ret;
......@@ -217,11 +223,11 @@ fn get_os() -> session.os {
parts += vec(".bc");
auto ofile = _str.concat(parts);
compile_input(sess, env, ifile, ofile, shared,
library_search_paths);
optimize, library_search_paths);
}
case (some[str](?ofile)) {
compile_input(sess, env, ifile, ofile, shared,
library_search_paths);
optimize, library_search_paths);
}
}
}
......
......@@ -7003,7 +7003,7 @@ fn make_glues(ModuleRef llmod, type_names tn) -> @glue_fns {
vec_append_glue = make_vec_append_glue(llmod, tn));
}
fn make_common_glue(str output) {
fn make_common_glue(str output, bool optimize) {
// FIXME: part of this is repetitive and is probably a good idea
// to autogen it, but things like the memcpy implementation are not
// and it might be better to just check in a .ll file.
......@@ -7029,14 +7029,15 @@ fn make_common_glue(str output) {
trans_exit_task_glue(glues, new_str_hash[ValueRef](), tn, llmod);
run_passes(llmod, true);
run_passes(llmod, optimize);
llvm.LLVMWriteBitcodeToFile(llmod, _str.buf(output));
llvm.LLVMDisposeModule(llmod);
}
fn trans_crate(session.session sess, @ast.crate crate,
&ty.type_cache type_cache, str output, bool shared) {
&ty.type_cache type_cache, str output, bool shared,
bool optimize) {
auto llmod =
llvm.LLVMModuleCreateWithNameInContext(_str.buf("rust_out"),
llvm.LLVMGetGlobalContext());
......@@ -7099,8 +7100,7 @@ fn trans_crate(session.session sess, @ast.crate crate,
// Translate the metadata.
middle.metadata.write_metadata(cx, crate);
// FIXME: Add an -O option
run_passes(llmod, true);
run_passes(llmod, optimize);
llvm.LLVMWriteBitcodeToFile(llmod, _str.buf(output));
llvm.LLVMDisposeModule(llmod);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册