[hackers] [scc] Add a tag field in Type || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Fri, 14 Aug 2015 17:08:59 +0200 (CEST)

commit 4dca54568291a99779209f6b381435a6a62a232d
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Fri Aug 14 15:25:23 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Fri Aug 14 15:25:23 2015 +0200

    Add a tag field in Type
    
    This field allows to print the name of the aggregate
    in the IR.

diff --git a/cc1/cc1.h b/cc1/cc1.h
index 3e69d9b..500bb15 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
_AT_@ -22,7 +22,7 @@ typedef struct input Input;
  */
 struct type {
         unsigned char op; /* type builder operator */
- unsigned char ns;
+ unsigned char ns; /* namespace for struct members */
         short id; /* type id, used in dcls */
         char letter; /* letter of the type */
         bool defined : 1; /* type defined */
_AT_@ -31,6 +31,7 @@ struct type {
         size_t size; /* sizeof the type */
         size_t align; /* align of the type */
         Type *type; /* base type */
+ Symbol *tag; /* symbol of the strug tag */
         Type *next; /* next element in the hash */
         union {
                 Type **pars; /* Function type parameters */
diff --git a/cc1/code.c b/cc1/code.c
index 677af97..8b324af 100644
--- a/cc1/code.c
+++ b/cc1/code.c
_AT_@ -226,6 +226,7 @@ emittype(Type *tp)
         int n;
         Type **vp;
         Symbol **sp;
+ char *tag;
 
         if (tp->printed || !tp->defined)
                 return;
_AT_@ -248,6 +249,8 @@ emittype(Type *tp)
                 for (sp = tp->p.fields; n-- > 0; ++sp)
                         emittype((*sp)->type);
                 emitletter(tp);
+ if ((tag = tp->tag->name) != NULL)
+ printf("\t%s", tag);
                 puts("\t(");
                 n = tp->n.elem;
                 for (sp = tp->p.fields; n-- > 0; ++sp)
diff --git a/cc1/decl.c b/cc1/decl.c
index ceb93de..2f12d4a 100644
--- a/cc1/decl.c
+++ b/cc1/decl.c
_AT_@ -393,6 +393,7 @@ newtag(void)
                 tp->ns = ns++;
                 tp->p.fields = NULL;
                 sym->type = tp;
+ tp->tag = sym;
         }
 
         if ((op = sym->type->op) != tag && op != INT)
Received on Fri Aug 14 2015 - 17:08:59 CEST

This archive was generated by hypermail 2.3.0 : Fri Aug 14 2015 - 17:12:21 CEST