summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--8/isel.c16
-rw-r--r--test/bsr.myr3
-rw-r--r--test/div.myr7
-rw-r--r--test/mod.myr4
4 files changed, 21 insertions, 9 deletions
diff --git a/8/isel.c b/8/isel.c
index 804bfbf..653c96d 100644
--- a/8/isel.c
+++ b/8/isel.c
@@ -425,16 +425,20 @@ Loc *selexpr(Isel *s, Node *n)
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);
}
diff --git a/test/bsr.myr b/test/bsr.myr
index bac2705..d2d7c5f 100644
--- a/test/bsr.myr
+++ b/test/bsr.myr
@@ -1,3 +1,4 @@
const main = {
- -> 42 >> 3
+ var a = 42
+ -> a >> 3
}
diff --git a/test/div.myr b/test/div.myr
index 4e5749f..fbb4947 100644
--- 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
}
diff --git a/test/mod.myr b/test/mod.myr
index ed4d820..842ab70 100644
--- a/test/mod.myr
+++ b/test/mod.myr
@@ -1,3 +1,5 @@
const main = {
- -> 42 % 9
+ var a = 42
+ var b = 9
+ -> a % b
}