2 * Author: Humberto Naves (hsnaves@gmail.com)
12 struct code
*code_alloc (void)
15 c
= (struct code
*) xmalloc (sizeof (struct code
));
16 memset (c
, 0, sizeof (struct code
));
18 c
->lstpool
= listpool_create (8192, 4096);
19 c
->switchpool
= fixedpool_create (sizeof (struct codeswitch
), 64, TRUE
);
20 c
->subspool
= fixedpool_create (sizeof (struct subroutine
), 1024, TRUE
);
21 c
->blockspool
= fixedpool_create (sizeof (struct basicblock
), 4096, TRUE
);
22 c
->edgespool
= fixedpool_create (sizeof (struct basicedge
), 8192, TRUE
);
23 c
->ssavarspool
= fixedpool_create (sizeof (struct ssavar
), 4096, TRUE
);
24 c
->opspool
= fixedpool_create (sizeof (struct operation
), 8192, TRUE
);
25 c
->valspool
= fixedpool_create (sizeof (struct value
), 8192, TRUE
);
26 c
->ctrlspool
= fixedpool_create (sizeof (struct ctrlstruct
), 256, TRUE
);
31 struct code
* code_analyse (struct prx
*p
)
33 struct code
*c
= code_alloc ();
34 struct subroutine
*sub
;
39 if (!decode_instructions (c
)) {
45 extract_subroutines (c
);
49 el
= list_head (c
->subroutines
);
51 sub
= element_getvalue (el
);
52 if (!sub
->import
&& !sub
->haserror
) {
53 cfg_traverse (sub
, FALSE
);
55 sub
->status
|= SUB_STAT_CFG_TRAVERSE
;
56 cfg_traverse (sub
, TRUE
);
60 sub
->status
|= SUB_STAT_CFG_TRAVERSE_REV
;
61 fixup_call_arguments (sub
);
65 sub
->status
|= SUB_STAT_FIXUP_CALL_ARGS
;
70 sub
->status
|= SUB_STAT_SSA
;
73 el
= element_next (el
);
76 live_registers_imports (c
);
78 el
= list_head (c
->subroutines
);
80 sub
= element_getvalue (el
);
81 if (!sub
->import
&& !sub
->haserror
) {
82 if (!(sub
->status
& SUB_STAT_FIXUP_CALL_ARGS
)) {
83 fixup_call_arguments (sub
);
85 sub
->status
|= SUB_STAT_FIXUP_CALL_ARGS
;
91 sub
->status
|= SUB_STAT_SSA
;
92 propagate_constants (sub
);
96 sub
->status
|= SUB_STAT_CONSTANTS_EXTRACTED
;
97 extract_variables (sub
);
100 if (!sub
->haserror
) {
101 sub
->status
|= SUB_STAT_VARIABLES_EXTRACTED
;
102 extract_structures (sub
);
105 if (!sub
->haserror
) {
106 sub
->status
|= SUB_STAT_STRUCTURES_EXTRACTED
;
109 el
= element_next (el
);
115 void code_free (struct code
*c
)
122 listpool_destroy (c
->lstpool
);
126 fixedpool_destroy (c
->subspool
, NULL
, NULL
);
130 fixedpool_destroy (c
->switchpool
, NULL
, NULL
);
131 c
->switchpool
= NULL
;
134 fixedpool_destroy (c
->blockspool
, NULL
, NULL
);
135 c
->blockspool
= NULL
;
138 fixedpool_destroy (c
->edgespool
, NULL
, NULL
);
142 fixedpool_destroy (c
->ssavarspool
, NULL
, NULL
);
143 c
->ssavarspool
= NULL
;
146 fixedpool_destroy (c
->opspool
, NULL
, NULL
);
150 fixedpool_destroy (c
->valspool
, NULL
, NULL
);
154 fixedpool_destroy (c
->ctrlspool
, NULL
, NULL
);