source: parabix-LLVM/llvm_git/bindings/python/llvm/tests/test_disassembler.py @ 4078

Last change on this file since 4078 was 4078, checked in by linmengl, 5 years ago

checkin llvm-meng source

File size: 1.4 KB
Line 
1from .base import TestBase
2
3from ..disassembler import Disassembler, Option_UseMarkup
4
5class TestDisassembler(TestBase):
6    def test_instantiate(self):
7         Disassembler('i686-apple-darwin9')
8
9    def test_basic(self):
10        sequence = '\x67\xe3\x81' # jcxz -127
11        triple = 'i686-apple-darwin9'
12
13        disassembler = Disassembler(triple)
14
15        count, s = disassembler.get_instruction(sequence)
16        self.assertEqual(count, 3)
17        self.assertEqual(s, '\tjcxz\t-127')
18
19    def test_nonexistent_triple(self):
20        with self.assertRaisesRegexp(Exception, "Could not obtain disassembler for triple"):
21            Disassembler("nonexistent-triple-raises")
22
23    def test_get_instructions(self):
24        sequence = '\x67\xe3\x81\x01\xc7' # jcxz -127; addl %eax, %edi
25
26        disassembler = Disassembler('i686-apple-darwin9')
27
28        instructions = list(disassembler.get_instructions(sequence))
29        self.assertEqual(len(instructions), 2)
30
31        self.assertEqual(instructions[0], (0, 3, '\tjcxz\t-127'))
32        self.assertEqual(instructions[1], (3, 2, '\taddl\t%eax, %edi'))
33
34    def test_set_options(self):
35        sequence = '\x10\x40\x2d\xe9'
36        triple = 'arm-linux-android'
37
38        disassembler = Disassembler(triple)
39        disassembler.set_options(Option_UseMarkup)
40        count, s = disassembler.get_instruction(sequence)
41        print s
42        self.assertEqual(count, 4)
43        self.assertEqual(s, '\tpush\t{<reg:r4>, <reg:lr>}')
Note: See TracBrowser for help on using the repository browser.