extern crate vermilion_codegen;
extern crate vermilion_vm;
use std::fs::write;
use vermilion_codegen::ir::{Function, Module};
use vermilion_codegen::binemit::Binemit;
use vermilion_vm::VermilionObject;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn textemit() {
let start = std::time::Instant::now();
let mut module = Module::new();
let mut func = Function::new();
let block0 = func.create_block();
func.switch_to_block(block0);
{
let tmp0 = func.iconst_integer(1);
let tmp1 = func.iconst_integer(1);
func.int_add(tmp0, tmp1);
func.return_(&[]);
}
module.define_function("main".to_string(), func);
let mut compiler = Binemit::new(module);
let mut artifact = compiler.emit();
let end = start.elapsed().as_nanos();
println!("Compile time: {}ms", end as f64 / 1e+6f64);
let bytes = artifact.into_bytes();
write("test.o", bytes).unwrap();
}
}