scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 4dca54568291a99779209f6b381435a6a62a232d
parent 79ba801de33247c1dd2fd984497be0a27a757643
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 14 Aug 2015 15:25:23 +0200

Add a tag field in Type

This field allows to print the name of the aggregate
in the IR.

Diffstat:
Mcc1/cc1.h | 3++-
Mcc1/code.c | 3+++
Mcc1/decl.c | 1+
3 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -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 */ @@ -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 @@ -226,6 +226,7 @@ emittype(Type *tp) int n; Type **vp; Symbol **sp; + char *tag; if (tp->printed || !tp->defined) return; @@ -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 @@ -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)