FUNCTION: void LLVMDisposeModule ( LLVMModuleRef M )
FUNCTION: void LLVMDumpModule ( LLVMModuleRef M )
FUNCTION: LLVMBool LLVMVerifyModule ( LLVMModuleRef M, int Action, char **OutMessage )
+FUNCTION: c-string LLVMGetTarget ( LLVMModuleRef M )
DESTRUCTOR: LLVMDisposeModule
! Types
LLVMTypeRef FunctionTy )
FUNCTION: LLVMValueRef LLVMGetParam ( LLVMValueRef Fn,
unsigned index )
+FUNCTION: c-string LLVMGetValueName ( LLVMValueRef Val )
! Basic blocks
FUNCTION: LLVMBasicBlockRef LLVMAppendBasicBlock ( LLVMValueRef Fn,
char **OutMessage )
FUNCTION: void LLVMDisposeExecutionEngine ( LLVMExecutionEngineRef E )
DESTRUCTOR: LLVMDisposeExecutionEngine
+
+! Memory buffers
+FUNCTION: LLVMBool LLVMCreateMemoryBufferWithContentsOfFile (
+ c-string Path,
+ LLVMMemoryBufferRef* OutMemBuf,
+ c-string* OutMessage )
+FUNCTION: void LLVMDisposeMemoryBuffer ( LLVMMemoryBufferRef MemBuf )
+FUNCTION: size_t LLVMGetBufferSize ( LLVMMemoryBufferRef MemBuf )
+FUNCTION: int LLVMParseBitcode ( LLVMMemoryBufferRef MemBuf,
+ LLVMModuleRef* OutModule,
+ c-string* OutMessage )
+
+! Module providers
+FUNCTION: LLVMModuleProviderRef LLVMCreateModuleProviderForExistingModule ( LLVMModuleRef M )
+FUNCTION: void LLVMDisposeModuleProvider ( LLVMModuleProviderRef MP )
+
+! Messages
+FUNCTION: void LLVMDisposeMessage ( char *Message )
--- /dev/null
+! Copyright (C) 2017 Björn Lindqvist.
+! See http://factorcode.org/license.txt for BSD license.
+USING: help.markup help.syntax llvm.wrappers strings ;
+
+IN: llvm.reader
+
+HELP: load-module
+{ $values { "path" string } { "module" module } }
+{ $description "Parses a file containing llvm bitcode into an llvm module." }
+{ $examples
+ { $unchecked-example
+ "USING: io.pathnames llvm.reader ;"
+ "\"resource:extra/llvm/wrappers/add.bc\" absolute-path load-module"
+ "T{ module { value ALIEN: 1be7120 } }"
+ }
+} ;
--- /dev/null
+! Copyright (C) 2009 Matthew Willis.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors alien.c-types alien.data destructors kernel llvm.ffi
+llvm.wrappers ;
+
+IN: llvm.reader
+
+: buffer>module ( buffer -- module )
+ [
+ value>> f void* <ref> f void* <ref>
+ [ LLVMParseBitcode drop ] 2keep
+ void* deref [ llvm-throw ] when* void* deref
+ module new swap >>value
+ ] with-disposal ;
+
+: load-module ( path -- module )
+ <buffer> buffer>module ;
--- /dev/null
+! Copyright (C) 2017 Björn Lindqvist.
+! See http://factorcode.org/license.txt for BSD license.
+USING: help.markup help.syntax ;
+IN: llvm.wrappers
+
+HELP: <provider>
+{ $values { "module" module } { "provider" provider } }
+{ $description "Creates a module provider from a given module. The provider takes ownership of the module." } ;
--- /dev/null
+USING: accessors alien destructors io.pathnames kernel llvm.ffi
+llvm.wrappers tools.test ;
+IN: llvm.wrappers.tests
+
+{ 728 t } [
+ "resource:extra/llvm/wrappers/add.bc" absolute-path <buffer>
+ [ value>> [ LLVMGetBufferSize ] keep ] with-disposal alien?
+] unit-test
--- /dev/null
+! Copyright (C) 2009 Matthew Willis.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors alien.c-types alien.data alien.strings destructors io
+io.encodings.utf8 kernel llvm.ffi ;
+IN: llvm.wrappers
+
+ERROR: llvm-error message ;
+
+: llvm-throw ( c-string -- )
+ [ utf8 alien>string ] [ LLVMDisposeMessage ] bi llvm-error ;
+
+: <dispose> ( alien class -- disposable ) new swap >>value ;
+
+TUPLE: module value disposed ;
+M: module dispose* value>> LLVMDisposeModule ;
+
+: <module> ( name -- module )
+ LLVMModuleCreateWithName module <dispose> ;
+
+TUPLE: provider value module disposed ;
+M: provider dispose* value>> LLVMDisposeModuleProvider ;
+
+: (provider) ( module -- provider )
+ [ value>> LLVMCreateModuleProviderForExistingModule provider <dispose> ]
+ [ t >>disposed value>> ] bi
+ >>module ;
+
+: <provider> ( module -- provider )
+ [ (provider) ] with-disposal ;
+
+TUPLE: buffer value disposed ;
+M: buffer dispose* value>> LLVMDisposeMemoryBuffer ;
+
+: <buffer> ( path -- buffer )
+ f void* <ref> f void* <ref>
+ [ LLVMCreateMemoryBufferWithContentsOfFile drop ] 2keep
+ void* deref [ llvm-throw ] when* void* deref buffer <dispose> ;