Example #1
0
 private void RewriteAlu(Operator op)
 {
     var dst = RewriteOp(instrCur.Op3);
     var src1 = RewriteOp(instrCur.Op1);
     var src2 = RewriteOp(instrCur.Op2);
     emitter.Assign(dst, new BinaryExpression(op, PrimitiveType.Word32, src1, src2));
 }
Example #2
0
 private void RewriteTrap(MipsInstruction instr, Operator op)
 {
     var trap = host.PseudoProcedure("__trap", VoidType.Instance, RewriteOperand(instr.op3));
     emitter.If(new BinaryExpression(op, PrimitiveType.Bool,
         RewriteOperand(instr.op1),
         RewriteOperand(instr.op2)),
         new RtlSideEffect(trap));
 }
Example #3
0
 private void RewriteFpuCmpD(MipsInstruction instr, Operator cmp)
 {
     emitter.Assign(
         RewriteOperand(instr.op1),
         new BinaryExpression(cmp, PrimitiveType.Bool,
             GetFpuRegPair(instr.op2),
             GetFpuRegPair(instr.op3)));
 }
Example #4
0
 private void RewriteAlu(Operator op, bool negateOp2)
 {
     var dst = RewriteRegister(instrCur.Op3);
     var src1 = RewriteOp(instrCur.Op1);
     var src2 = RewriteOp(instrCur.Op2);
     if (negateOp2)
     {
         src2 = emitter.Comp(src2);
     }
     emitter.Assign(dst, new BinaryExpression(op, PrimitiveType.Word32, src1, src2));
 }
Example #5
0
 private void RewriteBinOp(Operator op, bool setflags)
 {
     var opDst = this.Operand(Dst);
     var opSrc1 = this.Operand(Src1);
     var opSrc2 = this.Operand(Src2);
     ConditionalAssign(opDst, new BinaryExpression(op, PrimitiveType.Word32, opSrc1, opSrc2));
     if (setflags)
     {
         ConditionalAssign(frame.EnsureFlagGroup(A32Registers.cpsr, 0x1111, "SZCO", PrimitiveType.Byte), emitter.Cond(opDst));
     }
 }
Example #6
0
 private void RewriteRevBinOp(Operator op, bool setflags)
 {
     var ops = instr.ArchitectureDetail.Operands.ToArray();
     var opDst = this.Operand(Dst);
     var opSrc1 = this.Operand(Src1);
     var opSrc2 = this.Operand(Src2);
     ConditionalAssign(opDst, new BinaryExpression(op, PrimitiveType.Word32, opSrc1, opSrc2));
     if (setflags)
     {
         ConditionalAssign(frame.EnsureFlagGroup(0x1111, "SZCO", PrimitiveType.Byte), emitter.Cond(opDst));
     }
 }
Example #7
0
		public bool Match(BinaryExpression binExp)
		{
			cLeft = binExp.Left as Constant; 
			cRight = binExp.Right as Constant;
			if (cLeft != null && cRight != null && binExp.Operator != Operator.Eq)
			{
				if (!cLeft.IsReal && !cRight.IsReal)
				{
					op = binExp.Operator;
					return true;
				}
			}
			return false;
		}
Example #8
0
 private void RewriteAddxSubx(Operator op, bool emitCc)
 {
     var dst = RewriteRegister(instrCur.Op3);
     var src1 = RewriteOp(instrCur.Op1);
     var src2 = RewriteOp(instrCur.Op2);
     var C = frame.EnsureFlagGroup(Registers.C);
     emitter.Assign(
         dst,
         new BinaryExpression(
             op,
             dst.DataType,
             new BinaryExpression(op, src1.DataType, src1, src2),
             C));
     if (emitCc)
     {
         EmitCc(dst);
     }
 }
Example #9
0
 // (x << c) + x ==> x * ((1<<c) + 1)
 public bool Match(BinaryExpression b)
 {
     this.op = b.Operator;
     if (op != Operator.IAdd)
         return false;
     var bin = b.Left as BinaryExpression;
     id = b.Right as Identifier;
     if (bin == null || id == null)
     {
         bin = b.Right as BinaryExpression;
         id = b.Left as Identifier;
     }
     if (bin == null || bin.Left != id || bin.Operator != Operator.Shl)
         return false;
     this.c = bin.Right as Constant;
     this.dt = b.DataType;
     return c != null;
 }
Example #10
0
		public bool Match(BinaryExpression b)
		{
			op = b.Operator;
			if (op != Operator.Shl && op != Operator.Shr && op != Operator.Sar)
				return false;
			c1 = b.Right as Constant;
			if (c1 == null)
				return false;
			BinaryExpression b2 = b.Left as BinaryExpression;
			if (b2 == null)
				return false;
			if (op != b2.Operator)
				return false;
			c2 = b2.Right as Constant;
			if (c2 == null)
				return false;
			e = b2.Left;
			return true;
		}
Example #11
0
		public bool Match(BinaryExpression binExp)
		{
			cLeft = binExp.Left as Constant; 
			cRight = binExp.Right as Constant;
			op = binExp.Operator;
			if (cLeft != null && cRight != null && binExp.Operator != Operator.Eq)
			{
				if (!cLeft.IsReal && !cRight.IsReal)
				{
					return true;
				}
			}
            addr = binExp.Left as Address;
            if (addr != null && cRight != null &&
                (op == Operator.IAdd || op == Operator.ISub))
            {
                return true;
            }
			return false;
		}
