emit imcc instructions into Parrot interpreter

the e_pbc_emit function is called per instruction


I'm using existing data structures here (SymReg *) to store various global items (currently only PMC constants). The index in the constant table is in SymReg * ->color data member. This looks odd, but the register number from imc.c:allocate is also there for variables, so it's a little bit consistent at least.

So when reading color here it's either a constant table index or a Parrot register number, depending on data type.

TODO memory clean up


Functions ^

static void imcc_globals_destroy

Frees memory allocated for IMCC globals for one particular compilation unit.

static int add_const_table

Adds an empty item to constant table, returning its position.

static int add_const_table_pmc

Adds a PMC to the const table, returning its position.

static int add_const_table_key

Adds a key to the const table, returning its position.

int e_pbc_open

Opens a compilation unit to emit PBC.

static int old_blocks

Gets the size/line of bytecode in ops at this point.

opcode_t *make_jit_info

Creates JIT information for this compilation unit.

static void make_new_sub

Allocates a new globals->cs->subs structure.

static int get_old_size

Get the size/line of bytecode in ops to this point.

static void store_sub_size

Sets the given size and line parameters for the current compilation unit.

static void store_fixup

Stores fixup information for the given register, program counter, and offset.

static void store_key_const

Stores a constant key for the current compilation unit.

static int get_codesize

Stores globals for later fixup, returning the code size in number of ops.

static subs_t *find_global_label

Finds a global label, returning the symreg (and setting the (absolute) pc through the out parameter).

static void fixup_globals

Fixes global information -- particularly locations of global symbols.

STRING *IMCC_string_from_reg

Creates and returns a constant STRING, given a stringish SymReg.

static int add_const_str

Adds a constant string to constant_table.

static int add_const_num

Adds a constant num to constant_table.

static PMC *mk_multi_sig

Creates and returns a multi-signature PMC given a SymReg.

static PMC *create_lexinfo

Creates and returns a new LexInfo PMC for all lexicals in the given sub in the current compilation unit.

static PMC *find_outer

Returns any :outer sub for the current compilation unit.

static int add_const_pmc_sub

Adds a constant Sub in the current compilation unit, denoted by the offset and end positions.

static int add_const_key

Adds a constant key to constant_table.

static const char *slice_deb

Returns debugging information for the indicated slice type.

static opcode_t build_key

Builds a Key PMC from the given SymReg.

Color is a Parrot register number or a constant table index. For the rest, please consult PDD08_KEYS(1). Additionally, I build a string representation of the key, which gets cached in the globals.keys.

INTVAL IMCC_int_from_reg

Creates and returns an INTEGER given an integer-like SymReg.

static void make_pmc_const

Creates a constant PMC, given a SymReg.

static void add_1_const

Adds a constant SymReg to the constant table, depending on its type.

static void constant_folding

Stores a constant's idx for later reuse.

int e_pbc_new_sub

Starts a new PBC emitting of a compilation unit, if the given compilation unit has any instructions.

int e_pbc_end_sub

Finishes the PBC emitting of a given compilation unit.

static void verify_signature

Checks if any get_ argument contains constants and fills in type bits for argument types and constants, if missing.

int e_pbc_emit

Starts to emit code for one instruction.

int e_pbc_close

Closes this PMC unit.