@@ -26,7 +26,15 @@ typedef _PyCompilerSrcLocation location;
26
26
typedef _PyCfgJumpTargetLabel jump_target_label ;
27
27
typedef _PyCfgBasicblock basicblock ;
28
28
typedef _PyCfgBuilder cfg_builder ;
29
- typedef _PyCfgInstruction cfg_instr ;
29
+
30
+ typedef struct _PyCfgInstruction {
31
+ int i_opcode ;
32
+ int i_oparg ;
33
+ _PyCompilerSrcLocation i_loc ;
34
+ struct _PyCfgBasicblock_ * i_target ; /* target block (if jump instruction) */
35
+ struct _PyCfgBasicblock_ * i_except ; /* target block when exception is raised */
36
+ } cfg_instr ;
37
+
30
38
31
39
static const jump_target_label NO_LABEL = {-1 };
32
40
@@ -52,7 +60,7 @@ is_jump(cfg_instr *i)
52
60
#define INSTR_SET_OP1 (I , OP , ARG ) \
53
61
do { \
54
62
assert(OPCODE_HAS_ARG(OP)); \
55
- _PyCfgInstruction *_instr__ptr_ = (I); \
63
+ struct _PyCfgInstruction *_instr__ptr_ = (I); \
56
64
_instr__ptr_->i_opcode = (OP); \
57
65
_instr__ptr_->i_oparg = (ARG); \
58
66
} while (0);
@@ -61,7 +69,7 @@ is_jump(cfg_instr *i)
61
69
#define INSTR_SET_OP0 (I , OP ) \
62
70
do { \
63
71
assert(!OPCODE_HAS_ARG(OP)); \
64
- _PyCfgInstruction *_instr__ptr_ = (I); \
72
+ struct _PyCfgInstruction *_instr__ptr_ = (I); \
65
73
_instr__ptr_->i_opcode = (OP); \
66
74
_instr__ptr_->i_oparg = 0; \
67
75
} while (0);
@@ -151,7 +159,7 @@ basicblock_last_instr(const basicblock *b) {
151
159
152
160
static inline int
153
161
basicblock_nofallthrough (const _PyCfgBasicblock * b ) {
154
- _PyCfgInstruction * last = basicblock_last_instr (b );
162
+ struct _PyCfgInstruction * last = basicblock_last_instr (b );
155
163
return (last &&
156
164
(IS_SCOPE_EXIT_OPCODE (last -> i_opcode ) ||
157
165
IS_UNCONDITIONAL_JUMP_OPCODE (last -> i_opcode )));
@@ -581,10 +589,14 @@ mark_except_handlers(basicblock *entryblock) {
581
589
}
582
590
583
591
584
- typedef _PyCfgExceptStack ExceptStack ;
592
+ struct _PyCfgExceptStack {
593
+ struct _PyCfgBasicblock_ * handlers [CO_MAXBLOCKS + 1 ];
594
+ int depth ;
595
+ };
596
+
585
597
586
598
static basicblock *
587
- push_except_block (ExceptStack * stack , cfg_instr * setup ) {
599
+ push_except_block (struct _PyCfgExceptStack * stack , cfg_instr * setup ) {
588
600
assert (is_block_push (setup ));
589
601
int opcode = setup -> i_opcode ;
590
602
basicblock * target = setup -> i_target ;
@@ -596,19 +608,19 @@ push_except_block(ExceptStack *stack, cfg_instr *setup) {
596
608
}
597
609
598
610
static basicblock *
599
- pop_except_block (ExceptStack * stack ) {
611
+ pop_except_block (struct _PyCfgExceptStack * stack ) {
600
612
assert (stack -> depth > 0 );
601
613
return stack -> handlers [-- stack -> depth ];
602
614
}
603
615
604
616
static basicblock *
605
- except_stack_top (ExceptStack * stack ) {
617
+ except_stack_top (struct _PyCfgExceptStack * stack ) {
606
618
return stack -> handlers [stack -> depth ];
607
619
}
608
620
609
- static ExceptStack *
621
+ static struct _PyCfgExceptStack *
610
622
make_except_stack (void ) {
611
- ExceptStack * new = PyMem_Malloc (sizeof (ExceptStack ));
623
+ struct _PyCfgExceptStack * new = PyMem_Malloc (sizeof (struct _PyCfgExceptStack ));
612
624
if (new == NULL ) {
613
625
PyErr_NoMemory ();
614
626
return NULL ;
@@ -618,14 +630,14 @@ make_except_stack(void) {
618
630
return new ;
619
631
}
620
632
621
- static ExceptStack *
622
- copy_except_stack (ExceptStack * stack ) {
623
- ExceptStack * copy = PyMem_Malloc (sizeof (ExceptStack ));
633
+ static struct _PyCfgExceptStack *
634
+ copy_except_stack (struct _PyCfgExceptStack * stack ) {
635
+ struct _PyCfgExceptStack * copy = PyMem_Malloc (sizeof (struct _PyCfgExceptStack ));
624
636
if (copy == NULL ) {
625
637
PyErr_NoMemory ();
626
638
return NULL ;
627
639
}
628
- memcpy (copy , stack , sizeof (ExceptStack ));
640
+ memcpy (copy , stack , sizeof (struct _PyCfgExceptStack ));
629
641
return copy ;
630
642
}
631
643
@@ -751,7 +763,7 @@ label_exception_targets(basicblock *entryblock) {
751
763
if (todo_stack == NULL ) {
752
764
return ERROR ;
753
765
}
754
- ExceptStack * except_stack = make_except_stack ();
766
+ struct _PyCfgExceptStack * except_stack = make_except_stack ();
755
767
if (except_stack == NULL ) {
756
768
PyMem_Free (todo_stack );
757
769
PyErr_NoMemory ();
@@ -775,7 +787,7 @@ label_exception_targets(basicblock *entryblock) {
775
787
cfg_instr * instr = & b -> b_instr [i ];
776
788
if (is_block_push (instr )) {
777
789
if (!instr -> i_target -> b_visited ) {
778
- ExceptStack * copy = copy_except_stack (except_stack );
790
+ struct _PyCfgExceptStack * copy = copy_except_stack (except_stack );
779
791
if (copy == NULL ) {
780
792
goto error ;
781
793
}
@@ -794,7 +806,7 @@ label_exception_targets(basicblock *entryblock) {
794
806
assert (i == b -> b_iused - 1 );
795
807
if (!instr -> i_target -> b_visited ) {
796
808
if (BB_HAS_FALLTHROUGH (b )) {
797
- ExceptStack * copy = copy_except_stack (except_stack );
809
+ struct _PyCfgExceptStack * copy = copy_except_stack (except_stack );
798
810
if (copy == NULL ) {
799
811
goto error ;
800
812
}
0 commit comments