Go to the documentation of this file.
26 #define MEM_SIZE 65536
31 #define MAX_VIRTUAL_REGS 2048
36 #define MAX_INSTRUCTIONS 2048
43 #define PARAM_BP_OFFSET (2 * WORD_SIZE)
48 #define LOCAL_BP_OFFSET (-WORD_SIZE)
53 #define STATIC_VAR_OFFSET 0x100
Operand ASTNode_get_temp_reg(ASTNode *node)
Retrieve a temporary result register from an AST node.
Definition: iloc.c:461
Operand stack_register()
Create a SP operand.
Definition: iloc.c:13
@ CMP_GE
Compare integers and save the boolean result (r1 >= r2 => r3)
Definition: iloc.h:180
Linked list of ILOCInsn* elements.
Definition: iloc.h:347
OperandType type
Operand type (discriminator/tag for anonymous union)
Definition: iloc.h:79
Operand register_with_id(int id)
Create a virtual/physical register operand with a specific register ID.
Definition: iloc.c:38
Operand call_label(const char *label)
Create a call label with the a specific name.
Definition: iloc.c:51
struct ILOCInsn ILOCInsn
ILOC instruction.
@ JUMP_LABEL
Numbered jump label.
Definition: iloc.h:65
Operand op[3]
Operands.
Definition: iloc.h:234
@ BASE_REG
Base pointer register (BP)
Definition: iloc.h:62
@ ADD
Integer addition (r1 + r2 => r3)
Definition: iloc.h:160
void ILOCInsn_set_comment(ILOCInsn *insn, const char *comment)
Add a comment to an instruction.
Definition: iloc.c:125
Main AST node structure.
Definition: ast.h:470
@ CBR
Conditional control branch to one of two target labels.
Definition: iloc.h:176
@ STORE_AO
Store to memory using address + offset (reg/reg) addressing.
Definition: iloc.h:172
Operand int_const(long integer)
Create an integer constant operand with a specific value.
Definition: iloc.c:59
@ MULT_I
Multiply an immediate/constant value with a register value (r1 * c1 => r2)
Definition: iloc.h:187
void reg_attr_print(void *reg, FILE *output)
Print a register attribute.
Definition: iloc.c:397
void ASTNode_set_temp_reg(ASTNode *node, Operand reg)
Set a temporary result register for an AST node.
Definition: iloc.c:456
@ CALL_LABEL
Textual call label.
Definition: iloc.h:66
@ STORE_AI
Store to memory using address + immediate (reg/imm) addressing.
Definition: iloc.h:171
@ PRINT
Print a constant or register value.
Definition: iloc.h:195
@ PUSH
Push register value onto system stack (decrement SP and store from r1)
Definition: iloc.h:190
AST nodes and attributes.
int run_simulator(InsnList *program, bool print_trace)
Run ILOC simulator on an ILOC program.
Definition: iloc.c:920
Node visitor structure.
Definition: visitor.h:27
Operand virtual_register()
Create a new virtual register operand (uses next available ID)
Definition: iloc.c:31
@ LOAD
Load from memory using address (reg) addressing.
Definition: iloc.h:167
ILOCInsn * ILOCInsn_copy(ILOCInsn *insn)
Create a new instruction that is a copy of an existing instruction.
Definition: iloc.c:130
@ STACK_REG
Stack pointer register (SP)
Definition: iloc.h:61
struct Operand Operand
ILOC operand structure.
ILOC operand structure.
Definition: iloc.h:74
@ RETURN
Return from a function (pop return address and jump)
Definition: iloc.h:194
NodeVisitor * AllocateSymbolsVisitor_new()
Create a new AST visitor that allocates addresses for all variable symbols.
Definition: iloc.c:375
void ASTNode_copy_code(ASTNode *dest, ASTNode *src)
Copy code attribute from one AST node to another.
Definition: iloc.c:412
@ VIRTUAL_REG
Numbered virtual (or physical) register.
Definition: iloc.h:64
@ INT_CONST
Integer constant/literal.
Definition: iloc.h:67
void InsnList_print(InsnList *list, FILE *output)
Print an instruction list with proper indentation and comments.
Definition: iloc.c:279
Operand empty_operand()
Create a empty operand.
Definition: iloc.c:7
Operand str_const(const char *string)
Create a string constant operand with a specific value.
Definition: iloc.c:65
void ILOCInsn_print(ILOCInsn *insn, FILE *output)
Print an instruction.
Definition: iloc.c:146
void insnlist_attr_print(InsnList *list, FILE *output)
Print an instruction list attribute.
Definition: iloc.c:403
@ RETURN_REG
Return value register (RET)
Definition: iloc.h:63
int ILOCInsn_get_operand_count(ILOCInsn *insn)
Count the number of operands in an instruction.
Definition: iloc.c:199
InsnForm
ILOC instruction form.
Definition: iloc.h:156
@ NOP
Do nothing (sometimes useful for testing)
Definition: iloc.h:173
@ LOAD_AO
Load from memory using address + offset (reg/reg) addressing.
Definition: iloc.h:169
@ CMP_NE
Compare integers and save the boolean result (r1 != r2 => r3)
Definition: iloc.h:182
void Operand_print(Operand op, FILE *output)
Print an operand.
Definition: iloc.c:73
@ STORE
Store to memory using address (reg) addressing.
Definition: iloc.h:170
ILOCInsn * ILOCInsn_new_3op(InsnForm form, Operand op1, Operand op2, Operand op3)
Create a new 3-operand instruction.
Definition: iloc.c:97
#define DECL_LIST_TYPE(NAME, ELEMTYPE)
Declare a singly-linked list structure of the given type.
Definition: common.h:122
@ STR_CONST
String constant/literal.
Definition: iloc.h:68
long imm
Integer constant/literal.
Definition: iloc.h:83
@ NOT
Boolean NOT (!r1 => r2)
Definition: iloc.h:188
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:433
@ EMPTY
No operand.
Definition: iloc.h:60
@ I2I
Copy one integer register to another.
Definition: iloc.h:174
void ILOCInsn_free(ILOCInsn *insn)
Deallocate an instruction structure.
Definition: iloc.c:272
@ CMP_LT
Compare integers and save the boolean result (r1 < r2 => r3)
Definition: iloc.h:177
int id
Virtual/physical register or jump label ID.
Definition: iloc.h:82
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:443
char str[256]
String constant/literal.
Definition: iloc.h:84
@ CMP_LE
Compare integers and save the boolean result (r1 <= r2 => r3)
Definition: iloc.h:178
@ OR
Boolean OR (r1 || r2 => r3)
Definition: iloc.h:165
ILOCInsn * ILOCInsn_get_read_registers(ILOCInsn *insn)
Get a list of registers that are read from by this instruction.
Definition: iloc.c:210
Symbols, symbol tables, and static analysis errors.
@ CMP_EQ
Compare integers and save the boolean result (r1 == r2 => r3)
Definition: iloc.h:179
struct ILOCInsn * next
Next instruction (if stored in a list)
Definition: iloc.h:246
Operand base_register()
Create a BP operand.
Definition: iloc.c:19
@ LABEL
Jump label w/ integer ID (no effect)
Definition: iloc.h:192
#define MAX_LINE_LEN
Maximum length (in characters) of any single line of input.
Definition: common.h:42
Operand return_register()
Create a RET operand.
Definition: iloc.c:25
@ CMP_GT
Compare integers and save the boolean result (r1 > r2 => r3)
Definition: iloc.h:181
Operand ILOCInsn_get_write_register(ILOCInsn *insn)
Get the register (if any) that is written to by this instruction.
Definition: iloc.c:248
@ DIV
Integer division (r1 / r2 => r3) w/ truncation of answer if fractional.
Definition: iloc.h:163
ILOCInsn * ILOCInsn_new_1op(InsnForm form, Operand op1)
Create a new 1-operand instruction.
Definition: iloc.c:115
@ LOAD_AI
Load from memory using address + immediate (reg/imm) addressing.
Definition: iloc.h:168
Includes, constants, declarations, and macros used across the compiler.
@ AND
Boolean AND (r1 && r2 => r3)
Definition: iloc.h:164
@ SUB
Integer subtraction (r1 - r2 => r3)
Definition: iloc.h:161
@ MULT
Integer multiplication (r1 * r2 => r3)
Definition: iloc.h:162
ILOCInsn * ILOCInsn_new_0op(InsnForm form)
Create a new 0-operand instruction.
Definition: iloc.c:120
Operand anonymous_label()
Create a new jump label operand (uses next available ID)
Definition: iloc.c:44
@ PHI
Combine two registers in SSA form.
Definition: iloc.h:196
@ LOAD_I
Load/set a register to an immediate value.
Definition: iloc.h:166
ILOC instruction.
Definition: iloc.h:221
OperandType
Operand type.
Definition: iloc.h:58
@ CALL
Call a function (push return address and jump)
Definition: iloc.h:193
ILOCInsn * ILOCInsn_new_2op(InsnForm form, Operand op1, Operand op2)
Create a new 2-operand instruction.
Definition: iloc.c:110
@ ADD_I
Add an immediate/constant value to a register value (r1 + c1 => r2)
Definition: iloc.h:186
@ NEG
Integer negation (-r1 => r2)
Definition: iloc.h:189
char comment[256]
Comment associated with this instruction.
Definition: iloc.h:241
@ JUMP
Unconditional control branch to a target label.
Definition: iloc.h:175
Tokens and regular expressions.
InsnForm form
Type ("form") of instruction.
Definition: iloc.h:226
@ POP
Pop register value from system stack (load into r2 and increment SP)
Definition: iloc.h:191