librustc/libstd: No longer pass crate_map to start.

This commit is contained in:
Luqman Aden 2013-09-18 04:58:52 -04:00
parent d2b0b11aeb
commit 9621156fc3
6 changed files with 79 additions and 13 deletions

View File

@ -2442,11 +2442,6 @@ pub fn create_entry_wrapper(ccx: @mut CrateContext,
unsafe { unsafe {
llvm::LLVMPositionBuilderAtEnd(bld, llbb); llvm::LLVMPositionBuilderAtEnd(bld, llbb);
let crate_map = ccx.crate_map;
let opaque_crate_map = do "crate_map".with_c_str |buf| {
llvm::LLVMBuildPointerCast(bld, crate_map, Type::i8p().to_ref(), buf)
};
let (start_fn, args) = if use_start_lang_item { let (start_fn, args) = if use_start_lang_item {
let start_def_id = match ccx.tcx.lang_items.require(StartFnLangItem) { let start_def_id = match ccx.tcx.lang_items.require(StartFnLangItem) {
Ok(id) => id, Ok(id) => id,
@ -2469,8 +2464,7 @@ pub fn create_entry_wrapper(ccx: @mut CrateContext,
C_null(Type::opaque_box(ccx).ptr_to()), C_null(Type::opaque_box(ccx).ptr_to()),
opaque_rust_main, opaque_rust_main,
llvm::LLVMGetParam(llfn, 0), llvm::LLVMGetParam(llfn, 0),
llvm::LLVMGetParam(llfn, 1), llvm::LLVMGetParam(llfn, 1)
opaque_crate_map
] ]
}; };
(start_fn, args) (start_fn, args)
@ -2479,8 +2473,7 @@ pub fn create_entry_wrapper(ccx: @mut CrateContext,
let args = ~[ let args = ~[
C_null(Type::opaque_box(ccx).ptr_to()), C_null(Type::opaque_box(ccx).ptr_to()),
llvm::LLVMGetParam(llfn, 0 as c_uint), llvm::LLVMGetParam(llfn, 0 as c_uint),
llvm::LLVMGetParam(llfn, 1 as c_uint), llvm::LLVMGetParam(llfn, 1 as c_uint)
opaque_crate_map
]; ];
(rust_main, args) (rust_main, args)
@ -2659,6 +2652,8 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef {
let path = vec::append((*pth).clone(), [path_name(ni.ident)]); let path = vec::append((*pth).clone(), [path_name(ni.ident)]);
foreign::register_foreign_item_fn(ccx, abis, &path, ni) foreign::register_foreign_item_fn(ccx, abis, &path, ni)
} }
ast::foreign_item_static(*) if attr::contains_name(ni.attrs, "crate_map")
=> ccx.crate_map,
ast::foreign_item_static(*) => { ast::foreign_item_static(*) => {
let ident = foreign::link_name(ccx, ni); let ident = foreign::link_name(ccx, ni);
let g = do ident.with_c_str |buf| { let g = do ident.with_c_str |buf| {

View File

@ -402,8 +402,7 @@ fn check_start_fn_ty(ccx: &CrateCtxt,
bound_lifetime_names: opt_vec::Empty, bound_lifetime_names: opt_vec::Empty,
inputs: ~[ inputs: ~[
ty::mk_int(), ty::mk_int(),
ty::mk_imm_ptr(tcx, ty::mk_imm_ptr(tcx, ty::mk_u8())), ty::mk_imm_ptr(tcx, ty::mk_imm_ptr(tcx, ty::mk_u8()))
ty::mk_imm_ptr(tcx, ty::mk_u8())
], ],
output: ty::mk_int() output: ty::mk_int()
} }

View File

@ -16,6 +16,12 @@ use vec;
use hashmap::HashSet; use hashmap::HashSet;
use container::MutableSet; use container::MutableSet;
extern {
#[cfg(not(stage0))]
#[crate_map]
static CRATE_MAP: CrateMap;
}
pub struct ModEntry { pub struct ModEntry {
name: *c_char, name: *c_char,
log_level: *mut u32 log_level: *mut u32
@ -34,6 +40,11 @@ struct CrateMap {
children: [*CrateMap, ..1] children: [*CrateMap, ..1]
} }
#[cfg(not(stage0))]
pub fn get_crate_map() -> *CrateMap {
&'static CRATE_MAP as *CrateMap
}
unsafe fn version(crate_map: *CrateMap) -> i32 { unsafe fn version(crate_map: *CrateMap) -> i32 {
match (*crate_map).version { match (*crate_map).version {
1 => return 1, 1 => return 1,

View File

@ -12,6 +12,7 @@ use libc::{uintptr_t, exit, STDERR_FILENO};
use option::{Some, None, Option}; use option::{Some, None, Option};
use rt::util::dumb_println; use rt::util::dumb_println;
use rt::crate_map::{ModEntry, iter_crate_map}; use rt::crate_map::{ModEntry, iter_crate_map};
#[cfg(not(stage0))] use rt::crate_map::get_crate_map;
use str::StrSlice; use str::StrSlice;
use str::raw::from_c_str; use str::raw::from_c_str;
use u32; use u32;
@ -211,6 +212,7 @@ impl Logger for StdErrLogger {
/// Configure logging by traversing the crate map and setting the /// Configure logging by traversing the crate map and setting the
/// per-module global logging flags based on the logging spec /// per-module global logging flags based on the logging spec
#[fixed_stack_segment] #[inline(never)] #[fixed_stack_segment] #[inline(never)]
#[cfg(stage0)]
pub fn init(crate_map: *u8) { pub fn init(crate_map: *u8) {
use os; use os;
@ -224,6 +226,22 @@ pub fn init(crate_map: *u8) {
} }
} }
} }
#[cfg(not(stage0))]
pub fn init() {
use os;
let crate_map = get_crate_map() as *u8;
let log_spec = os::getenv("RUST_LOG");
match log_spec {
Some(spec) => {
update_log_settings(crate_map, spec);
}
None => {
update_log_settings(crate_map, ~"");
}
}
}
#[fixed_stack_segment] #[inline(never)] #[fixed_stack_segment] #[inline(never)]
pub fn console_on() { unsafe { rust_log_console_on() } } pub fn console_on() { unsafe { rust_log_console_on() } }

View File

@ -171,11 +171,11 @@ pub mod borrowck;
/// ///
/// * `argc` & `argv` - The argument vector. On Unix this information is used /// * `argc` & `argv` - The argument vector. On Unix this information is used
/// by os::args. /// by os::args.
/// * `crate_map` - Runtime information about the executing crate, mostly for logging
/// ///
/// # Return value /// # Return value
/// ///
/// The return value is used as the process return code. 0 on success, 101 on error. /// The return value is used as the process return code. 0 on success, 101 on error.
#[cfg(stage0)]
pub fn start(argc: int, argv: **u8, crate_map: *u8, main: ~fn()) -> int { pub fn start(argc: int, argv: **u8, crate_map: *u8, main: ~fn()) -> int {
init(argc, argv, crate_map); init(argc, argv, crate_map);
@ -184,12 +184,22 @@ pub fn start(argc: int, argv: **u8, crate_map: *u8, main: ~fn()) -> int {
return exit_code; return exit_code;
} }
#[cfg(not(stage0))]
pub fn start(argc: int, argv: **u8, main: ~fn()) -> int {
init(argc, argv);
let exit_code = run(main);
cleanup();
return exit_code;
}
/// Like `start` but creates an additional scheduler on the current thread, /// Like `start` but creates an additional scheduler on the current thread,
/// which in most cases will be the 'main' thread, and pins the main task to it. /// which in most cases will be the 'main' thread, and pins the main task to it.
/// ///
/// This is appropriate for running code that must execute on the main thread, /// This is appropriate for running code that must execute on the main thread,
/// such as the platform event loop and GUI. /// such as the platform event loop and GUI.
#[cfg(stage0)]
pub fn start_on_main_thread(argc: int, argv: **u8, crate_map: *u8, main: ~fn()) -> int { pub fn start_on_main_thread(argc: int, argv: **u8, crate_map: *u8, main: ~fn()) -> int {
init(argc, argv, crate_map); init(argc, argv, crate_map);
let exit_code = run_on_main_thread(main); let exit_code = run_on_main_thread(main);
@ -197,12 +207,21 @@ pub fn start_on_main_thread(argc: int, argv: **u8, crate_map: *u8, main: ~fn())
return exit_code; return exit_code;
} }
#[cfg(not(stage0))]
pub fn start_on_main_thread(argc: int, argv: **u8, main: ~fn()) -> int {
init(argc, argv);
let exit_code = run_on_main_thread(main);
cleanup();
return exit_code;
}
/// One-time runtime initialization. /// One-time runtime initialization.
/// ///
/// Initializes global state, including frobbing /// Initializes global state, including frobbing
/// the crate's logging flags, registering GC /// the crate's logging flags, registering GC
/// metadata, and storing the process arguments. /// metadata, and storing the process arguments.
#[cfg(stage0)]
pub fn init(argc: int, argv: **u8, crate_map: *u8) { pub fn init(argc: int, argv: **u8, crate_map: *u8) {
// XXX: Derefing these pointers is not safe. // XXX: Derefing these pointers is not safe.
// Need to propagate the unsafety to `start`. // Need to propagate the unsafety to `start`.
@ -212,6 +231,16 @@ pub fn init(argc: int, argv: **u8, crate_map: *u8) {
logging::init(crate_map); logging::init(crate_map);
} }
} }
#[cfg(not(stage0))]
pub fn init(argc: int, argv: **u8) {
// XXX: Derefing these pointers is not safe.
// Need to propagate the unsafety to `start`.
unsafe {
args::init(argc, argv);
env::init();
logging::init();
}
}
/// One-time runtime cleanup. /// One-time runtime cleanup.
pub fn cleanup() { pub fn cleanup() {

View File

@ -93,6 +93,7 @@ pub unsafe fn check_not_borrowed(a: *u8,
borrowck::check_not_borrowed(a, file, line) borrowck::check_not_borrowed(a, file, line)
} }
#[cfg(stage0)]
#[lang="start"] #[lang="start"]
pub fn start(main: *u8, argc: int, argv: **c_char, pub fn start(main: *u8, argc: int, argv: **c_char,
crate_map: *u8) -> int { crate_map: *u8) -> int {
@ -105,3 +106,16 @@ pub fn start(main: *u8, argc: int, argv: **c_char,
}; };
} }
} }
#[cfg(not(stage0))]
#[lang="start"]
pub fn start(main: *u8, argc: int, argv: **c_char) -> int {
use rt;
unsafe {
return do rt::start(argc, argv as **u8) {
let main: extern "Rust" fn() = transmute(main);
main();
};
}
}