hw/pci: Clean up global variable shadowing of address_space_io variable
[qemu/armbru.git] / scripts / feature_to_c.py
blobbcbcb83beb1f65d0e703b12b99696dec0a400d23
1 #!/usr/bin/env python3
2 # SPDX-License-Identifier: GPL-2.0-or-later
4 import os, sys
6 def writeliteral(indent, bytes):
7 sys.stdout.write(' ' * indent)
8 sys.stdout.write('"')
9 quoted = True
11 for c in bytes:
12 if not quoted:
13 sys.stdout.write('\n')
14 sys.stdout.write(' ' * indent)
15 sys.stdout.write('"')
16 quoted = True
18 if c == b'"'[0]:
19 sys.stdout.write('\\"')
20 elif c == b'\\'[0]:
21 sys.stdout.write('\\\\')
22 elif c == b'\n'[0]:
23 sys.stdout.write('\\n"')
24 quoted = False
25 elif c >= 32 and c < 127:
26 sys.stdout.write(c.to_bytes(1, 'big').decode())
27 else:
28 sys.stdout.write(f'\{c:03o}')
30 if quoted:
31 sys.stdout.write('"')
33 sys.stdout.write('#include "qemu/osdep.h"\n' \
34 '#include "exec/gdbstub.h"\n' \
35 '\n'
36 'const GDBFeature gdb_static_features[] = {\n')
38 for input in sys.argv[1:]:
39 with open(input, 'rb') as file:
40 read = file.read()
42 sys.stdout.write(' {\n')
43 writeliteral(8, bytes(os.path.basename(input), 'utf-8'))
44 sys.stdout.write(',\n')
45 writeliteral(8, read)
46 sys.stdout.write('\n },\n')
48 sys.stdout.write(' { NULL }\n};\n')