Skip to content

Commit fb762cd

Browse files
committed
Use explicit "void" parameter instead
Adds the keyword "void" to the parameter lists of functions. This helps validation of the implementation of "void" parameter lists in the bootstrapping process. Especially K&R style exists until C23, though it's not implemented in shecc now, shecc is first built by another compiler such as gcc and is written in C99 (as per Makefile). Suggested-by: Yu-En Hsiao <[email protected]>
1 parent e539092 commit fb762cd

File tree

12 files changed

+52
-52
lines changed

12 files changed

+52
-52
lines changed

lib/c.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
typedef int FILE;
4747

48-
void abort();
48+
void abort(void);
4949

5050
int strlen(char *str)
5151
{
@@ -458,15 +458,15 @@ int snprintf(char *buffer, int n, char *str, ...)
458458
return fmtbuf.len;
459459
}
460460

461-
int __free_all();
461+
int __free_all(void);
462462

463463
void exit(int exit_code)
464464
{
465465
__free_all();
466466
__syscall(__syscall_exit, exit_code);
467467
}
468468

469-
void abort()
469+
void abort(void)
470470
{
471471
printf("Abnormal program termination\n");
472472
exit(-1);
@@ -698,7 +698,7 @@ void __rfree(void *ptr, int size)
698698
__syscall(__syscall_munmap, ptr, size);
699699
}
700700

701-
int __free_all()
701+
int __free_all(void)
702702
{
703703
if (!__freelist_head && !__alloc_head)
704704
return 0;

src/arm-codegen.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ void update_elf_offset(ph2_ir_t *ph2_ir)
130130
}
131131
}
132132

133-
void cfg_flatten()
133+
void cfg_flatten(void)
134134
{
135135
func_t *func = find_func("__syscall");
136136
func->bbs->elf_offset = 44; /* offset of start + exit in codegen */
@@ -447,7 +447,7 @@ void emit_ph2_ir(ph2_ir_t *ph2_ir)
447447
}
448448
}
449449

450-
void code_generate()
450+
void code_generate(void)
451451
{
452452
elf_data_start = elf_code_start + elf_offset;
453453

src/arm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ int arm_encode(arm_cond_t cond, int opcode, int rn, int rd, int op2)
126126
return (cond << 28) + (opcode << 20) + (rn << 16) + (rd << 12) + op2;
127127
}
128128

129-
int __svc()
129+
int __svc(void)
130130
{
131131
return arm_encode(__AL, 240, 0, 0, 0);
132132
}

src/elf.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void elf_write_blk(strbuf_t *elf_array, void *blk, int sz)
4747
strbuf_putc(elf_array, ptr[i]);
4848
}
4949

50-
void elf_generate_header()
50+
void elf_generate_header(void)
5151
{
5252
elf32_hdr_t hdr;
5353
/*
@@ -173,7 +173,7 @@ void elf_generate_header()
173173
elf_write_blk(elf_header, &phdr, sizeof(elf32_phdr_t));
174174
}
175175

176-
void elf_generate_sections()
176+
void elf_generate_sections(void)
177177
{
178178
/* symtab section */
179179
for (int b = 0; b < elf_symtab->size; b++)
@@ -310,7 +310,7 @@ void elf_generate_sections()
310310
elf_write_blk(elf_section, &shdr, sizeof(elf32_shdr_t));
311311
}
312312

313-
void elf_align()
313+
void elf_align(void)
314314
{
315315
while (elf_data->size & 3)
316316
elf_write_byte(elf_data, 0);

src/globals.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ int find_macro_param_src_idx(char *name, block_t *parent)
600600
return 0;
601601
}
602602

603-
type_t *add_type()
603+
type_t *add_type(void)
604604
{
605605
return &TYPES[types_idx++];
606606
}
@@ -970,7 +970,7 @@ void strbuf_free(strbuf_t *src)
970970
/* This routine is required because the global variable initializations are
971971
* not supported now.
972972
*/
973-
void global_init()
973+
void global_init(void)
974974
{
975975
elf_code_start = ELF_START + elf_header_len;
976976

@@ -994,7 +994,7 @@ void global_init()
994994
elf_section = strbuf_create(MAX_SECTION);
995995
}
996996

997-
void global_release()
997+
void global_release(void)
998998
{
999999
free(MACROS);
10001000
free(TYPES);
@@ -1286,7 +1286,7 @@ void dump_bb_insn_by_dom(func_t *func, basic_block_t *bb, bool *at_func_start)
12861286
}
12871287
}
12881288

1289-
void dump_insn()
1289+
void dump_insn(void)
12901290
{
12911291
printf("==<START OF INSN DUMP>==\n");
12921292

src/lexer.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ bool is_numeric(char buffer[])
6363
return true;
6464
}
6565

