Move some more unsafe code into block

This commit is contained in:
greg 2016-12-21 17:50:13 -08:00
parent 8528c912bd
commit 96c51a9b88
1 changed files with 6 additions and 3 deletions

View File

@ -12,27 +12,30 @@ mod LLVMWrap {
use self::llvm_sys::prelude::*; use self::llvm_sys::prelude::*;
use self::llvm_sys::core; use self::llvm_sys::core;
use std::ptr; use std::ptr;
pub fn ContextCreate() -> LLVMContextRef { pub fn ContextCreate() -> LLVMContextRef {
unsafe { unsafe {
core::LLVMContextCreate() core::LLVMContextCreate()
} }
} }
pub fn ModuleCreateWithName(name: &str) -> LLVMModuleRef { pub fn ModuleCreateWithName(name: &str) -> LLVMModuleRef {
unsafe { unsafe {
let n = name.as_ptr() as *const _; let n = name.as_ptr() as *const _;
core::LLVMModuleCreateWithName(n) core::LLVMModuleCreateWithName(n)
} }
} }
pub fn CreateBuilderInContext(context: LLVMContextRef) -> LLVMBuilderRef {
unsafe {
core::LLVMCreateBuilderInContext(context)
}
}
} }
pub fn compile_ast(ast: AST) { pub fn compile_ast(ast: AST) {
println!("Compiling!"); println!("Compiling!");
let context = LLVMWrap::ContextCreate(); let context = LLVMWrap::ContextCreate();
let module = LLVMWrap::ModuleCreateWithName("schala"); let module = LLVMWrap::ModuleCreateWithName("schala");
let builder = LLVMWrap::CreateBuilderInContext(context);
unsafe { unsafe {
let builder = core::LLVMCreateBuilderInContext(context);
let void = core::LLVMVoidTypeInContext(context); let void = core::LLVMVoidTypeInContext(context);
let function_type = core::LLVMFunctionType(void, ptr::null_mut(), 0, 0); let function_type = core::LLVMFunctionType(void, ptr::null_mut(), 0, 0);