示例#1
0
 public Constant defineConstant(string name, Type type, object value)
 {
     if (null == name) name = ".C"+m_code.constants.Count;
     Constant c = new Constant(name, type, value);
     m_code.constants.Add(c);
     return c;
 }
        public void Constant_accepts_Visitor()
        {
            var constant = new Constant(typeof(string), "a");
            constant.AcceptVisitor(theVisitor);

            theVisitor.Received().Constant(constant);
        }
示例#3
0
 public override Constant ApplyConstant(Constant c)
 {
     if (c.IsValid)
         return c.Negate();
     else
         return c;
 }
示例#4
0
 public static string FormatValue(Constant c)
 {
     if (((PrimitiveType)c.DataType).Domain == Domain.SignedInt)
         return FormatSignedValue(c);
     else
         return FormatUnsignedValue(c);
 }
        public void Constant_accepts_Visitor()
        {
            var constant = new Constant(typeof(string), "a");
            constant.AcceptVisitor(theVisitor);

            theVisitor.AssertWasCalled(x => x.Constant(constant));
        }
示例#6
0
		public bool Match(BinaryExpression exp)
		{
			if (exp.Operator != Operator.IAdd)
				return false;
			id = exp.Left as Identifier;
			
			bin = exp.Right as BinaryExpression;
			if ((id == null || bin == null) && exp.Operator  == Operator.IAdd)
			{
				id = exp.Right as Identifier;
				bin = exp.Left as BinaryExpression;
			}
			if (id == null || bin == null)
				return false;

			if (bin.Operator != Operator.SMul && bin.Operator != Operator.UMul && bin.Operator != Operator.IMul)
				return false;

			Identifier idInner = bin.Left as Identifier;
			cInner = bin.Right as Constant;
			if (idInner == null ||cInner == null)
				return false;

			if (idInner != id)
				return false;

			return true;
		}
        //---------------------------------------------------------------------
        public static void ConstantQuery(OleDbConnection dbcon, CodeGenerator cg)
        {
            cg.ConstantList.Clear();
            OleDbCommand cmd = new OleDbCommand("SELECT * FROM Constants ORDER BY Topic, ID", dbcon);
            OleDbDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                Constant curConst = new Constant();
                curConst.Name = dr["Name"].ToString();
                curConst.Value = dr["Value"].ToString();
                Int32 nTopic = Convert.ToInt32(dr["Topic"].ToString());
                if (nTopic > 0)
                {
                    curConst.Topic = cg.TopicList[nTopic - 1].Name.ToString();
                }
                else
                {
                    curConst.Topic = "";
                }
                curConst.Description = dr["Description"].ToString();
                cg.ConstantList.Add(curConst);

                //curConst.Print();
            }

            dr.Close();
        }
示例#8
0
		public override Constant ApplyConstants(Constant c1, Constant c2)
		{
			return c1.ToInt32() != c2.ToInt32()
				? Constant.True() 
				: Constant.False();

		}
		public bool MatchMul(BinaryExpression b)
		{
			if (b.Operator == Operator.SMul || b.Operator == Operator.UMul || b.Operator == Operator.IMul)
			{
				Constant c = b.Left as Constant;
				Expression e = b.Right;
				if (c == null)
				{
					c = b.Right as Constant;
					e = b.Left;
				}
				if (c != null)
				{
					elemSize = c;
					Index = e;
					return true;
				}
			}
			if (b.Operator == Operator.Shl)
			{
				Constant c = b.Right as Constant;
				if (c != null)
				{
					elemSize = b.Operator.ApplyConstants(Constant.Create(b.Left.DataType, 1), c);
					Index = b.Left;
					return true;
				}
			}
			return false;
		}
示例#10
0
		public override Constant ApplyConstants(Constant c1, Constant c2)
		{
            if (!ValidArgs(c1, c2))
                return Constant.Invalid;

            return Constant.Bool(c1.ToInt32() >= c2.ToInt32());
        }
示例#11
0
    private void Initialize() {
      // create all symbols
      var sum = new Sum();
      var prog = new Prog();
      var frog = new Frog();
      var left = new Left();
      var forward = new Forward();
      var constant = new Constant();

      var allSymbols = new List<ISymbol>() { sum, prog, frog, left, forward, constant };

      // add all symbols to the grammar
      foreach (var s in allSymbols)
        AddSymbol(s);

      // define grammar rules
      foreach (var s in allSymbols) {
        AddAllowedChildSymbol(sum, s);
        AddAllowedChildSymbol(sum, s);
        AddAllowedChildSymbol(prog, s);
        AddAllowedChildSymbol(prog, s);
        AddAllowedChildSymbol(frog, s);
        AddAllowedChildSymbol(StartSymbol, s);
      }
    }
示例#12
0
        public override Constant ApplyConstants(Constant c1, Constant c2)
        {
            if (!ValidArgs(c1, c2))
                return Constant.Invalid;

            return BuildConstant(c1.DataType, c2.DataType, (int) (c1.ToUInt64() - c2.ToUInt64()));
        }
 /// <summary>
 /// Creates a slot with constant value being <paramref name="value"/>.
 /// </summary>
 internal ConstantProjectedSlot(Constant value, MemberPath memberPath)
 {
     Debug.Assert(value != null);
     Debug.Assert(value.IsNotNull() == false, "Cannot store NotNull in a slot - NotNull is only for conditions");
     m_constant = value;
     m_memberPath = memberPath;
 }
