} // namespace
+namespace
+{
+
+using ArgName = std::string;
+using ArgValue = std::string;
+using ArgDesc = std::pair<ArgName, ArgValue>;
+
+struct NodeDesc
+{
+public:
+ enum class State
+ {
+ // All the node descriptions are "Invalid" at the beginning.
+ //
+ // Any valid node description SHOULD NOT be at this state.
+ Invalid,
+ // This state means that the producer is **NOT** confident about the information that
+ // it generates.
+ //
+ // There may be some missing information.
+ PartiallyKnown,
+ // This state means that the producer is confident about the information that it
+ // generates.
+ Complete,
+ };
+
+public:
+ NodeDesc(const std::string &name) : _name{name}
+ {
+ // DO NOTHING
+ }
+
+public:
+ const std::string &name(void) const { return _name; }
+
+ uint32_t arg_size(void) const { return _args.size(); }
+ const ArgDesc &arg(uint32_t n) const { return _args.at(n); }
+ void arg(const ArgName &name, const ArgValue &value) { _args.emplace_back(name, value); }
+
+ const State &state(void) const { return _state; }
+ void state(const State &s) { _state = s; }
+
+private:
+ std::string _name;
+ std::vector<ArgDesc> _args;
+ State _state = State::Invalid;
+};
+
+std::ostream &operator<<(std::ostream &os, const NodeDesc &d)
+{
+ assert(d.state() != NodeDesc::State::Invalid);
+
+ std::vector<std::string> values;
+
+ for (uint32_t n = 0; n < d.arg_size(); ++n)
+ {
+ values.emplace_back(d.arg(n).first + ": " + d.arg(n).second);
+ }
+
+ if (d.state() == NodeDesc::State::PartiallyKnown)
+ {
+ values.emplace_back("...");
+ }
+
+ os << d.name();
+ os << "(";
+ if (values.size() > 0)
+ {
+ os << values.at(0);
+ for (uint32_t n = 1; n < values.size(); ++n)
+ {
+ os << ", " << values.at(n);
+ }
+ }
+ os << ")";
+
+ return os;
+}
+
+NodeDesc default_node_desc(const SymbolTable &tbl, loco::Node *node)
+{
+ NodeDesc res{opname(node)};
+
+ for (uint32_t n = 0; n < node->arity(); ++n)
+ {
+ res.arg(std::string{"arg"} + std::to_string(n), symbol_lookup(tbl, node->arg(n)));
+ }
+ res.state(NodeDesc::State::PartiallyKnown);
+
+ return res;
+}
+
+NodeDesc node_desc(const SymbolTable &tbl, loco::Node *node)
+{
+ if (node->dialect() == loco::CanonicalDialect::get())
+ {
+ // TODO Use dedicated pretty printer
+ return default_node_desc(tbl, node);
+ }
+
+ return default_node_desc(tbl, node);
+}
+
+} // namespace
+
namespace locop
{
}
}
- // TODO How to print arguments
for (auto node : loco::postorder_traversal(cluster_outputs))
{
- os << symbol(node) << " = " << opname(node) << "(";
- for (uint32_t n = 0; n < node->arity(); ++n)
- {
- os << " " << symbol(node->arg(n));
- }
- os << " )" << std::endl;
+ os << symbol(node) << " = " << node_desc(symbols, node) << std::endl;
}
os << std::endl;
}