mirror of https://github.com/rui314/chibicc
Support file-scope functions
This commit is contained in:
parent
7938157072
commit
ce61154cf5
|
@ -201,6 +201,7 @@ struct Function {
|
|||
Function *next;
|
||||
char *name;
|
||||
VarList *params;
|
||||
bool is_static;
|
||||
|
||||
Node *node;
|
||||
VarList *locals;
|
||||
|
|
|
@ -574,7 +574,8 @@ void emit_text(Program *prog) {
|
|||
printf(".text\n");
|
||||
|
||||
for (Function *fn = prog->fns; fn; fn = fn->next) {
|
||||
printf(".global %s\n", fn->name);
|
||||
if (!fn->is_static)
|
||||
printf(".global %s\n", fn->name);
|
||||
printf("%s:\n", fn->name);
|
||||
funcname = fn->name;
|
||||
|
||||
|
|
1
parse.c
1
parse.c
|
@ -575,6 +575,7 @@ Function *function() {
|
|||
// Construct a function object
|
||||
Function *fn = calloc(1, sizeof(Function));
|
||||
fn->name = name;
|
||||
fn->is_static = ty->is_static;
|
||||
expect("(");
|
||||
fn->params = read_func_params();
|
||||
|
||||
|
|
Loading…
Reference in New Issue