diff -r a428eeead6ad -r 9327987437ae Cface__LLVM_C_EXT.st --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Cface__LLVM_C_EXT.st Wed Aug 12 07:32:13 2015 +0100 @@ -0,0 +1,109 @@ +"{ Package: 'jv:cface' }" + +"{ NameSpace: Cface }" + +LLVM_C subclass:#LLVM_C_EXT + instanceVariableNames:'' + classVariableNames:'' + poolDictionaries:'' + category:'Cface-Mappings' +! + +!LLVM_C_EXT class methodsFor:'documentation'! + +documentation +" + Mappings for LLVM C Extensions API. Used to generate C callouts + for jv:llvm_s project. + + [author:] + Jan Vrany + + [instance variables:] + + [class variables:] + + [see also:] + https://bitbucket.org/janvrany/jv-llvm-s/llvm_c_ext + +" +! ! + +!LLVM_C_EXT class methodsFor:'generating'! + +generate + | llvmcextDir llvmcextDef | + + llvmcextDir := (Smalltalk getPackageDirectoryForPackage: 'jv:cface') / 'resources'/'examples'/'llvm-c-ext'. + llvmcextDef := llvmcextDir / 'llvm-c-ext.def'. + + ^Cface::Platform theInstance generatorCommand + definitions: llvmcextDef asFilename; + mappings: self new; + process + + "Created: / 06-07-2015 / 06:53:08 / Jan Vrany " + "Modified (format): / 12-08-2015 / 06:56:04 / Jan Vrany " +! ! + +!LLVM_C_EXT methodsFor:'accessing'! + +definitions:definitionFile + super definitions:definitionFile. + + "/ A hack to set Smalltalk classname for LLVMContextRef as it is not + "/ typedefd in headers + definitionFile definitions do:[:each | + ((each isKindOf: CTypedefNode) and:[ each cName = 'LLVMContextRef' ]) ifTrue:[ + each smalltalkName: #LLVMContext + ]. + ]. + + "Created: / 12-08-2015 / 07:24:07 / Jan Vrany " +! ! + +!LLVM_C_EXT methodsFor:'mapping - class names'! + +smalltalkClassNameForDerivedType: type + "Answers class which should contain function call" + + | baseName | + + baseName := super smalltalkClassNameForDerivedType:type. + (baseName endsWith: 'Ref') ifTrue:[ + baseName := baseName copyTo: baseName size - 3 + ]. + ^baseName + + "Created: / 30-06-2015 / 13:55:31 / Jan Vrany " + "Modified: / 01-07-2015 / 09:32:03 / Jan Vrany " + "Modified (format): / 01-07-2015 / 16:23:28 / Jan Vrany " +! + +smalltalkClassNameForFunction:cFunction +"/ | cFunctionName firstArgType returnType | +"/ +"/ cFunctionName := cFunction cName. +"/ cFunctionName = 'LLVMCreateMemoryBufferWithContentsOfFile' ifTrue:[ +"/ ^'LLVMMemoryBuffer' +"/ ]. +"/ cFunctionName = 'LLVMInitializeMCJITCompilerOptions' ifTrue:[ +"/ ^'LLVMMCJITCompilerOptions' +"/ ]. +"/ +"/ +"/ cFunction arguments notEmpty ifTrue:[ +"/ firstArgType := cFunction arguments first type. +"/ (firstArgType resolved isCPointerNode and:[ firstArgType resolved type resolved isCStructNode ]) +"/ ifTrue:[ ^ self smalltalkClassNameForDerivedType: firstArgType ]. +"/ ]. +"/ returnType := cFunction return. +"/ (returnType resolved isCPointerNode and:[ returnType resolved type resolved isCStructNode ]) +"/ ifTrue:[ ^ self smalltalkClassNameForDerivedType: returnType]. + + ^ #LLVMCEXT + + "Created: / 01-07-2015 / 06:12:28 / Jan Vrany " + "Modified: / 12-08-2015 / 06:57:48 / Jan Vrany " +! ! +