clean the commutativity + fix bug in emit

The commutativity information only makes sense for
arithmetic expressions.  To account for that, I introduced
a new tri-valued boolean type B3.  Memory operations, for
example, will receive an undefined commutativity trit.

The code emitter was buggy when rega emitted instructions
like 'rax = add 1, rax', this is now fixed using the
commutativity information (we rewrite it in 'rax = add
rax, 1').
This commit is contained in:
Quentin Carbonneaux 2015-07-31 10:21:10 -04:00
parent 1a78659dfa
commit d8d17705c4
5 changed files with 28 additions and 16 deletions

View file

@ -57,6 +57,15 @@ eins(Ins i, Fn *fn, FILE *f)
switch (i.op) {
case OAdd:
case OSub:
if (req(i.to, i.arg[1]))
switch (opdesc[i.op].comm) {
case T:
i.arg[1] = i.arg[0];
i.arg[0] = i.to;
break;
default:
diag("emit: instruction can't be encoded");
}
if (!req(i.to, i.arg[0]))
eop("mov", i.arg[0], i.to, fn, f);
eop(opi[i.op], i.arg[1], i.to, fn, f);