mod builtin_cells; mod frontend; mod literals; mod parser; mod rtlil; use std::fs::File; use std::io::prelude::*; use std::path::PathBuf; use structopt::StructOpt; #[derive(Debug, StructOpt)] #[structopt(name = "example", about = "An example of StructOpt usage.")] struct Opt { /// Input file #[structopt(parse(from_os_str))] input: PathBuf, /// Debug AST #[structopt(short)] debug: bool, /// Output file, stdout if not present #[structopt(short, parse(from_os_str))] output: Option, } fn main() { let opt = Opt::from_args(); let mut infile = File::open(opt.input).expect("could not open file"); let mut input = String::new(); infile .read_to_string(&mut input) .expect("error reading file"); let input: &str = input.as_str(); let input = parser::Span::new(input); let parsed = parser::parse(input); match parsed { Err(nom::Err::Error(err) | nom::Err::Failure(err)) => { // TODO: get pretty errors again // print!("{}", convert_error(*input, err)) print!("{}", err); } Err(_) => (), Ok(res) => { if opt.debug { println!("{:#?}", res); } let lowered = crate::frontend::lower_module(res.1); match lowered { Ok(res) => { let mut file = File::create(opt.output.unwrap_or("out.rtlil".into())).expect("could not open file"); file.write_all(res.as_bytes()).expect("failed to write output file"); }, Err(err) => eprintln!("{:#?}", err), } } } }