DESCRIPTION ^

This file contains emit functions. Depending on the requested output, the appropriate emit functions are used. Options are:

 -p     for PASM output
 -b     for bytecode output

The functions in this file walk the data structure that is built during the parse phase. During the traversal, bytecode for instructions and their operands are emitted through the bcgen module.

FUNCTIONS ^

void print_key(lexer_state *const lexer, key *const k)
Print the key k. The total key is enclosed in square brackets, and different key elements are separated by semicolons. Example:
 ["hi";42]
has two elements: "hi" and 42.
void print_target(lexer_state *const lexer, target *const t)
Print the target t; if t has a key, that key is printed as well. Examples:
 S1, P1[42]
void print_constant(lexer_state *const lexer, constant *const c)
Print the value of constant c. Based on c's type, the appropriate value is printed.
void print_expr(lexer_state *const lexer, expression *const expr)
Print the expression expr. This is a dispatch function, calling a specialized function based on expr's type.
void print_expressions(expression *const expr)
Print the list of expressions pointed to by expr, if expr is not NULL. If expr is NULL, the function does nothing and returns. Expressions are separated by commas.
void print_instruction(lexer_state *const lexer, instruction *const ins)
Print the instruction ins.
void print_statement(lexer_state *const lexer, subroutine *const sub)
XXX
void print_subs(struct lexer_state *const lexer)
Top-level function to print all generated code. This function iterates over all subs and prints their instructions.
static void emit_pir_instruction(lexer_state *const lexer, instruction *const instr)
Print the PIR representation of instr. If instr has a label, that is printed first.
static void emit_pir_statement(lexer_state *const lexer, subroutine *const sub)
Emit all statements of the subroutine sub. The statements are emitted in PIR format. If there are no statements in sub, this function returns.
void emit_pir_subs(lexer_state *const lexer)
Print the PIR representation of all subroutines stored in the lexer. If there are no subroutines, thre function does nothing and returns.
static void emit_pbc_const_arg(lexer_state *const lexer, constant *const c)
Emit a constant argument into the bytecode. An integer is emitted inline in the bytecode; other types are stored in the constant table, and their index in the constant table is emitted into the bytecode.
static void emit_pbc_label_arg(lexer_state *const lexer, label *const l)
Emit the value of the label offset of label l.
static void emit_pbc_key(lexer_state *const lexer, key *const k)
Emit bytecode for the key k. First the bytecode is written to a temporary buffer, which is later unpacked in the actual PackFile. See store_key_bytecode().
static void emit_pbc_target_arg(lexer_state *const lexer, target *const t)
Emit the assigned register of target t. The assigned register is stored in the color field, of either the pir_reg or symbol structure, depending on whether t is a register or a symbol, respectively. If t has a key, the key is emitted as well.
static void emit_pbc_expr(lexer_state *const lexer, expression *const operand)
Emit bytecode for the expression operand. This is a dispatch function, invoking the appropriate function depending on operand's type.
static void optimize_instr(lexer_state *const lexer, instruction *const instr)
Optimize the instruction instr. Currently, these instructions are optimized:
 box_p_ic  --> set_p_pc
 box_p_nc  --> set_p_pc
 box_p_sc  --> set_p_pc
static void emit_pbc_instr(lexer_state *const lexer, instruction *const instr)
Emit PBC for one instruction. If the opinfo attribute of instr is NULL, the function does nothing and returns.
static void emit_pbc_sub(lexer_state *const lexer, subroutine *const sub)
Emit bytecode for the subroutine sub.
static void emit_pbc_annotations(lexer_state *const lexer)
Emit all annotations into the PackFile. First a new annotations segment is created. Then, for each annotation, its value is stored in the constants table.
void emit_pbc(lexer_state *const lexer)
Generate Parrot Byte Code from the abstract syntax tree. This is the top-level function. After all instructions have been emitted, the PBC is written to a file.


parrot