compiler/TLLVMCodeGenerator.st
changeset 11 6d39860d0fdb
parent 10 2b9beeac547e
child 12 d716a8181fc1
equal deleted inserted replaced
10:2b9beeac547e 11:6d39860d0fdb
   115     self notYetImplemented
   115     self notYetImplemented
   116 
   116 
   117     "Created: / 31-08-2015 / 10:14:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   117     "Created: / 31-08-2015 / 10:14:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   118 !
   118 !
   119 
   119 
       
   120 acceptIfTrueIfFalseNode: node 
       
   121     | condition thenBody thenBlock thenResult elseBody elseBlock elseResult joinBlock result |
       
   122 
       
   123     condition := self visitNode: node receiver.  
       
   124     thenBody  := node arguments first body.
       
   125     thenBlock := function addBasicBlock.
       
   126 
       
   127     elseBody  := node arguments second body.
       
   128     elseBlock := function addBasicBlock.
       
   129 
       
   130     asm if: condition then: thenBlock else: elseBlock.
       
   131     "/ Code true-branch
       
   132     asm block: thenBlock.
       
   133     thenResult := self visitNode: thenBody.
       
   134     thenResult isReturnInst ifFalse:[  
       
   135         joinBlock notNil ifTrue:[ joinBlock function addBasicBlock ].
       
   136         asm br: joinBlock.
       
   137     ].
       
   138 
       
   139     "/ Code false-branch
       
   140     asm block: elseBlock.
       
   141     elseResult := self visitNode: elseBody.
       
   142     elseResult isReturnInst ifFalse:[  
       
   143         joinBlock notNil ifTrue:[ joinBlock function addBasicBlock ].
       
   144         asm br: joinBlock.
       
   145     ].
       
   146     joinBlock notNil ifTrue:[ 
       
   147         asm block: joinBlock.
       
   148     ].
       
   149 
       
   150     "Created: / 15-09-2015 / 11:59:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   151     "Modified: / 16-09-2015 / 05:28:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   152 !
       
   153 
   120 acceptInlineAssemblyNode: aTInlineAssemblyNode
   154 acceptInlineAssemblyNode: aTInlineAssemblyNode
   121     | emitMethodNode emitMethod|
   155     | emitMethodNode emitMethod|
   122 
   156 
   123     emitMethodNode := RBMethodNode new.
   157     emitMethodNode := RBMethodNode new.
   124     emitMethodNode arguments: (aTInlineAssemblyNode arguments collect:[ :e|e copy]) , { RBVariableNode named: 'zelf' } , (aTInlineAssemblyNode topNode arguments collect:[ :e|e copy]).
   158     emitMethodNode arguments: (aTInlineAssemblyNode arguments collect:[ :e|e copy]) , { RBVariableNode named: 'zelf' } , (aTInlineAssemblyNode topNode arguments collect:[ :e|e copy]).
   144     "Created: / 31-08-2015 / 10:13:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   178     "Created: / 31-08-2015 / 10:13:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   145     "Modified: / 31-08-2015 / 12:20:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   179     "Modified: / 31-08-2015 / 12:20:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   146 !
   180 !
   147 
   181 
   148 acceptMessageNode: aMessageNode
   182 acceptMessageNode: aMessageNode
   149     | receiver arguments methodName methodFunction |
   183     | receiver arguments methodFunction |
   150 
   184 
   151     receiver := self visitNode: aMessageNode receiver.
       
   152     receiver := self visitNode: aMessageNode receiver.
   185     receiver := self visitNode: aMessageNode receiver.
   153     arguments := aMessageNode arguments collect: [:argument | self visitNode: argument ].
   186     arguments := aMessageNode arguments collect: [:argument | self visitNode: argument ].
   154 
   187     methodFunction := aMessageNode binding asLLVMValueInModule: context module.  
   155     methodName := self class llvmFunctionNameForClass: aMessageNode binding mclass clazz selector: aMessageNode selector.
       
   156     methodFunction := context module getFunctionNamed: methodName.
       
   157 
   188 
   158     ^ asm call: methodFunction _: { receiver } , arguments
   189     ^ asm call: methodFunction _: { receiver } , arguments
   159 
   190 
   160     "Created: / 31-08-2015 / 10:13:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   191     "Created: / 31-08-2015 / 10:13:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   161     "Modified: / 03-09-2015 / 07:13:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   192     "Modified (format): / 15-09-2015 / 07:14:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   162 !
   193 !
   163 
   194 
   164 acceptMethodNode: aMethodNode 
   195 acceptMethodNode: aMethodNode 
   165     | binding |
   196     function := aMethodNode binding asLLVMValueInModule: context module.
   166 
       
   167     binding := aMethodNode binding.
       
   168     binding mclass isMetaclass ifTrue:[
       
   169         function := context module 
       
   170                         addFunctionNamed: (self class llvmFunctionNameForClass: currentClass selector: currentMethod selector)
       
   171                         type: (LLVMType 
       
   172                                 function:  (binding parameterTypes collect:[:t|t asLLVMTypeInModule: context module])
       
   173                                 returning: (binding returnType asLLVMTypeInModule: context module)).
       
   174     ] ifFalse:[ 
       
   175         function := context module 
       
   176                         addFunctionNamed: (self class llvmFunctionNameForClass: currentClass selector: currentMethod selector)      
       
   177                         type: (LLVMType 
       
   178                                 function:  {binding receiverType asLLVMTypeInModule: context module } ,
       
   179                                            (binding parameterTypes collect:[:t|t asLLVMTypeInModule: context module])
       
   180                                 returning: (binding returnType asLLVMTypeInModule: context module)).
       
   181         (function parameterAt: 1) name: 'self'.
       
   182     ].
       
   183     asm := function builder.
   197     asm := function builder.
   184     super acceptMethodNode: aMethodNode
   198     super acceptMethodNode: aMethodNode
   185 
   199 
   186     "Created: / 31-08-2015 / 09:42:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   200     "Created: / 31-08-2015 / 09:42:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   187     "Modified: / 14-09-2015 / 15:37:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   201     "Modified: / 15-09-2015 / 07:17:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   202     "Modified (format): / 15-09-2015 / 08:17:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   188 !
   203 !
   189 
   204 
   190 acceptOptimizedNode: anOptimizedNode 
   205 acceptOptimizedNode: anOptimizedNode 
   191     self notYetImplemented
   206     self notYetImplemented
   192 
   207