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
->varspool
= fixedpool_create (sizeof (struct variable
), 4096, TRUE
);
21 c
->opspool
= fixedpool_create (sizeof (struct operation
), 8192, TRUE
);
22 c
->valspool
= fixedpool_create (sizeof (struct value
), 8192, TRUE
);
23 c
->loopspool
= fixedpool_create (sizeof (struct loopstructure
), 256, TRUE
);
24 c
->ifspool
= fixedpool_create (sizeof (struct ifstructure
), 1024, TRUE
);
29 struct code
* code_analyse (struct prx
*p
)
31 struct code
*c
= code_alloc ();
32 struct subroutine
*sub
;
37 if (!decode_instructions (c
)) {
43 extract_subroutines (c
);
47 el
= list_head (c
->subroutines
);
49 sub
= element_getvalue (el
);
50 if (!sub
->import
&& !sub
->haserror
) {
51 cfg_traverse (sub
, FALSE
);
53 sub
->status
|= SUBROUTINE_CFG_TRAVERSE
;
54 cfg_traverse (sub
, TRUE
);
58 sub
->status
|= SUBROUTINE_CFG_TRAVERSE_REV
;
59 fixup_call_arguments (sub
);
63 sub
->status
|= SUBROUTINE_FIXUP_CALL_ARGS
;
68 sub
->status
|= SUBROUTINE_SSA
;
71 el
= element_next (el
);
74 live_registers_imports (c
);
76 el
= list_head (c
->subroutines
);
78 sub
= element_getvalue (el
);
79 if (!sub
->import
&& !sub
->haserror
) {
80 if (!(sub
->status
& SUBROUTINE_FIXUP_CALL_ARGS
)) {
81 fixup_call_arguments (sub
);
83 sub
->status
|= SUBROUTINE_FIXUP_CALL_ARGS
;
89 sub
->status
|= SUBROUTINE_SSA
;
90 propagate_constants (sub
);
94 sub
->status
|= SUBROUTINE_CONSTANTS_EXTRACTED
;
95 extract_variables (sub
);
99 sub
->status
|= SUBROUTINE_VARIABLES_EXTRACTED
;
100 extract_structures (sub
);
103 if (!sub
->haserror
) {
104 sub
->status
|= SUBROUTINE_STRUCTURES_EXTRACTED
;
107 el
= element_next (el
);
113 void code_free (struct code
*c
)
120 listpool_destroy (c
->lstpool
);
124 fixedpool_destroy (c
->subspool
, NULL
, NULL
);
128 fixedpool_destroy (c
->switchpool
, NULL
, NULL
);
129 c
->switchpool
= NULL
;
132 fixedpool_destroy (c
->blockspool
, NULL
, NULL
);
133 c
->blockspool
= NULL
;
136 fixedpool_destroy (c
->edgespool
, NULL
, NULL
);
140 fixedpool_destroy (c
->varspool
, NULL
, NULL
);
144 fixedpool_destroy (c
->opspool
, NULL
, NULL
);
148 fixedpool_destroy (c
->valspool
, NULL
, NULL
);
152 fixedpool_destroy (c
->loopspool
, NULL
, NULL
);
156 fixedpool_destroy (c
->ifspool
, NULL
, NULL
);