-
Notifications
You must be signed in to change notification settings - Fork 10
/
qemu_device_creator.py
executable file
·155 lines (130 loc) · 4.04 KB
/
qemu_device_creator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/python
from argparse import (
ArgumentTypeError,
ArgumentParser
)
from os.path import (
abspath,
dirname,
isdir
)
from qemu import (
qvd_load_with_cache
)
from common import (
execfile
)
from traceback import (
print_exc
)
import qdt
def arg_type_directory(string):
if not isdir(string):
raise ArgumentTypeError(string + " is not directory")
return string
def main():
parser = ArgumentParser(
description = "QEMU Project Generator\n"
"The tool generates source files inside QEMU source tree according to"
" settings read from project script."
)
parser.add_argument(
"--qemu-build", "-b",
default = None,
type = arg_type_directory,
metavar = "/path/to/qemu/build/directory",
help = "Override QEMU build path of the project."
)
parser.add_argument(
"--target-version", "-t",
default = None,
metavar = "<tree-ish>", # like in Git's docs
help = "Assume given version of Qemu."
" Overrides project's target_version."
)
parser.add_argument(
"--gen-header-tree",
default = None,
metavar = "header_tree.gv",
help = "Output QEMU header inclusion graph in Graphviz format."
)
parser.add_argument(
"--gen-chunk-graphs",
action = "store_true",
help = "Generate Graphviz files with graph of chunks per each "
"generated source."
)
parser.add_argument(
"--gen-intermediate-chunk-graphs",
action = "store_true",
help = "Generate Graphviz files with intermediate graph of chunks "
"during header inclusion optimization for each generated source."
)
parser.add_argument(
"--gen-debug-comments",
action = "store_true",
help = "Generate source files with debug comments."
)
parser.add_argument(
"--no-i3s",
action = "store_true",
help = "Disable automatic CPU semantics translation."
)
parser.add_argument(
"--no-instruction-tree-optimizations",
action = "store_true",
help = "Disable optimizations when building an instruction tree."
)
parser.add_argument(
"script",
help = "A Python script containing definition of a project to generate."
)
arguments = parser.parse_args()
script = arguments.script
loaded = dict(qdt.__dict__)
try:
execfile(script, loaded)
except:
print("Cannot load configuration from '%s'" % script)
print_exc()
return -1
for v in loaded.values():
if isinstance(v, qdt.QProject):
project = v
break
else:
print("Script '%s' does not define a project to generate." % script)
return -1
project.replace_relpaths_to_abspaths(abspath(dirname(script)))
if arguments.qemu_build is None:
qemu_build_path = getattr(project, "build_path", None)
else:
qemu_build_path = arguments.qemu_build
if not qemu_build_path: # None, empty
qemu_build_path = "."
version = arguments.target_version
if version is None:
version = getattr(project, "target_version", None)
try:
qvd = qvd_load_with_cache(qemu_build_path, version = version)
except:
print("QVD loading failed")
print_exc()
return -1
qvd.use()
if arguments.gen_header_tree is not None:
qvd.qvc.stc.gen_header_inclusion_dot_file(arguments.gen_header_tree)
project.gen_all(qvd.src_path,
intermediate_chunk_graphs = arguments.gen_intermediate_chunk_graphs,
with_chunk_graph = arguments.gen_chunk_graphs,
known_targets = qvd.qvc.known_targets,
with_debug_comments = arguments.gen_debug_comments,
translate_cpu_semantics = not arguments.no_i3s,
instruction_tree_optimizations = (
not arguments.no_instruction_tree_optimizations
),
include_paths = tuple(path for path, __ in qvd.include_paths)
)
return 0
if __name__ == "__main__":
exit(main())