66-
void skip_whitespace()
66+
void skip_whitespace(void)
6767
{
6868
while (true) {
6969
if (is_linebreak(next_char)) {
@@ -533,13 +533,13 @@ token_t lex_token_internal(bool aliasing)
533533
/* Lex next token and returns its token type. To disable aliasing on next
534534
* token, use 'lex_token_internal'.
535535
*/
536-
token_t lex_token()
536+
token_t lex_token(void)
537537
{
538538
return lex_token_internal(true);
539539
}
540540

541541
/* Skip the content. We only need the index where the macro body begins. */
542-
void skip_macro_body()
542+
void skip_macro_body(void)
543543
{
544544
while (!is_newline(next_char))
545545
next_token = lex_token();

src/parser.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void opstack_push(var_t *var)
108108
operand_stack[operand_stack_idx++] = var;
109109
}
110110

111-
var_t *opstack_pop()
111+
var_t *opstack_pop(void)
112112
{
113113
return operand_stack[--operand_stack_idx];
114114
}
@@ -179,7 +179,7 @@ int get_unary_operator_prio(opcode_t op)
179179
}
180180
}
181181

182-
opcode_t get_operator()
182+
opcode_t get_operator(void)
183183
{
184184
opcode_t op = OP_generic;
185185
if (lex_accept(T_plus))
@@ -317,7 +317,7 @@ int read_numeric_constant(char buffer[])
317317
return value;
318318
}
319319

320-
int read_constant_expr_operand()
320+
int read_constant_expr_operand(void)
321321
{
322322
char buffer[MAX_ID_LEN];
323323
int value;
@@ -449,15 +449,15 @@ int read_constant_infix_expr(int precedence)
449449
return lhs;
450450
}
451451

452-
int read_constant_expr()
452+
int read_constant_expr(void)
453453
{
454454
return read_constant_infix_expr(0);
455455
}
456456

457457
/* Skips lines where preprocessor match is false, this will stop once next
458458
* token is either 'T_cppd_elif', 'T_cppd_else' or 'cppd_endif'.
459459
*/
460-
void cppd_control_flow_skip_lines()
460+
void cppd_control_flow_skip_lines(void)
461461
{
462462
while (!lex_peek(T_cppd_elif, NULL) && !lex_peek(T_cppd_else, NULL) &&
463463
!lex_peek(T_cppd_endif, NULL)) {
@@ -472,7 +472,7 @@ void check_def(char *alias, bool expected)
472472
preproc_match = true;
473473
}
474474

475-
void read_defined_macro()
475+
void read_defined_macro(void)
476476
{
477477
char lookup_alias[MAX_TOKEN_LEN];
478478

@@ -487,7 +487,7 @@ void read_defined_macro()
487487
/* read preprocessor directive at each potential positions: e.g.,
488488
* global statement / body statement
489489
*/
490-
bool read_preproc_directive()
490+
bool read_preproc_directive(void)
491491
{
492492
char token[MAX_ID_LEN];
493493

@@ -1969,7 +1969,7 @@ bool read_body_assignment(char *token,
19691969
return false;
19701970
}
19711971

1972-
int read_primary_constant()
1972+
int read_primary_constant(void)
19731973
{
19741974
/* return signed constant */
19751975
int isneg = 0, res;
@@ -2834,7 +2834,7 @@ void read_global_decl(block_t *block)
28342834
error("Syntax error in global declaration");
28352835
}
28362836

2837-
void read_global_statement()
2837+
void read_global_statement(void)
28382838
{
28392839
char token[MAX_ID_LEN];
28402840
block_t *block = GLOBAL_BLOCK; /* global block */
@@ -2953,7 +2953,7 @@ void read_global_statement()
29532953
error("Syntax error in global statement");
29542954
}
29552955

2956-
void parse_internal()
2956+
void parse_internal(void)
29572957
{
29582958
/* set starting point of global stack manually */
29592959
GLOBAL_FUNC = add_func("", true);

src/peephole.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ bool insn_fusion(ph2_ir_t *ph2_ir)
146146
return false;
147147
}
148148

149-
void peephole()
149+
void peephole(void)
150150
{
151151
for (func_t *func = FUNC_LIST.head; func; func = func->next) {
152152
for (basic_block_t *bb = func->bbs; bb; bb = bb->rpo_next) {

src/reg-alloc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ void extend_liveness(basic_block_t *bb, insn_t *insn, var_t *var, int offset)
240240
var->consumed = insn->idx + offset;
241241
}
242242

243-
void reg_alloc()
243+
void reg_alloc(void)
244244
{
245245
/* TODO: .bss and .data section */
246246
for (insn_t *global_insn = GLOBAL_FUNC->bbs->insn_list.head; global_insn;
@@ -649,7 +649,7 @@ void reg_alloc()
649649
}
650650
}
651651

652-
void dump_ph2_ir()
652+
void dump_ph2_ir(void)
653653
{
654654
for (int i = 0; i < ph2_ir_idx; i++) {
655655
ph2_ir_t *ph2_ir = PH2_IR_FLATTEN[i];

src/riscv-codegen.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void update_elf_offset(ph2_ir_t *ph2_ir)
104104
}
105105
}
106106

107-
void cfg_flatten()
107+
void cfg_flatten(void)
108108
{
109109
func_t *func = find_func("__syscall");
110110
func->bbs->elf_offset = 48; /* offset of start + exit in codegen */
@@ -426,7 +426,7 @@ void emit_ph2_ir(ph2_ir_t *ph2_ir)
426426
}
427427
}
428428

429-
void code_generate()
429+
void code_generate(void)
430430
{
431431
elf_data_start = elf_code_start + elf_offset;
432432

0 commit comments

Comments
 (0)