#include <vector>
#include "assembly_grammar.h"
+#include "name_mapper.h"
namespace {
// a SPIR-V module.
class DotConverter {
public:
- DotConverter(std::iostream* out) : out_(*out) {}
+ DotConverter(libspirv::NameMapper name_mapper, std::iostream* out)
+ : name_mapper_(name_mapper), out_(*out) {}
// Emits the graph preamble.
void Begin() const {
// otherwise.
uint32_t continue_target_ = 0;
+ // An object for mapping Ids to names.
+ libspirv::NameMapper name_mapper_;
+
// The output stream.
std::ostream& out_;
};
void DotConverter::FlushBlock(const std::vector<uint32_t>& successors) {
out_ << current_block_id_;
if (!seen_function_entry_block_) {
- out_ << " [label=\"" << current_block_id_ << "\nFn " << current_function_id_
- << " entry\", shape=box]";
+ out_ << " [label=\"" << name_mapper_(current_block_id_) << "\nFn "
+ << name_mapper_(current_function_id_) << " entry\", shape=box];\n";
+ } else {
+ out_ << " [label=\"" << name_mapper_(current_block_id_) << "\"];\n";
}
- out_ << ";\n";
for (auto successor : successors) {
out_ << current_block_id_ << " -> " << successor << ";\n";
const libspirv::AssemblyGrammar grammar(context);
if (!grammar.isValid()) return SPV_ERROR_INVALID_TABLE;
- DotConverter converter(out);
+ libspirv::FriendlyNameMapper friendly_mapper(context, words, num_words);
+ DotConverter converter(friendly_mapper.GetNameMapper(), out);
converter.Begin();
if (auto error = spvBinaryParse(context, &converter, words, num_words,
nullptr, HandleInstruction, diagnostic)) {