示例#14
0
		public override Constant ApplyConstants(Constant c1, Constant c2)
		{
            if (!ValidArgs(c1, c2))
                return Constant.Invalid;
            uint v1 = c1.ToUInt32();
			uint v2 = c2.ToUInt32();
            return Constant.Bool(v1 <= v2);
		}
示例#15
0
		public MemoryOperand(PrimitiveType width, Constant off) : base(width)
		{
            SegOverride = RegisterStorage.None;
            Base = RegisterStorage.None;
			Offset = off;
            Index = RegisterStorage.None;
			Scale = 1;
		}
示例#16
0
 internal static CilConstant Create(Constant constant, ref CilReaders readers)
 {
     CilConstant ilConstant = new CilConstant();
     ilConstant._constant = constant;
     ilConstant._readers = readers;
     ilConstant._isTypeInitialized = false;
     return ilConstant;
 }
示例#17
0
		public MemoryOperand(PrimitiveType width, RegisterStorage @base, RegisterStorage index, byte scale,  Constant off) : base(width)
		{
            SegOverride = RegisterStorage.None;
			Base = @base;
			Offset = off;
			Index = index;
			Scale = scale;
		}
示例#18
0
		public override Constant ApplyConstants(Constant c1, Constant c2)
		{
            if (!ValidArgs(c1, c2))
                return Constant.Invalid;
            if (c2.IsIntegerZero)
                return Constant.Invalid;
			return BuildConstant(c1.DataType, c2.DataType, c1.ToInt32() % c2.ToInt32());
		}
示例#19
0
 public TextureReplacement(string fname, Constant fmt, int w, int h, float s)
 {
     filename = fname;
     format = (int)fmt;
     width = w;
     height = h;
     scale = s;
 }
示例#20
0
		public bool Match(Slice slice)
		{
            if (!(slice.DataType is PrimitiveType))//$TODO: remove this once varargs processing is complete.
                return false;
			this.slice = slice;
			this.c = slice.Expression as Constant;
            return c != null && c != Constant.Invalid;
		}
示例#21
0
		public bool Match(Expression e)
		{
			elemSize = null;
			Index = null;
			ArrayPointer = null;

			BinaryExpression b = e as BinaryExpression;
			if (b == null)
				return false;
            if (MatchMul(b))
            {
                ArrayPointer = Constant.Zero(b.DataType);
                return true;
            }

			// (+ x y)
			if (b.Operator == Operator.IAdd)
			{
				BinaryExpression bInner = b.Left as BinaryExpression;
				if (bInner != null)
				{
					if (MatchMul(bInner))
					{
						// (+ (* i c) ptr)
						ArrayPointer = b.Right;
						return true;
					}
				}
				bInner = b.Right as BinaryExpression;
				if (bInner != null)
				{
					if (MatchMul(bInner))
					{
						// (+ ptr (* i c))
						ArrayPointer = b.Left;
						return true;
					}
					if (bInner.Operator == Operator.IAdd)
					{
						// (+ x (+ a b)) 
						var bbInner = bInner.Left as BinaryExpression;
                        if (bbInner != null && MatchMul(bbInner))
                        {
                            // (+ x (+ (* i c) y)) rearranges to become
                            // (+ (* i c) (+ x y))

                            this.ArrayPointer = new BinaryExpression(
                                Operator.IAdd,
                                PrimitiveType.Create(Domain.Pointer, b.Left.DataType.Size),
                                b.Left,
                                bInner.Right);
                            return true;
                        }
					}
				}
			}
			return false;
		}
示例#22
0
 public bool Match(Identifier id)
 {
     Expression e = ctx.GetValue(id);
     cSrc = e as Constant;
     if (cSrc == null || !cSrc.IsValid)
         return false;
     idDst = id;
     return true;
 }
示例#23
0
 protected override bool IsEqualTo(Constant right)
 {
     TypeConstant rightTypeConstant = right as TypeConstant;
     if (rightTypeConstant == null)
     {
         return false;
     }
     return m_edmType == rightTypeConstant.m_edmType;
 }
		public void Setup()
		{
			m = new ProcedureBuilder();
			i = m.Local32("i");
			c = m.Int32(16);
			off = m.Int32(42);
			r = m.Local32("r");
			aem = new ArrayExpressionMatcher(PrimitiveType.Pointer32);
		}
示例#25
0
		public override Constant ApplyConstants(Constant c1, Constant c2)
		{
            if (!ValidArgs(c1, c2))
                return Constant.Invalid;
            return c1.ToInt32() != c2.ToInt32()
				? Constant.True() 
				: Constant.False();

		}
		public void Associate(Identifier basePtr, Constant memberPtr)
		{
			if (assocs.ContainsKey(basePtr))
			{
				assocs[basePtr] = overAssociatedId;
                consts[basePtr] = overAssociatedConst;
				return;
			}
			consts[basePtr] = memberPtr;
		}
