"
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 }"
LLVMValue subclass:#LLVMFunction
instanceVariableNames:''
classVariableNames:''
poolDictionaries:'LLVMVerifierFailureAction'
category:'LLVM-S-Core'
!
!LLVMFunction 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.
"
! !
!LLVMFunction methodsFor:'accessing'!
builder
^ self entry builder
"Created: / 08-08-2015 / 03:17:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
entry
"Returns function's entry basic block"
| numBBs |
numBBs := LLVM CountBasicBlocks: self.
numBBs == 0 ifTrue:[
^ self addBasicBlockNamed: 'entry'.
] ifFalse:[
^ LLVM GetEntryBasicBlock: self.
]
"Created: / 08-08-2015 / 03:27:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
numArgs
"Same as #numParams.
Defined here as a courtesy to Smalltalk/X programmer - Smalltalk/X
uses #numArgs."
^ self numParams
"Created: / 11-07-2015 / 09:42:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 14-08-2015 / 12:56:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
numParams
"Return a number of parameters that this function takes"
^ LLVM CountParams: self.
"Created: / 14-08-2015 / 12:54:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
parameterAt: index
^ LLVM GetParam: self _: index - 1.
"Created: / 07-07-2015 / 22:49:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 11-07-2015 / 10:13:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!LLVMFunction methodsFor:'functions-adding'!
addBasicBlock
"Adds an (anonymous) basic block with given nane."
^ self addBasicBlockNamed: ''
"Created: / 08-08-2015 / 04:11:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
addBasicBlockNamed: name
"Adds a basic block with given nane."
| bb |
self assert: name isSingleByteString.
bb := LLVM AppendBasicBlock: self _: name.
bb function: self.
^ bb
"Created: / 08-07-2015 / 23:09:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified (comment): / 08-08-2015 / 04:11:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!LLVMFunction methodsFor:'initialization'!
initialize
super initialize.
self initializeArgumentsNames.
"Created: / 11-07-2015 / 10:13:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 08-08-2015 / 04:11:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
initializeArgumentsNames
1 to: self numArgs do:[:numArg |
(self parameterAt: numArg) name: 'arg', numArg printString
].
"Created: / 11-07-2015 / 10:13:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!LLVMFunction methodsFor:'testing'!
isLLVMFunction
^ true
"Created: / 10-08-2015 / 19:02:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!LLVMFunction methodsFor:'utilities'!
verify
"Verifies that a function is valid. If yes, this method is no-op.
If false, throws LLVMModuleVerificationError."
(LLVM VerifyFunction: self _: LLVMReturnStatusAction) ifTrue:[
LLVMModuleVerificationError signal: 'Function is not valid (failed to verify)'
].
"Created: / 18-06-2016 / 15:56:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!LLVMFunction class methodsFor:'documentation'!
version_HG
^ '$Changeset: <not expanded> $'
! !