Esempio n. 1
0
 public static Int32Value Add(Int32Value a, Int32Value b)
 {
     if (a.allBitsValid() && b.allBitsValid())
         return new Int32Value(a.value + b.value);
     if (ReferenceEquals(a, b))
         return new Int32Value(a.value << 1, (a.validMask << 1) | 1);
     return createUnknown();
 }
		bool IBranchHandler.HandleSwitch(Int32Value switchIndex) {
			var target = CflowUtils.GetSwitchTarget(block.Targets, block.FallThrough, switchIndex);
			if (target == null)
				return false;

			PopPushedArgs(1);
			block.ReplaceSwitchWithBranch(target);
			return true;
		}
Esempio n. 3
0
		public static Block GetSwitchTarget(IList<Block> targets, Block fallThrough, Int32Value intValue) {
			if (!intValue.AllBitsValid())
				return null;

			int index = intValue.Value;
			if (targets == null || index < 0 || index >= targets.Count)
				return fallThrough;
			else
				return targets[index];
		}
Esempio n. 4
0
 public static Int32Value Add_Ovf(Int32Value a, Int32Value b)
 {
     if (a.AllBitsValid() && b.AllBitsValid()) {
         try {
             return new Int32Value(checked(a.Value + b.Value));
         }
         catch (OverflowException) {
         }
     }
     return CreateUnknown();
 }
		bool IBranchHandler.HandleSwitch(Int32Value switchIndex) {
			if (!switchIndex.AllBitsValid())
				return false;
			var instr = instructions[emulateIndex];
			var targets = (Instruction[])instr.Operand;
			if (switchIndex.Value >= 0 && switchIndex.Value < targets.Length)
				emulateIndex = instructions.IndexOf(targets[switchIndex.Value]);
			else
				emulateIndex++;
			return true;
		}
Esempio n. 6
0
 public static Int32Value Add_Ovf_Un(Int32Value a, Int32Value b)
 {
     if (a.AllBitsValid() && b.AllBitsValid()) {
         uint aa = (uint)a.Value, bb = (uint)b.Value;
         try {
             return new Int32Value((int)checked(aa + bb));
         }
         catch (OverflowException) {
         }
     }
     return CreateUnknown();
 }
Esempio n. 7
0
		public static Int32Value Mul(Int32Value a, Int32Value b) {
			if (a.AllBitsValid() && b.AllBitsValid())
				return new Int32Value(a.Value * b.Value);
			if (a.IsZero() || b.IsZero())
				return Zero;
			if (a.HasValue(1))
				return b;
			if (b.HasValue(1))
				return a;
			return CreateUnknown();
		}
Esempio n. 8
0
 public static Int32Value Conv_Ovf_U4_Un(Int32Value a)
 {
     return(a);
 }
Esempio n. 9
0
		public static Bool3 CompareGe(Int32Value a, Int32Value b) {
			if (a.AllBitsValid() && b.AllBitsValid())
				return a.Value >= b.Value ? Bool3.True : Bool3.False;
			if (a.HasValue(int.MaxValue))
				return Bool3.True;	// max >= x => true
			if (b.HasValue(int.MinValue))
				return Bool3.True;	// x >= min => true
			return Bool3.Unknown;
		}
Esempio n. 10
0
 public static Int32Value Clt(Int64Value a, Int64Value b) =>
 Int32Value.Create(CompareLt(a, b));
Esempio n. 11
0
		public static Int32Value Not(Int32Value a) {
			return new Int32Value(~a.Value, a.ValidMask);
		}
Esempio n. 12
0
		public static Int32Value Cgt(Int32Value a, Int32Value b) {
			return Create(CompareGt(a, b));
		}
Esempio n. 13
0
		public static Int32Value Conv_Ovf_I2(Int32Value a) {
			if (!a.AreBitsValid(NO_UNKNOWN_BITS << 15) ||
				!a.CheckSign(NO_UNKNOWN_BITS << 15))
				return CreateUnknown();
			return Conv_I2(a);
		}
