Skip to content

Commit d025779

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 878f6ae commit d025779

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
@@ -125,7 +125,7 @@ void update_elf_offset(ph2_ir_t *ph2_ir)
125125
}
126126
}
127127

128-
void cfg_flatten()
128+
void cfg_flatten(void)
129129
{
130130
func_t *func = find_func("__syscall");
131131
func->bbs->elf_offset = 44; /* offset of start + exit in codegen */
@@ -427,7 +427,7 @@ void emit_ph2_ir(ph2_ir_t *ph2_ir)
427427
}
428428
}
429429

430-
void code_generate()
430+
void code_generate(void)
431431
{
432432
elf_data_start = elf_code_start + elf_offset;
433433

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
@@ -43,7 +43,7 @@ void elf_write_blk(strbuf_t *elf_array, void *blk, int sz)
4343
strbuf_putc(elf_array, ptr[i]);
4444
}
4545

46-
void elf_generate_header()
46+
void elf_generate_header(void)
4747
{
4848
elf32_hdr_t hdr;
4949
/*
@@ -169,7 +169,7 @@ void elf_generate_header()
169169
elf_write_blk(elf_header, &phdr, sizeof(elf32_phdr_t));
170170
}
171171

172-
void elf_generate_sections()
172+
void elf_generate_sections(void)
173173
{
174174
/* symtab section */
175175
for (int b = 0; b < elf_symtab->size; b++)
@@ -306,7 +306,7 @@ void elf_generate_sections()
306306
elf_write_blk(elf_section, &shdr, sizeof(elf32_shdr_t));
307307
}
308308

309-
void elf_align()
309+
void elf_align(void)
310310
{
311311
while (elf_data->size & 3)
312312
elf_write_byte(elf_data, 0);

src/globals.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ int find_macro_param_src_idx(char *name, block_t *parent)
595595
return 0;
596596
}
597597

598-
type_t *add_type()
598+
type_t *add_type(void)
599599
{
600600
return &TYPES[types_idx++];
601601
}
@@ -966,7 +966,7 @@ void strbuf_free(strbuf_t *src)
966966
/* This routine is required because the global variable initializations are
967967
* not supported now.
968968
*/
969-
void global_init()
969+
void global_init(void)
970970
{
971971
elf_code_start = ELF_START + elf_header_len;
972972

@@ -992,7 +992,7 @@ void global_init()
992992
elf_section = strbuf_create(MAX_SECTION);
993993
}
994994

995-
void global_release()
995+
void global_release(void)
996996
{
997997
while (BLOCKS.head) {
998998
block_t *next = BLOCKS.head->next;
@@ -1270,7 +1270,7 @@ void dump_bb_insn_by_dom(func_t *func, basic_block_t *bb, bool *at_func_start)
12701270
}
12711271
}
12721272

1273-
void dump_insn()
1273+
void dump_insn(void)
12741274
{
12751275
printf("==<START OF INSN DUMP>==\n");
12761276

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
@@ -52,7 +52,7 @@ void opstack_push(var_t *var)
5252
operand_stack[operand_stack_idx++] = var;
5353
}
5454

55-
var_t *opstack_pop()
55+
var_t *opstack_pop(void)
5656
{
5757
return operand_stack[--operand_stack_idx];
5858
}
@@ -123,7 +123,7 @@ int get_unary_operator_prio(opcode_t op)
123123
}
124124
}
125125

126-
opcode_t get_operator()
126+
opcode_t get_operator(void)
127127
{
128128
opcode_t op = OP_generic;
129129
if (lex_accept(T_plus))
@@ -194,7 +194,7 @@ int read_numeric_constant(char buffer[])
194194
return value;
195195
}
196196

197-
int read_constant_expr_operand()
197+
int read_constant_expr_operand(void)
198198
{
199199
char buffer[MAX_ID_LEN];
200200
int value;
@@ -326,15 +326,15 @@ int read_constant_infix_expr(int precedence)
326326
return lhs;
327327
}
328328

329-
int read_constant_expr()
329+
int read_constant_expr(void)
330330
{
331331
return read_constant_infix_expr(0);
332332
}
333333

334334
/* Skips lines where preprocessor match is false, this will stop once next
335335
* token is either 'T_cppd_elif', 'T_cppd_else' or 'cppd_endif'.
336336
*/
337-
void cppd_control_flow_skip_lines()
337+
void cppd_control_flow_skip_lines(void)
338338
{
339339
while (!lex_peek(T_cppd_elif, NULL) && !lex_peek(T_cppd_else, NULL) &&
340340
!lex_peek(T_cppd_endif, NULL)) {
@@ -349,7 +349,7 @@ void check_def(char *alias, bool expected)
349349
preproc_match = true;
350350
}
351351

352-
void read_defined_macro()
352+
void read_defined_macro(void)
353353
{
354354
char lookup_alias[MAX_TOKEN_LEN];
355355

@@ -364,7 +364,7 @@ void read_defined_macro()
364364
/* read preprocessor directive at each potential positions: e.g.,
365365
* global statement / body statement
366366
*/
367-
bool read_preproc_directive()
367+
bool read_preproc_directive(void)
368368
{
369369
char token[MAX_ID_LEN];
370370

@@ -1816,7 +1816,7 @@ bool read_body_assignment(char *token,
18161816
return false;
18171817
}
18181818

1819-
int read_primary_constant()
1819+
int read_primary_constant(void)
18201820
{
18211821
/* return signed constant */
18221822
int isneg = 0, res;
@@ -2681,7 +2681,7 @@ void read_global_decl(block_t *block)
26812681
error("Syntax error in global declaration");
26822682
}
26832683

2684-
void read_global_statement()
2684+
void read_global_statement(void)
26852685
{
26862686
char token[MAX_ID_LEN];
26872687
block_t *block = BLOCKS.head; /* global block */
@@ -2799,7 +2799,7 @@ void read_global_statement()
27992799
error("Syntax error in global statement");
28002800
}
28012801

2802-
void parse_internal()
2802+
void parse_internal(void)
28032803
{
28042804
/* set starting point of global stack manually */
28052805
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;
@@ -641,7 +641,7 @@ void reg_alloc()
641641
}
642642
}
643643

644-
void dump_ph2_ir()
644+
void dump_ph2_ir(void)
645645
{
646646
for (int i = 0; i < ph2_ir_idx; i++) {
647647
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
@@ -99,7 +99,7 @@ void update_elf_offset(ph2_ir_t *ph2_ir)
9999
}
100100
}
101101

102-
void cfg_flatten()
102+
void cfg_flatten(void)
103103
{
104104
func_t *func = find_func("__syscall");
105105
func->bbs->elf_offset = 48; /* offset of start + exit in codegen */
@@ -402,7 +402,7 @@ void emit_ph2_ir(ph2_ir_t *ph2_ir)
402402
}
403403
}
404404

405-
void code_generate()
405+
void code_generate(void)
406406
{
407407
elf_data_start = elf_code_start + elf_offset;
408408

0 commit comments

Comments
 (0)