summary refs log tree commit diff
path: root/minic
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-10-12 12:40:55 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-10-12 12:40:55 -0400
commitd1b2cf2d49cad7978b7c6307a2c17cc3d34aa42c (patch)
tree65835c625dc474ee4ca8cbae68d22185413e4db4 /minic
parent7c7a8b30ea73cc5b402dab217ad6c0a72f601072 (diff)
downloadroux-d1b2cf2d49cad7978b7c6307a2c17cc3d34aa42c.tar.gz
add super cheap constant folding in minic
Diffstat (limited to 'minic')
-rw-r--r--minic/minic.y18
1 files changed, 11 insertions, 7 deletions
diff --git a/minic/minic.y b/minic/minic.y
index fbe4f89..79fb5f2 100644
--- a/minic/minic.y
+++ b/minic/minic.y
@@ -226,13 +226,17 @@ prom(int op, Symb *l, Symb *r)
 	}
 
 Scale:
-	if (irtyp(r->ctyp) != 'l')
-		sext(r);
 	sz = SIZE(DREF(l->ctyp));
-	fprintf(of, "\t%%t%d =l mul %d, ", tmp, sz);
-	psymb(*r);
-	fprintf(of, "\n");
-	r->u.n = tmp++;
+	if (r->t == Con)
+		r->u.n *= sz;
+	else {
+		if (irtyp(r->ctyp) != 'l')
+			sext(r);
+		fprintf(of, "\t%%t%d =l mul %d, ", tmp, sz);
+		psymb(*r);
+		fprintf(of, "\n");
+		r->u.n = tmp++;
+	}
 	return l->ctyp;
 }
 
@@ -255,7 +259,7 @@ expr(Node *n)
 		['*'] = "mul",
 		['/'] = "div",
 		['%'] = "rem",
-		['<'] = "cslt",  /* meeeeh, careful with pointers */
+		['<'] = "cslt",  /* meeeeh, careful with pointers/long */
 		['l'] = "csle",
 		['e'] = "ceq",
 		['n'] = "cne",