[hackers] [scc] Emit struct types || Roberto E. Vargas Caballero
commit cd295810c421544600c991fbf93c6d8c8b535231
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Thu Aug 13 11:55:21 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Thu Aug 13 11:55:21 2015 +0200
Emit struct types
diff --git a/cc1/cc1.h b/cc1/cc1.h
index 62781e6..f9ed793 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
_AT_@ -33,6 +33,7 @@ struct type {
Type *type; /* base type */
Type *next; /* next element in the hash */
Type **pars; /* type parameters */
+ Symbol **fields; /* fields of aggregate type */
union {
unsigned char rank; /* convertion rank */
short elem; /* number of type parameters */
diff --git a/cc1/code.c b/cc1/code.c
index 7f821a1..94c822d 100644
--- a/cc1/code.c
+++ b/cc1/code.c
_AT_@ -225,6 +225,7 @@ emittype(Type *tp)
{
int n;
Type **vp;
+ Symbol **sp;
if (tp->printed)
return;
_AT_@ -241,6 +242,18 @@ emittype(Type *tp)
case PTR:
emittype(tp->type);
return;
+ case UNION:
+ case STRUCT:
+ n = tp->n.elem;
+ for (sp = tp->fields; n-- > 0; ++sp)
+ emittype((*sp)->type);
+ emitletter(tp);
+ puts("\t(");
+ n = tp->n.elem;
+ for (sp = tp->fields; n-- > 0; ++sp)
+ emit(ODECL, *sp);
+ puts(")");
+ break;
case FTN:
emitletter(tp);
n = tp->n.elem;
diff --git a/cc1/decl.c b/cc1/decl.c
index 3a0abbe..68ca93c 100644
--- a/cc1/decl.c
+++ b/cc1/decl.c
_AT_@ -381,10 +381,14 @@ newtag(void)
break;
}
if (!sym->type) {
+ Type *tp;
+
if (ns == NS_STRUCTS + NR_MAXSTRUCTS)
error("too much tags declared");
- sym->type = mktype(NULL, tag, 0, NULL);
- sym->type->ns = ns++;
+ tp = mktype(NULL, tag, 0, NULL);
+ tp->ns = ns++;
+ tp->fields = NULL;
+ sym->type = tp;
}
if ((op = sym->type->op) != tag && op != INT)
_AT_@ -499,8 +503,8 @@ field(struct decl *dcl)
sym->flags |= ISFIELD;
if (n++ == NR_FUNPARAM)
error("too much fields in struct/union");
- structp->pars = xrealloc(structp->pars, n);
- structp->pars[n-1] = tp;
+ structp->fields = xrealloc(structp->fields, n * sizeof(*sym));
+ structp->fields[n-1] = sym;
structp->n.elem = n;
return sym;
diff --git a/cc1/types.c b/cc1/types.c
index 599378d..f1c57ed 100644
--- a/cc1/types.c
+++ b/cc1/types.c
_AT_@ -311,7 +311,7 @@ mktype(Type *tp, unsigned op, short nelem, Type *pars[])
t = (op ^ (uintptr_t) tp >> 3) & NR_TYPE_HASH-1;
tbl = &typetab[t];
for (bp = *tbl; bp; bp = bp->next) {
- if (eqtype(bp, &type)) {
+ if (eqtype(bp, &type) && op != STRUCT && op != UNION) {
/*
* pars was allocated by the caller
* but the type already exists, so
_AT_@ -353,7 +353,7 @@ eqtype(Type *tp1, Type *tp2)
}
return 1;
case ENUM:
- break;
+ return 0;
case INT:
case FLOAT:
return tp1->letter == tp2->letter;
Received on Thu Aug 13 2015 - 20:02:11 CEST
This archive was generated by hypermail 2.3.0
: Thu Aug 13 2015 - 20:12:14 CEST