Example #1
0
    def testOpsMerge(self):
        op1 = proof_tools.Operands(disasms=('0x0(%r13)', ),
                                   input_rr='%r13',
                                   output_rr=None)
        op2 = proof_tools.Operands(disasms=('0x0(%r14)', ),
                                   input_rr='%r14',
                                   output_rr=None)
        op3 = proof_tools.Operands(disasms=('%r12', ),
                                   input_rr=None,
                                   output_rr='%r12')
        self.assertEquals(
            proof_tools.Operands(disasms=('0x0(%r13)', '%r12'),
                                 input_rr='%r13',
                                 output_rr='%r12'),
            proof_tools.MergeOperands(op1, op3))

        self.assertEquals(
            proof_tools.Operands(disasms=('0x0(%r14)', '%r12'),
                                 input_rr='%r14',
                                 output_rr='%r12'),
            proof_tools.MergeOperands(op2, op3))

        try:
            proof_tools.MergeOperands(op1, op2)
        except AssertionError:
            pass
        else:
            self.fail('Should have thrown exception as restrictions conflict')
Example #2
0
 def testMemoryOperandsTemplate64(self):
     mem = proof_tools.MemoryOperandsTemplate(disp='0x0',
                                              base='%rsp',
                                              index='%r8',
                                              scale=2,
                                              bitness=64)
     self.assertEquals([
         proof_tools.Operands(disasms=('(%rsp)', )),
         proof_tools.Operands(disasms=('0x0(%rsp)', )),
         proof_tools.Operands(disasms=('(%rsp,%r8,2)', ), input_rr='%r8'),
         proof_tools.Operands(disasms=('0x0(%rsp,%r8,2)', ), input_rr='%r8')
     ], mem)
Example #3
0
def Validate(trie_diffs, bitness):
    """Validate that trie_diffs adds 16 bit shld/shrd in 32bit mode."""

    # No instructions should be removed for 32/64 bit DFAs.
    # No instructions should be added for 64 bit DFA because it already
    # contains 16 bit shld/shrd instructions.
    # in 32-bit mode, 16 bit shld/shrd should be added.
    # This is of the forms:
    # shld|shrd, imm|%cl, reg16, reg16|mem
    if bitness == 32:
        mnemonics = proof_tools.MnemonicOp('shld') | proof_tools.MnemonicOp(
            'shrd')
        reg16 = proof_tools.GprOperands(bitness=bitness, operand_size=16)
        mem = proof_tools.AllMemoryOperands(bitness=bitness)
        imm = proof_tools.ImmOp()
        cl = set([proof_tools.Operands(disasms=('%cl', ))])

        expected_adds = proof_tools.OpsProd(mnemonics, imm | cl, reg16,
                                            reg16 | mem)

    else:
        expected_adds = set()

    proof_tools.AssertDiffSetEquals(trie_diffs,
                                    expected_adds=expected_adds,
                                    expected_removes=set())
Example #4
0
 def testMemoryOperandsTemplate32(self):
     mem = proof_tools.MemoryOperandsTemplate(disp='0x0',
                                              base='%ebx',
                                              index='%eax',
                                              scale=2,
                                              bitness=32)
     self.assertEquals([
         proof_tools.Operands(disasms=('(%ebx)', )),
         proof_tools.Operands(disasms=('0x0', )),
         proof_tools.Operands(disasms=('(%ebx,%eax,2)', )),
         proof_tools.Operands(disasms=('0x0(,%eax,2)', )),
         proof_tools.Operands(disasms=('0x0(%ebx)', )),
         proof_tools.Operands(disasms=('0x0(%ebx,%eax,2)', ))
     ], mem)
Example #5
0
    def testOpsProd(self):
        ops1 = set([
            proof_tools.Operands(disasms=('a', )),
            proof_tools.Operands(disasms=('b', ))
        ])

        ops2 = set([
            proof_tools.Operands(disasms=('1', )),
            proof_tools.Operands(disasms=('2', ))
        ])

        ops3 = set([
            proof_tools.Operands(disasms=('i', )),
            proof_tools.Operands(disasms=('ii', ))
        ])

        self.assertEquals(
            set([
                proof_tools.Operands(disasms=('a', '1', 'i')),
                proof_tools.Operands(disasms=('a', '1', 'ii')),
                proof_tools.Operands(disasms=('a', '2', 'i')),
                proof_tools.Operands(disasms=('a', '2', 'ii')),
                proof_tools.Operands(disasms=('b', '1', 'i')),
                proof_tools.Operands(disasms=('b', '1', 'ii')),
                proof_tools.Operands(disasms=('b', '2', 'i')),
                proof_tools.Operands(disasms=('b', '2', 'ii'))
            ]), proof_tools.OpsProd(ops1, ops2, ops3))