llvm: more vocabs from factor-unmaintained added back

modern-harvey2
Björn Lindqvist 2017-07-12 15:19:07 +02:00
parent c90a2a28bd
commit 7044e398a0
7 changed files with 106 additions and 0 deletions

View File

@ -35,6 +35,7 @@ FUNCTION: LLVMModuleRef LLVMModuleCreateWithName ( c-string ModuleID )
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
@ -54,6 +55,7 @@ FUNCTION: LLVMValueRef LLVMAddFunction ( LLVMModuleRef M,
LLVMTypeRef FunctionTy )
FUNCTION: LLVMValueRef LLVMGetParam ( LLVMValueRef Fn,
unsigned index )
FUNCTION: c-string LLVMGetValueName ( LLVMValueRef Val )
! Basic blocks
FUNCTION: LLVMBasicBlockRef LLVMAppendBasicBlock ( LLVMValueRef Fn,
@ -86,3 +88,21 @@ FUNCTION: LLVMBool LLVMCreateExecutionEngineForModule (
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 )

View File

@ -0,0 +1,16 @@
! 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 } }"
}
} ;

View File

@ -0,0 +1,17 @@
! 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 ;

BIN
extra/llvm/wrappers/add.bc Normal file

Binary file not shown.

View File

@ -0,0 +1,8 @@
! 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." } ;

View File

@ -0,0 +1,8 @@
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

View File

@ -0,0 +1,37 @@
! 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> ;