compiler/TMethodBinding.st
changeset 11 6d39860d0fdb
parent 8 eec72263ed75
child 16 17a2d1d9f205
--- a/compiler/TMethodBinding.st	Mon Sep 14 16:27:00 2015 +0100
+++ b/compiler/TMethodBinding.st	Wed Sep 16 05:29:43 2015 +0100
@@ -36,6 +36,36 @@
     ^ selector
 ! !
 
+!TMethodBinding methodsFor:'converting'!
+
+asLLVMValueInModule: aLLVMModule
+    | name function |
+
+    name := TLLVMCodeGenerator llvmFunctionNameForClass: mclass clazz selector: selector.
+    function := aLLVMModule getFunctionNamed: name.
+    function isNil ifTrue:[ 
+        | type |
+
+        mclass isMetaclass ifTrue:[
+            type := LLVMType 
+                        function:  (parameterTypes collect:[:t|t asLLVMTypeInModule: aLLVMModule ])
+                        returning: (returnType asLLVMTypeInModule: aLLVMModule).                 
+        ] ifFalse:[ 
+            type := LLVMType
+                    function:  {mclass type asLLVMTypeInModule:  aLLVMModule } ,
+                               (parameterTypes collect:[:t|t asLLVMTypeInModule: aLLVMModule])
+                    returning: (returnType asLLVMTypeInModule: aLLVMModule).
+        ].
+        function := aLLVMModule addFunctionNamed: name type: type.
+        mclass isMetaclass ifFalse:[
+            (function parameterAt: 1) name: 'self'.
+        ]
+    ].
+    ^ function
+
+    "Created: / 15-09-2015 / 07:04:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !TMethodBinding methodsFor:'initialization'!
 
 initializeWithClass: aTClassBinding selector: aSymbol