31#define MAX_VIRTUAL_REGS 2048
36#define MAX_PHYSICAL_REGS 32
41#define MAX_INSTRUCTIONS 2048
48#define PARAM_BP_OFFSET (2 * WORD_SIZE)
53#define LOCAL_BP_OFFSET (-WORD_SIZE)
58#define STATIC_VAR_OFFSET 0x100
AST nodes and attributes.
Includes, constants, declarations, and macros used across the compiler.
#define MAX_LINE_LEN
Maximum length (in characters) of any single line of input.
Definition common.h:42
#define DECL_LIST_TYPE(NAME, ELEMTYPE)
Declare a singly-linked list structure of the given type.
Definition common.h:132
void InsnList_print(InsnList *list, FILE *output)
Print an instruction list with proper indentation and comments.
Definition iloc.c:281
Operand ILOCInsn_get_write_register(ILOCInsn *insn)
Get the register (if any) that is written to by this instruction.
Definition iloc.c:250
int run_simulator(InsnList *program, bool print_trace)
Run ILOC simulator on an ILOC program.
Definition iloc.c:951
InsnForm
ILOC instruction form.
Definition iloc.h:163
@ NOT
Boolean NOT (!r1 => r2)
Definition iloc.h:194
@ POP
Pop register value from system stack (load into r2 and increment SP)
Definition iloc.h:197
@ CMP_NE
Compare integers and save the boolean result (r1 != r2 => r3)
Definition iloc.h:188
@ LABEL
Jump label w/ integer ID (no effect)
Definition iloc.h:198
@ SUB
Integer subtraction (r1 - r2 => r3)
Definition iloc.h:167
@ LOAD_I
Load/set a register to an immediate value.
Definition iloc.h:172
@ MULT
Integer multiplication (r1 * r2 => r3)
Definition iloc.h:168
@ JUMP
Unconditional control branch to a target label.
Definition iloc.h:181
@ CMP_GT
Compare integers and save the boolean result (r1 > r2 => r3)
Definition iloc.h:187
@ CMP_LT
Compare integers and save the boolean result (r1 < r2 => r3)
Definition iloc.h:183
@ MULT_I
Multiply an immediate/constant value with a register value (r1 * c1 => r2)
Definition iloc.h:193
@ RETURN
Return from a function (pop return address and jump)
Definition iloc.h:200
@ CMP_GE
Compare integers and save the boolean result (r1 >= r2 => r3)
Definition iloc.h:186
@ I2I
Copy one integer register to another.
Definition iloc.h:180
@ CMP_LE
Compare integers and save the boolean result (r1 <= r2 => r3)
Definition iloc.h:184
@ PHI
Combine two registers in SSA form.
Definition iloc.h:202
@ DIV
Integer division (r1 / r2 => r3) w/ truncation of answer if fractional.
Definition iloc.h:169
@ AND
Boolean AND (r1 && r2 => r3)
Definition iloc.h:170
@ OR
Boolean OR (r1 || r2 => r3)
Definition iloc.h:171
@ LOAD
Load from memory using address (reg) addressing.
Definition iloc.h:173
@ PRINT
Print a constant or register value.
Definition iloc.h:201
@ LOAD_AI
Load from memory using address + immediate (reg/imm) addressing.
Definition iloc.h:174
@ STORE_AO
Store to memory using address + offset (reg/reg) addressing.
Definition iloc.h:178
@ LOAD_AO
Load from memory using address + offset (reg/reg) addressing.
Definition iloc.h:175
@ STORE_AI
Store to memory using address + immediate (reg/imm) addressing.
Definition iloc.h:177
@ CALL
Call a function (push return address and jump)
Definition iloc.h:199
@ CMP_EQ
Compare integers and save the boolean result (r1 == r2 => r3)
Definition iloc.h:185
@ ADD
Integer addition (r1 + r2 => r3)
Definition iloc.h:166
@ PUSH
Push register value onto system stack (decrement SP and store from r1)
Definition iloc.h:196
@ ADD_I
Add an immediate/constant value to a register value (r1 + c1 => r2)
Definition iloc.h:192
@ CBR
Conditional control branch to one of two target labels.
Definition iloc.h:182
@ NEG
Integer negation (-r1 => r2)
Definition iloc.h:195
@ NOP
Do nothing (sometimes useful for testing)
Definition iloc.h:179
@ STORE
Store to memory using address (reg) addressing.
Definition iloc.h:176
Operand empty_operand(void)
Create a empty operand.
Definition iloc.c:7
void reg_attr_print(void *reg, FILE *output)
Print a register attribute.
Definition iloc.c:399
Operand ASTNode_get_temp_reg(ASTNode *node)
Retrieve a temporary result register from an AST node.
Definition iloc.c:463
ILOCInsn * ILOCInsn_new_0op(InsnForm form)
Create a new 0-operand instruction.
Definition iloc.c:121
Operand str_const(const char *string)
Create a string constant operand with a specific value.
Definition iloc.c:65
Operand call_label(const char *label)
Create a call label with the a specific name.
Definition iloc.c:51
Operand base_register(void)
Create a BP operand.
Definition iloc.c:19
ILOCInsn * ILOCInsn_new_1op(InsnForm form, Operand op1)
Create a new 1-operand instruction.
Definition iloc.c:116
void ASTNode_copy_code(ASTNode *dest, ASTNode *src)
Copy code attribute from one AST node to another.
Definition iloc.c:414
Operand virtual_register(void)
Create a new virtual register operand (uses next available ID)
Definition iloc.c:31
NodeVisitor * AllocateSymbolsVisitor_new(void)
Create a new AST visitor that allocates addresses for all variable symbols.
Definition iloc.c:377
void insnlist_attr_print(InsnList *list, FILE *output)
Print an instruction list attribute.
Definition iloc.c:405
ILOCInsn * ILOCInsn_new_2op(InsnForm form, Operand op1, Operand op2)
Create a new 2-operand instruction.
Definition iloc.c:111
int ILOCInsn_get_operand_count(ILOCInsn *insn)
Count the number of operands in an instruction.
Definition iloc.c:200
Operand return_register(void)
Create a RET operand.
Definition iloc.c:25
Operand physical_register(int id)
Create a physical register operand with a specific register ID.
Definition iloc.c:38
void ASTNode_add_comment(ASTNode *dest, const char *comment)
Add a comment to the most recently-emitted instruction for an AST node.
Definition iloc.c:445
void ILOCInsn_set_comment(ILOCInsn *insn, const char *comment)
Add a comment to an instruction.
Definition iloc.c:126
void Operand_print(Operand op, FILE *output)
Print an operand.
Definition iloc.c:73
OperandType
Operand type.
Definition iloc.h:64
@ EMPTY
No operand.
Definition iloc.h:65
@ PHYSICAL_REG
Numbered physical register.
Definition iloc.h:70
@ STR_CONST
String constant/literal.
Definition iloc.h:74
@ INT_CONST
Integer constant/literal.
Definition iloc.h:73
@ RETURN_REG
Return value register (RET)
Definition iloc.h:68
@ JUMP_LABEL
Numbered jump label.
Definition iloc.h:71
@ STACK_REG
Stack pointer register (SP)
Definition iloc.h:66
@ BASE_REG
Base pointer register (BP)
Definition iloc.h:67
@ VIRTUAL_REG
Numbered virtual register.
Definition iloc.h:69
@ CALL_LABEL
Textual call label.
Definition iloc.h:72
void ILOCInsn_print(ILOCInsn *insn, FILE *output)
Print an instruction.
Definition iloc.c:147
void ILOCInsn_free(ILOCInsn *insn)
Deallocate an instruction structure.
Definition iloc.c:274
Operand int_const(long integer)
Create an integer constant operand with a specific value.
Definition iloc.c:59
ILOCInsn * ILOCInsn_get_read_registers(ILOCInsn *insn)
Get a list of registers that are read from by this instruction.
Definition iloc.c:211
Operand anonymous_label(void)
Create a new jump label operand (uses next available ID)
Definition iloc.c:44
ILOCInsn * ILOCInsn_new_3op(InsnForm form, Operand op1, Operand op2, Operand op3)
Create a new 3-operand instruction.
Definition iloc.c:98
void ASTNode_set_temp_reg(ASTNode *node, Operand reg)
Set a temporary result register for an AST node.
Definition iloc.c:458
ILOCInsn * ILOCInsn_copy(ILOCInsn *insn)
Create a new instruction that is a copy of an existing instruction.
Definition iloc.c:131
Operand stack_register(void)
Create a SP operand.
Definition iloc.c:13
void ASTNode_emit_insn(ASTNode *dest, ILOCInsn *insn)
Add/append an instruction to the code attribute (instruction list) for an AST node.
Definition iloc.c:435
Main AST node structure.
Definition ast.h:471
ILOC instruction.
Definition iloc.h:228
char comment[256]
Comment associated with this instruction.
Definition iloc.h:247
struct ILOCInsn * next
Next instruction (if stored in a list)
Definition iloc.h:252
InsnForm form
Type ("form") of instruction.
Definition iloc.h:232
Operand op[3]
Operands.
Definition iloc.h:240
Linked list of ILOCInsn* elements.
Definition iloc.h:353
Node visitor structure.
Definition visitor.h:28
ILOC operand structure.
Definition iloc.h:81
char str[256]
String constant/literal.
Definition iloc.h:90
long imm
Integer constant/literal.
Definition iloc.h:89
int id
Virtual/physical register or jump label ID.
Definition iloc.h:88
OperandType type
Operand type (discriminator/tag for anonymous union)
Definition iloc.h:85
Symbols, symbol tables, and static analysis errors.
Tokens and regular expressions.