shithub: mc

Download patch

ref: d9bac20cb9000c9cab98349cb63152e7e90e73ea
parent: 2b00b4a0fc8f56bd47fa9e8fab3a9e47add497fc
author: Ori Bernstein <[email protected]>
date: Wed Jun 6 20:52:50 EDT 2012

Add support for multiplication.

--- a/8/insns.def
+++ b/8/insns.def
@@ -24,6 +24,7 @@
 
 Insn(Iadd,      "\tadd%t %r,%x\n",              0)
 Insn(Isub,      "\tsub%t %r,%x\n",              0)
+Insn(Imul,      "\tmul%t %r\n",              0)
 Insn(Iand,      "\tand%d %r,%x\n",              0)
 Insn(Ior,       "\tor%d %r,%x\n",               0)
 Insn(Ixor,      "\txor%d %r,%x\n",              0)
--- a/8/isel.c
+++ b/8/isel.c
@@ -517,6 +517,7 @@
 
     args = n->expr.args;
     r = (Loc){Locnone, };
+    locreg(&eax, Reax);
     switch (exprop(n)) {
         case Oadd:      r = binop(s, Iadd, args[0], args[1]); break;
         case Osub:      r = binop(s, Isub, args[0], args[1]); break;
@@ -527,7 +528,11 @@
             claimreg(s, Redx);
             a = selexpr(s, args[0]);
             b = selexpr(s, args[1]);
-            r = 
+            b = inr(s, b);
+            g(s, Imov, &a, &eax, NULL);
+            g(s, Imul, &b, NULL);
+            freereg(s, Redx);
+            r = eax;
             break;
         case Odiv:      die("Unimplemented op %s", opstr(exprop(n))); break;
         case Omod:      die("Unimplemented op %s", opstr(exprop(n))); break;
--- a/8/reduce.c
+++ b/8/reduce.c
@@ -125,7 +125,6 @@
         case Tyslice:
             return 8; /* len; ptr */
         case Tyarray:
-            dump(t->asize, stdout);
             assert(exprop(t->asize) == Olit);
             return t->asize->expr.args[0]->lit.intval * tysize(t->sub[0]);
         case Tytuple:
--- a/test/tests
+++ b/test/tests
@@ -1,5 +1,6 @@
 main	E	0
 add	E	53
+mul     E       84
 struct1	E	12
 struct	E	42
 array	E	7