Cface__LLVM_C_EXT.st
changeset 43 9327987437ae
child 44 e698efa3708b
equal deleted inserted replaced
42:a428eeead6ad 43:9327987437ae
       
     1 "{ Package: 'jv:cface' }"
       
     2 
       
     3 "{ NameSpace: Cface }"
       
     4 
       
     5 LLVM_C subclass:#LLVM_C_EXT
       
     6 	instanceVariableNames:''
       
     7 	classVariableNames:''
       
     8 	poolDictionaries:''
       
     9 	category:'Cface-Mappings'
       
    10 !
       
    11 
       
    12 !LLVM_C_EXT class methodsFor:'documentation'!
       
    13 
       
    14 documentation
       
    15 "
       
    16     Mappings for LLVM C Extensions API. Used to generate C callouts
       
    17     for jv:llvm_s project.
       
    18 
       
    19     [author:]
       
    20         Jan Vrany <jan.vrany@fit.cvut.cz>
       
    21 
       
    22     [instance variables:]
       
    23 
       
    24     [class variables:]
       
    25 
       
    26     [see also:]
       
    27         https://bitbucket.org/janvrany/jv-llvm-s/llvm_c_ext
       
    28 
       
    29 "
       
    30 ! !
       
    31 
       
    32 !LLVM_C_EXT class methodsFor:'generating'!
       
    33 
       
    34 generate
       
    35     | llvmcextDir llvmcextDef |
       
    36 
       
    37     llvmcextDir := (Smalltalk getPackageDirectoryForPackage: 'jv:cface') / 'resources'/'examples'/'llvm-c-ext'.
       
    38     llvmcextDef := llvmcextDir / 'llvm-c-ext.def'.  
       
    39 
       
    40     ^Cface::Platform theInstance generatorCommand
       
    41         definitions: llvmcextDef asFilename;
       
    42         mappings: self new;
       
    43         process
       
    44 
       
    45     "Created: / 06-07-2015 / 06:53:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    46     "Modified (format): / 12-08-2015 / 06:56:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    47 ! !
       
    48 
       
    49 !LLVM_C_EXT methodsFor:'accessing'!
       
    50 
       
    51 definitions:definitionFile
       
    52     super definitions:definitionFile.
       
    53 
       
    54     "/ A hack to set Smalltalk classname for LLVMContextRef as it is not
       
    55     "/ typedefd in headers
       
    56     definitionFile definitions do:[:each | 
       
    57         ((each isKindOf: CTypedefNode) and:[ each cName = 'LLVMContextRef' ]) ifTrue:[ 
       
    58             each smalltalkName: #LLVMContext  
       
    59         ].
       
    60     ].
       
    61 
       
    62     "Created: / 12-08-2015 / 07:24:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    63 ! !
       
    64 
       
    65 !LLVM_C_EXT methodsFor:'mapping - class names'!
       
    66 
       
    67 smalltalkClassNameForDerivedType: type      
       
    68     "Answers class which should contain function call"
       
    69 
       
    70     | baseName |
       
    71 
       
    72     baseName := super smalltalkClassNameForDerivedType:type.
       
    73     (baseName endsWith: 'Ref') ifTrue:[
       
    74         baseName := baseName copyTo: baseName size - 3
       
    75     ].
       
    76     ^baseName
       
    77 
       
    78     "Created: / 30-06-2015 / 13:55:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    79     "Modified: / 01-07-2015 / 09:32:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    80     "Modified (format): / 01-07-2015 / 16:23:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    81 !
       
    82 
       
    83 smalltalkClassNameForFunction:cFunction 
       
    84 "/    | cFunctionName firstArgType returnType |
       
    85 "/
       
    86 "/    cFunctionName := cFunction cName.
       
    87 "/    cFunctionName = 'LLVMCreateMemoryBufferWithContentsOfFile' ifTrue:[ 
       
    88 "/        ^'LLVMMemoryBuffer'
       
    89 "/    ].
       
    90 "/    cFunctionName = 'LLVMInitializeMCJITCompilerOptions' ifTrue:[ 
       
    91 "/        ^'LLVMMCJITCompilerOptions'
       
    92 "/    ].
       
    93 "/
       
    94 "/
       
    95 "/    cFunction arguments notEmpty ifTrue:[
       
    96 "/        firstArgType := cFunction arguments first type.
       
    97 "/        (firstArgType resolved isCPointerNode and:[ firstArgType resolved type resolved isCStructNode ]) 
       
    98 "/            ifTrue:[ ^ self smalltalkClassNameForDerivedType: firstArgType ].
       
    99 "/    ].
       
   100 "/    returnType := cFunction return.
       
   101 "/    (returnType resolved isCPointerNode and:[ returnType resolved type resolved isCStructNode ]) 
       
   102 "/        ifTrue:[ ^ self smalltalkClassNameForDerivedType: returnType].
       
   103 
       
   104     ^ #LLVMCEXT
       
   105 
       
   106     "Created: / 01-07-2015 / 06:12:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   107     "Modified: / 12-08-2015 / 06:57:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   108 ! !
       
   109