1// Capstone Java binding
2// By Nguyen Anh Quynh & Dang Hoang Vu,  2013
3
4package capstone;
5
6import com.sun.jna.Structure;
7import com.sun.jna.Union;
8
9import java.util.List;
10import java.util.Arrays;
11
12import static capstone.Sparc_const.*;
13
14public class Sparc {
15
16  public static class MemType extends Structure {
17    public byte base;
18    public byte index;
19    public int disp;
20
21    @Override
22    public List getFieldOrder() {
23      return Arrays.asList("base", "index", "disp");
24    }
25  }
26
27  public static class OpValue extends Union {
28    public int reg;
29    public int imm;
30    public MemType mem;
31  }
32
33  public static class Operand extends Structure {
34    public int type;
35    public OpValue value;
36
37    public void read() {
38      readField("type");
39      if (type == SPARC_OP_MEM)
40        value.setType(MemType.class);
41      if (type == SPARC_OP_IMM || type == SPARC_OP_REG)
42        value.setType(Integer.TYPE);
43      if (type == SPARC_OP_INVALID)
44        return;
45      readField("value");
46    }
47
48    @Override
49    public List getFieldOrder() {
50      return Arrays.asList("type", "value");
51    }
52  }
53
54  public static class UnionOpInfo extends Capstone.UnionOpInfo {
55    public int cc;
56    public int hint;
57    public byte op_count;
58
59    public Operand [] op;
60
61    public UnionOpInfo() {
62      op = new Operand[4];
63    }
64
65    public void read() {
66      readField("cc");
67      readField("hint");
68      readField("op_count");
69      op = new Operand[op_count];
70      if (op_count != 0)
71        readField("op");
72    }
73
74    @Override
75    public List getFieldOrder() {
76      return Arrays.asList("cc", "hint", "op_count", "op");
77    }
78  }
79
80  public static class OpInfo extends Capstone.OpInfo {
81    public int cc;
82    public int hint;
83
84    public Operand [] op;
85
86    public OpInfo(UnionOpInfo op_info) {
87      cc = op_info.cc;
88      hint = op_info.hint;
89      op = op_info.op;
90    }
91  }
92}
93