3 * Copyright (C) 2006-2007, The Perl Foundation.
10 bcg.c Byte Code Generator (BCG) Public API implementation.
14 The functions in this file implement the API defined in bcg.h, the public API
19 List of methods imlemented in this file.
29 #include "bcg_private.h"
30 #include "bcg_logger.h"
31 #include "bcg_reg_alloc.h"
32 #include "bcg_emitter.h"
34 /* Forward decleration */
36 /* BCG state management functions. */
37 static void set_state(BCG_info
* bcg_info
, bcg_state state
);
38 static void unset_state(BCG_info
* bcg_info
, bcg_state state
);
39 static int in_state(BCG_info
* bcg_info
, bcg_state state
);
46 This function create an instance of Byte Code Generator.
56 bcg_info
= (BCG_info
*) mem_sys_allocate_zeroed(sizeof (BCG_info
));
57 bcg_info
->private_info
= bcg_info_private_create(bcg_info
);
58 BCG_INFO_PRIV(bcg_info
)->state
= 0;
59 set_state(bcg_info
, BCG_STATE_INIT
);
66 BCG_destroy(BCG_info *bcg_info)>
68 This methods destroys the specified instance of Byte Code Generator.
74 BCG_destroy(BCG_info
*bcg_info
)
76 bcg_info_private_destroy(bcg_info
, BCG_INFO_PRIV(bcg_info
));
77 if (bcg_info
->error_msg
!= NULL
) {
78 mem_sys_free(bcg_info
->error_msg
);
80 mem_sys_free(bcg_info
);
86 BCG_start_code_gen(BCG_info * bcg_info)>
88 RT#48260: Not yet documented!!!
95 BCG_start_code_gen(BCG_info
* bcg_info
)
97 if (BCG_INFO_PRIV(bcg_info
)->state
!= BCG_STATE_INIT
) {
98 bcg_throw_exception(bcg_info
, BCG_EXCEPTION
,
99 "Expected BCG to be in INIT state.");
102 set_state(bcg_info
, BCG_STATE_IN_CODEGEN
);
109 BCG_end_code_gen(BCG_info * bcg_info)>
111 RT#48260: Not yet documented!!!
118 BCG_end_code_gen(BCG_info
* bcg_info
)
120 if (BCG_INFO_PRIV(bcg_info
)->state
!= BCG_STATE_IN_CODEGEN
) {
121 bcg_throw_exception(bcg_info
, BCG_EXCEPTION
,
122 "Expected BCG to be in IN_CODEGEN state.");
125 unset_state(bcg_info
, BCG_STATE_IN_CODEGEN
);
131 BCG_start_sub(BCG_info * bcg_info, char *sub_name, char *pragma)>
133 RT#48260: Not yet documented!!!
140 BCG_start_sub(BCG_info
* bcg_info
, char *sub_name
, char *pragma
)
145 if (BCG_INFO_PRIV(bcg_info
)->state
!= BCG_STATE_IN_CODEGEN
) {
146 bcg_throw_exception(bcg_info
, BCG_EXCEPTION
,
147 "Expected BCG to be in IN_CODEGEN state.");
150 set_state(bcg_info
, BCG_STATE_IN_SUB
);
151 unit
= bcg_unit_create(bcg_info
, sub_name
, pragma
);
152 bcg_info_add_unit(bcg_info
, unit
);
153 unit
->symbol_table
= bcg_hash_create(bcg_info
);
159 BCG_end_sub(BCG_info * bcg_info)>
161 RT#48260: Not yet documented!!!
168 BCG_end_sub(BCG_info
* bcg_info
)
172 if (!in_state(bcg_info
, BCG_STATE_IN_SUB
)) {
173 bcg_throw_exception(bcg_info
, BCG_EXCEPTION
,
174 "Expected BCG to be in IN_SUB state.");
177 unset_state(bcg_info
, BCG_STATE_IN_SUB
);
178 curr_unit
= bcg_info_current_unit(bcg_info
);
179 reg_alloc_vanilla(bcg_info
, curr_unit
);
185 BCG_start_call(BCG_info * bcg_info, char *sub_name)>
187 RT#48260: Not yet documented!!!
194 BCG_start_call(BCG_info
* bcg_info
, char *sub_name
)
196 if (!in_state(bcg_info
, BCG_STATE_IN_SUB
)) {
197 bcg_throw_exception(bcg_info
, BCG_EXCEPTION
,
198 "Expected BCG to be in IN_SUB state.");
201 set_state(bcg_info
, BCG_STATE_IN_CALL
);
207 BCG_end_call(BCG_info * bcg_info)>
209 RT#48260: Not yet documented!!!
216 BCG_end_call(BCG_info
* bcg_info
)
218 if (!in_state(bcg_info
, BCG_STATE_IN_CALL
)) {
219 bcg_throw_exception(bcg_info
, BCG_EXCEPTION
,
220 "Expected BCG to be in IN_CALL state.");
223 unset_state(bcg_info
, BCG_STATE_IN_CALL
);
229 BCG_start_op(BCG_info * bcg_info, char *op_name)>
231 RT#48260: Not yet documented!!!
238 BCG_start_op(BCG_info
* bcg_info
, char *op_name
)
243 if (!in_state(bcg_info
, BCG_STATE_IN_SUB
)) {
244 bcg_throw_exception(bcg_info
, BCG_EXCEPTION
,
245 "Expected BCG to be in IN_SUB state.");
248 set_state(bcg_info
, BCG_STATE_IN_OP
);
249 curr_unit
= bcg_info_current_unit(bcg_info
);
250 op
= bcg_op_create(bcg_info
, op_name
, BCG_OP
);
251 bcg_unit_add_op(bcg_info
, curr_unit
, op
);
257 BCG_end_op(BCG_info * bcg_info)>
259 RT#48260: Not yet documented!!!
266 BCG_end_op(BCG_info
* bcg_info
)
270 if (!in_state(bcg_info
, BCG_STATE_IN_OP
)) {
271 bcg_throw_exception(bcg_info
, BCG_EXCEPTION
,
272 "Expected BCG to be in IN_CALL state.");
275 unset_state(bcg_info
, BCG_STATE_IN_OP
);
276 curr_op
= bcg_info_current_op(bcg_info
);
277 bcg_op_resolve_full_name(bcg_info
, curr_op
);
283 BCG_var(BCG_info * bcg_info, char *var_name, char var_type)>
285 RT#48260: Not yet documented!!!
292 BCG_var(BCG_info
* bcg_info
, char *var_name
, char var_type
)
298 if (!in_state(bcg_info
, BCG_STATE_IN_OP
)) {
299 bcg_throw_exception(bcg_info
, BCG_EXCEPTION
,
300 "Expected BCG to be in IN_OP state.");
303 curr_unit
= bcg_info_current_unit(bcg_info
);
304 curr_op
= bcg_info_current_op(bcg_info
);
305 op_arg
= (bcg_op_arg
*)bcg_hash_get(bcg_info
, curr_unit
->symbol_table
, var_name
);
308 op_arg
= bcg_op_arg_create(bcg_info
, var_name
, BCG_OP_ARG_VARIABLE
,
311 bcg_op_add_arg(bcg_info
, curr_op
, op_arg
);
312 bcg_hash_put(bcg_info
, curr_unit
->symbol_table
, var_name
, op_arg
);
318 BCG_val(BCG_info * bcg_info, char *val, char val_type)>
320 RT#48260: Not yet documented!!!
327 BCG_val(BCG_info
* bcg_info
, char *val
, char val_type
)
332 if (!in_state(bcg_info
, BCG_STATE_IN_OP
)) {
333 bcg_throw_exception(bcg_info
, BCG_EXCEPTION
,
334 "Expected BCG to be in IN_OP state.");
337 curr_op
= bcg_info_current_op(bcg_info
);
338 op_arg
= bcg_op_arg_create(bcg_info
, val
, BCG_OP_ARG_CONSTANT
, val_type
);
339 bcg_op_add_arg(bcg_info
, curr_op
, op_arg
);
345 BCG_label(BCG_info * bcg_info, char *label)>
347 RT#48260: Not yet documented!!!
354 BCG_label(BCG_info
* bcg_info
, char *label
)
359 if (!in_state(bcg_info
, BCG_STATE_IN_SUB
)) {
360 bcg_throw_exception(bcg_info
, BCG_EXCEPTION
,
361 "Expected BCG to be in IN_SUB state.");
364 curr_unit
= bcg_info_current_unit(bcg_info
);
365 op
= bcg_op_create(bcg_info
, label
, BCG_OP_LABEL
);
366 bcg_unit_add_op(bcg_info
, curr_unit
, op
);
372 BCG_print_pasm(BCG_info * bcg_info)>
374 RT#48260: Not yet documented!!!
381 BCG_print_pasm(BCG_info
* bcg_info
)
388 =item C<bcg_info_private *
389 bcg_info_private_create(BCG_info * bcg_info)>
391 RT#48260: Not yet documented!!!
398 bcg_info_private_create(BCG_info
* bcg_info
)
400 bcg_info_private
*bcg_info_priv
;
403 bcg_info_priv
= (bcg_info_private
*)
404 mem_sys_allocate_zeroed(sizeof (bcg_info_private
));
405 return bcg_info_priv
;
411 bcg_info_private_destroy(BCG_info * bcg_info, bcg_info_private * bcg_info_priv)>
413 RT#48260: Not yet documented!!!
420 bcg_info_private_destroy(BCG_info
* bcg_info
, bcg_info_private
* bcg_info_priv
)
422 bcg_unit
*unit
, *cur_unit
;
426 unit
= bcg_info_priv
->first_unit
;
430 bcg_unit_destroy(bcg_info
, cur_unit
);
433 mem_sys_free(bcg_info_priv
);
439 bcg_info_add_unit(BCG_info * bcg_info, bcg_unit * unit)>
441 RT#48260: Not yet documented!!!
448 bcg_info_add_unit(BCG_info
* bcg_info
, bcg_unit
* unit
)
450 bcg_info_private
*bcg_info_priv
= BCG_INFO_PRIV(bcg_info
);
451 if (!bcg_info_priv
->first_unit
) {
452 bcg_info_priv
->first_unit
= unit
;
457 bcg_info_priv
->last_unit
->next
= unit
;
458 unit
->prev
= bcg_info_priv
->last_unit
;
460 bcg_info_priv
->last_unit
= unit
;
467 set_state(BCG_info * bcg_info, bcg_state state)>
469 RT#48260: Not yet documented!!!
476 set_state(BCG_info
* bcg_info
, bcg_state state
)
478 BCG_INFO_PRIV(bcg_info
)->state
|= state
;
484 unset_state(BCG_info * bcg_info, bcg_state state)>
486 RT#48260: Not yet documented!!!
493 unset_state(BCG_info
* bcg_info
, bcg_state state
)
495 BCG_INFO_PRIV(bcg_info
)->state
&= (~state
);
501 in_state(BCG_info * bcg_info, bcg_state state)>
503 RT#48260: Not yet documented!!!
510 in_state(BCG_info
* bcg_info
, bcg_state state
)
512 return state
== (state
& BCG_INFO_PRIV(bcg_info
)->state
);
521 Copyright (C) 2006, The Perl Foundation.
523 This is free software; you may redistribute it and/or modify
524 it under the same terms as Parrot.
528 Vishal Soni <vishalrsoni@gmail.com>
536 * c-file-style: "parrot"
538 * vim: expandtab shiftwidth=4: