shithub: scc

Download patch

ref: 7741d58782520663fdc12c27a0c10b795b8d7fad
parent: d1c3a0d77670defbdac8bc39a5182170934d8063
author: Roberto E. Vargas Caballero <[email protected]>
date: Sun Mar 30 18:04:47 EDT 2014

Remove the complex types

It is obvious we are not going to implemente the complex types,
because it is a non sense in a compiler for a z80.

--- a/cc.h
+++ b/cc.h
@@ -45,11 +45,9 @@
 
 struct ctype {
 	uint8_t op;           /* type builder operator */
-	short size;           /* size of variables */
+	char letter;          /* letter of the type */
 	short nelem;          /* number of elements in arrays */
 	unsigned defined : 1; /* type defined (is not a forward reference) */
-	unsigned cplex : 1;   /* complex specifier */
-	unsigned imag : 1;
 	unsigned sign : 1;    /* sign type */
 	struct symbol *sym;   /* symbol of the tag identifier */
 	struct ctype *type;   /* base type */
@@ -79,7 +77,6 @@
 	int i;
 	struct symbol *sym;
 	uint8_t ns, token;
-	short offset;
 };
 
 struct symbol {
@@ -105,7 +102,7 @@
 extern void freesyms(uint8_t ns);
 
 extern Type *qualifier(Type *tp, uint8_t qlf),
-	*ctype(int8_t type, int8_t sign, int8_t size, int8_t cplex),
+	*ctype(int8_t type, int8_t sign, int8_t size),
 	*mktype(Type *tp,
 	        uint8_t op, Symbol *tag, uint16_t nelem);
 
@@ -121,9 +118,7 @@
 	*ushortype,   *shortype,
 	*longtype,    *ulongtype,
 	*ullongtype,  *llongtype,
-	*floattype,   *cfloattype,  *ifloattype,
-	*doubletype,  *cdoubletype, *idoubletype,
-	*ldoubletype, *cldoubletype,*ildoubletype;
+	*floattype,   *doubletype,  *ldoubletype;
 
 #define ISQUAL(t)    (isqual((t)->op))
 #define UNQUAL(t)    (ISQUAL(t) ? (t)->type : (t))
@@ -222,7 +217,7 @@
 
 extern void emitsym(Node *), emitunary(Node *), emitbin(Node *);
 extern Node
-	*node(void (*code)(Node *), Type *tp, union unode u, uint8_t nchilds),
+	*node(Inst code, Type *tp, union unode u, uint8_t nchilds),
 	*unarycode(char op, Type *tp, Node *child),
 	*bincode(char op, Node *np1, Node *np2);
 
--- a/decl.c
+++ b/decl.c
@@ -166,9 +166,9 @@
 specifier(int8_t *sclass)
 {
 	Type *tp = NULL;
-	int8_t qlf, sign, type, cls, cplex, size, t;
+	int8_t qlf, sign, type, cls, size, t;
 
-	qlf = sign = type = cls = size = cplex = 0;
+	qlf = sign = type = cls = size = 0;
 
 	for (;;) {
 		register uint8_t *p;
@@ -201,8 +201,6 @@
 				}
 			case SHORT:
 				p = &size; break;
-			case COMPLEX: case IMAGINARY:
-				p = &cplex; break;
 			}
 			break;
 		default:
@@ -226,7 +224,6 @@
 		type = INT;
 	}
 	if (sign && type != INT && type != CHAR ||
-	    cplex && type != FLOAT && type != DOUBLE ||
 	    size == SHORT && type != INT ||
 	    size == LONG  && type != INT && type != DOUBLE ||
 	    size == LONG+LONG && type != INT) {
@@ -235,7 +232,7 @@
 	if (sclass)
 		*sclass = cls;
 	if (!tp)
-		tp = ctype(type, sign, size, cplex);
+		tp = ctype(type, sign, size);
 	return (qlf) ? qualifier(tp, qlf) : tp;
 
 invalid_type:
@@ -262,7 +259,6 @@
 {
 	register struct field *p, *q;
 	register char *s, *t;
-	static short size, offset;
 	static uint8_t op;
 	static char *err;
 
@@ -279,25 +275,10 @@
 	p = xmalloc(sizeof(*p));
 	p->next = NULL;
 	p->sym = sym;
-	size = sym->type->size;
-	if (!q) {
+	if (!q)
 		tp->u.fields = p;
-		if (op != ENUM) {
-			tp->size = size;
-			sym->u.offset = 0;
-		}
-	} else {
+	else
 		q->next = p;
-		if (tp->op == STRUCT) {
-			offset = ALIGN(size, tp->size);
-			sym->u.offset = offset;
-			tp->size = offset + size;
-		} else if (op == UNION) {
-			sym->u.offset = 0;
-			if (tp->size < size)
-				tp->size = size;
-		}
-	}
 
 	return;
 
--- a/types.c
+++ b/types.c
@@ -11,101 +11,72 @@
 
 Type
 	*voidtype = &(Type) {
-		.op = VOID
+		.op = VOID,
+		.letter = 'W'
 	},
 	*booltype = &(Type) {
 		.op = INT,
+		.letter = 'B'
 	},
 	*uchartype = &(Type) {
 		.op = INT,
-		.size = CHARSIZE,
+		.letter = 'M',
 		.sign = 1
 	},
 	*chartype = &(Type) {
 		.op = INT,
-		.size = CHARSIZE,
+		.letter = 'C',
 	},
 	*uinttype = &(Type) {
 		.op = INT,
-		.size = INTSIZE,
+		.letter = 'U',
 		.sign = 1
 	},
 	*inttype = &(Type) {
 		.op = INT,
-		.size = INTSIZE,
-		.sign = 1
+		.letter = 'I',
 	},
 	*ushortype = &(Type) {
 		.op = INT,
-		.size = SHORTSIZE,
+		.letter = 'E'
 	},
 	*shortype = &(Type) {
 		.op = INT,
-		.size = SHORTSIZE,
+		.letter = 'K',
 	},
 	*longtype = &(Type) {
 		.op = INT,
-		.size = LONGSIZE,
+		.letter = 'L'
 	},
 	*ulongtype = &(Type) {
 		.op = INT,
-		.size = LONGSIZE,
+		.letter = 'Z',
 		.sign = 1
 	},
 	*ullongtype = &(Type) {
 		.op = INT,
-		.size = LLONGSIZE,
+		.letter = 'O',
 		.sign = 1
 	},
 	*llongtype = &(Type) {
 		.op = INT,
-		.size = LLONGSIZE,
+		.letter = 'G',
 	},
 	*floattype = &(Type) {
 		.op = FLOAT,
-		.size = FLOATSIZE
+		.letter = 'F'
 	},
-	*cfloattype = &(Type) {
-		.op = FLOAT,
-		.size = FLOATSIZE,
-		.cplex = 1
-	},
-	*ifloattype = &(Type) {
-		.op = FLOAT,
-		.size = FLOATSIZE,
-		.imag = 1
-	},
 	*doubletype = &(Type) {
 		.op = FLOAT,
-		.size = FLOATSIZE
+		.letter = 'D'
 	},
-	*cdoubletype = &(Type) {
-		.op = FLOAT,
-		.size = 0,
-		.cplex = 1
-	},
-	*idoubletype = &(Type) {
-		.op = FLOAT,
-		.size = 0,
-		.imag = 1
-	},
 	*ldoubletype = &(Type) {
 		.op = FLOAT,
-		.size = LLFLOATSIZE
-	},
-	*cldoubletype = &(Type) {
-		.op = FLOAT,
-		.size = 0,
-		.cplex = 1
-	},
-	*ildoubletype = &(Type) {
-		.op = FLOAT,
-		.size = 0,
-		.imag = 1
+		.letter = 'H'
 	};
 
 Type *
-ctype(int8_t type, int8_t sign, int8_t size, int8_t cplex)
+ctype(int8_t type, int8_t sign, int8_t size)
 {
 	if (type == CHAR && !sign)
 		sign = options.charsign;
@@ -125,22 +96,10 @@
 		case LONG+LONG:         return (sign) ? ullongtype : llongtype;
 		}
 	case FLOAT: switch (size) {
-		case 0: switch (cplex) {
-			case 0:         return floattype;
-			case COMPLEX:   return cfloattype;
-			case IMAGINARY: return ifloattype;
+		case 0:                 return floattype;
+		case LONG:              return doubletype;
+		case LONG+LONG:         return ldoubletype;
 		}
-		case LONG: switch (cplex) {
-			case 0:         return doubletype;
-			case COMPLEX:   return cdoubletype;
-			case IMAGINARY: return ifloattype;
-		}
-		case LONG+LONG: switch (cplex) {
-			case 0:         return ldoubletype;
-			case COMPLEX:   return cldoubletype;
-			case IMAGINARY: return ildoubletype;
-		}
-		}
 	}
 }
 
