More moving functions around

This commit is contained in:
greg 2016-12-25 12:05:24 -08:00
parent 2107e6344e
commit e0eef5e58f

View File

@ -43,21 +43,36 @@ mod LLVMWrap {
core::LLVMAddFunction(module, c_name.as_ptr(), function_type) core::LLVMAddFunction(module, c_name.as_ptr(), function_type)
} }
} }
//NOTE this is incomplete
pub fn FunctionType(return_type: LLVMTypeRef, param_types: &[LLVMTypeRef], is_var_rag: bool) -> LLVMTypeRef {
unsafe {
core::LLVMFunctionType(return_type, ptr::null_mut(), 0, 0)
}
}
pub fn VoidTypeInContext(context: LLVMContextRef) -> LLVMTypeRef {
unsafe {
core::LLVMVoidTypeInContext(context)
}
}
} }
pub fn compile_ast(ast: AST) { pub fn compile_ast(ast: AST) {
println!("Compiling!"); println!("Compiling!");
let context = LLVMWrap::create_context(); let context = LLVMWrap::create_context();
let module = LLVMWrap::module_create_with_name("schala"); let module = LLVMWrap::module_create_with_name("schala");
let builder = LLVMWrap::CreateBuilderInContext(context); let builder = LLVMWrap::CreateBuilderInContext(context);
unsafe {
let void = core::LLVMVoidTypeInContext(context); let void = LLVMWrap::VoidTypeInContext(context);
let function_type = core::LLVMFunctionType(void, ptr::null_mut(), 0, 0); let function_type = LLVMWrap::FunctionType(void, &Vec::new(), false);
let function = LLVMWrap::AddFunction(module, "nop", function_type); let function = LLVMWrap::AddFunction(module, "nop", function_type);
let bb = LLVMWrap::AppendBasicBlockInContext(context, function, "entry"); let bb = LLVMWrap::AppendBasicBlockInContext(context, function, "entry");
unsafe {
core::LLVMPositionBuilderAtEnd(builder, bb); core::LLVMPositionBuilderAtEnd(builder, bb);
// Emit a `ret void` into the function // Emit a `ret void` into the function