LLVMTypeFunction.st
changeset 27 b26354bbff25
child 50 dbda820d4d24
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LLVMTypeFunction.st	Fri Aug 14 06:26:02 2015 +0100
@@ -0,0 +1,113 @@
+"
+    Copyright (C) 2015-now Jan Vrany
+
+    This code is not an open-source (yet). You may use this code
+    for your own experiments and projects, given that:
+
+    * all modification to the code will be sent to the
+      original author for inclusion in future releases
+    * this is not used in any commercial software
+
+    This license is provisional and may (will) change in
+    a future.
+"
+"{ Package: 'jv:llvm_s' }"
+
+"{ NameSpace: Smalltalk }"
+
+LLVMType subclass:#LLVMTypeFunction
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'LLVM-S-Core-Types'
+!
+
+!LLVMTypeFunction class methodsFor:'documentation'!
+
+copyright
+"
+    Copyright (C) 2015-now Jan Vrany
+
+    This code is not an open-source (yet). You may use this code
+    for your own experiments and projects, given that:
+
+    * all modification to the code will be sent to the
+      original author for inclusion in future releases
+    * this is not used in any commercial software
+
+    This license is provisional and may (will) change in
+    a future.
+"
+! !
+
+!LLVMTypeFunction methodsFor:'accessing'!
+
+numArgs
+    "Return a number of arguments this function takes (excluding variadic, if any)
+
+     Same as numParams, defined here to match Smalltalk/X naming which uses #numArgs"
+
+    ^ self numArgs
+
+    "Created: / 13-08-2015 / 17:06:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+numParams
+    "Return a number of arguments this function takes (excluding variadic, if any)"
+
+    ^ LLVM CountParamTypes: self.
+
+    "Created: / 13-08-2015 / 17:07:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+parameterTypeAt: index
+    | numParams parameterTypePointers |
+
+    numParams := self numParams.
+    (index between: 1 and: numParams) ifTrue:[ 
+        parameterTypePointers := LLVMObjectArray new: numParams.
+        LLVM GetParamTypes: self _: parameterTypePointers.
+        ^ (LLVMType newAddress: (parameterTypePointers at: index))
+    ].
+    LLVMTypeError new signal: 'index out of bounds'
+
+    "Created: / 13-08-2015 / 17:16:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 14-08-2015 / 06:15:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+parameterTypes
+    | numParams parameterTypePointers parameterTypes |
+
+    numParams := self numParams.
+    numParams == 0 ifTrue:[ ^ #() ].
+    parameterTypePointers := LLVMObjectArray new: numParams.
+    parameterTypes := Array new: numParams.
+    LLVM GetParamTypes: self _: parameterTypePointers.
+    1 to: numParams do:[:i | parameterTypes at: i put: (LLVMType newAddress: (parameterTypePointers at: i)) ].
+    ^ parameterTypes
+
+    "Created: / 13-08-2015 / 17:16:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+returnType
+    ^ LLVM GetReturnType: self.
+
+    "Created: / 13-08-2015 / 17:11:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!LLVMTypeFunction methodsFor:'testing'!
+
+isFunctionType
+    ^ true
+
+    "Created: / 13-08-2015 / 16:51:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+isVarArg
+    "Return true if the function type designates a variadic function"
+
+    ^ LLVM IsFunctionVarArg: self
+
+    "Created: / 13-08-2015 / 17:05:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+