shithub: mc

Download patch

ref: 87c65208dece48a6d6005a221437bef879c65850
parent: 3a076cf836169c7483321ce396bf61ea6fd08db6
author: Ori Bernstein <[email protected]>
date: Fri Jun 15 09:18:17 EDT 2012

Allow shiftiing by constants.

--- a/8/isel.c
+++ b/8/isel.c
@@ -425,16 +425,20 @@
 
         case Obsl:
         case Obsr:
-            a = selexpr(s, args[0]);
-            a = inr(s, a);
+            a = inr(s, selexpr(s, args[0]));
             b = selexpr(s, args[1]);
-            c = coreg(Rcl, b->mode);
-            g(s, Imov, b, c, NULL);
+            if (b->type == Loclit) {
+                d = b;
+            } else {
+                c = coreg(Rcl, b->mode);
+                g(s, Imov, b, c, NULL);
+                d = cl;
+            }
             if (exprop(n) == Obsr) {
                 if (istysigned(n->expr.type))
-                    g(s, Isar, cl, a, NULL);
+                    g(s, Isar, d, a, NULL);
                 else
-                    g(s, Ishr, cl, a, NULL);
+                    g(s, Ishr, d, a, NULL);
             } else {
                 g(s, Ishl, cl, a, NULL);
             }
--- a/test/bsr.myr
+++ b/test/bsr.myr
@@ -1,3 +1,4 @@
 const main = {
-	-> 42 >> 3
+	var a = 42
+	-> a >> 3
 }
--- a/test/div.myr
+++ b/test/div.myr
@@ -1,3 +1,8 @@
 const main = {
-	-> 84 / 2
+	var a
+	var b
+
+	a = 84
+	b = 2
+	-> a / b
 }
--- a/test/mod.myr
+++ b/test/mod.myr
@@ -1,3 +1,5 @@
 const main = {
-	-> 42 % 9
+	var a = 42
+	var b = 9
+	-> a % b
 }