[logo] Introduce PhaseEventListener and enums (#6922)
author박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Tue, 27 Aug 2019 08:14:46 +0000 (17:14 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Tue, 27 Aug 2019 08:14:46 +0000 (17:14 +0900)
This will introduce PhaseEventListener as interface for event listener while running the Phase, Pass

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

index 1a1a6f0..35b3487 100644 (file)
@@ -30,6 +30,61 @@ namespace logo
 // Phase is a collection of Pass(es)
 using Phase = std::vector<std::unique_ptr<Pass>>;
 
+enum class PhaseEvent
+{
+  PhaseBegin,
+  PhaseEnd,
+
+  PassBegin,
+  PassEnd,
+};
+
+template <PhaseEvent E> struct PhaseEventInfo;
+
+template <> class PhaseEventInfo<PhaseEvent::PhaseBegin>
+{
+  // Empty
+};
+
+template <> class PhaseEventInfo<PhaseEvent::PhaseEnd>
+{
+  // Empty
+};
+
+template <> class PhaseEventInfo<PhaseEvent::PassBegin>
+{
+public:
+  void pass(const Pass *pass) { _pass = pass; }
+  const Pass *pass(void) const { return _pass; }
+
+private:
+  const Pass *_pass;
+};
+
+template <> class PhaseEventInfo<PhaseEvent::PassEnd>
+{
+public:
+  void pass(const Pass *pass) { _pass = pass; }
+  const Pass *pass(void) const { return _pass; }
+
+  void changed(bool changed) { _changed = changed; }
+  bool changed(void) const { return _changed; }
+
+private:
+  const Pass *_pass;
+  bool _changed;
+};
+
+struct PhaseEventListener
+{
+  virtual ~PhaseEventListener() = default;
+
+  virtual void notify(const PhaseEventInfo<PhaseEvent::PhaseBegin> *) { return; };
+  virtual void notify(const PhaseEventInfo<PhaseEvent::PhaseEnd> *) { return; };
+  virtual void notify(const PhaseEventInfo<PhaseEvent::PassBegin> *) { return; };
+  virtual void notify(const PhaseEventInfo<PhaseEvent::PassEnd> *) { return; };
+};
+
 enum class PhaseStrategy
 {
   // Run all the passes until there is no pass that makes a change