extensions.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 10 Aug 2015 19:26:29 +0100
changeset 24 7e7ddd55174c
parent 22 789a35bd30ac
child 33 feabf14b6c1d
permissions -rw-r--r--
Added support for intrinsics. As access to intrinsics is not exposed by LLVM-C API, a custom C++ library exposing those hase been added - llvm_c_ext. Smalltalk binds to this library in addition to LLVM's. In a future this library will expose whatever C++ API will be needed in scope of this project. However, it's designed to usable standalone, i.e., it contains no Smalltalk-specic code.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12
f98e97fd02ef Package renamed from jv:libllvms to jv:llvm_s
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
     1
"{ Package: 'jv:llvm_s' }"!
1
e3dcb6272f0b Introduced abstract superclasses LLVMObject and LLVMDisposableObject
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     2
22
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
     3
!Object methodsFor:'converting'!
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
     4
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
     5
asLLVMValue
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
     6
    "Return representation of the receiver as LLVMValue."
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
     7
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
     8
    "Raise an error - arbitrary object cannot be represented
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
     9
     as LLVM value"
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    10
    self error: 'cannot be converted to an LLVM value'
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    11
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    12
    "Created: / 08-08-2015 / 02:11:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    13
! !
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    14
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    15
!Object methodsFor:'converting'!
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    16
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    17
asLLVMValueOfType: anLLVMType
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    18
    "Return representation of the receiver as LLVMValue with given LLVMType. 
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    19
     If the object cannot be converted to the balue of requested type, 
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    20
     raise an error."
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    21
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    22
    self error: 'cannot be converted to an LLVM value'
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    23
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    24
    "Created: / 08-08-2015 / 02:27:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    25
! !
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    26
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    27
!Object methodsFor:'testing'!
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    28
24
7e7ddd55174c Added support for intrinsics.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 22
diff changeset
    29
isLLVMFunction
7e7ddd55174c Added support for intrinsics.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 22
diff changeset
    30
    "Return true, if receiver represents an LLVM value representing a function"
7e7ddd55174c Added support for intrinsics.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 22
diff changeset
    31
7e7ddd55174c Added support for intrinsics.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 22
diff changeset
    32
    ^ false
7e7ddd55174c Added support for intrinsics.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 22
diff changeset
    33
7e7ddd55174c Added support for intrinsics.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 22
diff changeset
    34
    "Created: / 10-08-2015 / 19:01:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
7e7ddd55174c Added support for intrinsics.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 22
diff changeset
    35
! !
7e7ddd55174c Added support for intrinsics.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 22
diff changeset
    36
7e7ddd55174c Added support for intrinsics.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 22
diff changeset
    37
!Object methodsFor:'testing'!
7e7ddd55174c Added support for intrinsics.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 22
diff changeset
    38
22
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    39
isLLVMType
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    40
    "Return true, if receiver represents an LLVM type"
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    41
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    42
    ^ false
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    43
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    44
    "Created: / 08-08-2015 / 02:45:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    45
! !
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    46
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    47
!Object methodsFor:'testing'!
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    48
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    49
isLLVMValue
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    50
    "Return true, if receiver represents an LLVM value"
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    51
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    52
    ^ false
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    53
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    54
    "Created: / 08-08-2015 / 02:21:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    55
! !
789a35bd30ac Added example for compiling conditional. Added convenience API to simply code generation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    56
1
e3dcb6272f0b Introduced abstract superclasses LLVMObject and LLVMDisposableObject
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    57
!SequenceableCollection methodsFor:'converting'!
e3dcb6272f0b Introduced abstract superclasses LLVMObject and LLVMDisposableObject
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    58
e3dcb6272f0b Introduced abstract superclasses LLVMObject and LLVMDisposableObject
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    59
asLLVMObjectArray
e3dcb6272f0b Introduced abstract superclasses LLVMObject and LLVMDisposableObject
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    60
    | array size | 
e3dcb6272f0b Introduced abstract superclasses LLVMObject and LLVMDisposableObject
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    61
e3dcb6272f0b Introduced abstract superclasses LLVMObject and LLVMDisposableObject
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    62
    size := self size.
