Skip to content
This repository has been archived by the owner on Mar 1, 2019. It is now read-only.

[WIP] Use the new rustc interface #11

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 13 additions & 61 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,20 @@ extern crate rustc_driver;
extern crate rustc_errors;
extern crate rustc_metadata;
extern crate rustc_codegen_utils;
extern crate rustc_interface;
extern crate syntax;

use rustc_metadata::cstore::CStore;
use rustc::session::{Session, early_error};
use rustc::session::config::{self, ErrorOutputType, Input};
use rustc_codegen_utils::codegen_backend::CodegenBackend;
use rustc_driver::driver::CompileController;
use rustc_driver::{run_compiler, CompilerCalls, RustcDefaultCalls, Compilation, enable_save_analysis};
use syntax::ast;
use rustc::session::early_error;
use rustc::session::config::ErrorOutputType;
use rustc_driver::{run_compiler, Callbacks};
use rustc_interface::interface;

use std::env;
use std::path::PathBuf;
use std::process;

pub fn run() {
drop(env_logger::init());
let result = rustc_driver::run(|| {
let result = rustc_driver::report_ices_to_stderr_if_any(|| {
let args = env::args_os().enumerate()
.map(|(i, arg)| arg.into_string().unwrap_or_else(|arg| {
early_error(ErrorOutputType::default(),
Expand All @@ -33,63 +30,18 @@ pub fn run() {
.collect::<Vec<_>>();

run_compiler(&args,
Box::new(ShimCalls),
&mut ShimCalls,
None,
None)
});
process::exit(result as i32);
}).and_then(|result| result);
process::exit(result.is_err() as i32);
}


struct ShimCalls;

impl<'a> CompilerCalls<'a> for ShimCalls {
fn early_callback(&mut self,
a: &getopts::Matches,
b: &config::Options,
c: &ast::CrateConfig,
d: &rustc_errors::registry::Registry,
e: ErrorOutputType)
-> Compilation {
RustcDefaultCalls.early_callback(a, b, c, d, e)
}

fn late_callback(&mut self,
a: &CodegenBackend,
b: &getopts::Matches,
c: &Session,
d: &CStore,
e: &Input,
f: &Option<PathBuf>,
g: &Option<PathBuf>)
-> Compilation {
RustcDefaultCalls.late_callback(a, b, c, d, e, f, g)
}

fn some_input(&mut self,
a: Input,
b: Option<PathBuf>)
-> (Input, Option<PathBuf>) {
RustcDefaultCalls.some_input(a, b)
}

fn no_input(&mut self,
a: &getopts::Matches,
b: &config::Options,
c: &ast::CrateConfig,
d: &Option<PathBuf>,
e: &Option<PathBuf>,
f: &rustc_errors::registry::Registry)
-> Option<(Input, Option<PathBuf>)> {
RustcDefaultCalls.no_input(a, b, c, d, e, f)
}

fn build_controller(self: Box<Self>, a: &Session, b: &getopts::Matches) -> CompileController<'a> {
let mut result = Box::new(RustcDefaultCalls).build_controller(a, b);

result.continue_parse_after_error = true;
enable_save_analysis(&mut result);

result
impl Callbacks for ShimCalls {
fn config(&mut self, config: &mut interface::Config) {
config.opts.debugging_opts.continue_parse_after_error = true;
config.opts.debugging_opts.save_analysis = true;
}
}