#[macro_use] extern crate lalrpop_util; #[macro_use] extern crate anyhow; lalrpop_mod!(parser); mod ast; mod utils; use std::fs::{self, File}; use std::path::PathBuf; use anyhow::Result; use clap::Parser; use inkwell::context::Context; use crate::parser::ProgramParser; #[derive(Debug, Parser)] struct Opt { path: PathBuf, /// Path to output the bitcode to. #[clap(short = 'o', long = "out", name = "bitcode-out")] out_path: PathBuf, /// Path to output the AST to, if at all. #[clap(long = "emit-ast", name = "ast-out")] emit_ast: Option, } 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(); let typed_ast = ast::typed::convert(ast)?; let context = Context::create(); let module = ast::llvm::convert(opts.path.display().to_string(), &context, typed_ast)?; { let file = File::create(&opts.out_path)?; module.write_bitcode_to_file(&file, true, true); println!("Emitted."); } Ok(()) }