|
1 "{ Package: 'ctu:ircompiler/tests' }" |
|
2 |
|
3 TestCase subclass:#IRTransformTest |
|
4 instanceVariableNames:'' |
|
5 classVariableNames:'' |
|
6 poolDictionaries:'' |
|
7 category:'IR Compiler-Tests' |
|
8 ! |
|
9 |
|
10 |
|
11 !IRTransformTest methodsFor:'testing'! |
|
12 |
|
13 testAdd |
|
14 |iRMethod aCompiledMethod| |
|
15 |
|
16 iRMethod := (IRBuilder new) |
|
17 numRargs:1; |
|
18 addTemps:#( #self ); |
|
19 pushLiteral:1; |
|
20 returnTop; |
|
21 ir. |
|
22 (iRMethod allSequences last) last delete. |
|
23 (iRMethod allSequences last) last delete. |
|
24 (iRMethod allSequences last) add:(IRInstruction pushLiteral:2). |
|
25 (iRMethod allSequences last) add:(IRInstruction returnTop). |
|
26 aCompiledMethod := iRMethod compiledCode. |
|
27 self should:[ (aCompiledMethod valueWithReceiver:nil arguments:#()) = 2 ]. |
|
28 ! |
|
29 |
|
30 testAddBefore |
|
31 |iRMethod aCompiledMethod ret| |
|
32 |
|
33 iRMethod := (IRBuilder new) |
|
34 numRargs:1; |
|
35 addTemps:#( #self ); |
|
36 pushLiteral:1; |
|
37 returnTop; |
|
38 ir. |
|
39 (iRMethod allSequences last) last delete. |
|
40 (iRMethod allSequences last) last delete. |
|
41 ret := (IRInstruction returnTop). |
|
42 (iRMethod allSequences last) add:ret. |
|
43 (iRMethod allSequences last) add:(IRInstruction pushLiteral:2) before:ret. |
|
44 aCompiledMethod := iRMethod compiledCode. |
|
45 self should:[ (aCompiledMethod valueWithReceiver:nil arguments:#()) = 2 ]. |
|
46 ! |
|
47 |
|
48 testAddIntructions |
|
49 |
|
50 | iRMethod aCompiledMethod | |
|
51 |
|
52 iRMethod := IRBuilder new |
|
53 numRargs: 1; |
|
54 addTemps: #(self); "receiver and args declarations" |
|
55 pushLiteral: 1; |
|
56 returnTop; |
|
57 ir. |
|
58 |
|
59 (iRMethod allSequences last) last delete. |
|
60 (iRMethod allSequences last) last delete. |
|
61 |
|
62 (iRMethod allSequences last) |
|
63 addInstructions: {(IRInstruction pushLiteral: 2). (IRInstruction returnTop)}. |
|
64 |
|
65 aCompiledMethod := iRMethod compiledCode. |
|
66 self should: [(aCompiledMethod valueWithReceiver: nil arguments: #() ) = 2]. |
|
67 |
|
68 "Modified: / 30-03-2009 / 19:40:10 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
69 ! |
|
70 |
|
71 testAddIntructionsBefore |
|
72 |
|
73 | iRMethod aCompiledMethod push | |
|
74 |
|
75 iRMethod := IRBuilder new |
|
76 numRargs: 1; |
|
77 addTemps: #(self); "receiver and args declarations" |
|
78 pushLiteral: 1; |
|
79 returnTop; |
|
80 ir. |
|
81 |
|
82 push := (iRMethod allSequences last) at: (iRMethod allSequences size - 1) . |
|
83 |
|
84 (iRMethod allSequences last) |
|
85 addInstructions: {(IRInstruction pushLiteral: 2). (IRInstruction returnTop)} before: push. |
|
86 |
|
87 aCompiledMethod := iRMethod compiledCode. |
|
88 self should: [(aCompiledMethod valueWithReceiver: nil arguments: #() ) = 2]. |
|
89 |
|
90 "Modified: / 30-03-2009 / 19:40:21 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
91 ! |
|
92 |
|
93 testAddIntructionsBeforeFromLList |
|
94 |iRMethod aCompiledMethod push llist col| |
|
95 |
|
96 iRMethod := (IRBuilder new) |
|
97 numRargs:1; |
|
98 addTemps:#( #self ); |
|
99 pushLiteral:1; |
|
100 returnTop; |
|
101 ir. |
|
102 push := (iRMethod allSequences last) at:(iRMethod allSequences size - 1). |
|
103 llist := LinkedList new. |
|
104 llist add:(IRInstruction pushLiteral:2). |
|
105 llist add:(IRInstruction returnTop). |
|
106 col := llist asOrderedCollection. |
|
107 (iRMethod allSequences last) addInstructions:col before:push. |
|
108 aCompiledMethod := iRMethod compiledCode. |
|
109 self should:[ (aCompiledMethod valueWithReceiver:nil arguments:#()) = 2 ]. |
|
110 ! |
|
111 |
|
112 testDelete |
|
113 |iRMethod aCompiledMethod| |
|
114 |
|
115 iRMethod := (IRBuilder new) |
|
116 numRargs:1; |
|
117 addTemps:#( #self ); |
|
118 pushLiteral:1; |
|
119 pushLiteral:2; |
|
120 returnTop; |
|
121 ir. |
|
122 ((iRMethod allSequences last) |
|
123 detect:[:each | each isConstant:[:c | c == 2 ] ]) delete. |
|
124 aCompiledMethod := iRMethod compiledCode. |
|
125 self should:[ (aCompiledMethod valueWithReceiver:nil arguments:#()) = 1 ]. |
|
126 ! |
|
127 |
|
128 testReplace |
|
129 |iRMethod aCompiledMethod| |
|
130 |
|
131 iRMethod := (IRBuilder new) |
|
132 numRargs:1; |
|
133 addTemps:#( #self ); |
|
134 pushLiteral:1; |
|
135 returnTop; |
|
136 ir. |
|
137 (iRMethod allSequences last at:1) |
|
138 replaceWith:(IRInstruction pushLiteral:2). |
|
139 aCompiledMethod := iRMethod compiledCode. |
|
140 self should:[ (aCompiledMethod valueWithReceiver:nil arguments:#()) = 2 ]. |
|
141 ! |
|
142 |
|
143 testReplaceInstr |
|
144 |
|
145 | iRMethod aCompiledMethod | |
|
146 |
|
147 iRMethod := IRBuilder new |
|
148 numRargs: 1; |
|
149 addTemps: #(self); "receiver and args declarations" |
|
150 pushLiteral: 1; |
|
151 returnTop; |
|
152 ir. |
|
153 |
|
154 (iRMethod allSequences last at: 1) |
|
155 replaceWithInstructions: {(IRInstruction pushLiteral: 2)}. |
|
156 |
|
157 aCompiledMethod := iRMethod compiledCode. |
|
158 self should: [(aCompiledMethod valueWithReceiver: nil arguments: #() ) = 2]. |
|
159 |
|
160 "Modified: / 30-03-2009 / 19:40:30 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
161 ! ! |
|
162 |
|
163 !IRTransformTest class methodsFor:'documentation'! |
|
164 |
|
165 version_CVS |
|
166 ^ 'Header: /cvs/stx/cvut/stx/goodies/newcompiler/IRTransformTest.st,v 1.3 2009/10/08 11:56:52 fm Exp ' |
|
167 ! |
|
168 |
|
169 version_SVN |
|
170 ^ '$Id:: $' |
|
171 ! ! |
|
172 |