Macro rustc_smir::run
source · macro_rules! run { ($args:expr, $callback_fn:ident) => { ... }; ($args:expr, $callback:expr) => { ... }; }
Expand description
Instantiate and run the compiler with the provided arguments and callback.
The callback will be invoked after the compiler ran all its analyses, but before code generation. Note that this macro accepts two different formats for the callback:
- An ident that resolves to a function that accepts no argument and returns
ControlFlow<B, C>
# extern crate rustc_driver;
# extern crate rustc_interface;
# #[macro_use]
# extern crate rustc_smir;
# extern crate stable_mir;
#
# fn main() {
# use std::ops::ControlFlow;
# use stable_mir::CompilerError;
fn analyze_code() -> ControlFlow<(), ()> {
// Your code goes in here.
# ControlFlow::Continue(())
}
# let args = vec!["--verbose".to_string()];
let result = run!(args, analyze_code);
# assert_eq!(result, Err(CompilerError::Skipped))
# }
- A closure expression:
# extern crate rustc_driver;
# extern crate rustc_interface;
# #[macro_use]
# extern crate rustc_smir;
# extern crate stable_mir;
#
# fn main() {
# use std::ops::ControlFlow;
# use stable_mir::CompilerError;
fn analyze_code(extra_args: Vec<String>) -> ControlFlow<(), ()> {
# let _ = extra_args;
// Your code goes in here.
# ControlFlow::Continue(())
}
# let args = vec!["--verbose".to_string()];
# let extra_args = vec![];
let result = run!(args, || analyze_code(extra_args));
# assert_eq!(result, Err(CompilerError::Skipped))
# }