jit: Clean rustllvm code, let rustc expose __morestack instead of linking in libmorestack and return _rust_main and call it from rustc

This commit is contained in:
Zack Corr
2012-08-29 15:49:35 +10:00
committed by Brian Anderson
parent e27b8f7f02
commit efb576a60d
4 changed files with 80 additions and 38 deletions

View File

@@ -12,7 +12,7 @@ import std::sha1::sha1;
import syntax::ast;
import syntax::print::pprust;
import lib::llvm::{ModuleRef, mk_pass_manager, mk_target_data, True, False,
FileType};
PassManagerRef, FileType};
import metadata::filesearch;
import syntax::ast_map::{path, path_mod, path_name};
import io::{Writer, WriterUtil};
@@ -54,6 +54,57 @@ fn WriteOutputFile(sess:session,
}
}
#[cfg(stage0)]
mod jit {
fn exec(_sess: session,
_pm: PassManagerRef,
_m: ModuleRef,
_opt: c_int,
_stacks: bool) {
fail
}
}
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
mod jit {
#[nolink]
#[abi = "rust-intrinsic"]
extern mod rusti {
fn morestack_addr() -> *();
}
struct Closure {
code: *();
env: *();
}
fn exec(sess: session,
pm: PassManagerRef,
m: ModuleRef,
opt: c_int,
stacks: bool) unsafe {
let ptr = llvm::LLVMRustJIT(rusti::morestack_addr(), pm, m, opt, stacks);
if ptr::is_null(ptr) {
llvm_err(sess, ~"Could not JIT");
} else {
let bin = match os::self_exe_path() {
Some(path) => path.to_str(),
_ => ~"rustc"
};
let closure = Closure {
code: ptr,
env: ptr::null()
};
let func: fn(~[~str]) = unsafe::transmute(closure);
func(~[bin]);
}
}
}
mod write {
fn is_object_or_assembly_or_exe(ot: output_type) -> bool {
if ot == output_type_assembly || ot == output_type_object ||
@@ -174,12 +225,7 @@ mod write {
});
}*/
if !llvm::LLVMRustJIT(pm.llpm,
llmod,
CodeGenOptLevel,
true) {
llvm_err(sess, ~"Could not JIT");
}
jit::exec(sess, pm.llpm, llmod, CodeGenOptLevel, true);
if sess.time_llvm_passes() {
llvm::LLVMRustPrintPassTimings();

View File

@@ -990,10 +990,11 @@ extern mod llvm {
fn LLVMRustLoadLibrary(Filename: *c_char) -> bool;
/** Create and execute the JIT engine. */
fn LLVMRustJIT(PM: PassManagerRef,
fn LLVMRustJIT(__morestack: *(),
PM: PassManagerRef,
M: ModuleRef,
OptLevel: c_int,
EnableSegmentedStacks: bool) -> bool;
EnableSegmentedStacks: bool) -> *();
/** Parses the bitcode in the given memory buffer. */
fn LLVMRustParseBitcode(MemBuf: MemoryBufferRef) -> ModuleRef;