Cface__LLVM_C.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 12 Aug 2015 07:32:13 +0100
changeset 43 9327987437ae
child 44 e698efa3708b
permissions -rw-r--r--
Added mappings for LLVM C and LLVM C Extensions These are used to generate C callouts for jv:llvm_s project.

"{ Package: 'jv:cface' }"

"{ NameSpace: Cface }"

TypeMapping subclass:#LLVM_C
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Cface-Mappings'
!

!LLVM_C class methodsFor:'documentation'!

documentation
"
    Mappings for LLVM C API. Used to generate C callouts
    for jv:llvm_s project.

    [author:]
        Jan Vrany <jan.vrany@fit.cvut.cz>

    [instance variables:]

    [class variables:]

    [see also:]
        https://bitbucket.org/janvrany/jv-llvm-s/

"
! !

!LLVM_C class methodsFor:'generating'!

generate
    |llvmcDir llvmcDef|

    llvmcDir := (Smalltalk getPackageDirectoryForPackage: 'jv:cface') / 'resources'/'examples'/'llvm-c'.
    llvmcDef := llvmcDir / 'llvm-c.def'.  

    ^Cface::Platform theInstance generatorCommand
        definitions: llvmcDef asFilename;
        mappings: self new;
        process

    "Created: / 06-07-2015 / 06:53:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 12-08-2015 / 06:54:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LLVM_C methodsFor:'accessing'!

smalltalkPackage

    ^#'jv:llvm_s'

    "Created: / 03-07-2008 / 21:14:47 / Jan Vrany <vranyj1@fel.cvut.cz>"
    "Modified: / 12-08-2015 / 06:56:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

smalltalkSelectorForFunction: cFunction

    ^String streamContents:
        [:s|
        | nm |

        nm := cFunction cName.
        (nm startsWith:'LLVM') ifTrue:[ 
            nm := nm copyFrom: 5.
        ] ifFalse:[ 
            nm := nm copy.
        ].
        s nextPutAll:nm.
        cFunction arguments notEmptyOrNil ifTrue:
            [s nextPut:$:].
        cFunction arguments size > 1 ifTrue:
            [(cFunction arguments copyFrom:2) do:
                [:argument|
                s 
                    nextPutAll: '_:']]]

    "Created: / 17-02-2008 / 22:16:03 / janfrog"
    "Modified: / 18-02-2008 / 14:58:43 / janfrog"
    "Modified: / 04-07-2008 / 15:33:31 / Jan Vrany <vranyj1@fel.cvut.cz>"
    "Modified: / 01-07-2015 / 10:57:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LLVM_C methodsFor:'filtering'!

shouldIgnoreStruct: cStructNode
    ^ (cStructNode cName startsWith: 'LLVMOpaque') or:[ super shouldIgnoreStruct: cStructNode  ]

    "Created: / 06-07-2015 / 07:00:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 06-07-2015 / 23:12:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LLVM_C methodsFor:'mapping - categories'!

smalltalkCategoryForDerivedType:cType
    | className class |

    className := cType smalltalkName asSymbol.
    (className notNil and:[(class := Smalltalk at: className) notNil]) ifTrue:[
        ^class category
    ].
    ^'LLVM-Core'

    "Created: / 05-09-2012 / 11:15:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 30-06-2015 / 13:53:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

smalltalkCategoryForEnum:cType
    | className class |

    className := cType smalltalkName asSymbol.
    (className notNil and:[(class := Smalltalk at: className) notNil]) ifTrue:[
        ^class category
    ].
    ^'LLVM-Core-Constants'

    "Created: / 07-07-2015 / 18:21:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LLVM_C 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 <jan.vrany@fit.cvut.cz>"
    "Modified: / 01-07-2015 / 09:32:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (format): / 01-07-2015 / 16:23:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

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].

    ^ #LLVM

    "Created: / 01-07-2015 / 06:12:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 01-07-2015 / 09:50:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LLVM_C class methodsFor:'documentation'!

version_HG

    ^ '$Changeset: <not expanded> $'
! !