blob: 89f0b717c8b1099810b53b7e8da5dbc4b51adf7e [file] [log] [blame]
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +08001/* Capstone Disassembler Engine */
2/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013> */
3
4#ifndef __CS_UTILS_H__
5#define __CS_UTILS_H__
6
7#include <stdbool.h>
8
9typedef struct Pair {
10 char *str;
11 unsigned num;
12} Pair;
13
14// map instruction to its characteristics
15typedef struct insn_map {
16 unsigned int id;
17 unsigned int mapid;
18 unsigned int regs_use[32]; // list of implicit registers used by this instruction
19 unsigned int regs_mod[32]; // list of implicit registers modified by this instruction
20 unsigned int groups[8]; // list of group this instruction belong to
21 bool branch; // branch instruction?
22 bool indirect_branch; // indirect branch instruction?
23} insn_map;
24
25bool str_in_list(char **list, char *s);
26
Nguyen Anh Quynhad61c492013-11-30 16:23:31 +080027// binary searching in @m, given its size in @max, and @id
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080028int insn_find(insn_map *m, unsigned int max, unsigned int id);
29
30// map id to string
31typedef struct name_map {
32 unsigned int id;
33 char *name;
34} name_map;
35
36// map a name to its ID
37// return 0 if not found
38int name2id(name_map* map, int max, char *name);
39
40// reverse mapid to id
41// return 0 if not found
42unsigned int insn_reverse_id(insn_map *insns, unsigned int max, unsigned int id);
43
44#define ARR_SIZE(a) (sizeof(a)/sizeof(a[0]))
45
46#endif
47