aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/ir.c4
-rw-r--r--src/ir.h3
-rw-r--r--src/viz.c6
3 files changed, 12 insertions, 1 deletions
diff --git a/src/ir.c b/src/ir.c
index 86a1a9a..7f841be 100644
--- a/src/ir.c
+++ b/src/ir.c
@@ -156,7 +156,9 @@ generate_basm(ParseTree *parse_tree) {
156 array_init(program->lines, 0); 156 array_init(program->lines, 0);
157 for (size_t i = 0; i < array_size(parse_tree->roots); ++i) { 157 for (size_t i = 0; i < array_size(parse_tree->roots); ++i) {
158 Node *root = parse_tree->roots[i]; 158 Node *root = parse_tree->roots[i];
159 emit_basm(program, root); 159 Operand ret = emit_basm(program, root);
160 LineInfo line = (LineInfo){.line = root->line, .col = root->col};
161 EMIT_0(program, line, OP_RETURN, ret);
160 } 162 }
161 return program; 163 return program;
162} 164}
diff --git a/src/ir.h b/src/ir.h
index c0ce22a..6df1e0d 100644
--- a/src/ir.h
+++ b/src/ir.h
@@ -44,6 +44,9 @@ typedef enum Operator {
44 OP_JMP_LT, 44 OP_JMP_LT,
45 OP_JMP_GE, 45 OP_JMP_GE,
46 OP_JMP_LE, 46 OP_JMP_LE,
47
48 // Return value from register.
49 OP_RETURN,
47} Operator; 50} Operator;
48 51
49typedef enum OperandType { 52typedef enum OperandType {
diff --git a/src/viz.c b/src/viz.c
index 8e31387..ebe1a4c 100644
--- a/src/viz.c
+++ b/src/viz.c
@@ -272,6 +272,7 @@ static const char* basm_op_str[] = {
272 [OP_JMP_LT] = "jlt ", 272 [OP_JMP_LT] = "jlt ",
273 [OP_JMP_GE] = "jge ", 273 [OP_JMP_GE] = "jge ",
274 [OP_JMP_LE] = "jle ", 274 [OP_JMP_LE] = "jle ",
275 [OP_RETURN] = "ret ",
275}; 276};
276 277
277void 278void
@@ -311,11 +312,16 @@ viz_instruction(Instruction *inst, LineInfo *line) {
311 viz_operand(inst->src_b); 312 viz_operand(inst->src_b);
312 } 313 }
313 } break; 314 } break;
315 case OP_RETURN:
314 case OP_JMP: 316 case OP_JMP:
315 case OP_LABEL: { 317 case OP_LABEL: {
316 printf(" "); 318 printf(" ");
317 viz_operand(inst->dst); 319 viz_operand(inst->dst);
318 } break; 320 } break;
321 case OP_CP8:
322 case OP_CP16:
323 case OP_CP32:
324 case OP_CP64:
319 case OP_JMP_TRUE: 325 case OP_JMP_TRUE:
320 case OP_JMP_FALSE: { 326 case OP_JMP_FALSE: {
321 printf(" "); 327 printf(" ");