Esempio n. 14
0
		public static Int32Value Conv_Ovf_I4(Int32Value a) => a;
Esempio n. 15
0
 public static Int32Value Clt(Int32Value a, Int32Value b)
 {
     return(Create(CompareLt(a, b)));
 }
Esempio n. 16
0
		public static Int32Value Conv_U4(Int32Value a) => a;
Esempio n. 17
0
 public static Int32Value Cgt_Un(Int32Value a, Int32Value b)
 {
     return(Create(CompareGt_Un(a, b)));
 }
Esempio n. 18
0
 public static Int32Value Ceq(Int32Value a, Int32Value b)
 {
     return(Create(CompareEq(a, b)));
 }
Esempio n. 19
0
 public static Int32Value Not(Int32Value a)
 {
     return(new Int32Value(~a.Value, a.ValidMask));
 }
Esempio n. 20
0
		public static Int32Value Rem_Un(Int32Value a, Int32Value b) {
			if (a.AllBitsValid() && b.AllBitsValid()) {
				try {
					return new Int32Value((int)((uint)a.Value % (uint)b.Value));
				}
				catch (ArithmeticException) {
					return CreateUnknown();
				}
			}
			if ((ReferenceEquals(a, b) && a.IsNonZero()) || b.HasValue(1))
				return Zero;
			return CreateUnknown();
		}
Esempio n. 21
0
		public static Int64Value Conv_Ovf_I8(Int32Value a) {
			ulong validMask = a.ValidMask;
			if (IsBitValid(a.ValidMask, 31))
				validMask |= Int64Value.NO_UNKNOWN_BITS << 32;
			return new Int64Value(a.Value, validMask);
		}
Esempio n. 22
0
		public static Int32Value Or(Int32Value a, Int32Value b) {
			int av = a.Value, bv = b.Value;
			uint am = a.ValidMask, bm = b.ValidMask;
			return new Int32Value(av | bv, (am & bm) | ((uint)av & am) | ((uint)bv & bm));
		}
Esempio n. 23
0
		public static Int32Value Conv_Ovf_U1_Un(Int32Value a) {
			if (!a.AreBitsValid(NO_UNKNOWN_BITS << 8) ||
				(uint)a.Value > byte.MaxValue)
				return CreateUnknownUInt8();
			return Conv_U1(a);
		}
Esempio n. 24
0
		public static Int32Value Shr_Un(Int32Value a, Int32Value b) {
			if (b.HasUnknownBits())
				return CreateUnknown();
			if (b.Value == 0)
				return a;
			if (b.Value < 0 || b.Value >= sizeof(int) * 8)
				return CreateUnknown();
			int shift = b.Value;
			uint validMask = (a.ValidMask >> shift) | (uint.MaxValue << (sizeof(int) * 8 - shift));
			return new Int32Value((int)((uint)a.Value >> shift), validMask);
		}
Esempio n. 25
0
 public static Int32Value Conv_I2(Int32Value a)
 {
     return(Conv_I2(a.Value, a.ValidMask));
 }
Esempio n. 26
0
		public static Bool3 CompareNeq(Int32Value a, Int32Value b) {
			if (a.AllBitsValid() && b.AllBitsValid())
				return a.Value != b.Value ? Bool3.True : Bool3.False;
			if (ReferenceEquals(a, b))
				return Bool3.False;
			if (((uint)a.Value & a.ValidMask & b.ValidMask) != ((uint)b.Value & a.ValidMask & b.ValidMask))
				return Bool3.True;
			return Bool3.Unknown;
		}
Esempio n. 27
0
		public static Int32Value Conv_Ovf_U4(Int32Value a) {
			if (!IsBitValid(a.ValidMask, 31) || a.Value < 0)
				return CreateUnknown();
			return a;
		}
Esempio n. 28
0
		public static Bool3 CompareLt_Un(Int32Value a, Int32Value b) {
			if (a.AllBitsValid() && b.AllBitsValid())
				return (uint)a.Value < (uint)b.Value ? Bool3.True : Bool3.False;
			if (a.HasValue(uint.MaxValue))
				return Bool3.False;	// max < x => false
			if (b.HasValue(uint.MinValue))
				return Bool3.False;	// x < min => false
			return Bool3.Unknown;
		}
