From 47f4c25020f375f086e6dae1801390f001acb4b0 Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 21 Dec 2016 03:18:30 -0800 Subject: [PATCH] Doing some wrapping --- src/compilation.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/compilation.rs b/src/compilation.rs index 24b321b..fc3c264 100644 --- a/src/compilation.rs +++ b/src/compilation.rs @@ -7,11 +7,31 @@ use std::ptr; use parser::{ParseResult, AST, ASTNode, Prototype, Function, Expression}; +mod LLVMWrap { + extern crate llvm_sys; + use self::llvm_sys::prelude::*; + use self::llvm_sys::core; + use std::ptr; + + pub fn ContextCreate() -> LLVMContextRef { + unsafe { + core::LLVMContextCreate() + } + } + + pub fn ModuleCreateWithName(name: &str) -> LLVMModuleRef { + unsafe { + let n = name.as_ptr() as *const _; + core::LLVMModuleCreateWithName(n) + } + } +} + pub fn compile_ast(ast: AST) { println!("Compiling!"); + let context = LLVMWrap::ContextCreate(); + let module = LLVMWrap::ModuleCreateWithName("schala"); unsafe { - let context = core::LLVMContextCreate(); - let module = core::LLVMModuleCreateWithName(b"schala\0".as_ptr() as *const _); let builder = core::LLVMCreateBuilderInContext(context); let void = core::LLVMVoidTypeInContext(context);