LLVMValue.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 06 Jul 2016 22:40:59 +0100
changeset 71 ab03b0a6d037
parent 68 a760b8536631
child 78 7a4c769a9fea
permissions -rw-r--r--
Implemented LLVMType>>sizeInBits/sizeInBytes for all data types ...i.e., also for structures, vectors and arrays.

"
    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 }"

LLVMObject subclass:#LLVMValue
	instanceVariableNames:'type'
	classVariableNames:''
	poolDictionaries:''
	category:'LLVM-S-Core'
!

!LLVMValue 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.
"
! !

!LLVMValue methodsFor:'accessing'!

initializer: value
    self assert: self isGlobalVariable description: 'Receiver is not a global variable'.
    self assert: value isConstant description: 'Initializer is not a constant value'.

    LLVM SetInitializer: self _: value

    "Created: / 20-06-2016 / 08:03:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

name
    ^ LLVM GetValueName: self

    "Created: / 11-07-2015 / 07:28:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

name: aString
    ^ LLVM SetValueName: self  _: aString

    "Created: / 11-07-2015 / 07:31:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

parent
    "Return owning LLVMBasicBlock for this instruction. If the receiver is not
     an instruction (i.e., #isInstruction returns false), then an error is raised"
    self isInstruction ifTrue:[  
        ^ LLVM GetInstructionParent: self.  
    ].
    self error: 'Not an instruction value'

    "Created: / 21-04-2016 / 22:37:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 22-04-2016 / 08:42:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

type
    type isNil ifTrue:[ 
        type := LLVM TypeOf: self.  
    ].
    ^ type

    "Created: / 11-07-2015 / 14:53:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LLVMValue methodsFor:'converting'!

asLLVMBasicBlock
    "Return the underlying basic block if the value represents
     a basic block. Otherwise raise an error"

    self isBasicBlock ifFalse:[ 
        self error: 'Not a basic block value'.
    ].
    ^ LLVM ValueAsBasicBlock: self

    "Created: / 21-04-2016 / 22:10:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

asLLVMMetadata
    ^ LLVMCEXT ValueAsMetadata: self

    "Created: / 15-08-2015 / 06:41:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

asLLVMValue
    ^ self

    "Created: / 08-08-2015 / 02:28:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LLVMValue methodsFor:'debugging'!

inspectorExtraAttributes 
    | d |

    d := super inspectorExtraAttributes.      
    d add: '-dump' -> [ self dumpString ].
    ^ d

    "Created: / 10-07-2015 / 14:36:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LLVMValue methodsFor:'debugging-dumping'!

dumpOn: aStream
    aStream nextPutAll: self dumpString

    "Created: / 10-07-2015 / 14:32:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

dumpString
    | cstr str|

    cstr := LLVM PrintValueToString: self.
    str := cstr copyCStringFromHeap.
    LLVM DisposeMessage: cstr.
    ^ str

    "Created: / 10-07-2015 / 14:31:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

printOn: aStream
    | name |

    super printOn: aStream.
    aStream nextPut: $(.
    name := self name.
    name notEmptyOrNil ifTrue:[ 
        aStream nextPutAll: name
    ] ifFalse:[ 
        aStream nextPutAll: '<anon>'
    ].
    aStream space.
    aStream nextPutAll: self type dumpString.
    aStream nextPut: $)

    "Created: / 11-07-2015 / 07:09:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 08-08-2015 / 04:22:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LLVMValue methodsFor:'initialization'!

initialize
    self class == LLVMValue ifTrue:[ 
        self isFunction ifTrue:[ 
            self changeClassTo: LLVMFunction.
        ].
    ].

    "Created: / 18-09-2015 / 06:14:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LLVMValue methodsFor:'testing'!

isAddrSpaceCastInst

    ^ LLVM IsAAddrSpaceCastInst: self
!

isAllocaInst

    ^ LLVM IsAAllocaInst: self
!

isArgument

    ^ LLVM IsAArgument: self
!

isBasicBlock

    ^ LLVM IsABasicBlock: self
!

isBinaryOperator

    ^ LLVM IsABinaryOperator: self
!

isBitCastInst

    ^ LLVM IsABitCastInst: self
!

isBlockAddress

    ^ LLVM IsABlockAddress: self
!

isBranchInst

    ^ LLVM IsABranchInst: self
!

isCallInst

    ^ LLVM IsACallInst: self
!

isCastInst

    ^ LLVM IsACastInst: self
!

isCatchEndPadInst

    ^ LLVM IsACatchEndPadInst: self
!

isCatchPadInst

    ^ LLVM IsACatchPadInst: self
!

isCatchReturnInst

    ^ LLVM IsACatchReturnInst: self
!

isCleanupPadInst

    ^ LLVM IsACleanupPadInst: self
!

isCleanupReturnInst

    ^ LLVM IsACleanupReturnInst: self
!

isCmpInst

    ^ LLVM IsACmpInst: self
!

isConstant

    ^ LLVM IsAConstant: self
!

isConstantAggregateZero

    ^ LLVM IsAConstantAggregateZero: self
!

isConstantArray

    ^ LLVM IsAConstantArray: self
!

isConstantDataArray

    ^ LLVM IsAConstantDataArray: self
!

isConstantDataSequential

    ^ LLVM IsAConstantDataSequential: self
!

isConstantDataVector

    ^ LLVM IsAConstantDataVector: self
!

isConstantExpr

    ^ LLVM IsAConstantExpr: self
!

isConstantFP

    ^ LLVM IsAConstantFP: self
!

isConstantInt

    ^ LLVM IsAConstantInt: self
!

isConstantPointerNull

    ^ LLVM IsAConstantPointerNull: self
!

isConstantStruct

    ^ LLVM IsAConstantStruct: self
!

isConstantVector

    ^ LLVM IsAConstantVector: self
!

isDbgDeclareInst

    ^ LLVM IsADbgDeclareInst: self
!

isDbgInfoIntrinsic

    ^ LLVM IsADbgInfoIntrinsic: self
!

isExtractElementInst

    ^ LLVM IsAExtractElementInst: self
!

isExtractValueInst

    ^ LLVM IsAExtractValueInst: self
!

isFCmpInst

    ^ LLVM IsAFCmpInst: self
!

isFPExtInst

    ^ LLVM IsAFPExtInst: self
!

isFPToSIInst

    ^ LLVM IsAFPToSIInst: self
!

isFPToUIInst

    ^ LLVM IsAFPToUIInst: self
!

isFPTruncInst

    ^ LLVM IsAFPTruncInst: self
!

isFunction

    ^ LLVM IsAFunction: self
!

isGetElementPtrInst

    ^ LLVM IsAGetElementPtrInst: self
!

isGlobalAlias

    ^ LLVM IsAGlobalAlias: self
!

isGlobalObject

    ^ LLVM IsAGlobalObject: self
!

isGlobalValue

    ^ LLVM IsAGlobalValue: self
!

isGlobalVariable

    ^ LLVM IsAGlobalVariable: self
!

isICmpInst

    ^ LLVM IsAICmpInst: self
!

isIndirectBrInst

    ^ LLVM IsAIndirectBrInst: self
!

isInlineAsm

    ^ LLVM IsAInlineAsm: self
!

isInsertElementInst

    ^ LLVM IsAInsertElementInst: self
!

isInsertValueInst

    ^ LLVM IsAInsertValueInst: self
!

isInstruction

    ^ LLVM IsAInstruction: self
!

isIntToPtrInst

    ^ LLVM IsAIntToPtrInst: self
!

isIntrinsicInst

    ^ LLVM IsAIntrinsicInst: self
!

isInvokeInst

    ^ LLVM IsAInvokeInst: self
!

isLLVMValue
    ^ true

    "Created: / 08-08-2015 / 03:28:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

isLandingPadInst

    ^ LLVM IsALandingPadInst: self
!

isLoadInst

    ^ LLVM IsALoadInst: self
!

isMDNode

    ^ LLVM IsAMDNode: self
!

isMDString

    ^ LLVM IsAMDString: self
!

isMemCpyInst

    ^ LLVM IsAMemCpyInst: self
!

isMemIntrinsic

    ^ LLVM IsAMemIntrinsic: self
!

isMemMoveInst

    ^ LLVM IsAMemMoveInst: self
!

isMemSetInst

    ^ LLVM IsAMemSetInst: self
!

isPHINode

    ^ LLVM IsAPHINode: self
!

isPtrToIntInst

    ^ LLVM IsAPtrToIntInst: self
!

isResumeInst

    ^ LLVM IsAResumeInst: self
!

isReturnInst

    ^ LLVM IsAReturnInst: self
!

isSExtInst

    ^ LLVM IsASExtInst: self
!

isSIToFPInst

    ^ LLVM IsASIToFPInst: self
!

isSelectInst

    ^ LLVM IsASelectInst: self
!

isShuffleVectorInst

    ^ LLVM IsAShuffleVectorInst: self
!

isStoreInst

    ^ LLVM IsAStoreInst: self
!

isSwitchInst

    ^ LLVM IsASwitchInst: self
!

isTerminatePadInst

    ^ LLVM IsATerminatePadInst: self
!

isTerminatorInst

    ^ LLVM IsATerminatorInst: self
!

isTruncInst

    ^ LLVM IsATruncInst: self
!

isUIToFPInst

    ^ LLVM IsAUIToFPInst: self
!

isUnaryInstruction

    ^ LLVM IsAUnaryInstruction: self
!

isUndefValue

    ^ LLVM IsAUndefValue: self
!

isUnreachableInst

    ^ LLVM IsAUnreachableInst: self
!

isUser

    ^ LLVM IsAUser: self
!

isVAArgInst

    ^ LLVM IsAVAArgInst: self
!

isZExtInst

    ^ LLVM IsAZExtInst: self
! !

!LLVMValue class methodsFor:'documentation'!

version_HG

    ^ '$Changeset: <not expanded> $'
! !