示例#27
0
		public LinearInductionVariable(
            Constant initial, 
            Constant delta, 
            Constant final,
            bool isSigned)
		{
			this.Initial = initial;
			this.Delta = delta;
			this.Final = final;
            this.IsSigned = isSigned;
		}
示例#28
0
		public static string FormatSignedValue(Constant c)
		{
			string s = "+";
			int tmp = c.ToInt32();
			if (tmp < 0)
			{
				s = "-";
				tmp = -tmp;
			}
			return s + tmp.ToString(FormatString(c.DataType));
		}
示例#29
0
 public override void SetRegister(RegisterStorage reg, Constant c)
 {
     if (c == null || !c.IsValid)
     {
         valid[reg.Number] = false;
     }
     else
     {
         reg.SetRegisterFileValues(regs, c.ToUInt32(), valid);	//$REVIEW: AsUint64 for PPC-64?
     }
 }
        internal override BoolExpr<DomainConstraint<BoolLiteral, Constant>> GetDomainBoolExpression(MemberDomainMap domainMap)
        {
            // Essentially say that the variable can take values true or false and here its value is only true
            IEnumerable<Constant> actualValues = new Constant[] { new ScalarConstant(true) };
            IEnumerable<Constant> possibleValues = new Constant[] { new ScalarConstant(true), new ScalarConstant(false) };
            var variableDomain = new Set<Constant>(possibleValues, Constant.EqualityComparer).MakeReadOnly();
            var thisDomain = new Set<Constant>(actualValues, Constant.EqualityComparer).MakeReadOnly();

            var result = MakeTermExpression(this, variableDomain, thisDomain);
            return result;
        }
示例#31
0
 public override Address MakeAddressFromConstant(Constant c, bool codeAlign)
 {
     throw new NotImplementedException();
 }
示例#32
0
        Expression ConvertExpression(ResolveContext ec)
        {
            // TODO: ImplicitConversionExists should take care of this
            if (left.eclass == ExprClass.MethodGroup)
            {
                return(null);
            }

            TypeSpec ltype = left.Type;

            //
            // If left is a nullable type and an implicit conversion exists from right to underlying type of left,
            // the result is underlying type of left
            //
            if (ltype.IsNullableType)
            {
                unwrap = Unwrap.Create(left, false);
                if (unwrap == null)
                {
                    return(null);
                }

                //
                // Reduce (left ?? null) to left
                //
                if (right.IsNull)
                {
                    return(ReducedExpression.Create(left, this));
                }

                if (Convert.ImplicitConversionExists(ec, right, unwrap.Type))
                {
                    left  = unwrap;
                    ltype = left.Type;

                    //
                    // If right is a dynamic expression, the result type is dynamic
                    //
                    if (right.Type.BuiltinType == BuiltinTypeSpec.Type.Dynamic)
                    {
                        type = right.Type;

                        // Need to box underlying value type
                        left = Convert.ImplicitBoxingConversion(left, ltype, type);
                        return(this);
                    }

                    right = Convert.ImplicitConversion(ec, right, ltype, loc);
                    type  = ltype;
                    return(this);
                }
            }
            else if (TypeSpec.IsReferenceType(ltype))
            {
                if (Convert.ImplicitConversionExists(ec, right, ltype))
                {
                    //
                    // If right is a dynamic expression, the result type is dynamic
                    //
                    if (right.Type.BuiltinType == BuiltinTypeSpec.Type.Dynamic)
                    {
                        type = right.Type;
                        return(this);
                    }

                    //
                    // Reduce ("foo" ?? expr) to expression
                    //
                    Constant lc = left as Constant;
                    if (lc != null && !lc.IsDefaultValue)
                    {
                        return(ReducedExpression.Create(lc, this));
                    }

                    //
                    // Reduce (left ?? null) to left OR (null-constant ?? right) to right
                    //
                    if (right.IsNull || lc != null)
                    {
                        return(ReducedExpression.Create(lc != null ? right : left, this));
                    }

                    right = Convert.ImplicitConversion(ec, right, ltype, loc);
                    type  = ltype;
                    return(this);
                }

                //
                // Special case null ?? null
                //
                if (ltype == right.Type)
                {
                    type = ltype;
                    return(this);
                }
            }
            else
            {
                return(null);
            }

            TypeSpec rtype = right.Type;

            if (!Convert.ImplicitConversionExists(ec, unwrap != null ? unwrap : left, rtype) || right.eclass == ExprClass.MethodGroup)
            {
                return(null);
            }

            //
            // Reduce (null ?? right) to right
            //
            if (left.IsNull)
            {
                return(ReducedExpression.Create(right, this).Resolve(ec));
            }

            left = Convert.ImplicitConversion(ec, unwrap != null ? unwrap : left, rtype, loc);
            type = rtype;
            return(this);
        }
示例#33
0
        private bool TryDecodeOperand(PrimitiveType width, int maxReg, out MachineOperand op)
        {
            op = null !;
            if (!rdr.TryReadByte(out byte bSpecifier))
            {
                return(false);
            }
            var reg = arch.GetRegister(bSpecifier & 0xF) !;

            switch (bSpecifier >> 4)
            {
            case 0: // Literal mode
            case 1:
            case 2:
            case 3:
                op = LiteralOperand(width, bSpecifier);
                break;

            case 4: // Index mode
                op = IndexOperand(width, reg) !;
                if (op == null)
                {
                    return(false);
                }
                break;

            case 5: // Register mode
                if (reg.Number > maxReg)
                {
                    return(false);
                }
                op = new RegisterOperand(reg);
                break;

            case 6: // Register deferred
                op = new MemoryOperand(width)
                {
                    Base = new RegisterOperand(reg)
                };
                break;

            case 7: // Autodecrement mode
                op = new MemoryOperand(width)
                {
                    Base          = new RegisterOperand(reg),
                    AutoDecrement = true,
                };
                break;

            case 8: // Autoincrement mode
                if (reg.Number == 0x0F)
                {
                    op = ImmediateOperand(width) !;
                    return(op != null);
                }
                else
                {
                    op = new MemoryOperand(width)
                    {
                        Base          = new RegisterOperand(reg),
                        AutoIncrement = true,
                    };
                }
                break;

            case 9: // Deferred Autoincrement mode
                op = new MemoryOperand(width)
                {
                    Base          = new RegisterOperand(reg),
                    AutoIncrement = true,
                    Deferred      = true,
                };
                break;

            case 0xA: // Displacement mode
            case 0xB:
                if (!rdr.TryReadByte(out byte b))
                {
                    return(false);
                }
                op = DisplacementOperand(width, reg, Constant.SByte((sbyte)b), bSpecifier);
                break;

            case 0xC:
            case 0xD:
                if (!rdr.TryReadUInt16(out ushort w))
                {
                    return(false);
                }
                op = DisplacementOperand(width, reg, Constant.Int16((short)w), bSpecifier);
                break;

            case 0xE:
            case 0xF:
                if (!rdr.TryReadUInt32(out uint dw))
                {
                    return(false);
                }
                op = DisplacementOperand(width, reg, Constant.Word32(dw), bSpecifier);
                break;

            default:
                throw new InvalidCastException("Impossiburu!");
            }
            return(true);
        }
示例#34
0
        private MachineOperand DisplacementOperand(PrimitiveType width, RegisterStorage reg, Constant c, byte bSpecifier)
        {
            bool deferred = ((bSpecifier >> 4) & 0x1) != 0;

            if (reg.Number == 15)
            {
                var addr = Address.Ptr32((uint)((int)rdr.Address.ToLinear() + c.ToInt32()));
                if (!deferred)
                {
                    return(AddressOperand.Create(addr));
                }
                else
                {
                    return(new MemoryOperand(width)
                    {
                        Offset = addr.ToConstant(),
                        Deferred = true
                    });
                }
            }
            return(new MemoryOperand(width)
            {
                Base = new RegisterOperand(reg),
                Offset = c,
                Deferred = deferred
            });
        }
示例#35
0
 private void RewriteOne(PrimitiveType dt)
 {
     m.Assign(RewriteSrc(instr.Operands[0]), Constant.Create(dt, 1));
 }
示例#36
0
        public void VpAddZero()
        {
            Identifier r = m.Reg32("r");

            var sub = new BinaryExpression(Operator.ISub, PrimitiveType.Word32, new MemoryAccess(MemoryIdentifier.GlobalMemory, r, PrimitiveType.Word32), Constant.Word32(0));
            var vp  = new ExpressionSimplifier(segmentMap, new SsaEvaluationContext(arch.Object, m.Ssa.Identifiers, dynamicLinker.Object), listener);
            var exp = sub.Accept(vp);

            Assert.AreEqual("Mem0[r:word32]", exp.ToString());
        }
示例#37
0
 public bool TryRead(PrimitiveType dataType, out Constant value) => TryReadBe(dataType, out value);
示例#38
0
 /// <inheritdoc/>
 public override bool Equals(Constant other)
 {
     return(other is MethodTokenConstant &&
            Method == ((MethodTokenConstant)other).Method);
 }
示例#39
0
 private void RewriteSet1()
 {
     RewriteDst(instr.Operands[0], Constant.Bool(true), (a, b) => b);
 }
示例#40
0
        private Expression MaybeShiftOperand(Expression exp, ArmInstructionOperand op)
        {
            switch (op.Shifter.Type)
            {
            case ArmShifterType.ASR: return(m.Sar(exp, op.Shifter.Value));

            case ArmShifterType.LSL: return(m.Shl(exp, op.Shifter.Value));

            case ArmShifterType.LSR: return(m.Shr(exp, op.Shifter.Value));

            case ArmShifterType.ROR: return(host.PseudoProcedure(PseudoProcedure.Ror, PrimitiveType.Word32, exp, Constant.Int32(op.Shifter.Value)));

            case ArmShifterType.RRX: return(host.PseudoProcedure("rrx", PrimitiveType.Word32, exp, Constant.Int32(op.Shifter.Value)));

            case ArmShifterType.ASR_REG: return(m.Sar(exp, Reg(op.Shifter.Value)));

            case ArmShifterType.LSL_REG: return(m.Shl(exp, Reg(op.Shifter.Value)));

            case ArmShifterType.LSR_REG: return(m.Shr(exp, Reg(op.Shifter.Value)));

            case ArmShifterType.ROR_REG: return(host.PseudoProcedure(PseudoProcedure.Ror, PrimitiveType.Word32, exp, Reg(op.Shifter.Value)));

            case ArmShifterType.RRX_REG: return(host.PseudoProcedure("rrx", PrimitiveType.Word32, exp, Reg(op.Shifter.Value)));

            default: return(exp);
            }
        }
