3 from __future__
import print_function
6 INCL_DIR =
'../include/capstone/'
8 include = [
'arm.h',
'arm64.h',
'm68k.h',
'mips.h',
'x86.h',
'ppc.h',
'sparc.h',
'systemz.h',
'xcore.h',
'tms320c64x.h',
'm680x.h',
'evm.h' ]
12 'header':
"// For Capstone Engine. AUTO-GENERATED FILE, DO NOT EDIT\npackage capstone;\n\npublic class %s_const {\n",
14 'line_format':
'\tpublic static final int %s = %s;\n',
15 'out_file':
'./java/capstone/%s_const.java',
26 'tms320c64x.h':
'TMS320C64x',
29 'comment_open':
'\t//',
33 'header':
"# For Capstone Engine. AUTO-GENERATED FILE, DO NOT EDIT [%s_const.py]\n",
35 'line_format':
'%s = %s\n',
36 'out_file':
'./python/capstone/%s_const.py',
47 'tms320c64x.h':
'tms320c64x',
54 'header':
"(* For Capstone Engine. AUTO-GENERATED FILE, DO NOT EDIT [%s_const.ml] *)\n",
56 'line_format':
'let _%s = %s;;\n',
57 'out_file':
'./ocaml/%s_const.ml',
68 'tms320c64x.h':
'tms320c64x',
72 'comment_close':
' *)',
80 global include, INCL_DIR
81 print(
'Generating bindings for', lang)
82 templ = template[lang]
83 print(
'Generating bindings for', lang)
84 for target
in include:
85 prefix = templ[target]
86 outfile = open(templ[
'out_file'] %(prefix),
'wb')
87 outfile.write((templ[
'header'] % (prefix)).
encode(
"utf-8"))
89 lines = open(INCL_DIR + target).readlines()
95 if line.startswith(MARKUP):
96 outfile.write((
"\n%s%s%s\n" %(templ[
'comment_open'], \
97 line.replace(MARKUP,
''), \
98 templ[
'comment_close']) ).
encode(
"utf-8"))
101 if line ==
'' or line.startswith(
'//'):
104 if line.startswith(
'#define '):
106 xline = re.split(
'\s+', line, 1)
109 if '(' in xline[0]
or ')' in xline[0]:
112 line =
' '.join(xline)
114 if not line.startswith(prefix.upper()):
117 tmp = line.strip().split(
',')
120 if not t
or t.startswith(
'//'):
continue
122 t = t.replace(
'(uint64_t)',
'')
123 t = re.sub(
r'\((\d+)ULL << (\d+)\)',
r'\1 << \2', t)
124 f = re.split(
'\s+', t)
126 if f[0].startswith(prefix.upper()):
127 if len(f) > 1
and f[1]
not in (
'//',
'///<',
'='):
128 print(
"Error: Unable to convert %s" % f)
130 elif len(f) > 1
and f[1] ==
'=':
139 outfile.write((
"\n").
encode(
"utf-8"))
143 rhs = rhs.replace(
'<<',
' lsl ')
144 rhs = rhs.replace(
'|',
' lor ')
149 outfile.write((templ[
'line_format'] %(f[0].
strip(), rhs)).
encode(
"utf-8"))
151 outfile.write((templ[
'footer']).
encode(
"utf-8"))
156 if sys.argv[1] ==
'all':
157 for key
in template.keys():
162 raise RuntimeError(
"Unsupported binding %s" % sys.argv[1])
164 if __name__ ==
"__main__":
165 if len(sys.argv) < 2:
166 print(
"Usage:", sys.argv[0],
" <bindings: java|python|ocaml|all>")
static void encode(size_t size, lzma_action action)