9 struct code
*code_alloc (void)
12 c
= (struct code
*) xmalloc (sizeof (struct code
));
13 memset (c
, 0, sizeof (struct code
));
15 c
->lstpool
= listpool_create (8192, 4096);
16 c
->switchpool
= fixedpool_create (sizeof (struct codeswitch
), 64, TRUE
);
17 c
->subspool
= fixedpool_create (sizeof (struct subroutine
), 1024, TRUE
);
18 c
->blockspool
= fixedpool_create (sizeof (struct basicblock
), 4096, TRUE
);
19 c
->edgespool
= fixedpool_create (sizeof (struct basicedge
), 8192, TRUE
);
20 c
->ssavarspool
= fixedpool_create (sizeof (struct ssavar
), 4096, TRUE
);
21 c
->opspool
= fixedpool_create (sizeof (struct operation
), 8192, TRUE
);
22 c
->valspool
= fixedpool_create (sizeof (struct value
), 8192, TRUE
);
23 c
->ctrlspool
= fixedpool_create (sizeof (struct ctrlstruct
), 256, TRUE
);
28 struct code
* code_analyse (struct prx
*p
)
30 struct code
*c
= code_alloc ();
31 struct subroutine
*sub
;
36 if (!decode_instructions (c
)) {
42 extract_subroutines (c
);
46 el
= list_head (c
->subroutines
);
48 sub
= element_getvalue (el
);
49 if (!sub
->import
&& !sub
->haserror
) {
50 cfg_traverse (sub
, FALSE
);
52 sub
->status
|= SUBROUTINE_CFG_TRAVERSE
;
53 cfg_traverse (sub
, TRUE
);
57 sub
->status
|= SUBROUTINE_CFG_TRAVERSE_REV
;
58 fixup_call_arguments (sub
);
62 sub
->status
|= SUBROUTINE_FIXUP_CALL_ARGS
;
67 sub
->status
|= SUBROUTINE_SSA
;
70 el
= element_next (el
);
73 live_registers_imports (c
);
75 el
= list_head (c
->subroutines
);
77 sub
= element_getvalue (el
);
78 if (!sub
->import
&& !sub
->haserror
) {
79 if (!(sub
->status
& SUBROUTINE_FIXUP_CALL_ARGS
)) {
80 fixup_call_arguments (sub
);
82 sub
->status
|= SUBROUTINE_FIXUP_CALL_ARGS
;
88 sub
->status
|= SUBROUTINE_SSA
;
89 propagate_constants (sub
);
93 sub
->status
|= SUBROUTINE_CONSTANTS_EXTRACTED
;
94 extract_variables (sub
);
98 sub
->status
|= SUBROUTINE_VARIABLES_EXTRACTED
;
99 extract_structures (sub
);
102 if (!sub
->haserror
) {
103 sub
->status
|= SUBROUTINE_STRUCTURES_EXTRACTED
;
106 el
= element_next (el
);
112 void code_free (struct code
*c
)
119 listpool_destroy (c
->lstpool
);
123 fixedpool_destroy (c
->subspool
, NULL
, NULL
);
127 fixedpool_destroy (c
->switchpool
, NULL
, NULL
);
128 c
->switchpool
= NULL
;
131 fixedpool_destroy (c
->blockspool
, NULL
, NULL
);
132 c
->blockspool
= NULL
;
135 fixedpool_destroy (c
->edgespool
, NULL
, NULL
);
139 fixedpool_destroy (c
->ssavarspool
, NULL
, NULL
);
140 c
->ssavarspool
= NULL
;
143 fixedpool_destroy (c
->opspool
, NULL
, NULL
);
147 fixedpool_destroy (c
->valspool
, NULL
, NULL
);
151 fixedpool_destroy (c
->ctrlspool
, NULL
, NULL
);