Skip to content

Commit 720a173

Browse files
committed
[Tolk] Output original .tolk lines into Fift as comments
This update greatly enhances reading Fift output: 1) stack comments are aligned 2) original lines from .tolk files are output as comments, grouping asm instructions Internally, every AsmOp now has SrcLocation. When outputting them one by one, an original .tolk line is inserted if locations differ. This can be optimized later by storing an index to fast mapping of location (offset) into a line in a file.
1 parent 0f9dd15 commit 720a173

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+944
-833
lines changed

tolk-tester/tests/allow-post-modification.tolk

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,14 @@ fun main() {
146146

147147
@fif_codegen
148148
"""
149-
~inc PROC:<{
150-
// self y
151-
inc CALLDICT // self newY
149+
~inc PROC:<{ // self y
150+
inc CALLDICT // self newY
152151
}>
153152
"""
154153

155154
@fif_codegen
156155
"""
157-
test_assign_tensor_global PROC:<{
158-
// x.0 x.1
156+
test_assign_tensor_global PROC:<{ // x.0 x.1
159157
"""
160158

161159
@code_hash 6737917279814799680932710799951154408447028229503449454536845752635763933556

tolk-tester/tests/assignment-tests.tolk

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,15 @@ fun main(value: int, ) {
245245

246246
@fif_codegen
247247
"""
248-
test116 PROC:<{
249-
//
250-
1 PUSHINT // '10=1
251-
2 PUSHINT // '10=1 '11=2
252-
3 PUSHINT // '10=1 '11=2 '12=3
253-
4 PUSHINT // '10=1 '11=2 '12=3 '13=4
254-
4 TUPLE // rhs
255-
DUP // rhs rhs
256-
4 UNTUPLE // rhs2 a b c d
257-
4 ROLL // a b c d rhs2
248+
test116 PROC:<{ //
249+
1 PUSHINT // '10=1
250+
2 PUSHINT // '10=1 '11=2
251+
3 PUSHINT // '10=1 '11=2 '12=3
252+
4 PUSHINT // '10=1 '11=2 '12=3 '13=4
253+
4 TUPLE // rhs
254+
DUP // rhs rhs
255+
4 UNTUPLE // rhs2 a b c d
256+
4 ROLL // a b c d rhs2
258257
}>
259258
"""
260259
*/

tolk-tester/tests/bit-operators.tolk

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,16 @@ fun testBoolCompareOptimized(x: bool) {
126126
@fif_codegen
127127
"""
128128
boolWithBitwiseConst PROC:<{
129-
//
130-
0 PUSHINT // '3
131-
-1 PUSHINT // '3 '5
132-
0 PUSHINT // '3 '5 '7
133-
-1 PUSHINT // '3 '5 '7 '8
129+
0 PUSHINT // '3
130+
-1 PUSHINT // '3 '5
131+
0 PUSHINT // '3 '5 '7
132+
-1 PUSHINT // '3 '5 '7 '8
134133
}>
135134
"""
136135

137136
@fif_codegen
138137
"""
139-
testDoUntilCodegen PROC:<{
140-
// i n
138+
testDoUntilCodegen PROC:<{ // i n
141139
0 PUSHINT // i n cnt=0
142140
UNTIL:<{
143141
INC // i n cnt
@@ -164,7 +162,6 @@ fun testBoolCompareOptimized(x: bool) {
164162
@fif_codegen
165163
"""
166164
testConstNegateCodegen PROC:<{
167-
//
168165
TRUE // '0
169166
FALSE // '0 '1
170167
FALSE // '0 '1 '2
@@ -176,26 +173,24 @@ fun testBoolCompareOptimized(x: bool) {
176173

177174
@fif_codegen
178175
"""
179-
testBoolNegateOptimized PROC:<{
180-
// x
181-
DUP // x x
182-
NOT // x '1
183-
OVER // x '1 x
184-
NOT // x '1 '2
176+
testBoolNegateOptimized PROC:<{ // x
177+
DUP // x x
178+
NOT // x '1
179+
OVER // x '1 x
180+
NOT // x '1 '2
185181
s2 s(-1) PUXC
186-
TRUE // x '1 x '2 '3
182+
TRUE // x '1 x '2 '3
187183
}>
188184
"""
189185

190186
@fif_codegen
191187
"""
192-
testBoolCompareOptimized PROC:<{
193-
// x
194-
DUP // x x
195-
NOT // x '1
188+
testBoolCompareOptimized PROC:<{ // x
189+
DUP // x x
190+
NOT // x '1
196191
OVER // x '1 x
197192
eqX CALLDICT // x '1 '2
198-
NOT // x '1 '3
193+
NOT // x '1 '3
199194
s2 PUSH // x '1 '3 x
200195
eqX CALLDICT // x '1 '3 '4
201196
s3 PUSH // x '1 '3 '4 x

tolk-tester/tests/cells-slices.tolk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ Note, that since 'compute-asm-ltr' became on be default, chaining methods codege
216216
@fif_codegen
217217
"""
218218
test6 PROC:<{
219-
//
220219
NEWC // '0
221220
1 PUSHINT // '0 '1=1
222221
SWAP // '1=1 '0

tolk-tester/tests/codegen-check-demo.tolk

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ Below, I just give examples of @fif_codegen tag:
3333

3434
@fif_codegen
3535
"""
36-
main PROC:<{
37-
// s
36+
main PROC:<{ // s
3837
17 PUSHINT // s '3=17
3938
OVER // s z=17 t
4039
WHILE:<{
@@ -78,7 +77,6 @@ main PROC:<{
7877
@fif_codegen
7978
"""
8079
test1 PROC:<{
81-
//
8280
FALSE
8381
}>
8482
"""
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
struct WithDef {
3+
f1: int,
4+
f2: int = 10,
5+
f3: int,
6+
f4: int,
7+
}
8+
9+
const C_20 = 20;
10+
11+
fun demo_fields_def(x: int) {
12+
var w: WithDef = {
13+
f1: x + C_20,
14+
f3: 100,
15+
f4: C_20
16+
};
17+
return (w.f4 + 5, w.f3, w.f2, w.f1);
18+
}
19+
20+
fun main() {
21+
return 1;
22+
}
23+
24+
/**
25+
@testcase | 0 | | 1
26+
27+
@fif_codegen_enable_comments
28+
@fif_codegen
29+
"""
30+
demo_fields_def PROC:<{ // x
31+
// 13: f1: x + C_20
32+
20 ADDCONST // '6
33+
10 PUSHINT // '6 '7=10
34+
// 14: f3: 100
35+
100 PUSHINT // w.f1 w.f2=10 w.f3=100
36+
// 17: return (w.f4 + 5, w.f3, w.f2, w.f1)
37+
25 PUSHINT // w.f1 w.f2=10 w.f3=100 '11
38+
s2 s3 XCHG2 // '11 w.f3=100 w.f2=10 w.f1
39+
}>
40+
"""
41+
42+
*/

tolk-tester/tests/generics-2.tolk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,6 @@ fun main(c: Wrapper<slice>, d: WrappedInt) {
453453
@fif_codegen
454454
"""
455455
test1 PROC:<{
456-
//
457456
23 PUSHINT // c1=23
458457
DUP // c1=23 c2=23
459458
}>

tolk-tester/tests/generics-3.tolk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ fun main() {
137137
@fif_codegen
138138
"""
139139
test3 PROC:<{
140-
//
141140
10 PUSHINT // r.USlot1=10
142141
-1 PUSHINT // r.USlot1=10 '11=-1
143142
FALSE // r.USlot1=10 '11=-1 '13

tolk-tester/tests/if-else-tests.tolk

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,23 +128,21 @@ fun main() {
128128

129129
@fif_codegen
130130
"""
131-
test3 PROC:<{
132-
// x
133-
DUP // x x
131+
test3 PROC:<{ // x
132+
DUP // x x
134133
20 NEQINT // x '2
135134
IFNOTJMP:<{ // x
136-
DROP //
135+
DROP //
137136
20 PUSHINT // '3=20
138-
}> // x
139-
DUP // x x
137+
}> // x
138+
DUP // x x
140139
50 EQINT // x '5
141140
IFNOTJMP:<{ // x
142141
"""
143142

144143
@fif_codegen
145144
"""
146145
withNoElse PROC:<{
147-
// op
148146
DUP
149147
123 EQINT
150148
IFJMP:<{
@@ -170,7 +168,6 @@ fun main() {
170168
@fif_codegen
171169
"""
172170
withElse PROC:<{
173-
// op
174171
DUP
175172
123 EQINT
176173
IFJMP:<{
@@ -196,7 +193,6 @@ fun main() {
196193
@fif_codegen
197194
"""
198195
withMatch PROC:<{
199-
// op
200196
DUP
201197
123 EQINT
202198
IFJMP:<{

tolk-tester/tests/indexed-access.tolk

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ fun main(){}
286286
@fif_codegen
287287
"""
288288
testCodegenSimple PROC:<{
289-
//
290289
1 PUSHINT // '2=1
291290
SINGLE // t1
292291
2 PUSHINT // t1 '3=2
@@ -336,24 +335,21 @@ fun main(){}
336335
@fif_codegen
337336
"""
338337
testCodegenNoPureIndexedAccess PROC:<{
339-
//
340338
0 PUSHINT // '8=0
341339
}>
342340
"""
343341

344342
@fif_codegen
345343
"""
346-
testCodegenIndexPostfix1 PROC:<{
347-
// x.0 x.1
344+
testCodegenIndexPostfix1 PROC:<{ // x.0 x.1
348345
// ab.1 ab.0
349346
SWAP // ab.0 ab.1
350347
}>
351348
"""
352349

353350
@fif_codegen
354351
"""
355-
testCodegenIndexPostfix2 PROC:<{
356-
// x.0 x.1.0 x.1.1 x.2
352+
testCodegenIndexPostfix2 PROC:<{ // x.0 x.1.0 x.1.1 x.2
357353
s2 POP // y.0 y.2 y.1.1
358354
s1 s2 XCHG // y.2 y.0 y.1.1
359355
}>

0 commit comments

Comments
 (0)