Skip to content

Commit dc5a335

Browse files
allightcopybara-github
authored andcommitted
Add more than a single 'source-location' to the ir_to_csvs output
PiperOrigin-RevId: 720335763
1 parent 007a6ce commit dc5a335

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

xls/visualization/ir_viz/ir_to_csvs_main.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "absl/status/statusor.h"
2828
#include "absl/strings/str_cat.h"
2929
#include "absl/strings/str_format.h"
30+
#include "absl/strings/str_join.h"
3031
#include "riegeli/bytes/fd_writer.h"
3132
#include "riegeli/csv/csv_record.h"
3233
#include "riegeli/csv/csv_writer.h"
@@ -97,7 +98,8 @@ constexpr riegeli::CsvHeaderConstant kNodeHeader = {"name",
9798
"area_um",
9899
"file",
99100
"line",
100-
"range"};
101+
"range",
102+
"all_locs"};
101103
riegeli::CsvRecord NodeRecord(const viz::Node& node) {
102104
return riegeli::CsvRecord(
103105
*kNodeHeader,
@@ -131,7 +133,6 @@ riegeli::CsvRecord NodeRecord(const viz::Node& node) {
131133
node.attributes().has_area_um()
132134
? ToFieldValue(static_cast<int64_t>(node.attributes().area_um()))
133135
: "",
134-
// TODO(allight): Handle nodes with multiple associated locations.
135136
node.loc_size() >= 1 && absl::c_all_of(node.loc(),
136137
[&](auto loc) {
137138
return loc.file() ==
@@ -141,6 +142,10 @@ riegeli::CsvRecord NodeRecord(const viz::Node& node) {
141142
: "",
142143
node.loc_size() == 1 ? ToFieldValue(node.loc()[0].line()) : "",
143144
node.attributes().has_ranges() ? node.attributes().ranges() : "",
145+
absl::StrJoin(node.loc(), "\n",
146+
[](std::string* out, const auto& loc) {
147+
absl::StrAppend(out, loc.file(), ":", loc.line());
148+
}),
144149
});
145150
}
146151

0 commit comments

Comments
 (0)