Merge remote-tracking branch 'origin/master' into xaig
[yosys.git] / kernel / rtlil.h
index 54c8ee3bdc85bff8779f241d1b5c58da948c3932..d3ad57d727bd496e1d945371a5de51e70dfc4df7 100644 (file)
@@ -50,7 +50,7 @@ namespace RTLIL
                CONST_FLAG_NONE   = 0,
                CONST_FLAG_STRING = 1,
                CONST_FLAG_SIGNED = 2,  // only used for parameters
-               CONST_FLAG_REAL   = 4   // unused -- to be used for parameters
+               CONST_FLAG_REAL   = 4   // only used for parameters
        };
 
        struct Const;
@@ -276,6 +276,12 @@ namespace RTLIL
                                return std::string(c_str() + pos, len);
                }
 
+               bool ends_with(const char* suffix) const {
+                       size_t len = strlen(suffix);
+                       if (size() < len) return false;
+                       return substr(size()-len) == suffix;
+               }
+
                size_t size() const {
                        return str().size();
                }
@@ -601,6 +607,7 @@ struct RTLIL::SigChunk
        RTLIL::SigChunk &operator =(const RTLIL::SigChunk &other) = default;
 
        RTLIL::SigChunk extract(int offset, int length) const;
+       inline int size() const { return width; }
 
        bool operator <(const RTLIL::SigChunk &other) const;
        bool operator ==(const RTLIL::SigChunk &other) const;
@@ -1001,6 +1008,7 @@ public:
        void fixup_ports();
 
        template<typename T> void rewrite_sigspecs(T &functor);
+       template<typename T> void rewrite_sigspecs2(T &functor);
        void cloneInto(RTLIL::Module *new_mod) const;
        virtual RTLIL::Module *clone() const;
 
@@ -1306,6 +1314,7 @@ public:
        }
 
        template<typename T> void rewrite_sigspecs(T &functor);
+       template<typename T> void rewrite_sigspecs2(T &functor);
 
 #ifdef WITH_PYTHON
        static std::map<unsigned int, RTLIL::Cell*> *get_all_cells(void);
@@ -1324,6 +1333,7 @@ struct RTLIL::CaseRule
        bool empty() const;
 
        template<typename T> void rewrite_sigspecs(T &functor);
+       template<typename T> void rewrite_sigspecs2(T &functor);
        RTLIL::CaseRule *clone() const;
 };
 
@@ -1337,6 +1347,7 @@ struct RTLIL::SwitchRule : public RTLIL::AttrObject
        bool empty() const;
 
        template<typename T> void rewrite_sigspecs(T &functor);
+       template<typename T> void rewrite_sigspecs2(T &functor);
        RTLIL::SwitchRule *clone() const;
 };
 
@@ -1347,6 +1358,7 @@ struct RTLIL::SyncRule
        std::vector<RTLIL::SigSig> actions;
 
        template<typename T> void rewrite_sigspecs(T &functor);
+       template<typename T> void rewrite_sigspecs2(T &functor);
        RTLIL::SyncRule *clone() const;
 };
 
@@ -1359,6 +1371,7 @@ struct RTLIL::Process : public RTLIL::AttrObject
        ~Process();
 
        template<typename T> void rewrite_sigspecs(T &functor);
+       template<typename T> void rewrite_sigspecs2(T &functor);
        RTLIL::Process *clone() const;
 };
 
@@ -1420,12 +1433,30 @@ void RTLIL::Module::rewrite_sigspecs(T &functor)
        }
 }
 
+template<typename T>
+void RTLIL::Module::rewrite_sigspecs2(T &functor)
+{
+       for (auto &it : cells_)
+               it.second->rewrite_sigspecs2(functor);
+       for (auto &it : processes)
+               it.second->rewrite_sigspecs2(functor);
+       for (auto &it : connections_) {
+               functor(it.first, it.second);
+       }
+}
+
 template<typename T>
 void RTLIL::Cell::rewrite_sigspecs(T &functor) {
        for (auto &it : connections_)
                functor(it.second);
 }
 
+template<typename T>
+void RTLIL::Cell::rewrite_sigspecs2(T &functor) {
+       for (auto &it : connections_)
+               functor(it.second);
+}
+
 template<typename T>
 void RTLIL::CaseRule::rewrite_sigspecs(T &functor) {
        for (auto &it : compare)
@@ -1438,6 +1469,17 @@ void RTLIL::CaseRule::rewrite_sigspecs(T &functor) {
                it->rewrite_sigspecs(functor);
 }
 
+template<typename T>
+void RTLIL::CaseRule::rewrite_sigspecs2(T &functor) {
+       for (auto &it : compare)
+               functor(it);
+       for (auto &it : actions) {
+               functor(it.first, it.second);
+       }
+       for (auto it : switches)
+               it->rewrite_sigspecs2(functor);
+}
+
 template<typename T>
 void RTLIL::SwitchRule::rewrite_sigspecs(T &functor)
 {
@@ -1446,6 +1488,14 @@ void RTLIL::SwitchRule::rewrite_sigspecs(T &functor)
                it->rewrite_sigspecs(functor);
 }
 
+template<typename T>
+void RTLIL::SwitchRule::rewrite_sigspecs2(T &functor)
+{
+       functor(signal);
+       for (auto it : cases)
+               it->rewrite_sigspecs2(functor);
+}
+
 template<typename T>
 void RTLIL::SyncRule::rewrite_sigspecs(T &functor)
 {
@@ -1456,6 +1506,15 @@ void RTLIL::SyncRule::rewrite_sigspecs(T &functor)
        }
 }
 
+template<typename T>
+void RTLIL::SyncRule::rewrite_sigspecs2(T &functor)
+{
+       functor(signal);
+       for (auto &it : actions) {
+               functor(it.first, it.second);
+       }
+}
+
 template<typename T>
 void RTLIL::Process::rewrite_sigspecs(T &functor)
 {
@@ -1464,6 +1523,14 @@ void RTLIL::Process::rewrite_sigspecs(T &functor)
                it->rewrite_sigspecs(functor);
 }
 
+template<typename T>
+void RTLIL::Process::rewrite_sigspecs2(T &functor)
+{
+       root_case.rewrite_sigspecs2(functor);
+       for (auto it : syncs)
+               it->rewrite_sigspecs2(functor);
+}
+
 YOSYS_NAMESPACE_END
 
 #endif