Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
use filament::{
backend, binding, cmdline, ir, ir_passes as ip, log_time, pass_pipeline,
passes::{self, Pass},
resolver::Resolver,
visitor::{Checker, Transform},
};
use std::time::Instant;
// Prints out the interface for main component in the input program.
fn run(opts: &cmdline::Opts) -> Result<(), u64> {
// enable tracing
env_logger::Builder::from_default_env()
.format_timestamp(None)
.format_module_path(false)
.format_target(false)
.filter_level(opts.log_level)
.target(env_logger::Target::Stderr)
.init();
let ns = match Resolver::from(opts).parse_namespace() {
Ok(mut ns) => {
ns.toplevel = opts.toplevel.clone();
ns
}
Err(e) => {
eprintln!("Error: {e:?}");
return Err(1);
}
};
log::debug!("{ns}");
// Construct a binding
let bind = binding::ProgBinding::try_from(&ns)?;
// Bind check
let t = Instant::now();
passes::BindCheck::check(opts, &ns, &bind)?;
log::info!("Parameteric Bind check: {}ms", t.elapsed().as_millis());
drop(bind);
if opts.ir {
let mut ir = ir::transform(ns);
pass_pipeline! {opts, ir;
ip::BuildDomination,
ip::TypeCheck,
ip::IntervalCheck,
ip::Assume,
ip::HoistFacts,
ip::Simplify,
ip::Discharge
}
// Return early if we're asked to dump the interface
if opts.check {
return Ok(());
}
// TODO(rachit): Once `BundleElim` implements `Visitor`, we can collapse this into
// one call to `pass_pipeline!`.
ir = log_time!(ip::Monomorphize::transform(&ir), "monomophization");
pass_pipeline! {opts, ir; ip::AssignCheck }
log_time!(ip::BundleElim::do_pass(&mut ir), "bundle-elim");
pass_pipeline! {opts, ir; ip::AssignCheck }
log_time!(ip::Compile::compile(ir), "compile");
return Ok(());
}
// Add default assumption constraints
let t = Instant::now();
let ns = passes::Assume::transform(ns);
log::info!("Assume: {}ms", t.elapsed().as_millis());
log::debug!("{ns}");
// Construct a binding
let bind = binding::ProgBinding::try_from(&ns)?;
// Interval checking
let t = Instant::now();
passes::IntervalCheck::check(opts, &ns, &bind)?;
log::info!("Interval check: {}ms", t.elapsed().as_millis());
// User-level @phantom ports
let t = Instant::now();
passes::PhantomCheck::check(opts, &ns, &bind)?;
log::info!("Phantom check: {}ms", t.elapsed().as_millis());
// Monomorphize the program.
let t = Instant::now();
let ns = passes::Monomorphize::transform(ns);
log::info!("Monomorphize: {}ms", t.elapsed().as_millis());
log::debug!("{ns}");
// Bundle elimination
let t = Instant::now();
let ns = passes::BundleElim::transform(ns);
log::info!("Bundle elimination: {}ms", t.elapsed().as_millis());
log::debug!("{ns}");
// Rebuild the binding
let bind = binding::ProgBinding::try_from(&ns)?;
// Monomorphic Bind check
let t = Instant::now();
passes::BindCheck::check(opts, &ns, &bind)?;
log::info!("Monomorphoic Bind check: {}ms", t.elapsed().as_millis());
// Monomorphic Interval checking
let t = Instant::now();
passes::IntervalCheck::check(opts, &ns, &bind)?;
log::info!("Monomorphoic Interval check: {}ms", t.elapsed().as_millis());
// Max state calculation
let states = passes::MaxStates::check(opts, &ns, &bind)?;
if opts.dump_interface {
passes::DumpInterface::print(&ns, &states.max_states);
return Ok(());
}
// Return early if we're asked to dump the interface
if opts.check {
return Ok(());
}
// Lowering
let t = Instant::now();
let Some(ns) =
passes::Lower::transform_unwrap(ns, states.max_states) else {
return Err(1);
};
log::info!("Lowering: {}ms", t.elapsed().as_millis());
log::debug!("{ns}");
// Compilation
let t = Instant::now();
backend::compile(ns);
log::info!("Compilation: {}ms", t.elapsed().as_millis());
Ok(())
}
fn main() {
let opts: cmdline::Opts = argh::from_env();
match run(&opts) {
Ok(_) => (),
Err(err) => {
eprintln!("Compilation failed with {err} errors.");
if !opts.show_models {
eprintln!("Run with --show-models to generate assignments for failing constraints.");
}
std::process::exit(1)
}
}
}
cdff47fcaThis file is pinned to the selected release. Download the original to open it in your design tool.