e0/src/main.rs

47 lines
870 B
Rust
Raw Normal View History

2022-04-06 02:33:16 +00:00
#[macro_use]
extern crate lalrpop_util;
#[macro_use]
extern crate anyhow;
lalrpop_mod!(parser);
mod ast;
2022-04-06 03:07:34 +00:00
use std::fs::{self, File};
2022-04-06 02:33:16 +00:00
use std::path::PathBuf;
use anyhow::Result;
use clap::Parser;
2022-04-06 03:07:34 +00:00
use inkwell::context::Context;
2022-04-06 02:33:16 +00:00
use crate::parser::ProgramParser;
#[derive(Debug, Parser)]
struct Opt {
path: PathBuf,
2022-04-06 03:07:34 +00:00
#[clap(short = 'o', long = "out")]
out_path: PathBuf,
2022-04-06 02:33:16 +00:00
}
fn main() -> Result<()> {
let opts = Opt::parse();
let contents = fs::read_to_string(opts.path)?;
let parser = ProgramParser::new();
let ast = parser.parse(&contents).unwrap();
println!("AST: {ast:?}");
2022-04-06 03:07:34 +00:00
let mut context = Context::create();
let module = ast::convert(&mut context, ast)?;
{
let file = File::create(&opts.out_path)?;
module.write_bitcode_to_file(&file, true, true);
println!("Emitted.");
}
2022-04-06 02:33:16 +00:00
Ok(())
}