@@ -32,6 +32,7 @@ def skip_if_different_mount_drives():
32
32
import analysis
33
33
import formatting
34
34
from parsing import StackEffect
35
+ import tier1_generator
35
36
36
37
37
38
def handle_stderr ():
@@ -108,13 +109,12 @@ def run_cases_test(self, input: str, expected: str):
108
109
temp_input .write (analysis .END_MARKER )
109
110
temp_input .flush ()
110
111
111
- a = generate_cases .Generator ([self .temp_input_filename ])
112
112
with handle_stderr ():
113
- a . parse ()
114
- a . analyze ()
115
- if a . errors :
116
- raise RuntimeError ( f"Found { a . errors } errors" )
117
- a . write_instructions ( self . temp_output_filename , False )
113
+ tier1_generator . generate_tier1_from_files (
114
+ [ self . temp_input_filename ],
115
+ self . temp_output_filename ,
116
+ False
117
+ )
118
118
119
119
with open (self .temp_output_filename ) as temp_output :
120
120
lines = temp_output .readlines ()
@@ -163,7 +163,7 @@ def test_inst_one_pop(self):
163
163
PyObject *value;
164
164
value = stack_pointer[-1];
165
165
spam();
166
- STACK_SHRINK(1) ;
166
+ stack_pointer += -1 ;
167
167
DISPATCH();
168
168
}
169
169
"""
@@ -182,8 +182,8 @@ def test_inst_one_push(self):
182
182
INSTRUCTION_STATS(OP);
183
183
PyObject *res;
184
184
spam();
185
- STACK_GROW(1) ;
186
- stack_pointer[-1] = res ;
185
+ stack_pointer[0] = res ;
186
+ stack_pointer += 1 ;
187
187
DISPATCH();
188
188
}
189
189
"""
@@ -227,8 +227,8 @@ def test_binary_op(self):
227
227
right = stack_pointer[-1];
228
228
left = stack_pointer[-2];
229
229
spam();
230
- STACK_SHRINK(1) ;
231
- stack_pointer[-1] = res ;
230
+ stack_pointer[-2] = res ;
231
+ stack_pointer += -1 ;
232
232
DISPATCH();
233
233
}
234
234
"""
@@ -273,7 +273,6 @@ def test_predictions_and_eval_breaker(self):
273
273
next_instr += 1;
274
274
INSTRUCTION_STATS(OP1);
275
275
PREDICTED(OP1);
276
- static_assert(INLINE_CACHE_ENTRIES_OP1 == 0, "incorrect cache size");
277
276
PyObject *arg;
278
277
PyObject *rest;
279
278
arg = stack_pointer[-1];
@@ -285,6 +284,7 @@ def test_predictions_and_eval_breaker(self):
285
284
frame->instr_ptr = next_instr;
286
285
next_instr += 1;
287
286
INSTRUCTION_STATS(OP3);
287
+ static_assert(INLINE_CACHE_ENTRIES_OP1 == 0, "incorrect cache size");
288
288
PyObject *arg;
289
289
PyObject *res;
290
290
arg = stack_pointer[-1];
@@ -325,6 +325,7 @@ def test_error_if_plain_with_comment(self):
325
325
next_instr += 1;
326
326
INSTRUCTION_STATS(OP);
327
327
if (cond) goto label;
328
+ // Comment is ok
328
329
DISPATCH();
329
330
}
330
331
"""
@@ -347,8 +348,8 @@ def test_error_if_pop(self):
347
348
right = stack_pointer[-1];
348
349
left = stack_pointer[-2];
349
350
if (cond) goto pop_2_label;
350
- STACK_SHRINK(1) ;
351
- stack_pointer[-1] = res ;
351
+ stack_pointer[-2] = res ;
352
+ stack_pointer += -1 ;
352
353
DISPATCH();
353
354
}
354
355
"""
@@ -368,7 +369,7 @@ def test_cache_effect(self):
368
369
value = stack_pointer[-1];
369
370
uint16_t counter = read_u16(&this_instr[1].cache);
370
371
uint32_t extra = read_u32(&this_instr[2].cache);
371
- STACK_SHRINK(1) ;
372
+ stack_pointer += -1 ;
372
373
DISPATCH();
373
374
}
374
375
"""
@@ -411,26 +412,26 @@ def test_macro_instruction(self):
411
412
INSTRUCTION_STATS(OP);
412
413
PREDICTED(OP);
413
414
_Py_CODEUNIT *this_instr = next_instr - 6;
414
- static_assert(INLINE_CACHE_ENTRIES_OP == 5, "incorrect cache size");
415
415
PyObject *right;
416
416
PyObject *left;
417
417
PyObject *arg2;
418
418
PyObject *res;
419
- // OP1
419
+ // _OP1
420
420
right = stack_pointer[-1];
421
421
left = stack_pointer[-2];
422
422
{
423
423
uint16_t counter = read_u16(&this_instr[1].cache);
424
424
op1(left, right);
425
425
}
426
+ /* Skip 2 cache entries */
426
427
// OP2
427
428
arg2 = stack_pointer[-3];
428
429
{
429
430
uint32_t extra = read_u32(&this_instr[4].cache);
430
431
res = op2(arg2, left, right);
431
432
}
432
- STACK_SHRINK(2) ;
433
- stack_pointer[-1] = res ;
433
+ stack_pointer[-3] = res ;
434
+ stack_pointer += -2 ;
434
435
DISPATCH();
435
436
}
436
437
@@ -451,6 +452,7 @@ def test_macro_instruction(self):
451
452
frame->instr_ptr = next_instr;
452
453
next_instr += 6;
453
454
INSTRUCTION_STATS(OP3);
455
+ static_assert(INLINE_CACHE_ENTRIES_OP == 5, "incorrect cache size");
454
456
PyObject *right;
455
457
PyObject *left;
456
458
PyObject *arg2;
@@ -459,8 +461,24 @@ def test_macro_instruction(self):
459
461
left = stack_pointer[-2];
460
462
arg2 = stack_pointer[-3];
461
463
res = op3(arg2, left, right);
462
- STACK_SHRINK(2);
463
- stack_pointer[-1] = res;
464
+ stack_pointer[-3] = res;
465
+ stack_pointer += -2;
466
+ DISPATCH();
467
+ }
468
+ """
469
+ self .run_cases_test (input , output )
470
+ def test_unused_caches (self ):
471
+ input = """
472
+ inst(OP, (unused/1, unused/2 --)) {
473
+ body();
474
+ }
475
+ """
476
+ output = """
477
+ TARGET(OP) {
478
+ frame->instr_ptr = next_instr;
479
+ next_instr += 4;
480
+ INSTRUCTION_STATS(OP);
481
+ body();
464
482
DISPATCH();
465
483
}
466
484
"""
@@ -519,11 +537,10 @@ def test_array_input(self):
519
537
PyObject **values;
520
538
PyObject *below;
521
539
above = stack_pointer[-1];
522
- values = stack_pointer - 1 - oparg*2;
540
+ values = & stack_pointer[- 1 - oparg*2] ;
523
541
below = stack_pointer[-2 - oparg*2];
524
542
spam();
525
- STACK_SHRINK(oparg*2);
526
- STACK_SHRINK(2);
543
+ stack_pointer += -2 - oparg*2;
527
544
DISPATCH();
528
545
}
529
546
"""
@@ -543,11 +560,11 @@ def test_array_output(self):
543
560
PyObject *below;
544
561
PyObject **values;
545
562
PyObject *above;
546
- values = stack_pointer - 1 ;
563
+ values = & stack_pointer[-1] ;
547
564
spam(values, oparg);
548
- STACK_GROW(oparg*3) ;
549
- stack_pointer[-2 - oparg*3] = below ;
550
- stack_pointer[-1] = above ;
565
+ stack_pointer[-2] = below ;
566
+ stack_pointer[-1 + oparg*3] = above ;
567
+ stack_pointer += oparg*3 ;
551
568
DISPATCH();
552
569
}
553
570
"""
@@ -566,10 +583,10 @@ def test_array_input_output(self):
566
583
INSTRUCTION_STATS(OP);
567
584
PyObject **values;
568
585
PyObject *above;
569
- values = stack_pointer - oparg;
586
+ values = & stack_pointer[- oparg] ;
570
587
spam(values, oparg);
571
- STACK_GROW(1) ;
572
- stack_pointer[-1] = above ;
588
+ stack_pointer[0] = above ;
589
+ stack_pointer += 1 ;
573
590
DISPATCH();
574
591
}
575
592
"""
@@ -588,11 +605,10 @@ def test_array_error_if(self):
588
605
INSTRUCTION_STATS(OP);
589
606
PyObject **values;
590
607
PyObject *extra;
591
- values = stack_pointer - oparg;
608
+ values = & stack_pointer[- oparg] ;
592
609
extra = stack_pointer[-1 - oparg];
593
- if (oparg == 0) { STACK_SHRINK(oparg); goto pop_1_somewhere; }
594
- STACK_SHRINK(oparg);
595
- STACK_SHRINK(1);
610
+ if (oparg == 0) { stack_pointer += -1 - oparg; goto somewhere; }
611
+ stack_pointer += -1 - oparg;
596
612
DISPATCH();
597
613
}
598
614
"""
@@ -616,14 +632,13 @@ def test_cond_effect(self):
616
632
PyObject *output = NULL;
617
633
PyObject *zz;
618
634
cc = stack_pointer[-1];
619
- if ((oparg & 1) == 1) { input = stack_pointer[-1 - ((oparg & 1) == 1 ? 1 : 0)]; }
620
- aa = stack_pointer[-2 - ((oparg & 1) == 1 ? 1 : 0)];
635
+ if ((oparg & 1) == 1) { input = stack_pointer[-1 - (((( oparg & 1) == 1) ? 1 : 0) )]; }
636
+ aa = stack_pointer[-2 - (((( oparg & 1) == 1) ? 1 : 0) )];
621
637
output = spam(oparg, input);
622
- STACK_SHRINK((((oparg & 1) == 1) ? 1 : 0));
623
- STACK_GROW(((oparg & 2) ? 1 : 0));
624
- stack_pointer[-2 - (oparg & 2 ? 1 : 0)] = xx;
625
- if (oparg & 2) { stack_pointer[-1 - (oparg & 2 ? 1 : 0)] = output; }
626
- stack_pointer[-1] = zz;
638
+ stack_pointer[-2 - ((((oparg & 1) == 1) ? 1 : 0))] = xx;
639
+ if (oparg & 2) stack_pointer[-1 - ((((oparg & 1) == 1) ? 1 : 0))] = output;
640
+ stack_pointer[-1 - ((((oparg & 1) == 1) ? 1 : 0)) + (((oparg & 2) ? 1 : 0))] = zz;
641
+ stack_pointer += -((((oparg & 1) == 1) ? 1 : 0)) + (((oparg & 2) ? 1 : 0));
627
642
DISPATCH();
628
643
}
629
644
"""
@@ -661,11 +676,10 @@ def test_macro_cond_effect(self):
661
676
{
662
677
# Body of B
663
678
}
664
- STACK_SHRINK(1);
665
- STACK_GROW((oparg ? 1 : 0));
666
- stack_pointer[-2 - (oparg ? 1 : 0)] = deep;
667
- if (oparg) { stack_pointer[-1 - (oparg ? 1 : 0)] = extra; }
668
- stack_pointer[-1] = res;
679
+ stack_pointer[-3] = deep;
680
+ if (oparg) stack_pointer[-2] = extra;
681
+ stack_pointer[-2 + (((oparg) ? 1 : 0))] = res;
682
+ stack_pointer += -1 + (((oparg) ? 1 : 0));
669
683
DISPATCH();
670
684
}
671
685
"""
@@ -696,9 +710,9 @@ def test_macro_push_push(self):
696
710
{
697
711
val2 = spam();
698
712
}
699
- STACK_GROW(2) ;
700
- stack_pointer[-2 ] = val1 ;
701
- stack_pointer[-1] = val2 ;
713
+ stack_pointer[0] = val1 ;
714
+ stack_pointer[1 ] = val2 ;
715
+ stack_pointer += 2 ;
702
716
DISPATCH();
703
717
}
704
718
"""
0 commit comments