3 # This creates a CSV file from the output of the debug output of subtarget:
4 # llvm-tblgen --gen-subtarget --debug-only=subtarget-emitter
5 # With thanks to Dave Estes for mentioning the idea at 2014 LLVM Developers' Meeting
16 def add(instr
, model
, resource
=None):
19 entry
= table
.setdefault(instr
, dict())
20 entry
[model
] = resource
26 return filt
.search(m
) != None
34 # remove default and itinerary so we can control their sort order to make
36 models
.discard("default")
37 models
.discard("itinerary")
39 ordered_table
= sorted(table
.items(), key
=operator
.itemgetter(0))
40 ordered_models
= ["itinerary", "default"]
41 ordered_models
.extend(sorted(models
))
42 ordered_models
= filter(filter_model
, ordered_models
)
45 sys
.stdout
.write("instruction")
46 for model
in ordered_models
:
47 sys
.stdout
.write(", {}".format(model
))
48 sys
.stdout
.write(os
.linesep
)
50 for (instr
, mapping
) in ordered_table
:
51 sys
.stdout
.write(instr
)
52 for model
in ordered_models
:
53 if model
in mapping
and mapping
[model
] is not None:
54 sys
.stdout
.write(", {}".format(mapping
[model
]))
56 sys
.stdout
.write(", ")
57 sys
.stdout
.write(os
.linesep
)
60 def machineModelCover(path
):
61 # The interesting bits
62 re_sched_default
= re
.compile("SchedRW machine model for ([^ ]*) (.*)\n");
63 re_sched_no_default
= re
.compile("No machine model for ([^ ]*)\n");
64 re_sched_spec
= re
.compile("InstRW on ([^ ]*) for ([^ ]*) (.*)\n");
65 re_sched_no_spec
= re
.compile("No machine model for ([^ ]*) on processor (.*)\n");
66 re_sched_itin
= re
.compile("Itinerary for ([^ ]*): ([^ ]*)\n")
69 with
open(path
, 'r') as f
:
70 for line
in f
.readlines():
71 match
= re_sched_default
.match(line
)
72 if match
: add(match
.group(1), "default", match
.group(2))
73 match
= re_sched_no_default
.match(line
)
74 if match
: add(match
.group(1), "default")
75 match
= re_sched_spec
.match(line
)
76 if match
: add(match
.group(2), match
.group(1), match
.group(3))
77 match
= re_sched_no_spec
.match(line
)
78 if match
: add(match
.group(1), match
.group(2))
79 match
= re_sched_itin
.match(line
)
80 if match
: add(match
.group(1), "itinerary", match
.group(2))
85 filt
= re
.compile(sys
.argv
[2], re
.IGNORECASE
)
86 machineModelCover(sys
.argv
[1])