105
105
(IS_VIRTUAL_JUMP_OPCODE(opcode) || \
106
106
is_bit_set_in_table(_PyOpcode_Jump, opcode))
107
107
108
+ #define IS_BLOCK_PUSH_OPCODE (opcode ) \
109
+ ((opcode) == SETUP_FINALLY || \
110
+ (opcode) == SETUP_WITH || \
111
+ (opcode) == SETUP_CLEANUP)
112
+
108
113
/* opcodes which are not emitted in codegen stage, only by the assembler */
109
114
#define IS_ASSEMBLER_OPCODE (opcode ) \
110
115
((opcode) == JUMP_FORWARD || \
@@ -191,7 +196,7 @@ static inline int
191
196
is_block_push (struct instr * instr )
192
197
{
193
198
int opcode = instr -> i_opcode ;
194
- return opcode == SETUP_FINALLY || opcode == SETUP_WITH || opcode == SETUP_CLEANUP ;
199
+ return IS_BLOCK_PUSH_OPCODE ( opcode ) ;
195
200
}
196
201
197
202
static inline int
@@ -1287,19 +1292,26 @@ compiler_use_new_implicit_block_if_needed(struct compiler *c)
1287
1292
*/
1288
1293
1289
1294
static int
1290
- basicblock_addop (basicblock * b , int opcode , struct location loc )
1295
+ basicblock_addop (basicblock * b , int opcode , int oparg ,
1296
+ basicblock * target , struct location loc )
1291
1297
{
1292
1298
assert (IS_WITHIN_OPCODE_RANGE (opcode ));
1293
1299
assert (!IS_ASSEMBLER_OPCODE (opcode ));
1294
- assert (!HAS_ARG (opcode ) || IS_ARTIFICIAL (opcode ));
1300
+ assert (HAS_ARG (opcode ) || oparg == 0 );
1301
+ assert (0 <= oparg && oparg <= 2147483647 );
1302
+ assert ((target == NULL ) ||
1303
+ IS_JUMP_OPCODE (opcode ) ||
1304
+ IS_BLOCK_PUSH_OPCODE (opcode ));
1305
+ assert (oparg == 0 || target == NULL );
1295
1306
1296
1307
int off = basicblock_next_instr (b );
1297
1308
if (off < 0 ) {
1298
1309
return 0 ;
1299
1310
}
1300
1311
struct instr * i = & b -> b_instr [off ];
1301
1312
i -> i_opcode = opcode ;
1302
- i -> i_oparg = 0 ;
1313
+ i -> i_oparg = oparg ;
1314
+ i -> i_target = target ;
1303
1315
i -> i_lineno = loc .lineno ;
1304
1316
i -> i_end_lineno = loc .end_lineno ;
1305
1317
i -> i_col_offset = loc .col_offset ;
@@ -1311,12 +1323,13 @@ basicblock_addop(basicblock *b, int opcode, struct location loc)
1311
1323
static int
1312
1324
compiler_addop (struct compiler * c , int opcode , bool line )
1313
1325
{
1326
+ assert (!HAS_ARG (opcode ) || IS_ARTIFICIAL (opcode ));
1314
1327
if (compiler_use_new_implicit_block_if_needed (c ) < 0 ) {
1315
1328
return -1 ;
1316
1329
}
1317
1330
1318
1331
struct location loc = line ? CU_LOCATION (c -> u ) : NO_LOCATION ;
1319
- return basicblock_addop (c -> u -> u_curblock , opcode , loc );
1332
+ return basicblock_addop (c -> u -> u_curblock , opcode , 0 , NULL , loc );
1320
1333
}
1321
1334
1322
1335
static Py_ssize_t
@@ -1507,11 +1520,12 @@ compiler_addop_name(struct compiler *c, int opcode, PyObject *dict,
1507
1520
/* Add an opcode with an integer argument.
1508
1521
Returns 0 on failure, 1 on success.
1509
1522
*/
1510
-
1511
1523
static int
1512
- basicblock_addop_i (basicblock * b , int opcode , Py_ssize_t oparg ,
1513
- struct location loc )
1524
+ compiler_addop_i (struct compiler * c , int opcode , Py_ssize_t oparg , bool line )
1514
1525
{
1526
+ if (compiler_use_new_implicit_block_if_needed (c ) < 0 ) {
1527
+ return -1 ;
1528
+ }
1515
1529
/* oparg value is unsigned, but a signed C int is usually used to store
1516
1530
it in the C code (like Python/ceval.c).
1517
1531
@@ -1520,57 +1534,10 @@ basicblock_addop_i(basicblock *b, int opcode, Py_ssize_t oparg,
1520
1534
The argument of a concrete bytecode instruction is limited to 8-bit.
1521
1535
EXTENDED_ARG is used for 16, 24, and 32-bit arguments. */
1522
1536
1523
- assert (IS_WITHIN_OPCODE_RANGE (opcode ));
1524
- assert (!IS_ASSEMBLER_OPCODE (opcode ));
1525
- assert (0 <= oparg && oparg <= 2147483647 );
1526
-
1527
- int off = basicblock_next_instr (b );
1528
- if (off < 0 ) {
1529
- return 0 ;
1530
- }
1531
- struct instr * i = & b -> b_instr [off ];
1532
- i -> i_opcode = opcode ;
1533
- i -> i_oparg = Py_SAFE_DOWNCAST (oparg , Py_ssize_t , int );
1534
- i -> i_lineno = loc .lineno ;
1535
- i -> i_end_lineno = loc .end_lineno ;
1536
- i -> i_col_offset = loc .col_offset ;
1537
- i -> i_end_col_offset = loc .end_col_offset ;
1537
+ int oparg_ = Py_SAFE_DOWNCAST (oparg , Py_ssize_t , int );
1538
1538
1539
- return 1 ;
1540
- }
1541
-
1542
- static int
1543
- compiler_addop_i (struct compiler * c , int opcode , Py_ssize_t oparg , bool line )
1544
- {
1545
- if (compiler_use_new_implicit_block_if_needed (c ) < 0 ) {
1546
- return -1 ;
1547
- }
1548
1539
struct location loc = line ? CU_LOCATION (c -> u ) : NO_LOCATION ;
1549
- return basicblock_addop_i (c -> u -> u_curblock , opcode , oparg , loc );
1550
- }
1551
-
1552
- static int
1553
- basicblock_add_jump (basicblock * b , int opcode ,
1554
- struct location loc , basicblock * target )
1555
- {
1556
- assert (IS_WITHIN_OPCODE_RANGE (opcode ));
1557
- assert (!IS_ASSEMBLER_OPCODE (opcode ));
1558
- assert (HAS_ARG (opcode ) || IS_VIRTUAL_OPCODE (opcode ));
1559
- assert (target != NULL );
1560
-
1561
- int off = basicblock_next_instr (b );
1562
- struct instr * i = & b -> b_instr [off ];
1563
- if (off < 0 ) {
1564
- return 0 ;
1565
- }
1566
- i -> i_opcode = opcode ;
1567
- i -> i_target = target ;
1568
- i -> i_lineno = loc .lineno ;
1569
- i -> i_end_lineno = loc .end_lineno ;
1570
- i -> i_col_offset = loc .col_offset ;
1571
- i -> i_end_col_offset = loc .end_col_offset ;
1572
-
1573
- return 1 ;
1540
+ return basicblock_addop (c -> u -> u_curblock , opcode , oparg_ , NULL , loc );
1574
1541
}
1575
1542
1576
1543
static int
@@ -1580,7 +1547,9 @@ compiler_addop_j(struct compiler *c, int opcode, basicblock *target, bool line)
1580
1547
return -1 ;
1581
1548
}
1582
1549
struct location loc = line ? CU_LOCATION (c -> u ) : NO_LOCATION ;
1583
- return basicblock_add_jump (c -> u -> u_curblock , opcode , loc , target );
1550
+ assert (target != NULL );
1551
+ assert (IS_JUMP_OPCODE (opcode ) || IS_BLOCK_PUSH_OPCODE (opcode ));
1552
+ return basicblock_addop (c -> u -> u_curblock , opcode , 0 , target , loc );
1584
1553
}
1585
1554
1586
1555
#define ADDOP (C , OP ) { \
@@ -7455,7 +7424,7 @@ push_cold_blocks_to_end(struct compiler *c, basicblock *entry, int code_flags) {
7455
7424
if (explicit_jump == NULL ) {
7456
7425
return -1 ;
7457
7426
}
7458
- basicblock_add_jump (explicit_jump , JUMP , NO_LOCATION , b -> b_next );
7427
+ basicblock_addop (explicit_jump , JUMP , 0 , b -> b_next , NO_LOCATION );
7459
7428
7460
7429
explicit_jump -> b_cold = 1 ;
7461
7430
explicit_jump -> b_next = b -> b_next ;
0 commit comments