summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-03-19 22:59:17 -0700
committerOri Bernstein <ori@eigenstate.org>2015-03-19 23:13:58 -0700
commit2fecc0b35b964469479c81cab2ebf5359f2bab89 (patch)
tree5e7b0e8f1bf6c7f236c19d6934e402e7968b858e
parenta252f51ddd3d85944a26a2f84e5d885eed504b98 (diff)
downloadmc-2fecc0b35b964469479c81cab2ebf5359f2bab89.tar.gz
Generate type descriptions for various types.
On our way to sane printf()!
-rw-r--r--6/gengas.c29
-rw-r--r--parse/gram.y1
-rw-r--r--parse/infer.c7
-rw-r--r--parse/parse.h3
-rw-r--r--parse/specialize.c1
5 files changed, 24 insertions, 17 deletions
diff --git a/6/gengas.c b/6/gengas.c
index 17215e5..0cddd57 100644
--- a/6/gengas.c
+++ b/6/gengas.c
@@ -506,17 +506,17 @@ static char *tydescid(char *buf, size_t bufsz, Type *ty)
static void genstructmemb(FILE *fd, Node *sdecl)
{
- fprintf(fd, ".ascii \"%s\" /* struct member */\n", namestr(sdecl->decl.name));
+ fprintf(fd, "\t.ascii \"%s\" /* struct member */\n", namestr(sdecl->decl.name));
gentydesc(fd, sdecl->decl.type);
}
static void genunionmemb(FILE *fd, Ucon *ucon)
{
- fprintf(fd, ".ascii \"%s\" /* union constructor */\n", namestr(ucon->name));
+ fprintf(fd, "\t.ascii \"%s\" /* union constructor */\n", namestr(ucon->name));
if (ucon->etype)
gentydesc(fd, ucon->etype);
else
- fprintf(fd, ".byte %d /* no union type */\n", Tybad);
+ fprintf(fd, "\t.byte %d /* no union type */\n", Tybad);
}
/* on x86, unaligned pointers are cheap. we shouldn't be introspecting too
@@ -528,7 +528,7 @@ static void gentydesc(FILE *fd, Type *ty)
Node *sz;
size_t i;
- fprintf(fd, ".byte %d /* type: %s */\n", ty->type, tidstr[ty->type]);
+ fprintf(fd, "\t.byte %d\n", ty->type);
switch (ty->type) {
case Ntypes: case Tyvar: case Tybad: case Typaram:
case Tygeneric: case Tyunres:
@@ -554,15 +554,15 @@ static void gentydesc(FILE *fd, Type *ty)
assert(sz->type == Nexpr);
sz = sz->expr.args[0];
assert(sz->type == Nlit && sz->lit.littype == Lint);
- fprintf(fd, ".quad %lld /* array size */\n", (vlong)sz->lit.intval);
+ fprintf(fd, "\t.quad %lld /* array size */\n", (vlong)sz->lit.intval);
} else {
- fprintf(fd, ".quad -1 /* array size */\n");
+ fprintf(fd, "\t.quad -1 /* array size */\n");
}
gentydesc(fd, ty->sub[0]);
break;
case Tyfunc:
- fprintf(fd, ".byte %zd /* nargs + ret */\n", ty->nsub);
+ fprintf(fd, "\t.byte %zd /* nargs + ret */\n", ty->nsub);
for (i = 0; i < ty->nsub; i++)
gentydesc(fd, ty->sub[i]);
break;
@@ -579,7 +579,7 @@ static void gentydesc(FILE *fd, Type *ty)
genunionmemb(fd, ty->udecls[i]);
break;
case Tyname:
- fprintf(fd, ".quad %s\n", tydescid(buf, sizeof buf, ty));
+ fprintf(fd, "\t.quad %s\n", tydescid(buf, sizeof buf, ty));
break;
}
}
@@ -593,7 +593,7 @@ void gentype(FILE *fd, Type *ty)
return;
tydescid(buf, sizeof buf, ty);
if (ty->vis == Visexport)
- fprintf(fd, ".globl %s\n", buf);
+ fprintf(fd, ".globl %s /* tid: %d */\n", buf, ty->tid);
fprintf(fd, "%s:\n", buf);
gentydesc(fd, ty->sub[0]);
} else {
@@ -651,11 +651,18 @@ void gengas(Node *file, char *out)
fprintf(fd, ".data\n");
for (i = 0; i < nblob; i++)
genblob(fd, blob[i], globls, strtab);
+ fprintf(fd, "\n");
+
fprintf(fd, ".text\n");
for (i = 0; i < nfn; i++)
genfunc(fd, fn[i], globls, strtab);
- for (i = 0; i < file->file.ntydefs; i++)
- gentype(fd, file->file.tydefs[i]);
+ fprintf(fd, "\n");
+
+ for (i = 0; i < ntypes; i++)
+ if (types[i]->isreflect && !types[i]->isimport)
+ gentype(fd, types[i]);
+ fprintf(fd, "\n");
+
genstrings(fd, strtab);
fclose(fd);
}
diff --git a/parse/gram.y b/parse/gram.y
index 6a4ca0c..8190e9c 100644
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -406,7 +406,6 @@ tydef : Ttype typeid {$$ = $2;}
$$ = $2;
if ($$.nparams == 0) {
$$.type = mktyname($2.loc, mkname($2.loc, $2.name), $4);
- lappend(&file->file.tydefs, &file->file.ntydefs, $$.type);
} else {
$$.type = mktygeneric($2.loc, mkname($2.loc, $2.name), $2.params, $2.nparams, $4);
}
diff --git a/parse/infer.c b/parse/infer.c
index f866a8c..1163a1d 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -2010,6 +2010,7 @@ static void taghidden(Type *t)
taghidden(t->udecls[i]->etype);
break;
case Tyname:
+ t->isreflect = 1;
for (i = 0; i < t->narg; i++)
taghidden(t->arg[i]);
case Tygeneric:
@@ -2167,12 +2168,14 @@ void tagexports(Stab *st, int hidelocal)
taghidden(t);
for (j = 0; j < t->nsub; j++)
taghidden(t->sub[j]);
- if (t->type == Tyname)
+ if (t->type == Tyname) {
+ t->isreflect = 1;
for (j = 0; j < t->narg; j++)
taghidden(t->arg[j]);
- if (t->type == Tygeneric)
+ } else if (t->type == Tygeneric) {
for (j = 0; j < t->ngparam; j++)
taghidden(t->gparam[j]);
+ }
}
free(k);
diff --git a/parse/parse.h b/parse/parse.h
index 7225803..08d9057 100644
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -171,6 +171,7 @@ struct Type {
char ishidden; /* Tyname: whether this is hidden or not */
char ispkglocal; /* Tyname: whether this is package local or not */
char isimport; /* Tyname: whether tyis type was imported. */
+ char isreflect; /* Tyname: whether this type has reflection info */
};
struct Ucon {
@@ -213,8 +214,6 @@ struct Node {
Node **stmts;
size_t nstmts;
Stab *globls;
- size_t ntydefs;
- Type **tydefs;
} file;
struct {
diff --git a/parse/specialize.c b/parse/specialize.c
index d869c2c..4cb38a0 100644
--- a/parse/specialize.c
+++ b/parse/specialize.c
@@ -52,7 +52,6 @@ Type *tyspecialize(Type *t, Htab *tsmap, Htab *delayed)
htput(tsmap, t, ret);
for (i = 0; i < t->ngparam; i++)
lappend(&ret->arg, &ret->narg, tyspecialize(t->gparam[i], tsmap, delayed));
- lappend(&file->file.tydefs, &file->file.ntydefs, ret);
break;
case Tyname:
arg = NULL;