Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/arm-codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,16 +485,18 @@ void code_generate(void)
emit_ph2_ir(ph2_ir);

/* prepare 'argc' and 'argv', then proceed to 'main' function */
emit(__movw(__AL, __r8, GLOBAL_FUNC->stack_size));
emit(__movt(__AL, __r8, GLOBAL_FUNC->stack_size));
emit(__add_r(__AL, __r8, __r12, __r8));
emit(__lw(__AL, __r0, __r8, 0));
emit(__add_i(__AL, __r1, __r8, 4));
emit(__bl(__AL, MAIN_BB->elf_offset - elf_code->size));
if (MAIN_BB) {
emit(__movw(__AL, __r8, GLOBAL_FUNC->stack_size));
emit(__movt(__AL, __r8, GLOBAL_FUNC->stack_size));
emit(__add_r(__AL, __r8, __r12, __r8));
emit(__lw(__AL, __r0, __r8, 0));
emit(__add_i(__AL, __r1, __r8, 4));
emit(__bl(__AL, MAIN_BB->elf_offset - elf_code->size));

/* exit with main's return value - r0 already has the return value */
emit(__mov_i(__AL, __r7, 1));
emit(__svc());
/* exit with main's return value - r0 already has the return value */
emit(__mov_i(__AL, __r7, 1));
emit(__svc());
}

for (int i = 0; i < ph2_ir_idx; i++) {
ph2_ir = PH2_IR_FLATTEN[i];
Expand Down
9 changes: 8 additions & 1 deletion src/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,14 @@ struct var {
int consumed;
bool is_ternary_ret;
bool is_logical_ret;
bool is_const; /* whether a constant representaion or not */
bool is_const; /* whether a constant representaion or not */
int vreg_id; /* Virtual register ID */
int phys_reg; /* Physical register assignment (-1 if unassigned) */
int vreg_flags; /* VReg flags */
int first_use; /* First instruction index where variable is used */
int last_use; /* Last instruction index where variable is used */
int loop_depth; /* Nesting depth if variable is in a loop */
int use_count; /* Number of times variable is used */
};

typedef struct {
Expand Down
5 changes: 5 additions & 0 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ var_t *require_var(block_t *blk)
var_t *var = arena_calloc(BLOCK_ARENA, 1, sizeof(var_t));
var_list->elements[var_list->size++] = var;
var->consumed = -1;
var->phys_reg = -1;
var->first_use = -1;
var->last_use = -1;
var->loop_depth = 0;
var->use_count = 0;
var->base = var;
var->type = TY_int;
return var;
Expand Down
Loading