Example #12
0
        public bool Match(BinaryExpression b)
        {
            if (b.Operator != Operator.Shl)
                return false;
            cShift = b.Right as Constant;
            if (cShift == null)
                return false;

            b = b.Left as BinaryExpression;
            if (b == null)
                return false;

            if (b.Operator != Operator.SMul && b.Operator != Operator.UMul && b.Operator != Operator.IMul)
                return false;
            op = b.Operator;
            cMul = b.Right as Constant;
            if (cMul == null)
                return false;

            e = b.Left;
            return true;
        }
Example #13
0
 private void RewriteAluCc(Operator op)
 {
     RewriteAlu(op);
     var dst = RewriteOp(instrCur.Op3);
     EmitCc(dst);
 }
Example #14
0
        public void VisitBinaryExpression(Operator op, DataType dataType, Expression left, Expression right)
        {
            if (op == Operator.IAdd || op == Operator.ISub)
            {
                // Handle mem[x+const] case. Array accesses of the form
                // mem[x + (i * const) + const] will have been converted
                // to ArrayAccesses by a previous stage.

                Constant offset = right as Constant;
                if (offset != null)
                {
                    if (op == Operator.ISub)
                        offset = offset.Negate();
                    var iv = GetInductionVariable(left);
                    if (iv != null)
                    {
                        VisitInductionVariable((Identifier) left, iv, offset);
                        return;
                    }
                    else if (left is BinaryExpression)
                    {
                        var bl = (BinaryExpression) left;
                        //$HACK: we've already done the analysis of the mul operator!
                        // We should be using the returned value of trait collection.
                        if (bl.Operator is IMulOperator)
                        {
                            arrayContext = true;
                            EmitAccessTrait(basePointer, left, dataType.Size, offset.ToInt32());
                            return;
                        }
                    }
                    EmitAccessTrait(basePointer, left, dataType.Size, offset.ToInt32());
                    return;
                }

                // Handle odd mem[x + y] case; perhaps a later stage can detect that x (or y)
                // is a pointer and therefore y isn't.

                EmitAccessTrait(basePointer, left, dataType.Size, 0);
                return;
            }
            throw new TypeInferenceException("Couldn't generate address traits for binary operator {0}.", op);
        }
Example #15
0
 private void RewriteSxx(MipsInstruction instr, Operator op)
 {
     var dst = RewriteOperand(instr.op1);
     var src1 = RewriteOperand(instr.op2);
     var src2 = RewriteOperand(instr.op3);
     emitter.Assign(
         dst,
         emitter.Cast(
             dst.DataType,
             new BinaryExpression(
                 op,
                 PrimitiveType.Bool,
                 src1,
                 src2)));
 }
 private bool IsSignedOperator(Operator op)
 {
     return
         op == Operator.Lt || op == Operator.Le ||
         op == Operator.Gt || op == Operator.Ge;
 }
Example #17
0
		private bool IsAddOrSub(Operator op)
		{
			return op == Operator.IAdd || op == Operator.ISub;
		}
Example #18
0
 private void RewriteAluCc(Operator op, bool negateOp2)
 {
     RewriteAlu(op, negateOp2);
     var dst = RewriteRegister(instrCur.Op3);
     EmitCc(dst);
 }
Example #19
0
 private static bool IsIAddOrISub(Operator op)
 {
     return (op == Operator.IAdd || op == Operator.ISub);
 }
Example #20
0
 public int FindUsingInstruction2(StatementList stms, int i, Operator next)
 {
     for (++i; i < stms.Count; ++i)
     {
         var ass = stms[i].Instruction as Assignment;
         if (ass == null)
             continue;
         var bin = ass.Src as BinaryExpression;
         if (bin == null)
             continue;
         if (bin.Operator == next)
             return i;
         if (IsCarryFlag(ass.Dst))
             return -1;
     }
     return -1;
 }
Example #21
0
        private void RewriteCtrBranch(bool updateLinkRegister, bool toLinkRegister, Operator decOp, bool ifSet)
        {
            cluster.Class = RtlClass.ConditionalTransfer;
            var ctr = frame.EnsureRegister(arch.ctr);
            var ccOp = instr.op1 as ConditionOperand;
            Expression dest;

            Expression cond = new BinaryExpression(
                decOp, 
                PrimitiveType.Bool,
                ctr,
                Constant.Zero(ctr.DataType));

            if (ccOp != null)
            {
                Expression test = emitter.Test(
                    CcFromOperand(ccOp),
                    frame.EnsureRegister(CrFromOperand(ccOp)));
                if (!ifSet)
                    test = test.Invert();
                cond = emitter.Cand(cond, test);
                dest = RewriteOperand(instr.op2);
            }
            else
            {
                dest = RewriteOperand(instr.op1);
            }
            
            emitter.Assign(ctr, emitter.ISub(ctr, 1));
            if (updateLinkRegister)
            {
                emitter.If(
                    cond,
                    new RtlCall(dest, 0, RtlClass.ConditionalTransfer));
            }
            else
            {
                emitter.Branch(
                    cond,
                    (Address)dest,
                    RtlClass.ConditionalTransfer);
            }
        }