Skip to content

Commit e95fccc

Browse files
authored
Merge pull request #274 from sysprog21/hotfix
Fix self-hosting compilation errors
2 parents b6dd21c + 3a2da76 commit e95fccc

File tree

13 files changed

+141
-13
lines changed

13 files changed

+141
-13
lines changed

src/arch-lower.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
void arm_lower(void)
1818
{
1919
for (func_t *func = FUNC_LIST.head; func; func = func->next) {
20+
/* Skip function declarations without bodies */
21+
if (!func->bbs)
22+
continue;
23+
2024
for (basic_block_t *bb = func->bbs; bb; bb = bb->rpo_next) {
2125
for (ph2_ir_t *insn = bb->ph2_ir_list.head; insn;
2226
insn = insn->next) {
@@ -37,6 +41,10 @@ void arm_lower(void)
3741
void riscv_lower(void)
3842
{
3943
for (func_t *func = FUNC_LIST.head; func; func = func->next) {
44+
/* Skip function declarations without bodies */
45+
if (!func->bbs)
46+
continue;
47+
4048
for (basic_block_t *bb = func->bbs; bb; bb = bb->rpo_next) {
4149
for (ph2_ir_t *insn = bb->ph2_ir_list.head; insn;
4250
insn = insn->next) {

src/arm-codegen.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ void cfg_flatten(void)
151151
elf_offset += 32; /* 6 insns for main call + 2 for exit */
152152

153153
for (func = FUNC_LIST.head; func; func = func->next) {
154+
/* Skip function declarations without bodies */
155+
if (!func->bbs)
156+
continue;
157+
154158
/* reserve stack */
155159
ph2_ir_t *flatten_ir = add_ph2_ir(OP_define);
156160
flatten_ir->src0 = func->stack_size;

src/defs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#define MAX_BB_DOM_SUCC 64
2626
#define MAX_BB_RDOM_SUCC 256
2727
#define MAX_GLOBAL_IR 256
28-
#define MAX_SOURCE 524288
28+
#define MAX_SOURCE 1048576
2929
#define MAX_CODE 262144
3030
#define MAX_DATA 262144
3131
#define MAX_SYMTAB 65536

src/globals.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,19 @@ strbuf_t *SOURCE;
9191
hashmap_t *INCLUSION_MAP;
9292

9393
/* ELF sections */
94-
strbuf_t *elf_code, *elf_data;
94+
strbuf_t *elf_code;
95+
strbuf_t *elf_data;
9596
strbuf_t *elf_rodata;
9697
strbuf_t *elf_header;
9798
strbuf_t *elf_symtab;
9899
strbuf_t *elf_strtab;
99100
strbuf_t *elf_section;
100101
int elf_header_len = 0x54; /* ELF fixed: 0x34 + 1 * 0x20 */
101-
int elf_code_start, elf_data_start;
102+
int elf_code_start;
103+
int elf_data_start;
102104
int elf_rodata_start;
103-
int elf_bss_start, elf_bss_size;
105+
int elf_bss_start;
106+
int elf_bss_size;
104107

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

348351
void arena_free(arena_t *arena)
349352
{
350-
arena_block_t *block = arena->head, *next;
353+
arena_block_t *block = arena->head;
354+
arena_block_t *next;
351355

352356
while (block) {
353357
next = block->next;
@@ -472,7 +476,9 @@ void hashmap_rehash(hashmap_t *map)
472476
}
473477

474478
for (int i = 0; i < old_cap; i++) {
475-
hashmap_node_t *cur = old_buckets[i], *next, *target_cur;
479+
hashmap_node_t *cur = old_buckets[i];
480+
hashmap_node_t *next;
481+
hashmap_node_t *target_cur;
476482

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

16511657
for (func_t *func = FUNC_LIST.head; func; func = func->next) {
1658+
/* Skip function declarations without bodies */
1659+
if (!func->bbs)
1660+
continue;
1661+
16521662
bool at_func_start = true;
16531663

16541664
printf("def %s", func->return_def.type->type_name);

src/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
int main(int argc, char *argv[])
5050
{
5151
bool libc = true;
52-
char *out = NULL, *in = NULL;
52+
char *out = NULL;
53+
char *in = NULL;
5354

5455
for (int i = 1; i < argc; i++) {
5556
if (!strcmp(argv[i], "--dump-ir"))

src/peephole.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,10 @@ bool triple_pattern_optimization(ph2_ir_t *ph2_ir)
878878
void peephole(void)
879879
{
880880
for (func_t *func = FUNC_LIST.head; func; func = func->next) {
881+
/* Skip function declarations without bodies */
882+
if (!func->bbs)
883+
continue;
884+
881885
/* Local peephole optimizations on post-register-allocation IR */
882886
for (basic_block_t *bb = func->bbs; bb; bb = bb->rpo_next) {
883887
for (ph2_ir_t *ir = bb->ph2_ir_list.head; ir; ir = ir->next) {

src/reg-alloc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,10 @@ void reg_alloc(void)
521521
}
522522

523523
for (func_t *func = FUNC_LIST.head; func; func = func->next) {
524+
/* Skip function declarations without bodies */
525+
if (!func->bbs)
526+
continue;
527+
524528
func->visited++;
525529

526530
if (!strcmp(func->return_def.var_name, "main"))

src/riscv-codegen.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ void cfg_flatten(void)
127127
elf_offset += 24;
128128

129129
for (func = FUNC_LIST.head; func; func = func->next) {
130+
/* Skip function declarations without bodies */
131+
if (!func->bbs)
132+
continue;
133+
130134
/* reserve stack */
131135
ph2_ir_t *flatten_ir = add_ph2_ir(OP_define);
132136
flatten_ir->src0 = func->stack_size;

0 commit comments

Comments
 (0)