@@ -374,26 +374,37 @@ translate_bytecode_to_trace(
374
374
uop_instruction * trace ,
375
375
int max_length )
376
376
{
377
- assert (max_length >= 3 ); // One op, one SET_IP, one END_TRACE
377
+ #define ADD_TO_TRACE (OPCODE , OPARG ) \
378
+ trace[trace_length].opcode = (OPCODE); \
379
+ trace[trace_length].oparg = (OPARG); \
380
+ trace_length++;
381
+
378
382
int trace_length = 0 ;
379
383
while (trace_length + 2 < max_length ) {
380
- if (trace_length >= 1 ) {
381
- break ; // Temporarily, only handle one instruction
382
- }
383
- if (instr -> op .code != LOAD_FAST ) {
384
- break ; // Temporarily, only handle LOAD_FAST
384
+ int opcode = instr -> op .code ;
385
+ int oparg = instr -> op .arg ;
386
+ switch (opcode ) {
387
+ // TODO: Tools/cases_generator should generate these from Python/bytecodes.c,
388
+ // or it should generate metadata that can be used to generate these.
389
+ case LOAD_FAST :
390
+ {
391
+ ADD_TO_TRACE (opcode , oparg );
392
+ break ;
393
+ }
394
+ default :
395
+ {
396
+ goto done ; // Break out of while loop
397
+ }
385
398
}
386
- trace [trace_length ].opcode = instr -> op .code ;
387
- trace [trace_length ].oparg = instr -> op .arg ;
388
399
instr ++ ;
389
- trace_length ++ ;
390
400
}
391
- int ip_offset = instr - (_Py_CODEUNIT * )code -> co_code_adaptive ;
392
- trace [trace_length ].opcode = SET_IP ;
393
- trace [trace_length ].oparg = ip_offset ;
394
- trace [trace_length + 1 ].opcode = EXIT_TRACE ;
395
- trace [trace_length + 1 ].oparg = 0 ;
396
- return trace_length + 2 ;
401
+ done :
402
+ if (trace_length > 0 ) {
403
+ int ip_offset = instr - (_Py_CODEUNIT * )code -> co_code_adaptive ;
404
+ ADD_TO_TRACE (SET_IP , ip_offset );
405
+ ADD_TO_TRACE (EXIT_TRACE , 0 );
406
+ }
407
+ return trace_length ;
397
408
}
398
409
399
410
static int
0 commit comments