@@ -150,8 +109,8 @@
 {
 	static Type *typetab[NR_TYPE_HASH], **tbl;
 	static uint8_t t;
-	static unsigned short size;
 	register Type *bp;
+	char letter;
 
 	t = (op  ^  (uint8_t) ((unsigned short) tp >> 3))
 	         & NR_TYPE_HASH-1;
@@ -166,12 +125,12 @@
 	}
 
 	switch (op) {
-	case PTR: size = PTRSIZE; break;
-	case FTN: size = 0; break;
-	case ARY: size = tp->size * nelem; break;
-	case ENUM: size = INTSIZE;
-	case STRUCT: size = 0; break;
-	default:  size = tp->size; break;
+	case PTR:    letter = 'R'; break;
+	case FTN:    letter = 'F'; break;
+	case ARY:    letter = 'V'; break;
+	case ENUM:   letter = 'E'; break;
+	case STRUCT: letter = 'S'; break;
+	default:     abort();
 	}
 	bp = xmalloc(sizeof(*bp));
 	bp->next = *tbl;
@@ -179,7 +138,7 @@
 	bp->op = op;
 	bp->nelem = nelem;
 	bp->sym = sym;
-	bp->size = size;
+	bp->letter = letter;
 	return *tbl = bp;
 }
 
