public void X86ic_CompareRegisters_NoNormalize_Fail()
 {
     var a = Create(Opcode.neg, "eax");
     var b = Create(Opcode.neg, "ecx");
     var cmp = new X86InstructionComparer(Normalize.Nothing);
     Assert.IsFalse(cmp.Equals(a, b));
     Assert.IsFalse(cmp.GetHashCode(a) == cmp.GetHashCode(b));
 }
 public void X86ic_CompareOpcodes()
 {
     var a = Create(Opcode.nop);
     var b = Create(Opcode.nop);
     var cmp = new X86InstructionComparer(Normalize.Nothing);
     Assert.IsTrue(cmp.Equals(a, b));
     Assert.IsTrue(cmp.GetHashCode(a) == cmp.GetHashCode(b));
 }
 public void X86ic_CompareMem_Normalize_Succeed()
 {
     var a = Create(Opcode.neg, Mem32(Registers.eax));
     var b = Create(Opcode.neg, Mem32(Registers.ecx));
     var cmp = new X86InstructionComparer(Normalize.Registers);
     Assert.IsTrue(cmp.Equals(a, b));
     Assert.IsTrue(cmp.GetHashCode(a) == cmp.GetHashCode(b));
 }
		public void Trie_AddInstructions()
		{
            X86InstructionComparer cmp = new X86InstructionComparer(Normalize.Nothing);
            var trie = new Trie<MachineInstruction>(cmp);
			IntelInstruction inst = CreatePush(Registers.bp);
			
			trie.Add(new [] { inst });
			Assert.AreEqual(trie.Count, 1);

			trie.Add(new [] {
				CreatePush(Registers.bp),
				CreateMov(Registers.bp, Registers.sp) });
			Assert.AreEqual(trie.Count, 3);
		}
		public void Trie_ScoreInstructions()
		{
			X86InstructionComparer cmp = new X86InstructionComparer(Normalize.Nothing);
			var trie = new Trie<IntelInstruction>(cmp);
			trie.Add(new [] {
				CreatePush(Registers.bp),
				CreateMov(Registers.bp, Registers.sp) });
			trie.Add(new [] {
				CreatePush(Registers.bp),
				CreateMov(Registers.bp, Registers.sp),
				CreatePush(Registers.si),
				CreatePush(Registers.di) });

			long score = trie.ScoreInstructions(new [] {
				CreatePush(Registers.bp) });
			Assert.AreEqual(2, score);
			score = trie.ScoreInstructions(new [] {
				CreatePush(Registers.bp),
				CreateMov(Registers.bp, Registers.sp) } );
			Assert.AreEqual(4, score);

			// This sequqnce matches one of the trie's strings exactly.
			score = trie.ScoreInstructions(new  [] {
				CreatePush(Registers.bp),
				CreateMov(Registers.bp, Registers.sp),
				CreatePush(Registers.si),
				CreatePush(Registers.di) });
			Assert.AreEqual(6, score);

			// A longer sequence runs 'off' the trie, so it should have the same score
			// as the previous test
			score = trie.ScoreInstructions(new [] {
				CreatePush(Registers.bp),
				CreateMov(Registers.bp, Registers.sp),
				CreatePush(Registers.si),
				CreatePush(Registers.di),
				CreatePush(Registers.bx)});
			Assert.AreEqual(6, score);

			// This doesn't exist in the trie at all, so it should score 0.

			score = trie.ScoreInstructions(new [] {
				CreateMov(Registers.ax, Registers.bx) });
			Assert.AreEqual(0, score);
		}
		public void Creation()
		{
			X86InstructionComparer cmp = new X86InstructionComparer(Normalize.Nothing);
			var trie = new Trie<MachineInstruction>(cmp);
		}