LLVMTypeStruct.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 17 Sep 2015 17:17:56 +0100
changeset 42 23ae490859cd
parent 27 b26354bbff25
child 50 dbda820d4d24
permissions -rw-r--r--
Fixed LLVMExamples>>example7_factorial_with_debug_info Pass DIFile instead of DICompileUnit to #createTypeFunctionIn:parameterTypes: Fixed #createParameterVariable: - parameters are numbered starting with 1.

"
    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:#LLVMTypeStruct
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'LLVM-S-Core-Types'
!

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

!LLVMTypeStruct methodsFor:'accessing'!

elementTypeAt: n
    "Return types of `n`th member of the structure. Index starts at 1 as
     customary in Smalltalk.

     Uses term `element` instead of `member` to be in sync
     with LLVM naming."

    (n between: 1 and: self numElements) ifTrue:[
        ^  LLVM StructGetTypeAtIndex: self _: n - 1.
    ].
    LLVMTypeError new signal: 'index out of bounds'.

    "Created: / 14-08-2015 / 05:56:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

elementTypes
    "Return types of members of this structure.

     Uses term `element` instead of `member` to be in sync
     with LLVM naming."

    | numElements elementTypePointers elementTypes |

    numElements := self numElements.
    numElements == 0 ifTrue:[ ^ #() ].
    elementTypePointers := LLVMObjectArray new: numElements.
    elementTypes := Array new: numElements.
    LLVM GetStructElementTypes: self _: elementTypePointers.
    1 to: numElements do:[:i | elementTypes at: i put: (LLVMType newAddress: (elementTypePointers at: i)) ].
    ^ elementTypes

    "Created: / 14-08-2015 / 05:54:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

numElements
    "Return a number of members of this structure"

    ^ LLVM CountStructElementTypes: self

    "Created: / 14-08-2015 / 05:53:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LLVMTypeStruct methodsFor:'testing'!

isOpaque
    ^ LLVM IsOpaqueStruct: self

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

isPacked
    ^ LLVM IsPackedStruct: self

    "Created: / 14-08-2015 / 06:11:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

isStructType
    ^ true

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