Skip to content

Commit e3a7201

Browse files
committed
Refactor the ELF generation process using strbuf_t functions
These changes use the strbuf_t structure and its functions to simplify the ELF generation process, making related arrays such as elf_code, elf_data, etc., dynamic. The ELF writing functions are also enhanced for more efficient reuse.
1 parent dd92e89 commit e3a7201

File tree

5 files changed

+191
-225
lines changed

5 files changed

+191
-225
lines changed

src/arm-codegen.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ void cfg_flatten()
179179

180180
void emit(int code)
181181
{
182-
elf_write_code_int(code);
182+
elf_write_int(elf_code, code);
183183
}
184184

185185
void emit_ph2_ir(ph2_ir_t *ph2_ir)
@@ -271,16 +271,16 @@ void emit_ph2_ir(ph2_ir_t *ph2_ir)
271271
emit(__teq(rn));
272272
if (ph2_ir->is_branch_detached) {
273273
emit(__b(__NE, 8));
274-
emit(__b(__AL, ph2_ir->else_bb->elf_offset - elf_code_idx));
274+
emit(__b(__AL, ph2_ir->else_bb->elf_offset - elf_code->size));
275275
} else
276-
emit(__b(__NE, ph2_ir->then_bb->elf_offset - elf_code_idx));
276+
emit(__b(__NE, ph2_ir->then_bb->elf_offset - elf_code->size));
277277
return;
278278
case OP_jump:
279-
emit(__b(__AL, ph2_ir->next_bb->elf_offset - elf_code_idx));
279+
emit(__b(__AL, ph2_ir->next_bb->elf_offset - elf_code->size));
280280
return;
281281
case OP_call:
282282
func = find_func(ph2_ir->func_name);
283-
emit(__bl(__AL, func->bbs->elf_offset - elf_code_idx));
283+
emit(__bl(__AL, func->bbs->elf_offset - elf_code->size));
284284
return;
285285
case OP_load_data_address:
286286
emit(__movw(__AL, rd, ph2_ir->src0 + elf_data_start));
@@ -436,7 +436,7 @@ void code_generate()
436436
emit(__movt(__AL, __r8, GLOBAL_FUNC->stack_size));
437437
emit(__sub_r(__AL, __sp, __sp, __r8));
438438
emit(__mov_r(__AL, __r12, __sp));
439-
emit(__bl(__AL, GLOBAL_FUNC->bbs->elf_offset - elf_code_idx));
439+
emit(__bl(__AL, GLOBAL_FUNC->bbs->elf_offset - elf_code->size));
440440

441441
/* exit */
442442
emit(__movw(__AL, __r8, GLOBAL_FUNC->stack_size));
@@ -468,7 +468,7 @@ void code_generate()
468468
emit(__add_r(__AL, __r8, __r12, __r8));
469469
emit(__lw(__AL, __r0, __r8, 0));
470470
emit(__add_i(__AL, __r1, __r8, 4));
471-
emit(__b(__AL, MAIN_BB->elf_offset - elf_code_idx));
471+
emit(__b(__AL, MAIN_BB->elf_offset - elf_code->size));
472472

473473
for (int i = 0; i < ph2_ir_idx; i++) {
474474
ph2_ir = PH2_IR_FLATTEN[i];

0 commit comments

Comments
 (0)