LLVMConstant.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 27 Jan 2016 14:20:58 +0000
changeset 54 a288aced3dd1
parent 50 dbda820d4d24
child 55 41b3437f1fc7
permissions -rw-r--r--
LLVM C API Extensions: Fixed DIBuilerCreateFunction() and DIBuilderCreateSubroutineType() for LLVM 3.9 In LLVM 3.9 some parameters to these functions were dropped. The DIBuilder interface has been changed to reflect these changes (i.e., C functions no longer require dropped argument). The LLVM C Extensions library can still be compiled against LLVM 3.8 (via #ifdef), but the API will be different. Also, the Smalltallks bindings will make use of LLVM 3.9 interface. That said, LLVM C API Extensions library may still be used by *other* projects on top of LLVM 3.8, though Smalltalk bindings require LLVM 3.9 from now on.

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

Object subclass:#LLVMConstant
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'LLVM-S-Core'
!

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

documentation
"
    A simple factory for creating constant values.

    LLVMConstant sint16: 10.
    LLVMConstant string: 'Hello World!!'.

    [author:]
        Jan Vrany <jan.vrany@fit.cvut.cz>

    [instance variables:]

    [class variables:]

    [see also:]

"
! !

!LLVMConstant class methodsFor:'assertions'!

assertIsType: type
    <resource: #skipInDebuggersWalkBack>

    self assert: type isLLVMType message: 'value is not an LLVMType'.

    "Created: / 10-08-2015 / 06:26:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 14-09-2015 / 11:09:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (format): / 17-09-2015 / 16:51:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

assertIsValue: value
    <resource: #skipInDebuggersWalkBack>

    self assert: value isLLVMValue message: 'value is not an LLVMValue'.

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

assertIsValue: value ofKind: kind
    <resource: #skipInDebuggersWalkBack>

    self assert: value isLLVMValue message: 'value is not an LLVMValue'.
    self assert: value type kind = kind message: 'value has incorrect kind'

    "Created: / 10-08-2015 / 17:40:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 14-09-2015 / 11:09:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

assertIsValue: value ofType: type
    <resource: #skipInDebuggersWalkBack>

    self assert: value isLLVMValue message: 'value is not an LLVMValue'.
    self assert: value type = type message: 'value has incorrect type'

    "Created: / 08-08-2015 / 02:49:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 14-09-2015 / 11:09:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LLVMConstant class methodsFor:'constants - construction'!

bitcast: value to: type
    self assertIsValue: value.
    self assertIsType: type.
    ^ LLVM ConstBitCast: value _: type.

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

!LLVMConstant class methodsFor:'constants - int - signed'!

sint16:value 
    ^ self sint:value type:LLVMType int16

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

sint1:value 
    ^ self sint:value type:LLVMType int1

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

sint32:value 
    ^ self sint:value type:LLVMType int32

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

sint64:value 
    ^ self sint:value type:LLVMType int64

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

sint:value type:type 
    self assert:type isIntegerType.
    self assert:value isInteger.
    ^ LLVM ConstInt:type _:value _:1

    "Created: / 11-07-2015 / 16:41:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (format): / 03-08-2015 / 17:08:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

sintptr:value 
    ^ self sint:value type:LLVMType intptr

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

!LLVMConstant class methodsFor:'constants - int - unsigned'!

uint16:value 
    ^ self uint:value type:LLVMType int16

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

uint1:value 
    ^ self uint:value type:LLVMType int1

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

uint32:value 
    ^ self uint:value type:LLVMType int32

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

uint64:value 
    ^ self uint:value type:LLVMType int64

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

uint:value type:type 
    self assert:type isIntegerType.
    self assert:value isInteger.
    ^ LLVM 
        ConstInt:type
        _:value
        _:0

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

uintptr:value 
    ^ self uint:value type:LLVMType intptr

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

!LLVMConstant class methodsFor:'constants - strings'!

string:aString 
    ^ self string:aString nullTerminate:true

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

string:aString nullTerminate:nullTerminate 
    self assert:aString isSingleByteString.
    ^ LLVM 
        ConstString:aString
        _:aString size
        _:((nullTerminate == true) ifTrue:[ 1 ] ifFalse:[ 0 ])
             "Created: / 03-08-2015 / 16:17:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !