29TRIGGER = re.compile(
r"^struct target_ops$")
31ENDER = re.compile(
r"^\s*};$")
34SYMBOL =
"[a-zA-Z_][a-zA-Z0-9_]*"
36NAME_PART =
r"(?P<name>" + SYMBOL +
")\s"
38ARGS_PART =
r"(?P<args>\(.*\))"
42POINTER_PART =
r"\s*(\*)?\s*"
46CP_SYMBOL =
r"[a-zA-Z_][a-zA-Z0-9_<>:]*"
48SIMPLE_RETURN_PART =
r"((struct|class|enum|union)\s+)?" + CP_SYMBOL
51RETURN_PART =
r"((const|volatile)\s+)?(" + SIMPLE_RETURN_PART +
")" + POINTER_PART
54VIRTUAL_PART =
r"virtual\s"
57TARGET_DEFAULT_PART =
r"TARGET_DEFAULT_(?P<style>[A-Z_]+)\s*\((?P<default_arg>.*)\)"
61METHOD_TRAILER =
r"\s*" + TARGET_DEFAULT_PART +
"$"
83 +
r"|(?P<T>.*(enum\s+)?"
92TARGET_DEBUG_PRINTER =
r"\s*TARGET_DEBUG_PRINTER\s*\((?P<arg>[^)]*)\)\s*"
98 with open(
"target.h",
"r")
as target_h:
101 if not found_trigger:
102 if TRIGGER.match(line):
107 elif ENDER.match(line):
111 line = re.split(
"//", line)[0]
112 all_the_text = all_the_text +
" " + line
113 if not found_trigger:
114 raise "Could not find trigger line"
116 all_the_text = re.sub(
r"/\*(.*?)\*/",
"", all_the_text)
130 all_the_text = re.sub(
r"\s+",
" ", all_the_text)
131 return all_the_text.split(
";")
137 typestr = re.sub(
r"^\((.*)\)$",
r"\1", typestr)
139 for item
in re.split(
r",\s*", typestr):
140 if item ==
"void" or item ==
"":
142 m = ARGTYPES.match(item)
145 onetype = m.group(
"E")
147 onetype = m.group(
"T")
150 result.append(onetype.strip())
157 print(return_type, file=f, end=
"")
159 if not return_type.endswith(
"*"):
160 print(
" ", file=f, end=
"")
163 print(name +
" (", file=f, end=
"")
166 for i
in range(len(argtypes)):
167 val = re.sub(TARGET_DEBUG_PRINTER,
"", argtypes[i])
168 if not val.endswith(
"*")
and not val.endswith(
"&"):
170 vname =
"arg" + str(i)
173 actuals.append(vname)
174 print(
", ".join(argdecls) +
")", file=f, end=
"")
176 print(
" override;", file=f)
190 f,
False,
"target_ops::" + name, return_type, argtypes
192 print(
" ", file=f, end=
"")
193 if return_type !=
"void":
194 print(
"return ", file=f, end=
"")
195 print(
"this->beneath ()->" + name +
" (", file=f, end=
"")
196 print(
", ".join(names), file=f, end=
"")
203 name =
"dummy_target::" + name
206 print(
" ", file=f, end=
"")
207 if return_type !=
"void":
208 print(
"return ", file=f, end=
"")
209 print(content +
" (", file=f, end=
"")
210 names.insert(0,
"this")
211 print(
", ".join(names) +
");", file=f)
212 elif style ==
"RETURN":
213 print(
" return " + content +
";", file=f)
214 elif style ==
"NORETURN":
215 print(
" " + content +
";", file=f)
216 elif style ==
"IGNORE":
220 raise "unrecognized style: " + style
225 m = re.search(TARGET_DEBUG_PRINTER, typename)
227 return m.group(
"arg")
228 typename = typename.rstrip()
229 typename = re.sub(
"[ ()<>:]",
"_", typename)
230 typename = re.sub(
"[*]",
"p", typename)
231 typename = re.sub(
"&",
"r", typename)
234 typename = re.sub(
"_+",
"_", typename)
238 typename = re.sub(
"_+$",
"", typename)
239 return "target_debug_print_" + typename
244 debugname =
"debug_target::" + name
246 if return_type !=
"void":
247 print(
" " + return_type +
" result;", file=f)
249 ' gdb_printf (gdb_stdlog, "-> %s->'
251 +
' (...)\\n", this->beneath ()->shortname ());',
256 print(
" ", file=f, end=
"")
257 if return_type !=
"void":
258 print(
"result = ", file=f, end=
"")
259 print(
"this->beneath ()->" + name +
" (", file=f, end=
"")
260 print(
", ".join(names), file=f, end=
"")
265 ' gdb_printf (gdb_stdlog, "<- %s->'
267 +
' (", this->beneath ()->shortname ());',
270 for i
in range(len(argtypes)):
272 print(
' gdb_puts (", ", gdb_stdlog);', file=f)
274 print(
" " + printer +
" (" + names[i] +
");", file=f)
275 if return_type !=
"void":
276 print(
' gdb_puts (") = ", gdb_stdlog);', file=f)
278 print(
" " + printer +
" (result);", file=f)
279 print(
' gdb_puts ("\\n", gdb_stdlog);', file=f)
281 print(
' gdb_puts (")\\n", gdb_stdlog);', file=f)
283 if return_type !=
"void":
284 print(
" return result;", file=f)
290 print(
"struct " + class_name +
" : public target_ops", file=f)
292 print(
" const target_info &info () const override;", file=f)
294 print(
" strata stratum () const override;", file=f)
297 for name
in delegators:
298 return_type = entries[name][
"return_type"]
299 argtypes = entries[name][
"argtypes"]
300 print(
" ", file=f, end=
"")
303 print(
"};\n", file=f)
311 current_line = current_line.strip()
312 m = METHOD.match(current_line)
317 data[
"return_type"] = data[
"return_type"].strip()
318 entries[data[
"name"]] = data
320 delegators.append(data[
"name"])
322with open(
"target-delegates.c",
"w")
as f:
325 "make-target-delegates.py",
"Boilerplate target methods for GDB"
329 print_class(f,
"dummy_target", delegators, entries)
330 print_class(f,
"debug_target", delegators, entries)
332 for name
in delegators:
333 tdefault = entries[name][
"default_arg"]
334 return_type = entries[name][
"return_type"]
335 style = entries[name][
"style"]
336 argtypes = entries[name][
"argtypes"]
def copyright(tool, description)
def write_declaration(f, name, return_type, argtypes)
def parse_argtypes(typestr)
def print_class(f, class_name, delegators, entries)
def write_tdefault(f, content, style, name, return_type, argtypes)
def write_delegator(f, name, return_type, argtypes)
def write_debugmethod(f, content, name, return_type, argtypes)
def write_function_header(f, decl, name, return_type, argtypes)