示例#41
0
        }                                                // the data width of the current instruction being rewritten.

        /// <summary>
        /// Rewrite operands being used as sources.
        /// </summary>
        /// <param name="operand"></param>
        /// <param name="addrInstr">Address of the current instruction</param>
        /// <returns></returns>
        public Expression RewriteSrc(MachineOperand operand, Address addrInstr, bool addressAsAddress = false)
        {
            var reg = operand as RegisterOperand;

            if (reg != null)
            {
                Expression r = binder.EnsureRegister(reg.Register);
                if (DataWidth != null && DataWidth.Size != reg.Width.Size)
                {
                    r = m.Cast(DataWidth, r);
                }
                return(r);
            }
            var imm = operand as M68kImmediateOperand;

            if (imm != null)
            {
                if (imm.Width.Domain == Domain.Real)
                {
                    return(imm.Constant.CloneExpression());
                }
                if (DataWidth != null && DataWidth.BitSize > imm.Width.BitSize)
                {
                    return(Constant.Create(DataWidth, imm.Constant.ToInt64()));
                }
                else
                {
                    return(Constant.Create(imm.Width, imm.Constant.ToUInt32()));
                }
            }
            var mem = operand as MemoryOperand;

            if (mem != null)
            {
                return(RewriteMemoryAccess(mem, DataWidth, addrInstr));
            }
            var addr = operand as M68kAddressOperand;

            if (addr != null)
            {
                if (addressAsAddress)
                {
                    return(addr.Address);
                }
                else
                {
                    return(m.Load(DataWidth, addr.Address));
                }
            }
            var pre = operand as PredecrementMemoryOperand;

            if (pre != null)
            {
                var ea = binder.EnsureRegister(pre.Register);
                m.Assign(ea, m.ISub(ea, DataWidth.Size));
                return(m.Load(DataWidth, ea));
            }
            var post = operand as PostIncrementMemoryOperand;

            if (post != null)
            {
                var r   = binder.EnsureRegister(post.Register);
                var tmp = binder.CreateTemporary(DataWidth);
                m.Assign(tmp, m.Load(DataWidth, r));
                m.Assign(r, m.IAdd(r, DataWidth.Size));
                return(tmp);
            }
            var indidx = operand as IndirectIndexedOperand;

            if (indidx != null)
            {
                Expression ea = RewriteIndirectBaseRegister(indidx, addrInstr);
                Expression ix = binder.EnsureRegister(indidx.XRegister);
                if (indidx.XWidth.Size != 4)
                {
                    ix = m.Cast(PrimitiveType.Int32, m.Cast(PrimitiveType.Int16, ix));
                }
                if (indidx.Scale > 1)
                {
                    ix = m.IMul(ix, Constant.Int32(indidx.Scale));
                }
                return(m.Load(DataWidth, m.IAdd(ea, ix)));
            }
            var indop = operand as IndexedOperand;

            if (indop != null)
            {
                Expression ea = Combine(indop.Base, indop.base_reg);
                if (indop.postindex)
                {
                    ea = m.LoadDw(ea);
                }
                if (indop.index_reg != null)
                {
                    var idx = Combine(null, indop.index_reg);
                    if (indop.index_scale > 1)
                    {
                        idx = m.IMul(idx, indop.index_scale);
                    }
                    ea = Combine(ea, idx);
                }
                if (indop.preindex)
                {
                    ea = m.LoadDw(ea);
                }
                ea = Combine(ea, indop.outer);
                return(m.Load(DataWidth, ea));
            }
            throw new NotImplementedException("Unimplemented RewriteSrc for operand type " + operand.GetType().Name);
        }
