summaryrefslogtreecommitdiff
path: root/6/gen.c
diff options
context:
space:
mode:
Diffstat (limited to '6/gen.c')
-rw-r--r--6/gen.c220
1 files changed, 110 insertions, 110 deletions
diff --git a/6/gen.c b/6/gen.c
index 5290e6d..608ca66 100644
--- a/6/gen.c
+++ b/6/gen.c
@@ -17,88 +17,88 @@
void fillglobls(Stab *st, Htab *globls)
{
- size_t i, j, nk, nns;
- void **k, **ns;
- Stab *stab;
- Node *s;
-
- k = htkeys(st->dcl, &nk);
- for (i = 0; i < nk; i++) {
- s = htget(st->dcl, k[i]);
- if (isconstfn(s))
- s->decl.type = codetype(s->decl.type);
- htput(globls, s, asmname(s));
- }
- free(k);
-
- ns = htkeys(file->file.ns, &nns);
- for (j = 0; j < nns; j++) {
- stab = htget(file->file.ns, ns[j]);
- k = htkeys(stab->dcl, &nk);
- for (i = 0; i < nk; i++) {
- s = htget(stab->dcl, k[i]);
- htput(globls, s, asmname(s));
- }
- free(k);
- }
- free(ns);
+ size_t i, j, nk, nns;
+ void **k, **ns;
+ Stab *stab;
+ Node *s;
+
+ k = htkeys(st->dcl, &nk);
+ for (i = 0; i < nk; i++) {
+ s = htget(st->dcl, k[i]);
+ if (isconstfn(s))
+ s->decl.type = codetype(s->decl.type);
+ htput(globls, s, asmname(s));
+ }
+ free(k);
+
+ ns = htkeys(file->file.ns, &nns);
+ for (j = 0; j < nns; j++) {
+ stab = htget(file->file.ns, ns[j]);
+ k = htkeys(stab->dcl, &nk);
+ for (i = 0; i < nk; i++) {
+ s = htget(stab->dcl, k[i]);
+ htput(globls, s, asmname(s));
+ }
+ free(k);
+ }
+ free(ns);
}
Type *codetype(Type *ft)
{
- ft = tybase(ft);
- if (ft->type == Tycode)
- return ft;
- assert(ft->type == Tyfunc);
- ft = tydup(ft);
- ft->type = Tycode;
- return ft;
+ ft = tybase(ft);
+ if (ft->type == Tycode)
+ return ft;
+ assert(ft->type == Tyfunc);
+ ft = tydup(ft);
+ ft->type = Tycode;
+ return ft;
}
Type *closuretype(Type *ft)
{
- ft = tybase(ft);
- if (ft->type == Tyfunc)
- return ft;
- assert(ft->type == Tycode);
- ft = tydup(ft);
- ft->type = Tyfunc;
- return ft;
+ ft = tybase(ft);
+ if (ft->type == Tyfunc)
+ return ft;
+ assert(ft->type == Tycode);
+ ft = tydup(ft);
+ ft->type = Tyfunc;
+ return ft;
}
static int islocal(Node *dcl)
{
- if (dcl->decl.vis != Visintern)
- return 0;
- if (dcl->decl.isimport || dcl->decl.isextern)
- return 0;
- return 1;
+ if (dcl->decl.vis != Visintern)
+ return 0;
+ if (dcl->decl.isimport || dcl->decl.isextern)
+ return 0;
+ return 1;
}
char *genlocallblstr(char *buf, size_t sz)
{
- if (asmsyntax == Plan9)
- return genlblstr(buf, 128, "<>");
- else
- return genlblstr(buf, 128, "");
+ if (asmsyntax == Plan9)
+ return genlblstr(buf, 128, "<>");
+ else
+ return genlblstr(buf, 128, "");
}
int isconstfn(Node *n)
{
- Node *d;
- Type *t;
-
- if (n->type == Nexpr) {
- if (exprop(n) != Ovar)
- return 0;
- d = decls[n->expr.did];
- } else {
- d = n;
- }
- t = tybase(decltype(d));
- if (d && d->decl.isconst && d->decl.isglobl)
- return t->type == Tyfunc || t->type == Tycode;
- return 0;
+ Node *d;
+ Type *t;
+
+ if (n->type == Nexpr) {
+ if (exprop(n) != Ovar)
+ return 0;
+ d = decls[n->expr.did];
+ } else {
+ d = n;
+ }
+ t = tybase(decltype(d));
+ if (d && d->decl.isconst && d->decl.isglobl)
+ return t->type == Tyfunc || t->type == Tycode;
+ return 0;
}
/*
@@ -110,60 +110,60 @@ int isconstfn(Node *n)
*/
char *asmname(Node *dcl)
{
- char buf[1024];
- char *vis, *pf, *ns, *name, *sep;
- Node *n;
-
- n = dcl->decl.name;
- pf = Symprefix;
- ns = n->name.ns;
- name = n->name.name;
- vis = "";
- sep = "";
- if (asmsyntax == Plan9)
- if (islocal(dcl))
- vis = "<>";
- if (!ns || !ns[0])
- ns = "";
- else
- sep = "$";
- if (name[0] == '.')
- pf = "";
-
- bprintf(buf, sizeof buf, "%s%s%s%s%s", pf, ns, sep, name, vis);
- return strdup(buf);
+ char buf[1024];
+ char *vis, *pf, *ns, *name, *sep;
+ Node *n;
+
+ n = dcl->decl.name;
+ pf = Symprefix;
+ ns = n->name.ns;
+ name = n->name.name;
+ vis = "";
+ sep = "";
+ if (asmsyntax == Plan9)
+ if (islocal(dcl))
+ vis = "<>";
+ if (!ns || !ns[0])
+ ns = "";
+ else
+ sep = "$";
+ if (name[0] == '.')
+ pf = "";
+
+ bprintf(buf, sizeof buf, "%s%s%s%s%s", pf, ns, sep, name, vis);
+ return strdup(buf);
}
char *tydescid(char *buf, size_t bufsz, Type *ty)
{
- char *sep, *ns;
-
- sep = "";
- ns = "";
- if (ty->type == Tyname) {
- if (ty->name->name.ns) {
- ns = ty->name->name.ns;
- sep = "$";
- }
- if (ty->vis == Visexport || ty->isimport)
- bprintf(buf, bufsz, "_tydesc$%s%s%s", ns, sep, ty->name->name.name);
- else
- bprintf(buf, bufsz, "_tydesc$%s%s%s$%d", ns, sep, ty->name->name.name, ty->tid);
- } else {
- if (file->file.globls->name) {
- ns = file->file.globls->name;
- sep = "$";
- }
- bprintf(buf, bufsz, "_tydesc%s%s$%d",sep, ns, ty->tid);
- }
- return buf;
+ char *sep, *ns;
+
+ sep = "";
+ ns = "";
+ if (ty->type == Tyname) {
+ if (ty->name->name.ns) {
+ ns = ty->name->name.ns;
+ sep = "$";
+ }
+ if (ty->vis == Visexport || ty->isimport)
+ bprintf(buf, bufsz, "_tydesc$%s%s%s", ns, sep, ty->name->name.name);
+ else
+ bprintf(buf, bufsz, "_tydesc$%s%s%s$%d", ns, sep, ty->name->name.name, ty->tid);
+ } else {
+ if (file->file.globls->name) {
+ ns = file->file.globls->name;
+ sep = "$";
+ }
+ bprintf(buf, bufsz, "_tydesc%s%s$%d",sep, ns, ty->tid);
+ }
+ return buf;
}
void gen(Node *file, char *out)
{
- switch (asmsyntax) {
- case Plan9: genp9(file, out); break;
- case Gnugas: gengas(file, out); break;
- default: die("unknown target"); break;
- }
+ switch (asmsyntax) {
+ case Plan9: genp9(file, out); break;
+ case Gnugas: gengas(file, out); break;
+ default: die("unknown target"); break;
+ }
}