nac3/nac3standalone/src/main.rs

31 lines
812 B
Rust
Raw Normal View History

2020-12-17 22:20:30 +08:00
use std::fs;
use inkwell::context::Context;
use inkwell::targets::*;
use rustpython_parser::parser;
use libnac3::CodeGen;
fn main() {
Target::initialize_all(&InitializationConfig::default());
let program = match fs::read_to_string("test.py") {
Ok(program) => program,
Err(err) => { println!("Cannot open input file: {}", err); return; }
};
let ast = match parser::parse_program(&program) {
Ok(ast) => ast,
Err(err) => { println!("Parse error: {}", err); return; }
};
let context = Context::create();
let mut codegen = CodeGen::new(&context);
match codegen.compile_toplevel(&ast.statements[0]) {
Ok(_) => (),
Err(err) => { println!("Compilation error: {}", err); return; }
}
codegen.print_ir();
codegen.output();
}