[enco] Backend as interface (#1671)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Fri, 28 Sep 2018 08:18:42 +0000 (17:18 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Fri, 28 Sep 2018 08:18:42 +0000 (17:18 +0900)
This commit makes Backend as interface, and hides its implementation
details.

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

index 570d96e..8ad3cd1 100644 (file)
@@ -22,7 +22,6 @@
 #include "coco/IR/Module.h"
 #include "coco/IR/Data.h"
 
-#include <ostream>
 #include <memory>
 
 namespace enco
@@ -30,17 +29,9 @@ namespace enco
 
 struct Backend
 {
-public:
-  Backend(std::ostream &os) : _os(os)
-  {
-    // DO NOTHING
-  }
+  virtual ~Backend() = default;
 
-public:
-  void compile(coco::Module *m, coco::Data *d);
-
-private:
-  std::ostream &_os;
+  virtual void compile(coco::Module *m, coco::Data *d) = 0;
 };
 
 } // namespace enco
index a910748..6c3162c 100644 (file)
 #include <nncc/foundation/Memory.h>
 
 #include <stdexcept>
+#include <iostream>
 
 using nncc::foundation::make_unique;
+using namespace enco;
 
 namespace
 {
@@ -52,12 +54,16 @@ bool has_inout_bag(const coco::Module *m)
   return false;
 }
 
-} // namespace
-
-namespace enco
+class BackendImpl final : public enco::Backend
 {
+public:
+  BackendImpl() = default;
+
+public:
+  void compile(coco::Module *m, coco::Data *d) override;
+};
 
-void Backend::compile(coco::Module *m, coco::Data *d)
+void BackendImpl::compile(coco::Module *m, coco::Data *d)
 {
   Code code{m, d};
 
@@ -98,7 +104,7 @@ void Backend::compile(coco::Module *m, coco::Data *d)
 
   // TODO Run various transforms over enco::Code
 
-  _os << CppCode{&code} << std::endl;
+  std::cout << CppCode{&code} << std::endl;
 }
 
 } // namespace enco
@@ -107,5 +113,5 @@ void Backend::compile(coco::Module *m, coco::Data *d)
 
 std::unique_ptr<enco::Backend> make_backend(const cmdline::View &)
 {
-  return make_unique<enco::Backend>(std::cout);
+  return make_unique<::BackendImpl>();
 }