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