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;
|
Function *next;
|
||||||
char *name;
|
char *name;
|
||||||
VarList *params;
|
VarList *params;
|
||||||
|
bool is_static;
|
||||||
|
|
||||||
Node *node;
|
Node *node;
|
||||||
VarList *locals;
|
VarList *locals;
|
||||||
|
|
|
@ -574,7 +574,8 @@ void emit_text(Program *prog) {
|
||||||
printf(".text\n");
|
printf(".text\n");
|
||||||
|
|
||||||
for (Function *fn = prog->fns; fn; fn = fn->next) {
|
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);
|
printf("%s:\n", fn->name);
|
||||||
funcname = fn->name;
|
funcname = fn->name;
|
||||||
|
|
||||||
|
|
1
parse.c
1
parse.c
|
@ -575,6 +575,7 @@ Function *function() {
|
||||||
// Construct a function object
|
// Construct a function object
|
||||||
Function *fn = calloc(1, sizeof(Function));
|
Function *fn = calloc(1, sizeof(Function));
|
||||||
fn->name = name;
|
fn->name = name;
|
||||||
|
fn->is_static = ty->is_static;
|
||||||
expect("(");
|
expect("(");
|
||||||
fn->params = read_func_params();
|
fn->params = read_func_params();
|
||||||
|
|
||||||
|
|
2
tests
2
tests
|
@ -96,6 +96,8 @@ int param_decay(int x[]) { return x[0]; }
|
||||||
|
|
||||||
void voidfn(void) {}
|
void voidfn(void) {}
|
||||||
|
|
||||||
|
static int static_fn(void) {}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
assert(8, ({ int a=3; int z=5; a+z; }), "int a=3; int z=5; a+z;");
|
assert(8, ({ int a=3; int z=5; a+z; }), "int a=3; int z=5; a+z;");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue