ref: 21246a29a61afa8882a4a7f43d84fb4cce9f5a03
parent: b160b439e1abe830322fc23019b7731820ba2c66
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue May 31 04:30:36 EDT 2016
[cc2] Simplify code.c:addr() This function can be called with multiple different arguments, and we where dealing the different symbols like different cases, but it was the same case because we only had to use the storage class already stored in the symbol by parser.c:vardecl().
--- a/cc2/code.c
+++ b/cc2/code.c
@@ -29,26 +29,31 @@
static void
addr(Node *np, Addr *addr)
{
+ Symbol *sym;
+
switch (np->op) {
case OREG:
+ /* TODO:
+ * At this moment this op is used also for register variables
+ */
addr->kind = SREG;
addr->u.reg = np->u.reg;
break;
case OCONST:
- addr->kind = OCONST;
+ addr->kind = SCONST;
+ /* TODO: Add support for more type of constants */
addr->u.i = np->u.i;
break;
+ case OTMP:
case OLABEL:
- addr->kind = SLABEL;
- goto symbol;
case OAUTO:
- addr->kind = SAUTO;
- goto symbol;
- case OTMP:
- addr->kind = STMP;;
- symbol:
- addr->u.sym = np->u.sym;
+ case OMEM:
+ sym = np->u.sym;
+ addr->kind = sym->kind;
+ addr->u.sym = sym;
break;
+ default:
+ abort();
}
}