forked from M-Labs/nac3
1
0
Fork 0
nac3/nac3standalone/src/main.rs

31 lines
813 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;
2020-12-18 10:18:21 +08:00
use nac3core::CodeGen;
2020-12-17 22:20:30 +08:00
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();
}