struct NodeDesc
{
public:
+ /**
+ * @brief Multi-line comments
+ */
+ class Comments final
+ {
+ public:
+ Comments() = default;
+
+ public:
+ uint32_t count(void) const { return _lines.size(); }
+ const std::string &at(uint32_t n) const { return _lines.at(n); }
+ void append(const std::string &s);
+
+ private:
+ std::vector<std::string> _lines;
+ };
+
+public:
enum class State
{
// All the node descriptions are "Invalid" at the beginning.
const ArgDesc &args(void) const { return _args; }
ArgDesc &args(void) { return _args; }
+ const Comments &comments(void) const { return _comments; }
+ Comments &comments(void) { return _comments; }
+
const State &state(void) const { return _state; }
void state(const State &s) { _state = s; }
private:
std::unique_ptr<OpName> _name = nullptr;
ArgDesc _args;
+ Comments _comments;
State _state = State::Invalid;
};
throw std::runtime_error{"Fail to build a node summary"};
}
+ for (uint32_t n = 0; n < node_summary.comments().count(); ++n)
+ {
+ os << "; " << node_summary.comments().at(n) << std::endl;
+ }
+
os << symbol(node) << " = " << node_summary << std::endl;
}
os << std::endl;
TEST(LinearV1FormatterTest, user_defined_node_summary_builder)
{
+ struct MyAnnotation final : public loco::NodeAnnotation
+ {
+ // DO NOTHING
+ };
+
auto g = loco::make_graph();
{
auto pull = g->nodes()->create<loco::Pull>();
auto push = g->nodes()->create<loco::Push>();
+ push->annot(stdex::make_unique<MyAnnotation>());
push->from(pull);
}
struct MyBuilder final : public locop::NodeSummaryBuilder
{
- bool build(const loco::Node *, locop::NodeSummary &s) const final
+ bool build(const loco::Node *node, locop::NodeSummary &s) const final
{
s.opname("my.op");
+ if (node->annot<MyAnnotation>())
+ {
+ s.comments().append("annotated");
+ }
s.state(locop::NodeSummary::State::PartiallyKnown);
return true;
}
namespace locop
{
+void NodeDesc::Comments::append(const std::string &s)
+{
+ // TODO Check whether s contains any newline character
+ _lines.emplace_back(s);
+}
+
const std::string &NodeDesc::opname(void) const
{
// _name SHOULD BE set before use