@@ -171,6 +171,24 @@ struct instr {
171171struct basicblock_ * i_except ;/* target block when exception is raised */
172172};
173173
174+ /* One arg*/
175+ #define INSTR_SET_OP1 (I ,OP ,ARG ) \
176+ do { \
177+ assert(HAS_ARG(OP)); \
178+ struct instr *_instr__ptr_ = (I); \
179+ _instr__ptr_->i_opcode = (OP); \
180+ _instr__ptr_->i_oparg = (ARG); \
181+ } while (0);
182+
183+ /* No args*/
184+ #define INSTR_SET_OP0 (I ,OP ) \
185+ do { \
186+ assert(!HAS_ARG(OP)); \
187+ struct instr *_instr__ptr_ = (I); \
188+ _instr__ptr_->i_opcode = (OP); \
189+ _instr__ptr_->i_oparg = 0; \
190+ } while (0);
191+
174192typedef struct exceptstack {
175193struct basicblock_ * handlers [CO_MAXBLOCKS + 1 ];
176194int depth ;
@@ -218,7 +236,8 @@ instr_size(struct instr *instruction)
218236{
219237int opcode = instruction -> i_opcode ;
220238assert (!IS_PSEUDO_OPCODE (opcode ));
221- int oparg = HAS_ARG (opcode ) ?instruction -> i_oparg :0 ;
239+ int oparg = instruction -> i_oparg ;
240+ assert (HAS_ARG (opcode )|| oparg == 0 );
222241int extended_args = (0xFFFFFF < oparg )+ (0xFFFF < oparg )+ (0xFF < oparg );
223242int caches = _PyOpcode_Caches [opcode ];
224243return extended_args + 1 + caches ;
@@ -229,7 +248,8 @@ write_instr(_Py_CODEUNIT *codestr, struct instr *instruction, int ilen)
229248{
230249int opcode = instruction -> i_opcode ;
231250assert (!IS_PSEUDO_OPCODE (opcode ));
232- int oparg = HAS_ARG (opcode ) ?instruction -> i_oparg :0 ;
251+ int oparg = instruction -> i_oparg ;
252+ assert (HAS_ARG (opcode )|| oparg == 0 );
233253int caches = _PyOpcode_Caches [opcode ];
234254switch (ilen - caches ) {
235255case 4 :
@@ -7598,7 +7618,7 @@ convert_exception_handlers_to_nops(basicblock *entryblock) {
75987618for (int i = 0 ;i < b -> b_iused ;i ++ ) {
75997619struct instr * instr = & b -> b_instr [i ];
76007620if (is_block_push (instr )|| instr -> i_opcode == POP_BLOCK ) {
7601- instr -> i_opcode = NOP ;
7621+ INSTR_SET_OP0 ( instr , NOP ) ;
76027622 }
76037623 }
76047624 }
@@ -8723,7 +8743,7 @@ remove_redundant_jumps(cfg_builder *g) {
87238743 }
87248744if (last -> i_target == b -> b_next ) {
87258745assert (b -> b_next -> b_iused );
8726- last -> i_opcode = NOP ;
8746+ INSTR_SET_OP0 ( last , NOP ) ;
87278747 }
87288748 }
87298749 }
@@ -8999,10 +9019,9 @@ fold_tuple_on_constants(PyObject *const_cache,
89999019 }
90009020Py_DECREF (newconst );
90019021for (int i = 0 ;i < n ;i ++ ) {
9002- inst [i ]. i_opcode = NOP ;
9022+ INSTR_SET_OP0 ( & inst [i ], NOP ) ;
90039023 }
9004- inst [n ].i_opcode = LOAD_CONST ;
9005- inst [n ].i_oparg = (int )index ;
9024+ INSTR_SET_OP1 (& inst [n ],LOAD_CONST , (int )index );
90069025return 0 ;
90079026}
90089027
@@ -9099,7 +9118,7 @@ swaptimize(basicblock *block, int *ix)
90999118 }
91009119// NOP out any unused instructions:
91019120while (0 <=current ) {
9102- instructions [current -- ]. i_opcode = NOP ;
9121+ INSTR_SET_OP0 ( & instructions [current -- ], NOP ) ;
91039122 }
91049123PyMem_Free (stack );
91059124* ix += len - 1 ;
@@ -9165,7 +9184,7 @@ apply_static_swaps(basicblock *block, int i)
91659184 }
91669185 }
91679186// Success!
9168- swap -> i_opcode = NOP ;
9187+ INSTR_SET_OP0 ( swap , NOP ) ;
91699188struct instr temp = block -> b_instr [j ];
91709189block -> b_instr [j ]= block -> b_instr [k ];
91719190block -> b_instr [k ]= temp ;
@@ -9202,7 +9221,7 @@ optimize_basic_block(PyObject *const_cache, basicblock *bb, PyObject *consts)
92029221assert (PyDict_CheckExact (const_cache ));
92039222assert (PyList_CheckExact (consts ));
92049223struct instr nop ;
9205- nop . i_opcode = NOP ;
9224+ INSTR_SET_OP0 ( & nop , NOP ) ;
92069225struct instr * target ;
92079226for (int i = 0 ;i < bb -> b_iused ;i ++ ) {
92089227struct instr * inst = & bb -> b_instr [i ];
@@ -9236,13 +9255,13 @@ optimize_basic_block(PyObject *const_cache, basicblock *bb, PyObject *consts)
92369255if (is_true == -1 ) {
92379256 gotoerror ;
92389257 }
9239- inst -> i_opcode = NOP ;
9258+ INSTR_SET_OP0 ( inst , NOP ) ;
92409259jump_if_true = nextop == POP_JUMP_IF_TRUE ;
92419260if (is_true == jump_if_true ) {
92429261bb -> b_instr [i + 1 ].i_opcode = JUMP ;
92439262 }
92449263else {
9245- bb -> b_instr [i + 1 ]. i_opcode = NOP ;
9264+ INSTR_SET_OP0 ( & bb -> b_instr [i + 1 ], NOP ) ;
92469265 }
92479266break ;
92489267case JUMP_IF_FALSE_OR_POP :
@@ -9261,8 +9280,8 @@ optimize_basic_block(PyObject *const_cache, basicblock *bb, PyObject *consts)
92619280bb -> b_instr [i + 1 ].i_opcode = JUMP ;
92629281 }
92639282else {
9264- inst -> i_opcode = NOP ;
9265- bb -> b_instr [i + 1 ]. i_opcode = NOP ;
9283+ INSTR_SET_OP0 ( inst , NOP ) ;
9284+ INSTR_SET_OP0 ( & bb -> b_instr [i + 1 ], NOP ) ;
92669285 }
92679286break ;
92689287case IS_OP :
@@ -9273,8 +9292,8 @@ optimize_basic_block(PyObject *const_cache, basicblock *bb, PyObject *consts)
92739292int jump_op = i + 2 < bb -> b_iused ?bb -> b_instr [i + 2 ].i_opcode :0 ;
92749293if (Py_IsNone (cnt )&& (jump_op == POP_JUMP_IF_FALSE || jump_op == POP_JUMP_IF_TRUE )) {
92759294unsignedchar nextarg = bb -> b_instr [i + 1 ].i_oparg ;
9276- inst -> i_opcode = NOP ;
9277- bb -> b_instr [i + 1 ]. i_opcode = NOP ;
9295+ INSTR_SET_OP0 ( inst , NOP ) ;
9296+ INSTR_SET_OP0 ( & bb -> b_instr [i + 1 ], NOP ) ;
92789297bb -> b_instr [i + 2 ].i_opcode = nextarg ^ (jump_op == POP_JUMP_IF_FALSE ) ?
92799298POP_JUMP_IF_NOT_NONE :POP_JUMP_IF_NONE ;
92809299 }
@@ -9292,12 +9311,12 @@ optimize_basic_block(PyObject *const_cache, basicblock *bb, PyObject *consts)
92929311if (nextop == UNPACK_SEQUENCE && oparg == bb -> b_instr [i + 1 ].i_oparg ) {
92939312switch (oparg ) {
92949313case 1 :
9295- inst -> i_opcode = NOP ;
9296- bb -> b_instr [i + 1 ]. i_opcode = NOP ;
9314+ INSTR_SET_OP0 ( inst , NOP ) ;
9315+ INSTR_SET_OP0 ( & bb -> b_instr [i + 1 ], NOP ) ;
92979316continue ;
92989317case 2 :
92999318case 3 :
9300- inst -> i_opcode = NOP ;
9319+ INSTR_SET_OP0 ( inst , NOP ) ;
93019320bb -> b_instr [i + 1 ].i_opcode = SWAP ;
93029321continue ;
93039322 }
@@ -9406,7 +9425,7 @@ optimize_basic_block(PyObject *const_cache, basicblock *bb, PyObject *consts)
94069425break ;
94079426case SWAP :
94089427if (oparg == 1 ) {
9409- inst -> i_opcode = NOP ;
9428+ INSTR_SET_OP0 ( inst , NOP ) ;
94109429break ;
94119430 }
94129431if (swaptimize (bb ,& i )) {
@@ -9418,8 +9437,7 @@ optimize_basic_block(PyObject *const_cache, basicblock *bb, PyObject *consts)
94189437break ;
94199438case PUSH_NULL :
94209439if (nextop == LOAD_GLOBAL && (inst [1 ].i_opcode & 1 )== 0 ) {
9421- inst -> i_opcode = NOP ;
9422- inst -> i_oparg = 0 ;
9440+ INSTR_SET_OP0 (inst ,NOP );
94239441inst [1 ].i_oparg |=1 ;
94249442 }
94259443break ;
@@ -9448,7 +9466,7 @@ inline_small_exit_blocks(basicblock *bb) {
94489466 }
94499467basicblock * target = last -> i_target ;
94509468if (basicblock_exits_scope (target )&& target -> b_iused <=MAX_COPY_SIZE ) {
9451- last -> i_opcode = NOP ;
9469+ INSTR_SET_OP0 ( last , NOP ) ;
94529470if (basicblock_append_instructions (bb ,target )< 0 ) {
94539471return -1 ;
94549472 }