@@ -195,62 +154,5 @@
 		qlf |= q;
 	}
 	return mktype(tp, qlf|TQUALIFIER, NULL, 0);
-}
-
-#include <stdio.h>
-
-static void
-ptype(Type *tp)
-{
-	uint8_t op;
-	struct funpar *fp;
-
-	if (!tp)
-		return;
-	op = tp->op;
-	if (op & TQUALIFIER) {
-		if (op & CONST)
-			fputs("const ", stdout);
-		if (op & VOLATILE)
-			fputs("volatile ", stdout);
-		if (op & RESTRICT)
-			fputs("restrict ", stdout);
-	} else {
-		switch (op) {
-		case PTR: fputs("pointer ", stdout); break;
-		case ARY: fputs("array ", stdout); break;
-		case STRUCT: fputs("struct", stdout); break;
-		case UNION: fputs("union", stdout); break;
-		case ENUM: fputs("enum", stdout); break;
-		case BOOL: fputs("bool", stdout); break;
-		case INT:
-			printf("int size=%u sign=%u", tp->size, tp->sign);
-			break;
-		case FLOAT:
-			printf("float size=%u cplex=%u", tp->size, tp->cplex);
-			break;
-		case TYPENAME:
-			printf("typename %s type ", tp->sym->name);
-			break;
-		case FTN:
-			fputs("function(", stdout);
-			for (fp = tp->u.pars; fp; fp = fp->next) {
-				ptype(tp);
-				if (fp->next)
-					fputs(", ", stdout);
-			}
-			fputs(") ", stdout);
-			break;
-		}
-	}
-	ptype(tp->type);
-}
-
-void
-printtype(Type *tp)
-{
-	printf("type = %p ", tp);
-	ptype(tp);
-	putchar('\n');
 }