feat: add compile cli
This commit is contained in:
30
src/bin/compile.rs
Normal file
30
src/bin/compile.rs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
use std::process::exit;
|
||||||
|
|
||||||
|
use itertools::Itertools;
|
||||||
|
|
||||||
|
use nixjit::compile::compile;
|
||||||
|
use nixjit::error::Error;
|
||||||
|
use nixjit::error::Result;
|
||||||
|
use nixjit::ir::downgrade;
|
||||||
|
|
||||||
|
fn main() -> Result<()> {
|
||||||
|
let mut args = std::env::args();
|
||||||
|
if args.len() != 2 {
|
||||||
|
eprintln!("Usage: {} expr", args.next().unwrap());
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
args.next();
|
||||||
|
let expr = args.next().unwrap();
|
||||||
|
let root = rnix::Root::parse(&expr);
|
||||||
|
if !root.errors().is_empty() {
|
||||||
|
return Err(Error::ParseError(
|
||||||
|
root.errors().iter().map(|err| err.to_string()).join(";"),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
let expr = root.tree().expr().unwrap();
|
||||||
|
let downgraded = downgrade(expr)?;
|
||||||
|
let prog = compile(downgraded);
|
||||||
|
println!("{:?}", prog);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user