[logo] Introduce PhaseRunnerMixinObservable (#6971)
author박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Wed, 28 Aug 2019 03:31:50 +0000 (12:31 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 28 Aug 2019 03:31:50 +0000 (12:31 +0900)
This will introduce PhaseRunnerMixinObservable for Phase/Pass run stage notification

Signed-off-by: SaeHie Park <saehie.park@samsung.com>
compiler/logo/include/logo/Phase.h

index 35b3487..efbad2a 100644 (file)
@@ -85,6 +85,68 @@ struct PhaseEventListener
   virtual void notify(const PhaseEventInfo<PhaseEvent::PassEnd> *) { return; };
 };
 
+// TODO Will be other mix-ins for Phase Runners?
+class PhaseRunnerMixinObservable
+{
+public:
+  PhaseRunnerMixinObservable() = default;
+
+public:
+  virtual ~PhaseRunnerMixinObservable() = default;
+
+public:
+  void attach(PhaseEventListener *listener) { _listener = listener; }
+
+public:
+  void notifyPhaseBegin(void) const
+  {
+    if (_listener)
+    {
+      PhaseEventInfo<PhaseEvent::PhaseBegin> info;
+
+      _listener->notify(&info);
+    }
+  }
+
+  void notifyPhaseEnd(void) const
+  {
+    if (_listener)
+    {
+      PhaseEventInfo<PhaseEvent::PhaseEnd> info;
+
+      _listener->notify(&info);
+    }
+  }
+
+  void notifyPassBegin(Pass *pass) const
+  {
+    if (_listener)
+    {
+      PhaseEventInfo<PhaseEvent::PassBegin> info;
+
+      info.pass(pass);
+
+      _listener->notify(&info);
+    }
+  }
+
+  void notifyPassEnd(Pass *pass, bool changed) const
+  {
+    if (_listener)
+    {
+      PhaseEventInfo<PhaseEvent::PassEnd> info;
+
+      info.pass(pass);
+      info.changed(changed);
+
+      _listener->notify(&info);
+    }
+  }
+
+private:
+  PhaseEventListener *_listener = nullptr;
+};
+
 enum class PhaseStrategy
 {
   // Run all the passes until there is no pass that makes a change