8
|
1 |
"{ Package: 'jv:libllvms' }"
|
|
2 |
|
|
3 |
"{ NameSpace: Smalltalk }"
|
|
4 |
|
|
5 |
Object subclass:#LLVMExamples
|
|
6 |
instanceVariableNames:''
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'LLVM-Core-Examples'
|
|
10 |
!
|
|
11 |
|
|
12 |
|
|
13 |
!LLVMExamples class methodsFor:'examples'!
|
|
14 |
|
|
15 |
example1_sum
|
|
16 |
| module functionType function functionEntry asm jit externalFunction |
|
|
17 |
|
|
18 |
module := LLVMModule newWithName: thisContext selector.
|
|
19 |
functionType := LLVMType function: { LLVMType intptr . LLVMType intptr } returning: LLVMType intptr.
|
|
20 |
function := module addFunctionNamed: 'sum' type: functionType.
|
|
21 |
|
|
22 |
functionEntry := function addBasicBlockNamed: 'entry'.
|
|
23 |
asm := LLVMBuilder new.
|
|
24 |
asm positionAtEnd: functionEntry.
|
|
25 |
asm ret: (asm add: (function parameterAt: 1) and: (function parameterAt: 2)).
|
|
26 |
|
|
27 |
jit := LLVMExecutionEngine newForModule: module.
|
|
28 |
externalFunction := jit externalOfFunction: function.
|
|
29 |
|
|
30 |
^ externalFunction callWith: 3 with: 4.
|
|
31 |
|
|
32 |
"
|
|
33 |
LLVMExamples example1_sum
|
|
34 |
"
|
|
35 |
|
|
36 |
"Created: / 17-07-2015 / 11:47:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
37 |
! !
|
|
38 |
|
|
39 |
!LLVMExamples class methodsFor:'documentation'!
|
|
40 |
|
|
41 |
version_HG
|
|
42 |
|
|
43 |
^ '$Changeset: <not expanded> $'
|
|
44 |
! !
|
|
45 |
|