diff options
| author | Xavier Del Campo Romero <xavi92@disroot.org> | 2026-10-01 01:04:30 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi92@disroot.org> | 2026-10-11 00:14:35 +0200 |
| commit | 4ce39e4fc1de9536de7dedfe91b6dee38dec76ae (patch) | |
| tree | f9820f96b8eab624430c3700f32a2878a7036ee2 /src/prc1/cgen/global.c | |
| parent | 9140988be4e5bb028b7140aca1a67af1370c72a7 (diff) | |
| download | prc-4ce39e4fc1de9536de7dedfe91b6dee38dec76ae.tar.gz | |
WIP sym + cgen
Diffstat (limited to 'src/prc1/cgen/global.c')
| -rw-r--r-- | src/prc1/cgen/global.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/prc1/cgen/global.c b/src/prc1/cgen/global.c new file mode 100644 index 0000000..6371b96 --- /dev/null +++ b/src/prc1/cgen/global.c @@ -0,0 +1,32 @@ +#include "cgen.h" +#include <string.h> + +int cgen_global(const struct fn *fn, const struct stentry *e) +{ + const struct storage *ws = fn->ws, *gl = fn->gl; + const struct pr *pr = fn->pr; + const struct param *ret = pr->ret; + const char *name = e->tk->s; + + /* A variable is only global if it is defined inside the global + * variables section ("gl"), or if it is not listed on the working + * storage section ("ws"), as a function parameter or a return value. */ + + if (gl) + for (size_t i = 0; i < gl->nentries; i++) + if (!strcmp(gl->entries[i].tk->s, name)) + return 1; + + if (cgen_param(fn, e) || (ret && !strcmp(ret->tk->s, name))) + return 0; + else if (ws) + for (size_t i = 0; i < ws->nentries; i++) + if (!strcmp(ws->entries[i].tk->s, name)) + return 0; + + for (const struct tmp *t = fn->tmps; t; t = t->next) + if (!strcmp(t->tk.s, name)) + return 0; + + return 1; +} |