示例#42
0
        public Expression RewriteMoveDst(MachineOperand opDst, Address addrInstr, PrimitiveType dataWidth, Expression src)
        {
            var reg = opDst as RegisterOperand;

            if (reg != null)
            {
                var r = binder.EnsureRegister(reg.Register);
                if (r.DataType.Size > dataWidth.Size)
                {
                    var tmp = binder.CreateTemporary(dataWidth);
                    m.Assign(r, m.Dpb(r, src, 0));
                    return(tmp);
                }
                else
                {
                    m.Assign(r, src);
                    return(r);
                }
            }
            var mem = opDst as MemoryOperand;

            if (mem != null)
            {
                src = Spill(src, binder.EnsureRegister(mem.Base));
                var load = RewriteMemoryAccess(mem, dataWidth, addrInstr);
                var tmp  = binder.CreateTemporary(dataWidth);
                m.Assign(load, src);
                return(tmp);
            }
            var post = opDst as PostIncrementMemoryOperand;

            if (post != null)
            {
                var r    = binder.EnsureRegister(post.Register);
                var rExp = Spill(src, r);
                var load = m.Load(dataWidth, r);
                m.Assign(load, rExp);
                m.Assign(r, m.IAdd(r, dataWidth.Size));
                return(src);
            }
            var pre = opDst as PredecrementMemoryOperand;

            if (pre != null)
            {
                var r = binder.EnsureRegister(pre.Register);
                m.Assign(r, m.ISub(r, dataWidth.Size));
                var rExp = Spill(src, r);
                var load = m.Load(dataWidth, rExp);
                m.Assign(load, src);
                return(src);
            }
            var idxop = opDst as IndexedOperand;

            if (idxop != null)
            {
                var b    = binder.EnsureRegister(idxop.base_reg);
                var i    = binder.EnsureRegister(idxop.index_reg);
                var s    = m.Const(i.DataType, idxop.index_scale);
                var load = m.Load(dataWidth, m.IAdd(b, m.IMul(i, s)));
                m.Assign(load, src);
                return(src);
            }
            var indidx = opDst as IndirectIndexedOperand;

            if (indidx != null)
            {
                var a    = binder.EnsureRegister(indidx.ARegister);
                var x    = binder.EnsureRegister(indidx.XRegister);
                var load = m.Load(dataWidth, m.IAdd(a, x));
                m.Assign(load, src);
                return(src);
            }
            var mAddr = opDst as M68kAddressOperand;

            if (mAddr != null)
            {
                m.Assign(
                    m.Load(
                        dataWidth,
                        Constant.Word32(mAddr.Address.ToUInt32())),
                    src);
                return(src);
            }
            throw new NotImplementedException("Unimplemented RewriteMoveDst for operand type " + opDst.GetType().Name);
        }
示例#43
0
        public string CreateRequest(List <IOrderItemMessage> items, Guid orderId, string processorUrl, Dictionary <string, string> settings)
        {
            //PayPal cart version
            string PostUrl = processorUrl;
            string Cmd     = "_cart";
            //string Cmd = "_xclick";
            string        Upload        = "1";
            string        BusinessEmail = settings["BusinessEmail"];
            string        Currency      = "USD";
            string        ShipAmount    = "1";
            StringBuilder ppForm        = new StringBuilder();
            var           convRate      = new ConversionRate();

            ppForm.Append("<HTML><BODY><form name='frmPP' id='frmPP' action='" + PostUrl + "' method='post'>");
            ppForm.Append("<input type='hidden' name='shipping' value='" + ShipAmount + "'>");
            ppForm.Append("<input type='hidden' name='cmd' value='" + Cmd + "'>");
            ppForm.Append("<input type='hidden' name='upload' value='" + Upload + "}'>");
            ppForm.Append("<input type='hidden' name='business' value='" + BusinessEmail + "'>");
            ppForm.Append("<input type='hidden' name='currency_code' value='" + Currency + "'>");
            ppForm.Append("<input type='hidden' name='rm' value='1'>");
            ppForm.Append("<input type='hidden' name='return' value='" + settings["ReturnUrl"] + "'>");
            ppForm.Append("<input type='hidden' name='notify_url' value='" + settings["NotifyUrl"] + "'>");
            ppForm.Append("<input type='hidden' name='cancel_return' value='" + settings["CancelPurchaseUrl"] + "'>");
            ppForm.Append("<input type='hidden' name='custom' value='" + orderId.ToString() + "'>");

            for (int i = 0; i < items.Count; i++)
            {
                var item = items[i];
                ppForm.Append("<input type='hidden' name='item_number_" + (i + 1).ToString() + "' value='" + (i + 1).ToString() + "'>");
                ppForm.Append("<input type='hidden' name='item_name_" + (i + 1).ToString() + "' value='" + Constant.GetItemDescription(item.DomainName, GetPlan(item.SubPlanID).ProductName, GetPlan(item.SubPlanID).DisplayName) + "'>");
                ppForm.Append("<input type='hidden' name='amount_" + (i + 1).ToString() + "' value='" + convRate.ConvertRupeeToDollar(GetPlan(item.SubPlanID)).ToString() + "'>");
                ppForm.Append("<input type='hidden' name='quantity_" + (i + 1).ToString() + "' value='1'>");
            }

            ppForm.Append("</form>" + PayPalPostScript() + "</BODY></HTML>");

            return(ppForm.ToString());
        }
 public StoreOffset(Statement stm, Store store, Constant Offset)
 {
     this.Statement = stm;
     this.Store     = store;
     this.Offset    = Offset;
 }
示例#45
0
        public void X86Orw32_IndexedAccess()
        {
            MemoryOperand mem  = new MemoryOperand(PrimitiveType.Word32, Registers.eax, Registers.edx, 4, Constant.Word32(0x24));
            Expression    expr = orw.Transform(instr, mem, PrimitiveType.Word32, state);

            Assert.AreEqual("Mem0[eax + 0x24<32> + edx * 4<32>:word32]", expr.ToString());
        }
