3 * Copyright (C) 2002-2007, The Perl Foundation.
14 Routines for handling imc_units, which represent subs.
16 Moved all register allocation and spill code to reg_alloc.c
28 #include "optimizer.h"
30 /* HEADERIZER HFILE: compilers/imcc/imc.h */
32 /* HEADERIZER BEGIN: static */
34 static void imc_free_unit(PARROT_INTERP
, ARGMOD(IMC_Unit
*unit
))
35 __attribute__nonnull__(1)
36 __attribute__nonnull__(2)
39 PARROT_CANNOT_RETURN_NULL
41 static IMC_Unit
* imc_new_unit(IMC_Unit_Type t
);
43 /* HEADERIZER END: static */
45 #define COMPILE_IMMEDIATE 1
53 =item C<void imc_compile_all_units>
55 Compile all imc_units, and free all memory of instructions
56 and structures afterwards.
64 imc_compile_all_units(PARROT_INTERP
)
66 /* compile all units created during the parse */
68 #if ! COMPILE_IMMEDIATE
69 for (unit
= IMCC_INFO(interp
)->imc_units
; unit
;) {
70 IMC_Unit
* const unit_next
= unit
->next
;
71 imc_compile_unit(interp
, unit
);
75 emit_close(interp
, NULL
);
77 /* All done with compilation, now free all memory allocated
78 * for instructions and other structures.
80 for (unit
= IMCC_INFO(interp
)->imc_units
; unit
;) {
81 IMC_Unit
* const unit_next
= unit
->next
;
84 for (ins
= unit
->instructions
; ins
;) {
85 Instruction
* const ins_next
= ins
->next
;
89 imc_free_unit(interp
, unit
);
93 IMCC_INFO(interp
)->imc_units
= NULL
;
94 IMCC_INFO(interp
)->last_unit
= NULL
;
99 =item C<void imc_compile_unit>
101 imc_compile_unit is the main loop of the IMC compiler for each unit. It
102 operates on a single compilation unit at a time.
110 imc_compile_unit(PARROT_INTERP
, ARGIN(IMC_Unit
*unit
))
112 /* Not much here for now except the allocator */
113 IMCC_INFO(interp
)->cur_unit
= unit
;
115 imc_reg_alloc(interp
, unit
);
116 emit_flush(interp
, NULL
, unit
);
121 =item C<void imc_cleanup>
123 Any activity required to cleanup the compiler state and be
124 ready for a new compiler invocation goes here.
132 imc_cleanup(PARROT_INTERP
, ARGIN_NULLOK(void *yyscanner
))
134 IMCC_pop_parser_state(interp
, yyscanner
);
135 clear_globals(interp
);
136 mem_sys_free(IMCC_INFO(interp
)->ghash
.data
);
137 IMCC_INFO(interp
)->ghash
.data
= NULL
;
142 =item C<static IMC_Unit * imc_new_unit>
144 Create a new IMC_Unit.
150 PARROT_CANNOT_RETURN_NULL
153 imc_new_unit(IMC_Unit_Type t
)
155 IMC_Unit
* const unit
= mem_allocate_zeroed_typed(IMC_Unit
);
156 create_symhash(&unit
->hash
);
163 =item C<IMC_Unit * imc_open_unit>
165 Create a new IMC_Unit and "open" it for construction.
166 This sets the current state of the parser. The unit
167 can be closed later retaining all the current state.
173 PARROT_CANNOT_RETURN_NULL
175 imc_open_unit(PARROT_INTERP
, IMC_Unit_Type t
)
177 IMC_Unit
* const unit
= imc_new_unit(t
);
178 imc_info_t
* const imc_info
= IMCC_INFO(interp
);
180 if (!imc_info
->imc_units
)
181 imc_info
->imc_units
= unit
;
182 if (!imc_info
->ghash
.data
)
183 create_symhash(&imc_info
->ghash
);
184 unit
->prev
= imc_info
->last_unit
;
185 if (imc_info
->last_unit
)
186 imc_info
->last_unit
->next
= unit
;
187 imc_info
->last_unit
= unit
;
188 imc_info
->n_comp_units
++;
189 unit
->file
= imc_info
->state
->file
;
190 unit
->pasm_file
= imc_info
->state
->pasm_file
;
197 =item C<void imc_close_unit>
199 Close a unit from compilation.
200 Does not destroy the unit, leaves it on the list.
207 imc_close_unit(PARROT_INTERP
, ARGIN_NULLOK(IMC_Unit
*unit
))
209 #if COMPILE_IMMEDIATE
211 imc_compile_unit(interp
, unit
);
215 IMCC_INFO(interp
)->cur_unit
= NULL
;
220 =item C<static void imc_free_unit>
222 Free all memory allocated of an IMC_Unit structure.
229 imc_free_unit(PARROT_INTERP
, ARGMOD(IMC_Unit
*unit
))
231 imc_info_t
* const imc
= IMCC_INFO(interp
);
234 fprintf(stderr
, "imc_free_unit()\n");
239 clear_basic_blocks(unit
); /* and cfg ... */
240 if (!imc
->n_comp_units
)
241 IMCC_fatal(interp
, 1, "imc_free_unit: non existent unit\n");
245 free(unit
->hash
.data
);
260 * c-file-style: "parrot"
262 * vim: expandtab shiftwidth=4: