compiler/TLLVMCodeGenerator.st
changeset 11 6d39860d0fdb
parent 10 2b9beeac547e
child 12 d716a8181fc1
--- a/compiler/TLLVMCodeGenerator.st	Mon Sep 14 16:27:00 2015 +0100
+++ b/compiler/TLLVMCodeGenerator.st	Wed Sep 16 05:29:43 2015 +0100
@@ -117,6 +117,40 @@
     "Created: / 31-08-2015 / 10:14:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+acceptIfTrueIfFalseNode: node 
+    | condition thenBody thenBlock thenResult elseBody elseBlock elseResult joinBlock result |
+
+    condition := self visitNode: node receiver.  
+    thenBody  := node arguments first body.
+    thenBlock := function addBasicBlock.
+
+    elseBody  := node arguments second body.
+    elseBlock := function addBasicBlock.
+
+    asm if: condition then: thenBlock else: elseBlock.
+    "/ Code true-branch
+    asm block: thenBlock.
+    thenResult := self visitNode: thenBody.
+    thenResult isReturnInst ifFalse:[  
+        joinBlock notNil ifTrue:[ joinBlock function addBasicBlock ].
+        asm br: joinBlock.
+    ].
+
+    "/ Code false-branch
+    asm block: elseBlock.
+    elseResult := self visitNode: elseBody.
+    elseResult isReturnInst ifFalse:[  
+        joinBlock notNil ifTrue:[ joinBlock function addBasicBlock ].
+        asm br: joinBlock.
+    ].
+    joinBlock notNil ifTrue:[ 
+        asm block: joinBlock.
+    ].
+
+    "Created: / 15-09-2015 / 11:59:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 16-09-2015 / 05:28:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 acceptInlineAssemblyNode: aTInlineAssemblyNode
     | emitMethodNode emitMethod|
 
@@ -146,45 +180,26 @@
 !
 
 acceptMessageNode: aMessageNode
-    | receiver arguments methodName methodFunction |
+    | receiver arguments methodFunction |
 
     receiver := self visitNode: aMessageNode receiver.
-    receiver := self visitNode: aMessageNode receiver.
     arguments := aMessageNode arguments collect: [:argument | self visitNode: argument ].
-
-    methodName := self class llvmFunctionNameForClass: aMessageNode binding mclass clazz selector: aMessageNode selector.
-    methodFunction := context module getFunctionNamed: methodName.
+    methodFunction := aMessageNode binding asLLVMValueInModule: context module.  
 
     ^ asm call: methodFunction _: { receiver } , arguments
 
     "Created: / 31-08-2015 / 10:13:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 03-09-2015 / 07:13:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified (format): / 15-09-2015 / 07:14:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 acceptMethodNode: aMethodNode 
-    | binding |
-
-    binding := aMethodNode binding.
-    binding mclass isMetaclass ifTrue:[
-        function := context module 
-                        addFunctionNamed: (self class llvmFunctionNameForClass: currentClass selector: currentMethod selector)
-                        type: (LLVMType 
-                                function:  (binding parameterTypes collect:[:t|t asLLVMTypeInModule: context module])
-                                returning: (binding returnType asLLVMTypeInModule: context module)).
-    ] ifFalse:[ 
-        function := context module 
-                        addFunctionNamed: (self class llvmFunctionNameForClass: currentClass selector: currentMethod selector)      
-                        type: (LLVMType 
-                                function:  {binding receiverType asLLVMTypeInModule: context module } ,
-                                           (binding parameterTypes collect:[:t|t asLLVMTypeInModule: context module])
-                                returning: (binding returnType asLLVMTypeInModule: context module)).
-        (function parameterAt: 1) name: 'self'.
-    ].
+    function := aMethodNode binding asLLVMValueInModule: context module.
     asm := function builder.
     super acceptMethodNode: aMethodNode
 
     "Created: / 31-08-2015 / 09:42:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 14-09-2015 / 15:37:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 15-09-2015 / 07:17:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified (format): / 15-09-2015 / 08:17:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 acceptOptimizedNode: anOptimizedNode