forked from M-Labs/nac3
1
0
Fork 0

add simple output function

This commit is contained in:
Sebastien Bourdeauducq 2020-03-30 22:30:32 +08:00
parent 2fae28eb70
commit 1eac097706
1 changed files with 11 additions and 0 deletions

View File

@ -98,6 +98,10 @@ impl<'ctx> CodeGen<'ctx> {
pass_manager.add_reassociate_pass();
pass_manager.initialize();
let i32_type = context.i32_type();
let fn_type = i32_type.fn_type(&[i32_type.into()], false);
module.add_function("output", fn_type, None);
CodeGen {
context, module, pass_manager,
builder: context.create_builder(),
@ -394,6 +398,12 @@ impl<'ctx> CodeGen<'ctx> {
Ok(a.into())
}
},
("output", values::BasicValueEnum::IntValue(a)) => {
let fn_value = self.module.get_function("output").unwrap();
Ok(self.builder.build_call(fn_value, &[a.into()], "call")
.try_as_basic_value().left().unwrap())
},
_ => Err(self.compile_error(CompileErrorKind::Unsupported("unrecognized call")))
}
} else {
@ -430,6 +440,7 @@ impl<'ctx> CodeGen<'ctx> {
}
}
},
Expression { expression } => { self.compile_expression(expression)?; },
If { test, body, orelse } => {
let test = self.compile_expression(test)?;
if test.get_type() != self.context.bool_type().into() {