[enco] Common nullptr handler in debuging API (#2247)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Tue, 13 Nov 2018 09:40:09 +0000 (18:40 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Tue, 13 Nov 2018 09:40:09 +0000 (18:40 +0900)
With this commit, every debugging API shares the same nullptr handler
(which is generated via macro).

This change makes it easy to extend debugging API.

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

index f1597b7..25ad1e4 100644 (file)
@@ -8,9 +8,20 @@
 #include <iostream>
 
 #define DEBUGGING_API_P(NAME, TYPE, VAR)                         \
-  void NAME(const TYPE *);                                       \
+  static void _##NAME(const TYPE *);                             \
   void NAME(long p) { NAME(reinterpret_cast<const TYPE *>(p)); } \
-  void NAME(const TYPE *VAR)
+  void NAME(const TYPE *p)                                       \
+  {                                                              \
+    if (p == nullptr)                                            \
+    {                                                            \
+      std::cout << "(nullptr)" << std::endl;                     \
+    }                                                            \
+    else                                                         \
+    {                                                            \
+      _##NAME(p);                                                \
+    }                                                            \
+  }                                                              \
+  void _##NAME(const TYPE *VAR)
 
 namespace
 {
@@ -180,36 +191,20 @@ pp::LinearDocument describe(const OpTree &t)
 
 DEBUGGING_API_P(enco_dump_op, coco::Op, op)
 {
-  if (op != nullptr)
   {
     std::cout << describe(op) << std::endl;
   }
-  else
-  {
-    std::cout << "(nullptr)" << std::endl;
-  }
 }
 
 DEBUGGING_API_P(enco_dump_op_tree, coco::Op, op)
 {
-  if (op != nullptr)
   {
     std::cout << describe(OpTree(op)) << std::endl;
   }
-  else
-  {
-    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)