LLVMFunction.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 17 Aug 2015 09:08:47 +0100
changeset 30 c789c1390911
parent 24 7e7ddd55174c
child 33 feabf14b6c1d
permissions -rw-r--r--
LLVM C API Extensions: added llvm-c-ext/DWARF.h with (some) DWARF constants required to generate debug info. Most importantly, DWARF encoding used when describing a variable to tell the debugger how to interpret the data (as float, signed/unsigned int, etc). More constants will be added as needed.

"
    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:'numArgs'
	classVariableNames:''
	poolDictionaries:''
	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
    | last current |

    numArgs isNil ifTrue:[
        numArgs := 0.
"/        current := LLVM GetFirstParam: self.
"/        last := LLVM GetLastParam: self.  
"/        [ current ~= last ] whileTrue:[
"/            numArgs := numArgs + 1.
"/            current := LLVM GetNextFunction: current.
"/            self halt.
"/        ].
    ].
    ^ numArgs

    "Created: / 11-07-2015 / 09:42:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 11-07-2015 / 11:23:52 / 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>"
! !