Cface__LLVM_C.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 TypeMapping subclass:#LLVM_C
       
     6 	instanceVariableNames:''
       
     7 	classVariableNames:''
       
     8 	poolDictionaries:''
       
     9 	category:'Cface-Mappings'
       
    10 !
       
    11 
       
    12 !LLVM_C class methodsFor:'documentation'!
       
    13 
       
    14 documentation
       
    15 "
       
    16     Mappings for LLVM C 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/
       
    28 
       
    29 "
       
    30 ! !
       
    31 
       
    32 !LLVM_C class methodsFor:'generating'!
       
    33 
       
    34 generate
       
    35     |llvmcDir llvmcDef|
       
    36 
       
    37     llvmcDir := (Smalltalk getPackageDirectoryForPackage: 'jv:cface') / 'resources'/'examples'/'llvm-c'.
       
    38     llvmcDef := llvmcDir / 'llvm-c.def'.  
       
    39 
       
    40     ^Cface::Platform theInstance generatorCommand
       
    41         definitions: llvmcDef 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: / 12-08-2015 / 06:54:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    47 ! !
       
    48 
       
    49 !LLVM_C methodsFor:'accessing'!
       
    50 
       
    51 smalltalkPackage
       
    52 
       
    53     ^#'jv:llvm_s'
       
    54 
       
    55     "Created: / 03-07-2008 / 21:14:47 / Jan Vrany <vranyj1@fel.cvut.cz>"
       
    56     "Modified: / 12-08-2015 / 06:56:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    57 !
       
    58 
       
    59 smalltalkSelectorForFunction: cFunction
       
    60 
       
    61     ^String streamContents:
       
    62         [:s|
       
    63         | nm |
       
    64 
       
    65         nm := cFunction cName.
       
    66         (nm startsWith:'LLVM') ifTrue:[ 
       
    67             nm := nm copyFrom: 5.
       
    68         ] ifFalse:[ 
       
    69             nm := nm copy.
       
    70         ].
       
    71         s nextPutAll:nm.
       
    72         cFunction arguments notEmptyOrNil ifTrue:
       
    73             [s nextPut:$:].
       
    74         cFunction arguments size > 1 ifTrue:
       
    75             [(cFunction arguments copyFrom:2) do:
       
    76                 [:argument|
       
    77                 s 
       
    78                     nextPutAll: '_:']]]
       
    79 
       
    80     "Created: / 17-02-2008 / 22:16:03 / janfrog"
       
    81     "Modified: / 18-02-2008 / 14:58:43 / janfrog"
       
    82     "Modified: / 04-07-2008 / 15:33:31 / Jan Vrany <vranyj1@fel.cvut.cz>"
       
    83     "Modified: / 01-07-2015 / 10:57:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    84 ! !
       
    85 
       
    86 !LLVM_C methodsFor:'filtering'!
       
    87 
       
    88 shouldIgnoreStruct: cStructNode
       
    89     ^ (cStructNode cName startsWith: 'LLVMOpaque') or:[ super shouldIgnoreStruct: cStructNode  ]
       
    90 
       
    91     "Created: / 06-07-2015 / 07:00:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    92     "Modified: / 06-07-2015 / 23:12:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    93 ! !
       
    94 
       
    95 !LLVM_C methodsFor:'mapping - categories'!
       
    96 
       
    97 smalltalkCategoryForDerivedType:cType
       
    98     | className class |
       
    99 
       
   100     className := cType smalltalkName asSymbol.
       
   101     (className notNil and:[(class := Smalltalk at: className) notNil]) ifTrue:[
       
   102         ^class category
       
   103     ].
       
   104     ^'LLVM-Core'
       
   105 
       
   106     "Created: / 05-09-2012 / 11:15:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   107     "Modified: / 30-06-2015 / 13:53:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   108 !
       
   109 
       
   110 smalltalkCategoryForEnum:cType
       
   111     | className class |
       
   112 
       
   113     className := cType smalltalkName asSymbol.
       
   114     (className notNil and:[(class := Smalltalk at: className) notNil]) ifTrue:[
       
   115         ^class category
       
   116     ].
       
   117     ^'LLVM-Core-Constants'
       
   118 
       
   119     "Created: / 07-07-2015 / 18:21:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   120 ! !
       
   121 
       
   122 !LLVM_C methodsFor:'mapping - class names'!
       
   123 
       
   124 smalltalkClassNameForDerivedType: type      
       
   125     "Answers class which should contain function call"
       
   126 
       
   127     | baseName |
       
   128 
       
   129     baseName := super smalltalkClassNameForDerivedType:type.
       
   130     (baseName endsWith: 'Ref') ifTrue:[
       
   131         baseName := baseName copyTo: baseName size - 3
       
   132     ].
       
   133     ^baseName
       
   134 
       
   135     "Created: / 30-06-2015 / 13:55:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   136     "Modified: / 01-07-2015 / 09:32:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   137     "Modified (format): / 01-07-2015 / 16:23:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   138 !
       
   139 
       
   140 smalltalkClassNameForFunction:cFunction 
       
   141 "/    | cFunctionName firstArgType returnType |
       
   142 "/
       
   143 "/    cFunctionName := cFunction cName.
       
   144 "/    cFunctionName = 'LLVMCreateMemoryBufferWithContentsOfFile' ifTrue:[ 
       
   145 "/        ^'LLVMMemoryBuffer'
       
   146 "/    ].
       
   147 "/    cFunctionName = 'LLVMInitializeMCJITCompilerOptions' ifTrue:[ 
       
   148 "/        ^'LLVMMCJITCompilerOptions'
       
   149 "/    ].
       
   150 "/
       
   151 "/
       
   152 "/    cFunction arguments notEmpty ifTrue:[
       
   153 "/        firstArgType := cFunction arguments first type.
       
   154 "/        (firstArgType resolved isCPointerNode and:[ firstArgType resolved type resolved isCStructNode ]) 
       
   155 "/            ifTrue:[ ^ self smalltalkClassNameForDerivedType: firstArgType ].
       
   156 "/    ].
       
   157 "/    returnType := cFunction return.
       
   158 "/    (returnType resolved isCPointerNode and:[ returnType resolved type resolved isCStructNode ]) 
       
   159 "/        ifTrue:[ ^ self smalltalkClassNameForDerivedType: returnType].
       
   160 
       
   161     ^ #LLVM
       
   162 
       
   163     "Created: / 01-07-2015 / 06:12:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   164     "Modified: / 01-07-2015 / 09:50:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   165 ! !
       
   166 
       
   167 !LLVM_C class methodsFor:'documentation'!
       
   168 
       
   169 version_HG
       
   170 
       
   171     ^ '$Changeset: <not expanded> $'
       
   172 ! !
       
   173