Ejemplo 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;
		}
Ejemplo 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];
		}
Ejemplo 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;
		}
Ejemplo 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();
 }
Ejemplo 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();
		}
Ejemplo n.º 8
0
 public static Int32Value Conv_Ovf_U4_Un(Int32Value a)
 {
     return(a);
 }
Ejemplo 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;
		}
Ejemplo n.º 10
0
 public static Int32Value Clt(Int64Value a, Int64Value b) =>
 Int32Value.Create(CompareLt(a, b));
Ejemplo n.º 11
0
		public static Int32Value Not(Int32Value a) {
			return new Int32Value(~a.Value, a.ValidMask);
		}
Ejemplo n.º 12
0
		public static Int32Value Cgt(Int32Value a, Int32Value b) {
			return Create(CompareGt(a, b));
		}
Ejemplo 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);
		}
Ejemplo n.º 14
0
		public static Int32Value Conv_Ovf_I4(Int32Value a) => a;
Ejemplo n.º 15
0
 public static Int32Value Clt(Int32Value a, Int32Value b)
 {
     return(Create(CompareLt(a, b)));
 }
Ejemplo n.º 16
0
		public static Int32Value Conv_U4(Int32Value a) => a;
Ejemplo n.º 17
0
 public static Int32Value Cgt_Un(Int32Value a, Int32Value b)
 {
     return(Create(CompareGt_Un(a, b)));
 }
Ejemplo n.º 18
0
 public static Int32Value Ceq(Int32Value a, Int32Value b)
 {
     return(Create(CompareEq(a, b)));
 }
Ejemplo n.º 19
0
 public static Int32Value Not(Int32Value a)
 {
     return(new Int32Value(~a.Value, a.ValidMask));
 }
Ejemplo 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();
		}
Ejemplo 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);
		}
Ejemplo 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));
		}
Ejemplo 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);
		}
Ejemplo 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);
		}
Ejemplo n.º 25
0
 public static Int32Value Conv_I2(Int32Value a)
 {
     return(Conv_I2(a.Value, a.ValidMask));
 }
Ejemplo 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;
		}
Ejemplo n.º 27
0
		public static Int32Value Conv_Ovf_U4(Int32Value a) {
			if (!IsBitValid(a.ValidMask, 31) || a.Value < 0)
				return CreateUnknown();
			return a;
		}
Ejemplo 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;
		}
Ejemplo 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));
		}
Ejemplo n.º 30
0
 public static Int32Value Ceq(Int64Value a, Int64Value b) =>
 Int32Value.Create(CompareEq(a, b));
Ejemplo n.º 31
0
		public static Real8Value Conv_R8(Int32Value a) {
			if (a.AllBitsValid())
				return new Real8Value((double)(int)a.Value);
			return Real8Value.CreateUnknown();
		}
Ejemplo 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);
		}
Ejemplo n.º 33
0
 public static Int32Value Conv_I4(Int32Value a)
 {
     return(a);
 }
Ejemplo n.º 34
0
		public static Int32Value Conv_Ovf_U4(Int32Value a) {
			if (!IsBitValid(a.ValidMask, 31) || a.Value < 0)
				return CreateUnknown();
			return a;
		}
Ejemplo n.º 35
0
		public static Int32Value Conv_Ovf_U4_Un(Int32Value a) => a;
Ejemplo n.º 36
0
		public static Int32Value Conv_Ovf_U4_Un(Int32Value a) {
			return a;
		}
Ejemplo 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));
		}
Ejemplo 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));
		}
Ejemplo 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));
Ejemplo 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();
		}
Ejemplo n.º 41
0
		public static Real8Value Conv_R8(Int32Value a) {
			if (a.AllBitsValid())
				return new Real8Value((double)(int)a.Value);
			return Real8Value.CreateUnknown();
		}
Ejemplo 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();
		}
Ejemplo n.º 43
0
		public static Int32Value Neg(Int32Value a) {
			if (a.AllBitsValid())
				return new Int32Value(-a.Value);
			return CreateUnknown();
		}
Ejemplo n.º 44
0
		public static Int32Value Neg(Int32Value a) {
			if (a.AllBitsValid())
				return new Int32Value(-a.Value);
			return CreateUnknown();
		}
Ejemplo 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));
		}
Ejemplo 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);
		}
Ejemplo n.º 47
0
		public static Int32Value Not(Int32Value a) => new Int32Value(~a.Value, a.ValidMask);
Ejemplo 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);
		}
Ejemplo n.º 49
0
		public static Int32Value Cgt(Int32Value a, Int32Value b) => Create(CompareGt(a, b));
Ejemplo n.º 50
0
		public static Int32Value Ceq(Int32Value a, Int32Value b) {
			return Create(CompareEq(a, b));
		}
Ejemplo n.º 51
0
		public static Int32Value Clt_Un(Int32Value a, Int32Value b) => Create(CompareLt_Un(a, b));
Ejemplo n.º 52
0
		public static Int32Value Clt_Un(Int32Value a, Int32Value b) {
			return Create(CompareLt_Un(a, b));
		}
Ejemplo n.º 53
0
		public static Int32Value Conv_I1(Int32Value a) => Conv_I1(a.Value, a.ValidMask);
Ejemplo 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;
		}
Ejemplo n.º 55
0
 public static Int32Value Cgt(Int64Value a, Int64Value b)
 {
     return(Int32Value.Create(CompareGt(a, b)));
 }
Ejemplo 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;
		}
Ejemplo n.º 57
0
 public static Int32Value Clt_Un(Int64Value a, Int64Value b)
 {
     return(Int32Value.Create(CompareLt_Un(a, b)));
 }
Ejemplo 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;
		}
Ejemplo n.º 59
0
 public static Int32Value Cgt_Un(Int64Value a, Int64Value b) =>
 Int32Value.Create(CompareGt_Un(a, b));