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 {
|
2022-04-06 03:17:53 +00:00
|
|
|
path: PathBuf,
|
2022-04-06 03:07:34 +00:00
|
|
|
|
2022-04-06 03:17:53 +00:00
|
|
|
#[clap(short = 'o', long = "out")]
|
|
|
|
out_path: PathBuf,
|
2022-04-06 02:33:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() -> Result<()> {
|
2022-04-06 03:17:53 +00:00
|
|
|
let opts = Opt::parse();
|
2022-04-06 02:33:16 +00:00
|
|
|
|
2022-04-06 03:17:53 +00:00
|
|
|
let contents = fs::read_to_string(opts.path)?;
|
2022-04-06 02:33:16 +00:00
|
|
|
|
2022-04-06 03:17:53 +00:00
|
|
|
let parser = ProgramParser::new();
|
|
|
|
let ast = parser.parse(&contents).unwrap();
|
|
|
|
println!("AST: {ast:?}");
|
2022-04-06 02:33:16 +00:00
|
|
|
|
2022-04-06 03:17:53 +00:00
|
|
|
let mut context = Context::create();
|
|
|
|
let module = ast::llvm::convert(&mut context, ast)?;
|
2022-04-06 03:07:34 +00:00
|
|
|
|
2022-04-06 03:17:53 +00:00
|
|
|
{
|
|
|
|
let file = File::create(&opts.out_path)?;
|
|
|
|
module.write_bitcode_to_file(&file, true, true);
|
|
|
|
println!("Emitted.");
|
|
|
|
}
|
2022-04-06 03:07:34 +00:00
|
|
|
|
2022-04-06 03:17:53 +00:00
|
|
|
Ok(())
|
2022-04-06 02:33:16 +00:00
|
|
|
}
|