Esempio n. 29
0
		public static Int64Value Conv_Ovf_U8(Int32Value a) {
			if (!IsBitValid(a.ValidMask, 31) || a.Value < 0)
				return Int64Value.CreateUnknown();
			return new Int64Value(a.Value, (ulong)a.ValidMask | (Int64Value.NO_UNKNOWN_BITS << 32));
		}
Esempio n. 30
0
 public static Int32Value Ceq(Int64Value a, Int64Value b) =>
 Int32Value.Create(CompareEq(a, b));
Esempio n. 31
0
		public static Real8Value Conv_R8(Int32Value a) {
			if (a.AllBitsValid())
				return new Real8Value((double)(int)a.Value);
			return Real8Value.CreateUnknown();
		}
Esempio n. 32
0
		public static Int32Value Conv_Ovf_U2_Un(Int32Value a) {
			if (!a.AreBitsValid(NO_UNKNOWN_BITS << 16) ||
				(uint)a.Value > ushort.MaxValue)
				return CreateUnknownUInt16();
			return Conv_U2(a);
		}
Esempio n. 33
0
 public static Int32Value Conv_I4(Int32Value a)
 {
     return(a);
 }
Esempio n. 34
0
		public static Int32Value Conv_Ovf_U4(Int32Value a) {
			if (!IsBitValid(a.ValidMask, 31) || a.Value < 0)
				return CreateUnknown();
			return a;
		}
Esempio n. 35
0
		public static Int32Value Conv_Ovf_U4_Un(Int32Value a) => a;
Esempio n. 36
0
		public static Int32Value Conv_Ovf_U4_Un(Int32Value a) {
			return a;
		}
Esempio n. 37
0
		public static Int64Value Conv_Ovf_U8(Int32Value a) {
			if (!IsBitValid(a.ValidMask, 31) || a.Value < 0)
				return Int64Value.CreateUnknown();
			return new Int64Value(a.Value, (ulong)a.ValidMask | (Int64Value.NO_UNKNOWN_BITS << 32));
		}
Esempio n. 38
0
		public static Int64Value Conv_Ovf_U8_Un(Int32Value a) {
			return new Int64Value((long)(uint)a.Value, a.ValidMask | (Int64Value.NO_UNKNOWN_BITS << 32));
		}
Esempio n. 39
0
		public static Int64Value Conv_Ovf_U8_Un(Int32Value a) =>
			new Int64Value((long)(uint)a.Value, a.ValidMask | (Int64Value.NO_UNKNOWN_BITS << 32));
Esempio n. 40
0
		public static Int32Value Sub(Int32Value a, Int32Value b) {
			if (a.AllBitsValid() && b.AllBitsValid())
				return new Int32Value(a.Value - b.Value);
			if (ReferenceEquals(a, b))
				return Zero;
			return CreateUnknown();
		}
Esempio n. 41
0
		public static Real8Value Conv_R8(Int32Value a) {
			if (a.AllBitsValid())
				return new Real8Value((double)(int)a.Value);
			return Real8Value.CreateUnknown();
		}
Esempio n. 42
0
		public static Int32Value Div(Int32Value a, Int32Value b) {
			if (a.AllBitsValid() && b.AllBitsValid()) {
				try {
					return new Int32Value(a.Value / b.Value);
				}
				catch (ArithmeticException) {
					return CreateUnknown();
				}
			}
			if (ReferenceEquals(a, b) && a.IsNonZero())
				return One;
			if (b.HasValue(1))
				return a;
			return CreateUnknown();
		}
Esempio n. 43
0
		public static Int32Value Neg(Int32Value a) {
			if (a.AllBitsValid())
				return new Int32Value(-a.Value);
			return CreateUnknown();
		}
