diff --git a/sources/zweic/Generator.scala b/sources/zweic/Generator.scala index 59d0a81..8c7e5a9 100644 --- a/sources/zweic/Generator.scala +++ b/sources/zweic/Generator.scala @@ -6,7 +6,6 @@ */ package zweic; -import Operators._; class Generator(analyzer: Analyzer) { import RISC._; @@ -140,22 +139,40 @@ code.emit(SYSCALL, targetReg, ZERO, SYS_IO_RD_CHR, "readChar") case Unop(op, expr) => - op match { - case NOT => - //TODO + genTmp { tmpReg => + op match { + case Operators.NOT => + genTmp { allOnes => + code.emit(XOR, allOnes, ZERO, ZERO); + genLoad(expr, tmpReg); + code.emit(BIC, targetReg, allOnes, tmpReg); + } - case NEG => - genTmp { tmpReg => + case Operators.NEG => genLoad(expr, tmpReg); code.emit(SUB, targetReg, ZERO, tmpReg, "-"); - } - - case _ => - Console.println("unop _________"); + } } case Binop(op, left, right) => - // ... � compl�ter ... + genTmp { tmpLeft => + genLoad(left, tmpLeft); + genTmp { tmpRight => + genLoad(right, tmpRight); + op match { + case Operators.ADD => + code.emit(ADD, targetReg, tmpLeft, tmpRight, "+"); + case Operators.SUB => + code.emit(SUB, targetReg, tmpLeft, tmpRight, "-"); + case Operators.MUL => + code.emit(MUL, targetReg, tmpLeft, tmpRight, "*"); + case Operators.DIV => + code.emit(DIV, targetReg, tmpLeft, tmpRight, "/"); + case Operators.MOD => + code.emit(MOD, targetReg, tmpLeft, tmpRight, "%"); + } + } + } case Block(stats, main) => // ... � compl�ter ... @@ -198,7 +215,22 @@ case _ => () //TODO: caseDefault(tree) - +/* + case Operators.EQ => + code.emit(CMP, targetReg, tmpLeft, tmpRight, "*"); + + case Operators.LT => + //TODO + case Operators.LE => + //TODO + case Operators.GT => + //TODO + case Operators.GE => + //TODO + + case Operators.AND => + code.emit(AND, targetReg, tmpLeft, tmpRight, "*"); +*/ } } // genCond diff --git a/sources/zweic/Parser.scala b/sources/zweic/Parser.scala index 815a29d..4649f67 100755 --- a/sources/zweic/Parser.scala +++ b/sources/zweic/Parser.scala @@ -363,8 +363,7 @@ private def _negFactor(): Expr = { val pos = start; if ( token == SUB || token == NOT ) { - val op = Operators.token2op(token); - nextToken; + val op = negateOp(); val e = factor(); e.brackets = true; return Unop(op, e).setPos(pos); @@ -470,10 +469,12 @@ /** * NegateOp = "-" | "!" */ - private def negateOp(): Operators.Operator = token match { - case SUB => nextToken; return Operators.NEG; - case NOT => nextToken; return Operators.NOT; - case _ => error("'-' or '!' token"); return null; + private def negateOp(): Operators.Operator = { + token match { + case SUB => nextToken; return Operators.NEG; + case NOT => nextToken; return Operators.NOT; + case _ => error("'-' or '!' token"); return null; + } } /**