shithub: scc

Download patch

ref: 4dca54568291a99779209f6b381435a6a62a232d
parent: 79ba801de33247c1dd2fd984497be0a27a757643
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Aug 14 11:25:23 EDT 2015

Add a tag field in Type

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

--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -22,7 +22,7 @@
  */
 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 @@
 	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 */
--- a/cc1/code.c
+++ b/cc1/code.c
@@ -226,6 +226,7 @@
 	int n;
 	Type **vp;
 	Symbol **sp;
+	char *tag;
 
 	if (tp->printed || !tp->defined)
 		return;
@@ -248,6 +249,8 @@
 		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)
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -393,6 +393,7 @@
 		tp->ns = ns++;
 		tp->p.fields = NULL;
 		sym->type = tp;
+		tp->tag = sym;
 	}
 
 	if ((op = sym->type->op) != tag &&  op != INT)