示例#46
0
        public void VpMulAddShift()
        {
            Identifier       id = m.Reg32("id");
            var              vp = new ExpressionSimplifier(segmentMap, new SsaEvaluationContext(arch.Object, m.Ssa.Identifiers, dynamicLinker.Object), listener);
            PrimitiveType    t  = PrimitiveType.Int32;
            BinaryExpression b  = new BinaryExpression(Operator.Shl, t,
                                                       new BinaryExpression(Operator.IAdd, t,
                                                                            new BinaryExpression(Operator.SMul, t, id, Constant.Create(t, 4)),
                                                                            id),
                                                       Constant.Create(t, 2));
            Expression e = vp.VisitBinaryExpression(b);

            Assert.AreEqual("id *s 20", e.ToString());
        }
示例#47
0
 public IncrementedUse(Statement stm, BinaryExpression exp, Constant inc)
 {
     this.Statement  = stm;
     this.Expression = exp;
     this.Increment  = inc;
 }
示例#48
0
        private void RewriteSel()
        {
            var bank = (RegisterBankOperand)instr.Operands[0];

            m.SideEffect(host.Intrinsic("__select_register_bank", false, VoidType.Instance, Constant.Byte((byte)bank.Bank)));
        }
示例#49
0
 public abstract bool TryRead(MemoryArea mem, Address addr, PrimitiveType dt, out Constant value);
示例#50
0
 public override Address MakeAddressFromConstant(Constant c)
 {
     return(Address.Ptr16(c.ToUInt16()));
 }
示例#51
0
 public Address MakeSegmentedAddress(Constant selector, Constant offset)
 {
     throw new NotImplementedException();
 }
示例#52
0
 private void RewriteClr(PrimitiveType dt)
 {
     m.Assign(RewriteSrc(instr.Operands[0]), Constant.Zero(dt));
 }
示例#53
0
 public Address MakeAddressFromConstant(Constant c)
 {
     return(program.Architecture.MakeAddressFromConstant(c, true));
 }
示例#54
0
 /// <summary>
 /// Adds the specified constant as a member to this class.
 ///
 /// <param name="c">a constant</param>
 /// </summary>
 public override void add_constant(Constant c)
 {
     constants.Add(c);
     scope.add(c.name, c);
 }
示例#55
0
文件: Driver.cs 项目: zvonimir/corral
        private static void addInitializersToMain(Program prog, string mainProcName)
        {
            if (mainProcName == "")
            {
                List <string> entrypoints = EntrypointScanner.FindEntrypoint(prog);
                if (entrypoints.Count == 0)
                {
                    //throw new InternalError("Main procedure not found");
                    Console.WriteLine("Main procedure not found");
                    return;
                }
                mainProcName = entrypoints[0];
            }
            var mainProc = cba.Util.BoogieUtil.findProcedureImpl(prog.TopLevelDeclarations, mainProcName);

            if (mainProc == null)
            {
                Console.WriteLine("Implementation of main procedure " + mainProcName + " not found");
                return;
            }

            // Find all initializers
            List <Cmd> newCmds = new List <Cmd>();

            foreach (var decl in prog.TopLevelDeclarations)
            {
                var impl = decl as Implementation;
                if (impl == null)
                {
                    continue;
                }
                if (impl.Name.EndsWith("cctor"))
                {
                    if (impl.InParams.Count == 0)
                    {
                        newCmds.Add(new CallCmd(Token.NoToken, impl.Name, new List <Expr>(), new List <IdentifierExpr>()));
                    }
                }
            }

            // Find relevant variables and constants
            GlobalVariable exceptionVariable = null;
            Constant       nullConstant      = null;

            foreach (var decl in prog.TopLevelDeclarations)
            {
                GlobalVariable globalVariable = decl as GlobalVariable;
                if (globalVariable != null)
                {
                    if (globalVariable.Name == "$Exception")
                    {
                        exceptionVariable = globalVariable;
                    }
                }

                Constant constant = decl as Constant;
                if (constant != null)
                {
                    if (constant.Name == "null")
                    {
                        nullConstant = constant;
                    }
                }

                if (exceptionVariable != null && nullConstant != null)
                {
                    break;
                }
            }

            // Create initialization of exception variable
            if (exceptionVariable == null)
            {
                throw new InternalError("Variable $Exception not found");
            }
            else if (nullConstant == null)
            {
                throw new InternalError("Constant null not found");
            }
            else
            {
                List <AssignLhs> lhss = new List <AssignLhs>();
                lhss.Add(new SimpleAssignLhs(Token.NoToken, Expr.Ident(exceptionVariable)));
                List <Expr> rhss = new List <Expr>();
                rhss.Add(Expr.Ident(nullConstant));
                newCmds.Add(new AssignCmd(Token.NoToken, lhss, rhss));
            }

            // Create initialization of track variable for GetMeHere
            {
                GlobalVariable trackVariable = new GlobalVariable(Token.NoToken, new TypedIdent(Token.NoToken, "$GetMeHereTracker", Microsoft.Boogie.Type.Int));
                prog.AddTopLevelDeclaration(trackVariable);
                List <AssignLhs> lhss = new List <AssignLhs>();
                lhss.Add(new SimpleAssignLhs(Token.NoToken, Expr.Ident(trackVariable)));
                List <Expr> rhss = new List <Expr>();
                rhss.Add(new LiteralExpr(Token.NoToken, Microsoft.Basetypes.BigNum.ZERO));
                newCmds.Add(new AssignCmd(Token.NoToken, lhss, rhss));
            }

            // Add call to all initializers in main
            var block = mainProc.Blocks[0];

            newCmds.AddRange(block.Cmds);
            block.Cmds = newCmds;
        }
