|
1 "{ Package: 'jv:dragonfly/c1' }" |
|
2 |
|
3 "{ NameSpace: DragonFly }" |
|
4 |
|
5 TestCase subclass:#C1CompilerTests |
|
6 instanceVariableNames:'' |
|
7 classVariableNames:'' |
|
8 poolDictionaries:'DragonFly::C1LLVMMTypes LLVMIntPredicate VMData VMOffsets' |
|
9 category:'DragonFly-C1-Tests' |
|
10 ! |
|
11 |
|
12 !C1CompilerTests methodsFor:'tests'! |
|
13 |
|
14 test_fetchClassOf |
|
15 | compiler module function asm jit test | |
|
16 |
|
17 compiler := C1Compiler new. |
|
18 module := LLVMModule newWithName: testSelector. |
|
19 function := module addFunctionNamed: 'test' |
|
20 type: (LLVMType function: { TyOBJ } returning: TyOBJ). |
|
21 asm := function builder. |
|
22 compiler |
|
23 instVarNamed: #module put: module; |
|
24 instVarNamed: #function put: function; |
|
25 instVarNamed: #asm put: asm. |
|
26 |
|
27 asm ret: (compiler fetchClassOf: (function parameterAt: 1)). |
|
28 |
|
29 jit := LLVMExecutionEngine newForModule: module. |
|
30 test := jit externalOfFunction: function. |
|
31 |
|
32 self assert: (test callOWith: 1) == SmallInteger. |
|
33 self assert: (test callOWith: self) == self class. |
|
34 self assert: (test callOWith: 1.0) == 1.0 class. |
|
35 |
|
36 "Created: / 12-02-2016 / 12:27:26 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
37 ! |
|
38 |
|
39 test_fetchClassSmallInteger |
|
40 | compiler module function asm jit test | |
|
41 |
|
42 compiler := C1Compiler new. |
|
43 module := LLVMModule newWithName: testSelector. |
|
44 function := module addFunctionNamed: 'test' |
|
45 type: (LLVMType function: { } returning: TyOBJ). |
|
46 asm := function builder. |
|
47 compiler |
|
48 instVarNamed: #module put: module; |
|
49 instVarNamed: #function put: function; |
|
50 instVarNamed: #asm put: asm. |
|
51 |
|
52 asm ret: (compiler fetchClassSmallInteger). |
|
53 |
|
54 jit := LLVMExecutionEngine newForModule: module. |
|
55 test := jit externalOfFunction: function. |
|
56 |
|
57 self assert: (test callO) == SmallInteger. |
|
58 |
|
59 "Created: / 12-02-2016 / 12:26:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
60 ! |
|
61 |
|
62 test_isSmallIntegerObject |
|
63 | compiler module function asm jit test | |
|
64 |
|
65 compiler := C1Compiler new. |
|
66 module := LLVMModule newWithName: testSelector. |
|
67 function := module addFunctionNamed: 'test' |
|
68 type: (LLVMType function: { TyOBJ } returning: LLVMType int1). |
|
69 asm := function builder. |
|
70 compiler |
|
71 instVarNamed: #module put: module; |
|
72 instVarNamed: #function put: function; |
|
73 instVarNamed: #asm put: asm. |
|
74 |
|
75 asm ret: (compiler isSmallIntegerObject: (function parameterAt: 1)). |
|
76 |
|
77 jit := LLVMExecutionEngine newForModule: module. |
|
78 test := jit externalOfFunction: function. |
|
79 |
|
80 self assert: (test callWith: 1) == 1. |
|
81 self assert: (test callWith: self) == 0. |
|
82 |
|
83 "Created: / 12-02-2016 / 12:17:57 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
84 ! ! |
|
85 |