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
155 ADD, SUB, MULT, DIV, AND, OR,
156 LOAD_I, LOAD, LOAD_AI, LOAD_AO,
157 STORE, STORE_AI, STORE_AO,
159 CMP_LT, CMP_LE, CMP_EQ, CMP_GE, CMP_GT, CMP_NE,
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
Linked list of ILOCInsn* elements.
Definition: iloc.h:320
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
Numbered jump label.
Definition: iloc.h:65
Operand op[3]
Operands.
Definition: iloc.h:208
Base pointer register (BP)
Definition: iloc.h:62
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:449
Operand int_const(long integer)
Create an integer constant operand with a specific value.
Definition: iloc.c:59
Multiply an immediate/constant value with a register value (r1 * c1 => r2)
Definition: iloc.h:162
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
Textual call label.
Definition: iloc.h:66
Print a constant or register value.
Definition: iloc.h:170
Push register value onto system stack (decrement SP and store from r1)
Definition: iloc.h:165
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
ILOCInsn * ILOCInsn_copy(ILOCInsn *insn)
Create a new instruction that is a copy of an existing instruction.
Definition: iloc.c:130
Stack pointer register (SP)
Definition: iloc.h:61
ILOC operand structure.
Definition: iloc.h:74
Return from a function (pop return address and jump)
Definition: iloc.h:169
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
Numbered virtual (or physical) register.
Definition: iloc.h:64
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 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:153
void Operand_print(Operand op, FILE *output)
Print an operand.
Definition: iloc.c:73
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
String constant/literal.
Definition: iloc.h:68
long imm
Integer constant/literal.
Definition: iloc.h:83
Boolean NOT (!r1 => r2)
Definition: iloc.h:163
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
No operand.
Definition: iloc.h:60
void ILOCInsn_free(ILOCInsn *insn)
Deallocate an instruction structure.
Definition: iloc.c:272
int id
Virtual/physical register or jump label ID.
Definition: iloc.h:82
struct Operand Operand
ILOC operand structure.
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
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.
struct ILOCInsn * next
Next instruction (if stored in a list)
Definition: iloc.h:220
Operand base_register()
Create a BP operand.
Definition: iloc.c:19
Jump label w/ integer ID (no effect)
Definition: iloc.h:167
#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
Operand ILOCInsn_get_write_register(ILOCInsn *insn)
Get the register (if any) that is written to by this instruction.
Definition: iloc.c:248
ILOCInsn * ILOCInsn_new_1op(InsnForm form, Operand op1)
Create a new 1-operand instruction.
Definition: iloc.c:115
Includes, constants, declarations, and macros used across the compiler.
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
Combine two registers in SSA form.
Definition: iloc.h:171
ILOC instruction.
Definition: iloc.h:195
OperandType
Operand type.
Definition: iloc.h:58
Call a function (push return address and jump)
Definition: iloc.h:168
ILOCInsn * ILOCInsn_new_2op(InsnForm form, Operand op1, Operand op2)
Create a new 2-operand instruction.
Definition: iloc.c:110
Add an immediate/constant value to a register value (r1 + c1 => r2)
Definition: iloc.h:161
Integer negation (-r1 => r2)
Definition: iloc.h:164
char comment[256]
Comment associated with this instruction.
Definition: iloc.h:215
Tokens and regular expressions.
InsnForm form
Type ("form") of instruction.
Definition: iloc.h:200
struct ILOCInsn ILOCInsn
ILOC instruction.
Pop register value from system stack (load into r2 and increment SP)
Definition: iloc.h:166