futilehdl/src/main.rs

58 lines
1.6 KiB
Rust
Raw Normal View History

2022-01-05 01:09:08 +00:00
mod builtin_cells;
mod frontend;
2021-12-30 19:46:28 +00:00
mod literals;
2022-01-01 21:43:38 +00:00
mod parser;
mod rtlil;
2021-12-30 19:46:28 +00:00
2022-01-04 16:24:21 +00:00
use std::fs::File;
use std::io::prelude::*;
2022-01-04 18:09:33 +00:00
use std::path::PathBuf;
2022-01-04 00:38:35 +00:00
use structopt::StructOpt;
2021-12-30 19:46:28 +00:00
2022-01-04 16:24:21 +00:00
#[derive(Debug, StructOpt)]
#[structopt(name = "example", about = "An example of StructOpt usage.")]
struct Opt {
/// Input file
#[structopt(parse(from_os_str))]
input: PathBuf,
2022-01-17 23:11:37 +00:00
/// Debug AST
#[structopt(short)]
debug: bool,
/// Output file, stdout if not present
#[structopt(short, parse(from_os_str))]
output: Option<PathBuf>,
2022-01-04 16:24:21 +00:00
}
2021-12-30 19:46:28 +00:00
fn main() {
2022-01-04 16:24:21 +00:00
let opt = Opt::from_args();
let mut infile = File::open(opt.input).expect("could not open file");
let mut input = String::new();
2022-01-04 18:09:33 +00:00
infile
.read_to_string(&mut input)
.expect("error reading file");
2022-01-04 16:24:21 +00:00
let input: &str = input.as_str();
2022-01-04 19:05:10 +00:00
let input = parser::Span::new(input);
let parsed = parser::parse(input);
2021-12-30 19:46:28 +00:00
match parsed {
2022-01-16 20:46:44 +00:00
Err(nom::Err::Error(err) | nom::Err::Failure(err)) => {
// TODO: get pretty errors again
// print!("{}", convert_error(*input, err))
print!("{}", err);
2021-12-30 19:46:28 +00:00
}
Err(_) => (),
2022-01-01 21:43:38 +00:00
Ok(res) => {
2022-01-17 23:11:37 +00:00
if opt.debug {
println!("{:#?}", res);
}
2022-01-04 22:05:25 +00:00
let lowered = crate::frontend::lower_module(res.1);
match lowered {
2022-01-17 23:11:37 +00:00
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),
2022-01-04 22:05:25 +00:00
}
2022-01-01 21:43:38 +00:00
}
2021-12-30 19:46:28 +00:00
}
}