Decaf Compiler
|
Declarations of ILOC structures. More...
Go to the source code of this file.
Classes | |
struct | Operand |
ILOC operand structure. More... | |
struct | ILOCInsn |
ILOC instruction. More... | |
struct | InsnList |
Linked list of ILOCInsn* elements. More... | |
Macros | |
#define | WORD_SIZE 8 |
Machine word size (64 bits) | |
#define | MEM_SIZE 65536 |
Machine memory size (64K) | |
#define | MAX_VIRTUAL_REGS 2048 |
Maximum number of virtual registers. | |
#define | MAX_INSTRUCTIONS 2048 |
Maximum number of instructions. | |
#define | PARAM_BP_OFFSET (2 * WORD_SIZE) |
Base pointer offset for parameters. More... | |
#define | LOCAL_BP_OFFSET (-WORD_SIZE) |
Base pointer offset for local variables. | |
#define | STATIC_VAR_OFFSET 0x100 |
Base offset/address in memory for static/global variables. | |
Typedefs | |
typedef enum OperandType | OperandType |
Operand type. | |
typedef struct Operand | Operand |
ILOC operand structure. | |
typedef enum InsnForm | InsnForm |
ILOC instruction form. More... | |
typedef struct ILOCInsn | ILOCInsn |
ILOC instruction. More... | |
typedef struct InsnList | InsnList |
Linked list of ILOCInsn* elements. | |
Enumerations | |
enum | OperandType { EMPTY, STACK_REG, BASE_REG, RETURN_REG, VIRTUAL_REG, JUMP_LABEL, CALL_LABEL, INT_CONST, STR_CONST } |
Operand type. More... | |
enum | InsnForm { ADD, SUB, MULT, DIV, AND, OR, LOAD_I, LOAD, LOAD_AI, LOAD_AO, STORE, STORE_AI, STORE_AO, NOP, I2I, JUMP, CBR, CMP_LT, CMP_LE, CMP_EQ, CMP_GE, CMP_GT, CMP_NE, ADD_I, MULT_I, NOT, NEG, PUSH, POP, LABEL, CALL, RETURN, PRINT, PHI } |
ILOC instruction form. More... | |
Functions | |
Operand | empty_operand () |
Create a empty operand. | |
Operand | stack_register () |
Create a SP operand. | |
Operand | base_register () |
Create a BP operand. | |
Operand | return_register () |
Create a RET operand. | |
Operand | virtual_register () |
Create a new virtual register operand (uses next available ID) | |
Operand | register_with_id (int id) |
Create a virtual/physical register operand with a specific register ID. | |
Operand | anonymous_label () |
Create a new jump label operand (uses next available ID) | |
Operand | call_label (const char *label) |
Create a call label with the a specific name. | |
Operand | int_const (long integer) |
Create an integer constant operand with a specific value. | |
Operand | str_const (const char *string) |
Create a string constant operand with a specific value. | |
void | Operand_print (Operand op, FILE *output) |
Print an operand. More... | |
ILOCInsn * | ILOCInsn_new_3op (InsnForm form, Operand op1, Operand op2, Operand op3) |
Create a new 3-operand instruction. More... | |
ILOCInsn * | ILOCInsn_new_2op (InsnForm form, Operand op1, Operand op2) |
Create a new 2-operand instruction. More... | |
ILOCInsn * | ILOCInsn_new_1op (InsnForm form, Operand op1) |
Create a new 1-operand instruction. More... | |
ILOCInsn * | ILOCInsn_new_0op (InsnForm form) |
Create a new 0-operand instruction. More... | |
void | ILOCInsn_set_comment (ILOCInsn *insn, const char *comment) |
Add a comment to an instruction. More... | |
ILOCInsn * | ILOCInsn_copy (ILOCInsn *insn) |
Create a new instruction that is a copy of an existing instruction. More... | |
void | ILOCInsn_print (ILOCInsn *insn, FILE *output) |
Print an instruction. More... | |
int | ILOCInsn_get_operand_count (ILOCInsn *insn) |
Count the number of operands in an instruction. More... | |
ILOCInsn * | ILOCInsn_get_read_registers (ILOCInsn *insn) |
Get a list of registers that are read from by this instruction. More... | |
Operand | ILOCInsn_get_write_register (ILOCInsn *insn) |
Get the register (if any) that is written to by this instruction. More... | |
void | ILOCInsn_free (ILOCInsn *insn) |
Deallocate an instruction structure. More... | |
InsnList * | InsnList_new () |
Allocate and initialize a new, empty list. | |
void | InsnList_add (InsnList *list, ILOCInsn *item) |
Add an item to the end of a list. | |
int | InsnList_size (InsnList *list) |
Look up the size of a list. | |
bool | InsnList_is_empty (InsnList *list) |
Test a list to see if it is empty. | |
void | InsnList_free (InsnList *list) |
Deallocate a list and any contained items. | |
void | InsnList_print (InsnList *list, FILE *output) |
Print an instruction list with proper indentation and comments. More... | |
NodeVisitor * | AllocateSymbolsVisitor_new () |
Create a new AST visitor that allocates addresses for all variable symbols. More... | |
void | reg_attr_print (void *reg, FILE *output) |
Print a register attribute. More... | |
void | insnlist_attr_print (InsnList *list, FILE *output) |
Print an instruction list attribute. More... | |
void | ASTNode_copy_code (ASTNode *dest, ASTNode *src) |
Copy code attribute from one AST node to another. More... | |
void | ASTNode_emit_insn (ASTNode *dest, ILOCInsn *insn) |
Add/append an instruction to the code attribute (instruction list) for an AST node. More... | |
void | ASTNode_add_comment (ASTNode *dest, const char *comment) |
Add a comment to the most recently-emitted instruction for an AST node. More... | |
void | ASTNode_set_temp_reg (ASTNode *node, Operand reg) |
Set a temporary result register for an AST node. More... | |
Operand | ASTNode_get_temp_reg (ASTNode *node) |
Retrieve a temporary result register from an AST node. More... | |
int | run_simulator (InsnList *program, bool print_trace) |
Run ILOC simulator on an ILOC program. More... | |
Declarations of ILOC structures.
This module provides declarations of all structures and framework functions for ILOC programs. It is necessary for Projects 4 (code generation) and 5 (register allocation).
#define PARAM_BP_OFFSET (2 * WORD_SIZE) |
Base pointer offset for parameters.
Skips base pointer and return address
ILOC instruction.
There are four normal constructors, based on the number of operands needed:
There is also a copy constructor (ILOCInsn_copy). Instructions should be deallocated using ILOCInsn_free.
Members:
ILOC instruction form.
Most of these are as documented in EAC2 (Appendix A). New or modified forms are documented here.
enum InsnForm |
ILOC instruction form.
Most of these are as documented in EAC2 (Appendix A). New or modified forms are documented here.
enum OperandType |
Operand type.
NodeVisitor* AllocateSymbolsVisitor_new | ( | ) |
Create a new AST visitor that allocates addresses for all variable symbols.
void ASTNode_add_comment | ( | ASTNode * | dest, |
const char * | comment | ||
) |
Add a comment to the most recently-emitted instruction for an AST node.
If there is no code attribute or if it's an empty list, nothing is done.
dest | Pointer to destination AST node |
comment | Comment to add |
Copy code attribute from one AST node to another.
dest | Pointer to destination AST node |
src | Pointer to source AST node |
Add/append an instruction to the code attribute (instruction list) for an AST node.
dest | Pointer to destination AST node |
insn | Instruction to add |
Retrieve a temporary result register from an AST node.
Aborts with an error message if the given node has no "reg" attribute.
node | AST node |
Set a temporary result register for an AST node.
node | AST node |
reg | Register as an operand |
Create a new instruction that is a copy of an existing instruction.
insn | Instruction to copy |
void ILOCInsn_free | ( | ILOCInsn * | insn | ) |
Deallocate an instruction structure.
insn | Instruction to deallocate |
int ILOCInsn_get_operand_count | ( | ILOCInsn * | insn | ) |
Count the number of operands in an instruction.
insn | Instruction to count operands of |
Get a list of registers that are read from by this instruction.
This function returns the registers inside of a new "fake" instruction – don't forget to deallocate that instruction when you're done with it.
insn | Instruction to examine |
NOP
instruction with the relevant registers as operands Get the register (if any) that is written to by this instruction.
insn | Instruction to examine |
EMPTY
operand if there is none) Create a new 0-operand instruction.
form | Instruction type/form |
Create a new 1-operand instruction.
form | Instruction type/form |
op1 | First operand |
Create a new 2-operand instruction.
form | Instruction type/form |
op1 | First operand |
op2 | Second operand |
Create a new 3-operand instruction.
form | Instruction type/form |
op1 | First operand |
op2 | Second operand |
op3 | Third operand |
void ILOCInsn_print | ( | ILOCInsn * | insn, |
FILE * | output | ||
) |
Print an instruction.
insn | Instruction to print |
output | File stream to print to |
void ILOCInsn_set_comment | ( | ILOCInsn * | insn, |
const char * | comment | ||
) |
Add a comment to an instruction.
insn | Instruction to add a comment to |
comment | Comment to add |
void insnlist_attr_print | ( | InsnList * | list, |
FILE * | output | ||
) |
Print an instruction list attribute.
list | Pointer to instruction list to print |
output | File stream to print to |
void InsnList_print | ( | InsnList * | list, |
FILE * | output | ||
) |
Print an instruction list with proper indentation and comments.
list | List of instructions to print |
output | File stream to print to |
void Operand_print | ( | Operand | op, |
FILE * | output | ||
) |
Print an operand.
op | Operand to print |
output | File stream to print to |
void reg_attr_print | ( | void * | reg, |
FILE * | output | ||
) |
Print a register attribute.
reg | Pointer to register attribute to print |
output | File stream to print to |
int run_simulator | ( | InsnList * | program, |
bool | print_trace | ||
) |
Run ILOC simulator on an ILOC program.
If tracing is enabled, the simulator will print the machine state before executing each instruction.
program | List of ILOC instructions |
print_trace | Enable/disable debug tracing |