1# Capstone Python bindings, by Nguyen Anh Quynnh <aquynh@gmail.com>
2
3import ctypes
4from . import copy_ctypes_list
5from .xcore_const import *
6
7# define the API
8class XcoreOpMem(ctypes.Structure):
9    _fields_ = (
10        ('base', ctypes.c_uint8),
11        ('index', ctypes.c_uint8),
12        ('disp', ctypes.c_int32),
13        ('direct', ctypes.c_int),
14    )
15
16class XcoreOpValue(ctypes.Union):
17    _fields_ = (
18        ('reg', ctypes.c_uint),
19        ('imm', ctypes.c_int32),
20        ('mem', XcoreOpMem),
21    )
22
23class XcoreOp(ctypes.Structure):
24    _fields_ = (
25        ('type', ctypes.c_uint),
26        ('value', XcoreOpValue),
27    )
28
29    @property
30    def imm(self):
31        return self.value.imm
32
33    @property
34    def reg(self):
35        return self.value.reg
36
37    @property
38    def mem(self):
39        return self.value.mem
40
41
42class CsXcore(ctypes.Structure):
43    _fields_ = (
44        ('op_count', ctypes.c_uint8),
45        ('operands', XcoreOp * 8),
46    )
47
48def get_arch_info(a):
49    return (copy_ctypes_list(a.operands[:a.op_count]))
50
51