parrotcode: Untitled | |
Contents | Compilers |
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.
void print_key(lexer_state *const lexer, key *const k)
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)
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)
c
. Based on c
's type, the appropriate value is printed.
void print_expr(lexer_state *const lexer, expression *const expr)
expr
. This is a dispatch function, calling a specialized function based on expr
's type.
void print_expressions(expression *const expr)
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)
ins
.
void print_statement(lexer_state *const lexer, subroutine *const sub)
void print_subs(struct lexer_state *const lexer)
static void emit_pir_instruction(lexer_state *const lexer, instruction *const instr)
instr
. If instr
has a label, that is printed first.
static void emit_pir_statement(lexer_state *const lexer, subroutine *const sub)
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)
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)
static void emit_pbc_label_arg(lexer_state *const lexer, label *const l)
l
.
static void emit_pbc_key(lexer_state *const lexer, key *const k)
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)
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)
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)
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)
opinfo
attribute of instr
is NULL, the function does nothing and returns.
static void emit_pbc_sub(lexer_state *const lexer, subroutine *const sub)
sub
.
static void emit_pbc_annotations(lexer_state *const lexer)
void emit_pbc(lexer_state *const lexer)
|