示例#56
0
 private void RewriteClr1()
 {
     RewriteDst(instr.Operands[0], Constant.Bool(false), (a, b) => b);
 }
示例#57
0
 public override Address MakeAddressFromConstant(Constant c)
 => Address.Ptr32(c.ToUInt32());
示例#58
0
 public abstract Address MakeAddressFromConstant(Constant c, bool codeAlign);
示例#59
0
        public Expression RewriteDst(
            MachineOperand operand,
            Address addrInstr,
            PrimitiveType dataWidth,
            Expression src,
            Func <Expression, Expression, Expression> opGen)
        {
            var reg = operand as RegisterOperand;

            if (reg != null)
            {
                Expression r   = binder.EnsureRegister(reg.Register);
                Expression tmp = r;
                if (dataWidth != null &&
                    reg.Width.BitSize > dataWidth.BitSize &&
                    reg.Width.Domain != Domain.Real)
                {
                    Expression rSub   = m.Cast(dataWidth, r);
                    var        srcExp = opGen(src, rSub);
                    if (srcExp is Identifier || srcExp is Constant || srcExp is DepositBits)
                    {
                        tmp = srcExp;
                    }
                    else
                    {
                        tmp = binder.CreateTemporary(dataWidth);
                        m.Assign(tmp, srcExp);
                    }
                    src = m.Dpb(r, tmp, 0);
                }
                else
                {
                    src = opGen(src, r);
                }
                m.Assign(r, src);
                return(tmp);
            }
            var dbl = operand as DoubleRegisterOperand;

            if (dbl != null)
            {
                Identifier h      = binder.EnsureRegister(dbl.Register1);
                Identifier l      = binder.EnsureRegister(dbl.Register2);
                var        d      = binder.EnsureSequence(h.Storage, l.Storage, PrimitiveType.Word64);
                var        result = opGen(src, l);
                m.Assign(d, result);
                return(d);
            }
            var addr = operand as M68kAddressOperand;

            if (addr != null)
            {
                var load = m.Load(dataWidth, addr.Address);
                var tmp  = binder.CreateTemporary(dataWidth);
                m.Assign(tmp, opGen(src, load));
                m.Assign(load, tmp);
                return(tmp);
            }
            var mem = operand as MemoryOperand;

            if (mem != null)
            {
                var load = RewriteMemoryAccess(mem, dataWidth, addrInstr);
                var tmp  = binder.CreateTemporary(dataWidth);
                m.Assign(tmp, opGen(src, load));
                m.Assign(load, tmp);
                return(tmp);
            }
            var post = operand as PostIncrementMemoryOperand;

            if (post != null)
            {
                var r   = binder.EnsureRegister(post.Register);
                var tmp = binder.CreateTemporary(dataWidth);
                m.Assign(tmp, opGen(src, m.Load(post.Width, r)));
                m.Assign(m.Load(dataWidth, r), tmp);
                m.Assign(r, m.IAdd(r, dataWidth.Size));
                return(tmp);
            }
            var pre = operand as PredecrementMemoryOperand;

            if (pre != null)
            {
                var r = binder.EnsureRegister(pre.Register);
                src = Spill(src, r);
                m.Assign(r, m.ISub(r, dataWidth.Size));
                var load = m.Load(dataWidth, r);
                var tmp  = binder.CreateTemporary(dataWidth);
                m.Assign(tmp, opGen(src, load));
                m.Assign(m.Load(dataWidth, r), tmp);
                return(tmp);
            }
            var indidx = operand as IndirectIndexedOperand;

            if (indidx != null)
            {
                Expression ea = binder.EnsureRegister(indidx.ARegister);
                if (indidx.Imm8 != 0)
                {
                    ea = m.IAdd(ea, Constant.Int32(indidx.Imm8));
                }
                Expression ix = binder.EnsureRegister(indidx.XRegister);
                if (indidx.Scale > 1)
                {
                    ix = m.IMul(ix, Constant.Int32(indidx.Scale));
                }
                var load = m.Load(dataWidth, m.IAdd(ea, ix));
                var tmp  = binder.CreateTemporary(dataWidth);
                m.Assign(tmp, opGen(src, load));
                m.Assign(load, tmp);
                return(tmp);
            }
            return(null);
        }
示例#60
0
 public virtual Address MakeSegmentedAddress(Constant seg, Constant offset)
 {
     throw new NotSupportedException("This architecture doesn't support segmented addresses.");
 }