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
8 changes: 8 additions & 0 deletions src/arch-lower.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
void arm_lower(void)
{
for (func_t *func = FUNC_LIST.head; func; func = func->next) {
/* Skip function declarations without bodies */
if (!func->bbs)
continue;

for (basic_block_t *bb = func->bbs; bb; bb = bb->rpo_next) {
for (ph2_ir_t *insn = bb->ph2_ir_list.head; insn;
insn = insn->next) {
Expand All @@ -37,6 +41,10 @@ void arm_lower(void)
void riscv_lower(void)
{
for (func_t *func = FUNC_LIST.head; func; func = func->next) {
/* Skip function declarations without bodies */
if (!func->bbs)
continue;

for (basic_block_t *bb = func->bbs; bb; bb = bb->rpo_next) {
for (ph2_ir_t *insn = bb->ph2_ir_list.head; insn;
insn = insn->next) {
Expand Down
4 changes: 4 additions & 0 deletions src/arm-codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ void cfg_flatten(void)
elf_offset += 32; /* 6 insns for main call + 2 for exit */

for (func = FUNC_LIST.head; func; func = func->next) {
/* Skip function declarations without bodies */
if (!func->bbs)
continue;

/* reserve stack */
ph2_ir_t *flatten_ir = add_ph2_ir(OP_define);
flatten_ir->src0 = func->stack_size;
Expand Down
2 changes: 1 addition & 1 deletion src/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#define MAX_BB_DOM_SUCC 64
#define MAX_BB_RDOM_SUCC 256
#define MAX_GLOBAL_IR 256
#define MAX_SOURCE 524288
#define MAX_SOURCE 1048576
#define MAX_CODE 262144
#define MAX_DATA 262144
#define MAX_SYMTAB 65536
Expand Down
20 changes: 15 additions & 5 deletions src/globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,19 @@ strbuf_t *SOURCE;
hashmap_t *INCLUSION_MAP;

/* ELF sections */
strbuf_t *elf_code, *elf_data;
strbuf_t *elf_code;
strbuf_t *elf_data;
strbuf_t *elf_rodata;
strbuf_t *elf_header;
strbuf_t *elf_symtab;
strbuf_t *elf_strtab;
strbuf_t *elf_section;
int elf_header_len = 0x54; /* ELF fixed: 0x34 + 1 * 0x20 */
int elf_code_start, elf_data_start;
int elf_code_start;
int elf_data_start;
int elf_rodata_start;
int elf_bss_start, elf_bss_size;
int elf_bss_start;
int elf_bss_size;

/* Create a new arena block with given capacity.
* @capacity: The capacity of the arena block. Must be positive.
Expand Down Expand Up @@ -347,7 +350,8 @@ bb_traversal_args_t *arena_alloc_traversal_args(void)

void arena_free(arena_t *arena)
{
arena_block_t *block = arena->head, *next;
arena_block_t *block = arena->head;
arena_block_t *next;

while (block) {
next = block->next;
Expand Down Expand Up @@ -472,7 +476,9 @@ void hashmap_rehash(hashmap_t *map)
}

for (int i = 0; i < old_cap; i++) {
hashmap_node_t *cur = old_buckets[i], *next, *target_cur;
hashmap_node_t *cur = old_buckets[i];
hashmap_node_t *next;
hashmap_node_t *target_cur;

while (cur) {
next = cur->next;
Expand Down Expand Up @@ -1649,6 +1655,10 @@ void dump_insn(void)
printf("==<START OF INSN DUMP>==\n");

for (func_t *func = FUNC_LIST.head; func; func = func->next) {
/* Skip function declarations without bodies */
if (!func->bbs)
continue;

bool at_func_start = true;

printf("def %s", func->return_def.type->type_name);
Expand Down
3 changes: 2 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
int main(int argc, char *argv[])
{
bool libc = true;
char *out = NULL, *in = NULL;
char *out = NULL;
char *in = NULL;

for (int i = 1; i < argc; i++) {
if (!strcmp(argv[i], "--dump-ir"))
Expand Down
4 changes: 4 additions & 0 deletions src/peephole.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,10 @@ bool triple_pattern_optimization(ph2_ir_t *ph2_ir)
void peephole(void)
{
for (func_t *func = FUNC_LIST.head; func; func = func->next) {
/* Skip function declarations without bodies */
if (!func->bbs)
continue;

/* Local peephole optimizations on post-register-allocation IR */
for (basic_block_t *bb = func->bbs; bb; bb = bb->rpo_next) {
for (ph2_ir_t *ir = bb->ph2_ir_list.head; ir; ir = ir->next) {
Expand Down
4 changes: 4 additions & 0 deletions src/reg-alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,10 @@ void reg_alloc(void)
}

for (func_t *func = FUNC_LIST.head; func; func = func->next) {
/* Skip function declarations without bodies */
if (!func->bbs)
continue;

func->visited++;

if (!strcmp(func->return_def.var_name, "main"))
Expand Down
4 changes: 4 additions & 0 deletions src/riscv-codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ void cfg_flatten(void)
elf_offset += 24;

for (func = FUNC_LIST.head; func; func = func->next) {
/* Skip function declarations without bodies */
if (!func->bbs)
continue;

/* reserve stack */
ph2_ir_t *flatten_ir = add_ph2_ir(OP_define);
flatten_ir->src0 = func->stack_size;
Expand Down
Loading