From e0eef5e58fa17eadd42a7f003d06fd0186e5a606 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 25 Dec 2016 12:05:24 -0800 Subject: [PATCH] More moving functions around --- src/compilation.rs | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/compilation.rs b/src/compilation.rs index 2ac153a..fdbdddf 100644 --- a/src/compilation.rs +++ b/src/compilation.rs @@ -43,21 +43,36 @@ mod LLVMWrap { 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) { println!("Compiling!"); let context = LLVMWrap::create_context(); let module = LLVMWrap::module_create_with_name("schala"); let builder = LLVMWrap::CreateBuilderInContext(context); + + let void = LLVMWrap::VoidTypeInContext(context); + let function_type = LLVMWrap::FunctionType(void, &Vec::new(), false); + let function = LLVMWrap::AddFunction(module, "nop", function_type); + + let bb = LLVMWrap::AppendBasicBlockInContext(context, function, "entry"); + unsafe { - let void = core::LLVMVoidTypeInContext(context); - let function_type = core::LLVMFunctionType(void, ptr::null_mut(), 0, 0); - let function = LLVMWrap::AddFunction(module, "nop", function_type); - - let bb = LLVMWrap::AppendBasicBlockInContext(context, function, "entry"); - core::LLVMPositionBuilderAtEnd(builder, bb); // Emit a `ret void` into the function