[enco] Introduce enco_dump_all_ops debugging helper (#2170)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 8 Nov 2018 07:47:06 +0000 (16:47 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 8 Nov 2018 07:47:06 +0000 (16:47 +0900)
This commit introduces enco_dump_all_ops debugging helper which dumps
all the allocated Ops in a given module.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/enco/core/src/Support/Debugging.cpp
contrib/enco/core/src/Support/Debugging.h
contrib/enco/core/src/Support/Debugging.test.cpp

index 7faad96..bf0159f 100644 (file)
   void NAME(long p) { NAME(reinterpret_cast<const TYPE *>(p)); } \
   void NAME(const TYPE *VAR)
 
+namespace
+{
+
+class SectionBuilder
+{
+public:
+  SectionBuilder(const std::string &tag) : _tag{tag}
+  {
+    // DO NOTHING
+  }
+
+public:
+  template <typename Callback> pp::LinearDocument build(Callback cb) const
+  {
+    pp::LinearDocument res;
+
+    res.append(_tag, " {");
+    res.indent();
+
+    cb(res);
+
+    res.unindent();
+    res.append("}");
+
+    return res;
+  }
+
+private:
+  std::string _tag;
+};
+
+template <typename Callback>
+pp::LinearDocument operator<<(const SectionBuilder &builder, Callback cb)
+{
+  return builder.build(std::forward<Callback>(cb));
+}
+
+SectionBuilder section(const std::string &tag) { return SectionBuilder{tag}; }
+}
+
 /**
  * SECTION: Op
  */
@@ -61,3 +101,24 @@ DEBUGGING_API_P(enco_dump_op, coco::Op, op)
     std::cout << "(nullptr)" << std::endl;
   }
 }
+
+DEBUGGING_API_P(enco_dump_all_ops, coco::Module, m)
+{
+  if (m == nullptr)
+  {
+    std::cout << "(nullptr)" << std::endl;
+    return;
+  }
+
+  SectionBuilder section_builder{"op"};
+
+  for (uint32_t n = 0; n < m->entity()->op()->size(); ++n)
+  {
+    auto op = m->entity()->op()->at(n);
+    assert(op != nullptr);
+
+    auto desc = section("op").build([op](pp::LinearDocument &doc) { doc.append(describe(op)); });
+
+    std::cout << desc << std::endl;
+  }
+}
index 98c126d..308b0c9 100644 (file)
@@ -41,6 +41,14 @@ static_assert(sizeof(long) == sizeof(void *), "sizeof(long) == sizeof(pointer)")
  */
 DEBUGGING_API_P(enco_dump_op, coco::Op);
 
+/**
+ * Print the details of all the allocated coco::Op in coco::Module
+ *
+ * (gdb) call enco_dump_all_ops(module)
+ * (gdb) call enco_dump_all_ops(0x....)
+ */
+DEBUGGING_API_P(enco_dump_all_ops, coco::Module);
+
 #undef DEBUGGING_API_P
 
 #endif // __ENCO_SUPPORT_DEBUGGING_H__
index eb20b32..49a2ad1 100644 (file)
@@ -19,4 +19,8 @@
 #include <gtest/gtest.h>
 
 // This test aims to check whether debugging API is actually defined
-TEST(DebuggingTest, defined) { enco_dump_op(nullptr); }
+TEST(DebuggingTest, defined)
+{
+  enco_dump_op(nullptr);
+  enco_dump_all_ops(nullptr);
+}