Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Broken execution example...

  • Loading branch information...
commit 1d55be111862072ac7ee7e65c3d392c0be2cfc9f 1 parent 568d275
@tsion authored
View
2  Makefile
@@ -1,7 +1,7 @@
OOC?=ooc
all:
- ${OOC} $(shell llvm-config --ldflags --libs core) -v -noclean -driver=sequence -linker=g++ +-DNDEBUG +-D_GNU_SOURCE +-D__STDC_LIMIT_MACROS +-D__STDC_CONSTANT_MACROS +-O3 +-fPIC +-fomit-frame-pointer test
+ ${OOC} $(shell llvm-config --ldflags --libs core executionengine) -v -noclean -driver=sequence -linker=g++ +-DNDEBUG +-D_GNU_SOURCE +-D__STDC_LIMIT_MACROS +-D__STDC_CONSTANT_MACROS +-O3 +-fPIC +-fomit-frame-pointer test
clean:
rm -rf ooc_tmp/ rock_tmp/ test
View
2  llvm.use
@@ -1,5 +1,5 @@
Name: LLVM
Description: Low Level Virtual Machine
Libs: -L/usr/lib/llvm -lpthread -lffi -ldl -lm -lLLVMCore -lLLVMSupport -lLLVMSystem
-Includes: llvm-c/Core.h
+Includes: llvm-c/Core.h, llvm-c/ExecutionEngine.h
SourcePath: .
View
8 llvm/Core.ooc
@@ -250,6 +250,14 @@ Builder: cover from LLVMBuilderRef {
}
+// Module providers
+ModuleProvider: cover from LLVMModuleProviderRef {
+ new: extern(LLVMCreateModuleProviderForExistingModule) static func (Module) -> This
+
+ dispose: extern(LLVMDisposeModuleProvider) func
+}
+
+
LLVMGetFirstParam: extern func (Function) -> Value
LLVMGetNextParam: extern func (Value) -> Value
View
42 llvm/ExecutionEngine.ooc
@@ -0,0 +1,42 @@
+use llvm
+import Core
+
+// Generic values
+GenericValue: cover from LLVMGenericValueRef {
+// new: extern(LLVMCreateGenericValueOfInt) static func ~int (Type, ULLong, isSigned: Int) -> This
+// new: extern(LLVMCreateGenericValueOfPointer) static func ~pointer (Pointer) -> This
+// new: extern(LLVMCreateGenericValueOfFloat) static func ~float (Type, Double) -> This
+
+ new: extern(LLVMCreateGenericValueOfInt) static func (Type, ULLong, Int) -> This
+
+ intWidth: extern(LLVMGenericValueIntWidth) func -> UInt
+ toInt: extern(LLVMGenericValueToInt) func (isSigned: Int) -> ULLong
+ toPointer: extern(LLVMGenericValueToPointer) func -> Pointer
+ toFloat: func (ty: Type) -> Double {
+ LLVMGenericValueToFloat(ty, this)
+ }
+}
+
+LLVMGenericValueToFloat: extern func (Type, GenericValue) -> Double
+
+// Execution engines
+ExecutionEngine: cover from LLVMExecutionEngineRef {
+ new: static func (mp: ModuleProvider) -> This {
+ e: This = null
+ error := null as String
+ LLVMCreateJITCompiler(e&, mp, 0, error&)
+ if(error) {
+// Exception new(This, error) throw()
+ }
+ if(!e) {
+ Exception new(This, "Wtf?") throw()
+ }
+ return e
+ }
+
+ dispose: extern(LLVMDisposeExecutionEngine) func
+
+ runFunction: extern(LLVMRunFunction) func (fn: Value, numArgs: UInt, args: GenericValue[]) -> GenericValue
+}
+
+LLVMCreateJITCompiler: extern func (ExecutionEngine*, ModuleProvider, UInt, String*) -> Int
View
19 test.ooc
@@ -1,10 +1,10 @@
use llvm
-import llvm/Core
+import llvm/[Core, ExecutionEngine]
import structs/ArrayList
main: func {
// Create an (empty) module.
- my_module := Module new("my_module")
+ myModule := Module new("my_module")
// Get the i32 type
int_t := Type int32()
@@ -16,7 +16,7 @@ main: func {
// Now we need a function named 'sum' using this type. Functions are not
// free-standing; thye need to be contained in a module.
- sum := my_module addFunction(func_t, "sum")
+ sum := myModule addFunction(func_t, "sum")
// Let's name the function arguments 'a', 'b', and 'c'.
sum args()[0] setName("a")
@@ -41,7 +41,18 @@ main: func {
// We've completed the definition now! Let's see the LLVM assembly
// language representation of what we've created:
- my_module dump()
+ myModule dump()
+
+ // Now, to try to run the function!
+ provider := ModuleProvider new(myModule)
+ engine := ExecutionEngine new(provider)
+
+ arg1 := GenericValue new(int_t, 10 as ULLong, 0)
+ arg2 := GenericValue new(int_t, 5 as ULLong, 0)
+ arg3 := GenericValue new(int_t, 2 as ULLong, 0)
+
+ result := engine runFunction(sum, 3, [arg1, arg2, arg3] as GenericValue[])
+ result toInt(0) toString() println()
// A simple test for the enum covers. Currently broken in rock.
foo := Attribute naked
Please sign in to comment.
Something went wrong with that request. Please try again.