]>
Witch of Git - ivy/blob - tools/format_trace.py
8 result
= subprocess
.run(
9 ["nm", "-defined-only", "-demangle", program
],
15 for line
in result
.stdout
.split("\n"):
18 addr
, _
, name
= line
.split(' ', 2)
19 if name
.startswith("ivy_builtin$"):
20 name
= name
.split("$", 2)[1]
25 def handle_trace(lines
, syms
={}, only_debug
=False):
28 if int(x
, 16) % 2 == 1:
29 return int(x
, 16) >> 1
40 kind
, *args
= line
.split()
42 objs
[args
[0]] = syms
.get(args
[1], f
"fn@{args[1]}")
44 print("MAKE", objs
[args
[0]])
46 objs
[args
[1]] = obj(args
[0])
48 if int(args
[1], 16) == 0:
49 objs
[args
[0]] = f
"({obj(args[0])})"
51 objs
[args
[0]] = f
"({obj(args[0])} {obj(args[1])})"
53 print("APP", objs
[args
[0]])
58 print("DEBUG", obj(args
[0]))
63 print(kind
, *(obj(x
) for x
in args
))
66 if __name__
== "__main__":
67 parser
= argparse
.ArgumentParser(
68 description
="Make an Ivy runtime trace more readable",
70 parser
.add_argument("program", help="The program that produced the trace")
71 parser
.add_argument("trace", help="A file containing the trace")
73 "-d", "--only-debug", action
="store_true",
74 help="If set, only print the DEBUG outputs",
76 if len(sys
.argv
) == 1:
79 args
= parser
.parse_args()
81 syms
= get_syms(args
.program
)
82 with
open(args
.trace
, "r") as f
:
83 lines
= [line
.strip() for line
in f
if line
.strip()]
84 handle_trace(lines
, syms
, ags
.only_debug
)