/// Compiles input up to phase 4, translation to LLVM.
///
/// Returns the LLVM `ModuleRef` and a series of paths to dynamic libraries
/// for crates used in the given input.
Compiles input up to phase 4, translation to LLVM.
Returns the LLVM `ModuleRef` and a series of paths to dynamic libraries
for crates used in the given input.
Compiles input up to phase 4 translation to LLVM . Returns the LLVM ` ModuleRef ` and a series of paths to dynamic libraries for crates used in the given input .
fn compile_program(input: &str, sysroot: PathBuf)
                   -> Option<(llvm::ModuleRef, Vec<PathBuf>)> {
    let input = Input::Str(input.to_string());
    let thread = Builder::new().name("compile_program".to_string());
    let handle = thread.spawn(move || {
        let opts = build_exec_options(sysroot);
        let sess = build_session(opts, None, Registry::new(&rustc::DIAGNOSTICS));
        rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
        let cfg = build_configuration(&sess);
        let id = "input".to_string();
        let krate = driver::phase_1_parse_input(&sess, cfg, &input);
        let krate = driver::phase_2_configure_and_expand(&sess, krate, &id, None)
            .expect("phase_2 returned `None`");
        let krate = driver::assign_node_ids(&sess, krate);
        let mut hir_forest = ast_map::Forest::new(lower_crate(&krate));
        let arenas = ty::CtxtArenas::new();
        let ast_map = driver::make_map(&sess, &mut hir_forest);
        driver::phase_3_run_analysis_passes(
            sess, ast_map, &krate, &arenas, id, MakeGlobMap::No, |tcx, analysis| {
            let trans = driver::phase_4_translate_to_llvm(tcx, analysis);
            let crates = tcx.sess.cstore.get_used_crates(RequireDynamic);
            // Collect crates used in the session.
            // Reverse order finds dependencies first.
            let deps = crates.into_iter().rev()
                .filter_map(|(_, p)| p).collect();
            assert_eq!(trans.modules.len(), 1);
            let llmod = trans.modules[0].llmod;
            // Workaround because raw pointers do not impl Send
            let modp = llmod as usize;
            (modp, deps)
        }).1
    }).unwrap();
    match handle.join() {
        Ok((llmod, deps)) => Some((llmod as llvm::ModuleRef, deps)),
        Err(_) => None
    }
}
fn compile_program ( input : & str , sysroot : PathBuf ) -> Option < ( llvm :: ModuleRef , Vec < PathBuf > ) > { let input = Input :: Str ( input . to_string ( ) ) ; let thread = Builder :: new ( ) . name ( " " . to_string ( ) ) ; let handle = thread . spawn ( move | | { let opts = build_exec_options ( sysroot ) ; let sess = build_session ( opts , None , Registry :: new ( & rustc :: DIAGNOSTICS ) ) ; rustc_lint :: register_builtins ( & mut sess . lint_store . borrow_mut ( ) , Some ( & sess ) ) ; let cfg = build_configuration ( & sess ) ; let id = " " . to_string ( ) ; let krate = driver :: phase_1_parse_input ( & sess , cfg , & input ) ; let krate = driver :: phase_2_configure_and_expand ( & sess , krate , & id , None ) . expect ( " " ) ; let krate = driver :: assign_node_ids ( & sess , krate ) ; let mut hir_forest = ast_map :: Forest :: new ( lower_crate ( & krate ) ) ; let arenas = ty :: CtxtArenas :: new ( ) ; let ast_map = driver :: make_map ( & sess , & mut hir_forest ) ; driver :: phase_3_run_analysis_passes ( sess , ast_map , & krate , & arenas , id , MakeGlobMap :: No , | tcx , analysis | { let trans = driver :: phase_4_translate_to_llvm ( tcx , analysis ) ; let crates = tcx . sess . cstore . get_used_crates ( RequireDynamic ) ; // Collect crates used in the session. // Reverse order finds dependencies first. let deps = crates . into_iter ( ) . rev ( ) . filter_map ( | ( _ , p ) | p ) . collect ( ) ; assert_eq ! ( trans modules len ( ) 1 ) ; let llmod = trans . modules [ 0 ] . llmod ; // Workaround because raw pointers do not impl Send let modp = llmod as usize ; ( modp , deps ) } ) . 1 } ) . unwrap ( ) ; match handle . join ( ) { Ok ( ( llmod , deps ) ) => Some ( ( llmod as llvm :: ModuleRef , deps ) ) , Err ( _ ) => None } }
Compiles input up to phase 4, translation to LLVM.
Compiles input up to phase 4 translation to LLVM .
input
&str
sysroot
PathBuf