diff options
| author | Rafael Ávila de Espíndola <[email protected]> | 2011-04-15 17:35:46 -0400 |
|---|---|---|
| committer | Rafael Ávila de Espíndola <[email protected]> | 2011-04-15 17:41:14 -0400 |
| commit | 2214b6835d8bf5b33a3fb8b6a897abaea55ef368 (patch) | |
| tree | d6209d2e1dca535f4e0e5225108a6b8cb876c266 /src/comp | |
| parent | rustc: Make fold_ty no longer use an object; introduce walk_ty (diff) | |
| download | rust-2214b6835d8bf5b33a3fb8b6a897abaea55ef368.tar.xz rust-2214b6835d8bf5b33a3fb8b6a897abaea55ef368.zip | |
Add a -S option for producing assembly. I will move more of it to
rust once the necessary APIs are available in C.
Diffstat (limited to 'src/comp')
| -rw-r--r-- | src/comp/driver/rustc.rs | 21 | ||||
| -rw-r--r-- | src/comp/lib/llvm.rs | 3 | ||||
| -rw-r--r-- | src/comp/middle/trans.rs | 34 |
3 files changed, 38 insertions, 20 deletions
diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs index 9b2d88e8..d6f6f694 100644 --- a/src/comp/driver/rustc.rs +++ b/src/comp/driver/rustc.rs @@ -60,12 +60,12 @@ impure fn compile_input(session.session sess, str input, str output, bool shared, bool optimize, - bool parse_only, + trans.output_type ot, vec[str] library_search_paths) { auto def = tup(0, 0); auto p = parser.new_parser(sess, env, def, input, 0u); auto crate = parse_input(sess, p, input); - if (parse_only) {ret;} + if (ot == trans.output_type_none) {ret;} crate = creader.read_crates(sess, crate, library_search_paths); crate = resolve.resolve_crate(sess, crate); capture.check_for_captures(sess, crate); @@ -74,7 +74,8 @@ impure fn compile_input(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, optimize); + trans.trans_crate(sess, crate, type_cache, output, shared, optimize, + ot); } impure fn pretty_print_input(session.session sess, @@ -137,7 +138,7 @@ impure fn main(vec[str] args) { let bool shared = false; let bool pretty = false; let bool ls = false; - let bool parse_only = false; + auto ot = trans.output_type_bitcode; let bool glue = false; // FIXME: Maybe we should support -O0, -O1, -Os, etc @@ -163,7 +164,9 @@ impure fn main(vec[str] args) { } else if (_str.eq(arg, "-ls")) { ls = true; } else if (_str.eq(arg, "-parse-only")) { - parse_only = true; + ot = trans.output_type_none; + } else if (_str.eq(arg, "-S")) { + ot = trans.output_type_assembly; } else if (_str.eq(arg, "-o")) { if (i+1u < len) { output_file = some(args.(i+1u)); @@ -207,10 +210,10 @@ impure fn main(vec[str] args) { if (glue) { alt (output_file) { case (none[str]) { - middle.trans.make_common_glue("glue.bc", optimize); + middle.trans.make_common_glue("glue.bc", optimize, ot); } case (some[str](?s)) { - middle.trans.make_common_glue(s, optimize); + middle.trans.make_common_glue(s, optimize, ot); } } ret; @@ -236,12 +239,12 @@ impure fn main(vec[str] args) { parts += vec(".bc"); auto ofile = _str.concat(parts); compile_input(sess, env, ifile, ofile, shared, - optimize, parse_only, + optimize, ot, library_search_paths); } case (some[str](?ofile)) { compile_input(sess, env, ifile, ofile, shared, - optimize, parse_only, + optimize, ot, library_search_paths); } } diff --git a/src/comp/lib/llvm.rs b/src/comp/lib/llvm.rs index 67703205..8d0910d5 100644 --- a/src/comp/lib/llvm.rs +++ b/src/comp/lib/llvm.rs @@ -815,6 +815,9 @@ native mod llvm = llvm_lib { fn LLVMRustCreateMemoryBufferWithContentsOfFile(sbuf Path) -> MemoryBufferRef; + fn LLVMRustWriteAssembly(PassManagerRef PM, ModuleRef M, + sbuf Triple, sbuf Output); + /** Returns a string describing the last error caused by an LLVMRust* call. */ fn LLVMRustGetLastError() -> sbuf; diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 71ad468c..187265e9 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -6675,8 +6675,14 @@ fn trap(@block_ctxt bcx) { let vec[ValueRef] v = vec(); bcx.build.Call(bcx.fcx.ccx.intrinsics.get("llvm.trap"), v); } +tag output_type { + output_type_none; + output_type_bitcode; + output_type_assembly; +} -fn run_passes(ModuleRef llmod, bool opt) { +fn run_passes(ModuleRef llmod, bool opt, str output, + output_type ot) { auto pm = mk_pass_manager(); // TODO: run the linter here also, once there are llvm-c bindings for it. @@ -6741,7 +6747,18 @@ fn run_passes(ModuleRef llmod, bool opt) { llvm.LLVMAddConstantMergePass(pm.llpm); } llvm.LLVMAddVerifierPass(pm.llpm); + + if (ot == output_type_assembly) { + llvm.LLVMRustWriteAssembly(pm.llpm, llmod, + _str.buf(x86.get_target_triple()), + _str.buf(output)); + ret; + } + llvm.LLVMRunPassManager(pm.llpm, llmod); + + llvm.LLVMWriteBitcodeToFile(llmod, _str.buf(output)); + llvm.LLVMDisposeModule(llmod); } fn decl_no_op_type_glue(ModuleRef llmod, type_names tn) -> ValueRef { @@ -7073,7 +7090,8 @@ 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, bool optimize) { +fn make_common_glue(str output, bool optimize, + output_type ot) { // 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. @@ -7099,15 +7117,12 @@ fn make_common_glue(str output, bool optimize) { trans_exit_task_glue(glues, new_str_hash[ValueRef](), tn, llmod); - run_passes(llmod, optimize); - - llvm.LLVMWriteBitcodeToFile(llmod, _str.buf(output)); - llvm.LLVMDisposeModule(llmod); + run_passes(llmod, optimize, output, ot); } fn trans_crate(session.session sess, @ast.crate crate, &ty.type_cache type_cache, str output, bool shared, - bool optimize) { + bool optimize, output_type ot) { auto llmod = llvm.LLVMModuleCreateWithNameInContext(_str.buf("rust_out"), llvm.LLVMGetGlobalContext()); @@ -7170,10 +7185,7 @@ fn trans_crate(session.session sess, @ast.crate crate, // Translate the metadata. middle.metadata.write_metadata(cx, crate); - run_passes(llmod, optimize); - - llvm.LLVMWriteBitcodeToFile(llmod, _str.buf(output)); - llvm.LLVMDisposeModule(llmod); + run_passes(llmod, optimize, output, ot); } // |