#include "cgen.h" #include 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; }