-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add new interface to smir #115187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new interface to smir #115187
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,18 +9,12 @@ | |
#![feature(rustc_private)] | ||
#![feature(assert_matches)] | ||
|
||
extern crate rustc_driver; | ||
extern crate rustc_hir; | ||
extern crate rustc_interface; | ||
extern crate rustc_middle; | ||
extern crate rustc_session; | ||
extern crate rustc_smir; | ||
|
||
use rustc_driver::{Callbacks, Compilation, RunCompiler}; | ||
oli-obk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
use rustc_hir::def::DefKind; | ||
use rustc_interface::{interface, Queries}; | ||
use rustc_middle::ty::TyCtxt; | ||
use rustc_session::EarlyErrorHandler; | ||
use rustc_smir::{rustc_internal, stable_mir}; | ||
use std::assert_matches::assert_matches; | ||
use std::io::Write; | ||
|
@@ -130,8 +124,8 @@ fn get_item<'a>( | |
|
||
/// This test will generate and analyze a dummy crate using the stable mir. | ||
/// For that, it will first write the dummy crate into a file. | ||
/// It will invoke the compiler using a custom Callback implementation, which will | ||
/// invoke Stable MIR APIs after the compiler has finished its analysis. | ||
/// Then it will create a `StableMir` using custom arguments and then | ||
/// it will run the compiler. | ||
fn main() { | ||
let path = "input.rs"; | ||
generate_input(&path).unwrap(); | ||
|
@@ -142,29 +136,7 @@ fn main() { | |
CRATE_NAME.to_string(), | ||
oli-obk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
path.to_string(), | ||
]; | ||
rustc_driver::catch_fatal_errors(|| { | ||
RunCompiler::new(&args, &mut SMirCalls {}).run().unwrap(); | ||
}) | ||
.unwrap(); | ||
} | ||
|
||
struct SMirCalls {} | ||
|
||
impl Callbacks for SMirCalls { | ||
/// Called after analysis. Return value instructs the compiler whether to | ||
/// continue the compilation afterwards (defaults to `Compilation::Continue`) | ||
fn after_analysis<'tcx>( | ||
&mut self, | ||
_handler: &EarlyErrorHandler, | ||
_compiler: &interface::Compiler, | ||
queries: &'tcx Queries<'tcx>, | ||
) -> Compilation { | ||
queries.global_ctxt().unwrap().enter(|tcx| { | ||
rustc_smir::rustc_internal::run(tcx, || test_stable_mir(tcx)); | ||
}); | ||
// No need to keep going. | ||
Compilation::Stop | ||
} | ||
rustc_internal::StableMir::new(args, test_stable_mir).run(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the piecemeal comments. I was playing with this code while creating a test driver for stable-mir. I was wondering if we could move this to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see #115187 (comment) I think it should stay in |
||
} | ||
|
||
fn generate_input(path: &str) -> std::io::Result<()> { | ||
|
Uh oh!
There was an error while loading. Please reload this page.