LLVMTypeStruct.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 15 Sep 2016 22:14:32 +0100
changeset 79 6d6e5a3ec6b1
parent 50 dbda820d4d24
permissions -rw-r--r--
llvm_c_ext: Updated to use `llvm::DINode::DIFlags` rather than just `unsigned`. Added new constantpool `LLVMDIFLags`

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

elementTypes: elementTypes
    "Set member types of the structure.

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

    ^ self elementTypes: elementTypes package: false.

    "Created: / 12-10-2015 / 14:58:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

elementTypes: elementTypes package: packed
    "Set member types of the structure.

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

    self assertIsTypeArray: elementTypes.
    self assertIsBoolean: packed.    
    ^ LLVM StructSetBody: self _: elementTypes asLLVMObjectArray _: elementTypes size _: packed

    "Created: / 12-10-2015 / 14:57:41 / 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:'inspecting'!

inspectorExtraAttributes
    | extras |

    extras := super inspectorExtraAttributes.
    self elementTypes withIndexDo:[:type :index | 
        extras at: '-element type ', index printString put: type
    ].
    ^ extras

    "Created: / 12-10-2015 / 17:00:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 12-10-2015 / 18:05:51 / 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>"
! !