16
23e82cf19788 Tests refactored to be actually a testcase. Introduced LLVMConstant class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 12
diff changeset
    63
    size == 0 ifTrue:[ 
23e82cf19788 Tests refactored to be actually a testcase. Introduced LLVMConstant class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 12
diff changeset
    64
        ^ nil
23e82cf19788 Tests refactored to be actually a testcase. Introduced LLVMConstant class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 12
diff changeset
    65
    ].
1
e3dcb6272f0b Introduced abstract superclasses LLVMObject and LLVMDisposableObject
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    66
    array := LLVMObjectArray new: size.
e3dcb6272f0b Introduced abstract superclasses LLVMObject and LLVMDisposableObject
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    67
    array replaceFrom: 1 count: size with: self.
e3dcb6272f0b Introduced abstract superclasses LLVMObject and LLVMDisposableObject
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    68
    ^array
e3dcb6272f0b Introduced abstract superclasses LLVMObject and LLVMDisposableObject
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    69
e3dcb6272f0b Introduced abstract superclasses LLVMObject and LLVMDisposableObject
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    70
    "Created: / 08-07-2015 / 22:58:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
16
23e82cf19788 Tests refactored to be actually a testcase. Introduced LLVMConstant class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 12
diff changeset
    71
    "Modified: / 03-08-2015 / 17:04:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
23e82cf19788 Tests refactored to be actually a testcase. Introduced LLVMConstant class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 12
diff changeset
    72
! !
23e82cf19788 Tests refactored to be actually a testcase. Introduced LLVMConstant class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 12
diff changeset
    73
23e82cf19788 Tests refactored to be actually a testcase. Introduced LLVMConstant class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 12
diff changeset
    74
!stx_goodies_sunit class methodsFor:'documentation'!
23e82cf19788 Tests refactored to be actually a testcase. Introduced LLVMConstant class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 12
diff changeset
    75
23e82cf19788 Tests refactored to be actually a testcase. Introduced LLVMConstant class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 12
diff changeset
    76
version_HG
23e82cf19788 Tests refactored to be actually a testcase. Introduced LLVMConstant class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 12
diff changeset
    77
    ^ '$Changeset: <not expanded> $'
23e82cf19788 Tests refactored to be actually a testcase. Introduced LLVMConstant class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 12
diff changeset
    78
! !
23e82cf19788 Tests refactored to be actually a testcase. Introduced LLVMConstant class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 12
diff changeset
    79
23e82cf19788 Tests refactored to be actually a testcase. Introduced LLVMConstant class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 12
diff changeset
    80
!stx_libbasic class methodsFor:'documentation'!
23e82cf19788 Tests refactored to be actually a testcase. Introduced LLVMConstant class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 12
diff changeset
    81
23e82cf19788 Tests refactored to be actually a testcase. Introduced LLVMConstant class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 12
diff changeset
    82
version_HG
23e82cf19788 Tests refactored to be actually a testcase. Introduced LLVMConstant class
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 12
diff changeset
    83
    ^ '$Changeset: <not expanded> $'
1
e3dcb6272f0b Introduced abstract superclasses LLVMObject and LLVMDisposableObject
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    84
! !
e3dcb6272f0b Introduced abstract superclasses LLVMObject and LLVMDisposableObject
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    85
12
f98e97fd02ef Package renamed from jv:libllvms to jv:llvm_s
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    86
!jv_llvm_s class methodsFor:'documentation'!
1
e3dcb6272f0b Introduced abstract superclasses LLVMObject and LLVMDisposableObject
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    87
e3dcb6272f0b Introduced abstract superclasses LLVMObject and LLVMDisposableObject
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    88
extensionsVersion_HG
e3dcb6272f0b Introduced abstract superclasses LLVMObject and LLVMDisposableObject
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    89
e3dcb6272f0b Introduced abstract superclasses LLVMObject and LLVMDisposableObject
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    90
    ^ '$Changeset: <not expanded> $'
e3dcb6272f0b Introduced abstract superclasses LLVMObject and LLVMDisposableObject
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    91
! !