Esempio n. 44
0
		public static Int32Value Neg(Int32Value a) {
			if (a.AllBitsValid())
				return new Int32Value(-a.Value);
			return CreateUnknown();
		}
Esempio n. 45
0
		public static Int32Value Or(Int32Value a, Int32Value b) {
			int av = a.Value, bv = b.Value;
			uint am = a.ValidMask, bm = b.ValidMask;
			return new Int32Value(av | bv, (am & bm) | ((uint)av & am) | ((uint)bv & bm));
		}
Esempio n. 46
0
		public static Int32Value Xor(Int32Value a, Int32Value b) {
			if (ReferenceEquals(a, b))
				return Zero;
			int av = a.Value, bv = b.Value;
			uint am = a.ValidMask, bm = b.ValidMask;
			return new Int32Value(av ^ bv, am & bm);
		}
Esempio n. 47
0
		public static Int32Value Not(Int32Value a) => new Int32Value(~a.Value, a.ValidMask);
Esempio n. 48
0
		public static Int32Value Shr(Int32Value a, Int32Value b) {
			if (b.HasUnknownBits())
				return CreateUnknown();
			if (b.Value == 0)
				return a;
			if (b.Value < 0 || b.Value >= sizeof(int) * 8)
				return CreateUnknown();
			int shift = b.Value;
			uint validMask = a.ValidMask >> shift;
			if (a.IsBitValid(sizeof(int) * 8 - 1))
				validMask |= (uint.MaxValue << (sizeof(int) * 8 - shift));
			return new Int32Value(a.Value >> shift, validMask);
		}
Esempio n. 49
0
		public static Int32Value Cgt(Int32Value a, Int32Value b) => Create(CompareGt(a, b));
Esempio n. 50
0
		public static Int32Value Ceq(Int32Value a, Int32Value b) {
			return Create(CompareEq(a, b));
		}
Esempio n. 51
0
		public static Int32Value Clt_Un(Int32Value a, Int32Value b) => Create(CompareLt_Un(a, b));
Esempio n. 52
0
		public static Int32Value Clt_Un(Int32Value a, Int32Value b) {
			return Create(CompareLt_Un(a, b));
		}
Esempio n. 53
0
		public static Int32Value Conv_I1(Int32Value a) => Conv_I1(a.Value, a.ValidMask);
Esempio n. 54
0
		public static Bool3 CompareGt(Int32Value a, Int32Value b) {
			if (a.AllBitsValid() && b.AllBitsValid())
				return a.Value > b.Value ? Bool3.True : Bool3.False;
			if (a.HasValue(int.MinValue))
				return Bool3.False;	// min > x => false
			if (b.HasValue(int.MaxValue))
				return Bool3.False;	// x > max => false
			return Bool3.Unknown;
		}
Esempio n. 55
0
 public static Int32Value Cgt(Int64Value a, Int64Value b)
 {
     return(Int32Value.Create(CompareGt(a, b)));
 }
Esempio n. 56
0
		public static Bool3 CompareLe_Un(Int32Value a, Int32Value b) {
			if (a.AllBitsValid() && b.AllBitsValid())
				return (uint)a.Value <= (uint)b.Value ? Bool3.True : Bool3.False;
			if (a.HasValue(uint.MinValue))
				return Bool3.True;	// min <= x => true
			if (b.HasValue(uint.MaxValue))
				return Bool3.True;	// x <= max => true
			return Bool3.Unknown;
		}
Esempio n. 57
0
 public static Int32Value Clt_Un(Int64Value a, Int64Value b)
 {
     return(Int32Value.Create(CompareLt_Un(a, b)));
 }
Esempio n. 58
0
		public static Bool3 CompareFalse(Int32Value a) {
			if (a.AllBitsValid())
				return a.Value == 0 ? Bool3.True : Bool3.False;
			if (((uint)a.Value & a.ValidMask) != 0)
				return Bool3.False;
			return Bool3.Unknown;
		}
Esempio n. 59
0
 public static Int32Value Cgt_Un(Int64Value a, Int64Value b) =>
 Int32Value.Create(CompareGt_Un(a, b));