Change implicit conversions from bool to Sig* to explicit.
[yosys.git] / kernel / rtlil.h
index 86b4e25b6bfe5d0353b2af6b76c59948d6893a64..96982d2d96c934959ed525229ae923e66ab64352 100644 (file)
@@ -1,7 +1,7 @@
 /* -*- c++ -*-
  *  yosys -- Yosys Open SYnthesis Suite
  *
- *  Copyright (C) 2012  Clifford Wolf <clifford@clifford.at>
+ *  Copyright (C) 2012  Claire Xenia Wolf <claire@yosyshq.com>
  *
  *  Permission to use, copy, modify, and/or distribute this software for any
  *  purpose with or without fee is hereby granted, provided that the above
@@ -69,8 +69,10 @@ namespace RTLIL
        struct SigSpec;
        struct CaseRule;
        struct SwitchRule;
+       struct MemWriteAction;
        struct SyncRule;
        struct Process;
+       struct Binding;
 
        typedef std::pair<SigSpec, SigSpec> SigSig;
 
@@ -165,7 +167,8 @@ namespace RTLIL
                        log_assert(p[0] == '$' || p[0] == '\\');
                        log_assert(p[1] != 0);
                        for (const char *c = p; *c; c++)
-                               log_assert((unsigned)*c > (unsigned)' ');
+                               if ((unsigned)*c <= (unsigned)' ')
+                                       log_error("Found control character or space (0x%02hhx) in string '%s' which is not allowed in RTLIL identifiers\n", *c, p);
 
                #ifndef YOSYS_NO_IDS_REFCNT
                        if (global_free_idx_list_.empty()) {
@@ -334,6 +337,10 @@ namespace RTLIL
                        return compare(size()-len, len, suffix) == 0;
                }
 
+               bool contains(const char* str) const {
+                       return strstr(c_str(), str);
+               }
+
                size_t size() const {
                        return strlen(c_str());
                }
@@ -375,6 +382,8 @@ namespace RTLIL
                bool in(const char *rhs) const { return *this == rhs; }
                bool in(const std::string &rhs) const { return *this == rhs; }
                bool in(const pool<IdString> &rhs) const { return rhs.count(*this) != 0; }
+
+               bool isPublic() const { return begins_with("\\"); }
        };
 
        namespace ID {
@@ -554,6 +563,29 @@ namespace RTLIL
                        return *this;
                }
 
+               inline ObjIterator<T>& operator+=(int amt) {
+                       log_assert(list_p != nullptr);
+                       it += amt;
+                       if (it == list_p->end()) {
+                               (*refcount_p)--;
+                               list_p = nullptr;
+                               refcount_p = nullptr;
+                       }
+                       return *this;
+               }
+
+               inline ObjIterator<T> operator+(int amt) {
+                       log_assert(list_p != nullptr);
+                       ObjIterator<T> new_obj(*this);
+                       new_obj.it += amt;
+                       if (new_obj.it == list_p->end()) {
+                               (*(new_obj.refcount_p))--;
+                               new_obj.list_p = nullptr;
+                               new_obj.refcount_p = nullptr;
+                       }
+                       return new_obj;
+               }
+
                inline const ObjIterator<T> operator++(int) {
                        ObjIterator<T> result(*this);
                        ++(*this);
@@ -631,6 +663,7 @@ struct RTLIL::Const
        bool is_fully_ones() const;
        bool is_fully_def() const;
        bool is_fully_undef() const;
+       bool is_onehot(int *pos = nullptr) const;
 
        inline RTLIL::Const extract(int offset, int len = 1, RTLIL::State padding = RTLIL::State::S0) const {
                RTLIL::Const ret;
@@ -682,6 +715,9 @@ struct RTLIL::AttrObject
        std::string get_src_attribute() const {
                return get_string_attribute(ID::src);
        }
+
+       void set_hdlname_attribute(const vector<string> &hierarchy);
+       vector<string> get_hdlname_attribute() const;
 };
 
 struct RTLIL::SigChunk
@@ -703,6 +739,7 @@ struct RTLIL::SigChunk
 
        RTLIL::SigChunk extract(int offset, int length) const;
        inline int size() const { return width; }
+       inline bool is_wire() const { return wire != NULL; }
 
        bool operator <(const RTLIL::SigChunk &other) const;
        bool operator ==(const RTLIL::SigChunk &other) const;
@@ -719,7 +756,7 @@ struct RTLIL::SigBit
 
        SigBit();
        SigBit(RTLIL::State bit);
-       SigBit(bool bit);
+       explicit SigBit(bool bit);
        SigBit(RTLIL::Wire *wire);
        SigBit(RTLIL::Wire *wire, int offset);
        SigBit(const RTLIL::SigChunk &chunk);
@@ -728,6 +765,8 @@ struct RTLIL::SigBit
        SigBit(const RTLIL::SigBit &sigbit) = default;
        RTLIL::SigBit &operator =(const RTLIL::SigBit &other) = default;
 
+       inline bool is_wire() const { return wire != NULL; }
+
        bool operator <(const RTLIL::SigBit &other) const;
        bool operator ==(const RTLIL::SigBit &other) const;
        bool operator !=(const RTLIL::SigBit &other) const;
@@ -799,7 +838,7 @@ public:
        SigSpec(const std::vector<RTLIL::SigBit> &bits);
        SigSpec(const pool<RTLIL::SigBit> &bits);
        SigSpec(const std::set<RTLIL::SigBit> &bits);
-       SigSpec(bool bit);
+       explicit SigSpec(bool bit);
 
        SigSpec(RTLIL::SigSpec &&other) {
                width_ = other.width_;
@@ -897,6 +936,7 @@ public:
        bool is_fully_undef() const;
        bool has_const() const;
        bool has_marked_bits() const;
+       bool is_onehot(int *pos = nullptr) const;
 
        bool as_bool() const;
        int as_int(bool is_signed = false) const;
@@ -925,9 +965,9 @@ public:
        unsigned int hash() const { if (!hash_) updhash(); return hash_; };
 
 #ifndef NDEBUG
-       void check() const;
+       void check(Module *mod = nullptr) const;
 #else
-       void check() const { }
+       void check(Module *mod = nullptr) const { }
 #endif
 };
 
@@ -994,6 +1034,8 @@ struct RTLIL::Design
 
        int refcount_modules_;
        dict<RTLIL::IdString, RTLIL::Module*> modules_;
+       std::vector<RTLIL::Binding*> bindings_;
+
        std::vector<AST::AstNode*> verilog_packages, verilog_globals;
        std::unique_ptr<define_map_t> verilog_defines;
 
@@ -1006,6 +1048,7 @@ struct RTLIL::Design
 
        RTLIL::ObjRange<RTLIL::Module*> modules();
        RTLIL::Module *module(RTLIL::IdString name);
+       const RTLIL::Module *module(RTLIL::IdString name) const;
        RTLIL::Module *top_module();
 
        bool has(RTLIL::IdString id) const {
@@ -1013,6 +1056,8 @@ struct RTLIL::Design
        }
 
        void add(RTLIL::Module *module);
+       void add(RTLIL::Binding *binding);
+
        RTLIL::Module *addModule(RTLIL::IdString name);
        void remove(RTLIL::Module *module);
        void rename(RTLIL::Module *module, RTLIL::IdString new_name);
@@ -1058,6 +1103,13 @@ struct RTLIL::Design
                return selected_member(module->name, member->name);
        }
 
+       template<typename T1> void select(T1 *module) {
+               if (selection_stack.size() > 0) {
+                       RTLIL::Selection &sel = selection_stack.back();
+                       sel.select(module);
+               }
+       }
+
        template<typename T1, typename T2> void select(T1 *module, T2 *member) {
                if (selection_stack.size() > 0) {
                        RTLIL::Selection &sel = selection_stack.back();
@@ -1068,7 +1120,7 @@ struct RTLIL::Design
 
        std::vector<RTLIL::Module*> selected_modules() const;
        std::vector<RTLIL::Module*> selected_whole_modules() const;
-       std::vector<RTLIL::Module*> selected_whole_modules_warn() const;
+       std::vector<RTLIL::Module*> selected_whole_modules_warn(bool include_wb = false) const;
 #ifdef WITH_PYTHON
        static std::map<unsigned int, RTLIL::Design*> *get_all_designs(void);
 #endif
@@ -1082,6 +1134,7 @@ struct RTLIL::Module : public RTLIL::AttrObject
 protected:
        void add(RTLIL::Wire *wire);
        void add(RTLIL::Cell *cell);
+       void add(RTLIL::Process *process);
 
 public:
        RTLIL::Design *design;
@@ -1092,7 +1145,9 @@ public:
 
        dict<RTLIL::IdString, RTLIL::Wire*> wires_;
        dict<RTLIL::IdString, RTLIL::Cell*> cells_;
-       std::vector<RTLIL::SigSig> connections_;
+
+       std::vector<RTLIL::SigSig>   connections_;
+       std::vector<RTLIL::Binding*> bindings_;
 
        RTLIL::IdString name;
        idict<RTLIL::IdString> avail_parameters;
@@ -1147,12 +1202,24 @@ public:
                return it == cells_.end() ? nullptr : it->second;
        }
 
+       const RTLIL::Wire* wire(RTLIL::IdString id) const{
+               auto it = wires_.find(id);
+               return it == wires_.end() ? nullptr : it->second;
+       }
+       const RTLIL::Cell* cell(RTLIL::IdString id) const {
+               auto it = cells_.find(id);
+               return it == cells_.end() ? nullptr : it->second;
+       }
+
        RTLIL::ObjRange<RTLIL::Wire*> wires() { return RTLIL::ObjRange<RTLIL::Wire*>(&wires_, &refcount_wires_); }
        RTLIL::ObjRange<RTLIL::Cell*> cells() { return RTLIL::ObjRange<RTLIL::Cell*>(&cells_, &refcount_cells_); }
 
+       void add(RTLIL::Binding *binding);
+
        // Removing wires is expensive. If you have to remove wires, remove them all at once.
        void remove(const pool<RTLIL::Wire*> &wires);
        void remove(RTLIL::Cell *cell);
+       void remove(RTLIL::Process *process);
 
        void rename(RTLIL::Wire *wire, RTLIL::IdString new_name);
        void rename(RTLIL::Cell *cell, RTLIL::IdString new_name);
@@ -1172,6 +1239,9 @@ public:
 
        RTLIL::Memory *addMemory(RTLIL::IdString name, const RTLIL::Memory *other);
 
+       RTLIL::Process *addProcess(RTLIL::IdString name);
+       RTLIL::Process *addProcess(RTLIL::IdString name, const RTLIL::Process *other);
+
        // The add* methods create a cell and return the created cell. All signals must exist in advance.
 
        RTLIL::Cell* addNot (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
@@ -1239,8 +1309,16 @@ public:
        RTLIL::Cell* addDff   (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_d,   const RTLIL::SigSpec &sig_q, bool clk_polarity = true, const std::string &src = "");
        RTLIL::Cell* addDffe  (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_en,  const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, bool clk_polarity = true, bool en_polarity = true, const std::string &src = "");
        RTLIL::Cell* addDffsr (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_set, const RTLIL::SigSpec &sig_clr, RTLIL::SigSpec sig_d, const RTLIL::SigSpec &sig_q, bool clk_polarity = true, bool set_polarity = true, bool clr_polarity = true, const std::string &src = "");
+       RTLIL::Cell* addDffsre (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_set, const RTLIL::SigSpec &sig_clr, RTLIL::SigSpec sig_d, const RTLIL::SigSpec &sig_q, bool clk_polarity = true, bool en_polarity = true, bool set_polarity = true, bool clr_polarity = true, const std::string &src = "");
        RTLIL::Cell* addAdff (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_arst, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, RTLIL::Const arst_value, bool clk_polarity = true, bool arst_polarity = true, const std::string &src = "");
+       RTLIL::Cell* addAdffe (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_arst,  const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, RTLIL::Const arst_value, bool clk_polarity = true, bool en_polarity = true, bool arst_polarity = true, const std::string &src = "");
+       RTLIL::Cell* addAldff (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_aload, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, const RTLIL::SigSpec &sig_ad, bool clk_polarity = true, bool aload_polarity = true, const std::string &src = "");
+       RTLIL::Cell* addAldffe (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_aload,  const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, const RTLIL::SigSpec &sig_ad, bool clk_polarity = true, bool en_polarity = true, bool aload_polarity = true, const std::string &src = "");
+       RTLIL::Cell* addSdff (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_srst, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, RTLIL::Const srst_value, bool clk_polarity = true, bool srst_polarity = true, const std::string &src = "");
+       RTLIL::Cell* addSdffe (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_srst,  const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, RTLIL::Const srst_value, bool clk_polarity = true, bool en_polarity = true, bool srst_polarity = true, const std::string &src = "");
+       RTLIL::Cell* addSdffce (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_srst, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, RTLIL::Const srst_value, bool clk_polarity = true, bool en_polarity = true, bool srst_polarity = true, const std::string &src = "");
        RTLIL::Cell* addDlatch (RTLIL::IdString name, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, bool en_polarity = true, const std::string &src = "");
+       RTLIL::Cell* addAdlatch (RTLIL::IdString name, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_arst, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, RTLIL::Const arst_value, bool en_polarity = true, bool arst_polarity = true, const std::string &src = "");
        RTLIL::Cell* addDlatchsr (RTLIL::IdString name, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_set, const RTLIL::SigSpec &sig_clr, RTLIL::SigSpec sig_d, const RTLIL::SigSpec &sig_q, bool en_polarity = true, bool set_polarity = true, bool clr_polarity = true, const std::string &src = "");
 
        RTLIL::Cell* addBufGate    (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_y, const std::string &src = "");
@@ -1260,14 +1338,32 @@ public:
        RTLIL::Cell* addAoi4Gate   (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const RTLIL::SigBit &sig_c, const RTLIL::SigBit &sig_d, const RTLIL::SigBit &sig_y, const std::string &src = "");
        RTLIL::Cell* addOai4Gate   (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const RTLIL::SigBit &sig_c, const RTLIL::SigBit &sig_d, const RTLIL::SigBit &sig_y, const std::string &src = "");
 
+       RTLIL::Cell* addSrGate     (RTLIL::IdString name, const RTLIL::SigSpec &sig_set, const RTLIL::SigSpec &sig_clr,
+                       const RTLIL::SigSpec &sig_q, bool set_polarity = true, bool clr_polarity = true, const std::string &src = "");
        RTLIL::Cell* addFfGate     (RTLIL::IdString name, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, const std::string &src = "");
        RTLIL::Cell* addDffGate    (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, bool clk_polarity = true, const std::string &src = "");
        RTLIL::Cell* addDffeGate   (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, bool clk_polarity = true, bool en_polarity = true, const std::string &src = "");
        RTLIL::Cell* addDffsrGate  (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_set, const RTLIL::SigSpec &sig_clr,
                        RTLIL::SigSpec sig_d, const RTLIL::SigSpec &sig_q, bool clk_polarity = true, bool set_polarity = true, bool clr_polarity = true, const std::string &src = "");
+       RTLIL::Cell* addDffsreGate (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_set, const RTLIL::SigSpec &sig_clr,
+                       RTLIL::SigSpec sig_d, const RTLIL::SigSpec &sig_q, bool clk_polarity = true, bool en_polarity = true, bool set_polarity = true, bool clr_polarity = true, const std::string &src = "");
        RTLIL::Cell* addAdffGate   (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_arst, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q,
                        bool arst_value = false, bool clk_polarity = true, bool arst_polarity = true, const std::string &src = "");
+       RTLIL::Cell* addAdffeGate  (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_arst, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q,
+                       bool arst_value = false, bool clk_polarity = true, bool en_polarity = true, bool arst_polarity = true, const std::string &src = "");
+       RTLIL::Cell* addAldffGate   (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_aload, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q,
+                       const RTLIL::SigSpec &sig_ad, bool clk_polarity = true, bool aload_polarity = true, const std::string &src = "");
+       RTLIL::Cell* addAldffeGate  (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_aload, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q,
+                       const RTLIL::SigSpec &sig_ad, bool clk_polarity = true, bool en_polarity = true, bool aload_polarity = true, const std::string &src = "");
+       RTLIL::Cell* addSdffGate   (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_srst, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q,
+                       bool srst_value = false, bool clk_polarity = true, bool srst_polarity = true, const std::string &src = "");
+       RTLIL::Cell* addSdffeGate  (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_srst, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q,
+                       bool srst_value = false, bool clk_polarity = true, bool en_polarity = true, bool srst_polarity = true, const std::string &src = "");
+       RTLIL::Cell* addSdffceGate (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_srst, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q,
+                       bool srst_value = false, bool clk_polarity = true, bool en_polarity = true, bool srst_polarity = true, const std::string &src = "");
        RTLIL::Cell* addDlatchGate (RTLIL::IdString name, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, bool en_polarity = true, const std::string &src = "");
+       RTLIL::Cell* addAdlatchGate(RTLIL::IdString name, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_arst, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q,
+                       bool arst_value = false, bool en_polarity = true, bool arst_polarity = true, const std::string &src = "");
        RTLIL::Cell* addDlatchsrGate  (RTLIL::IdString name, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_set, const RTLIL::SigSpec &sig_clr,
                        RTLIL::SigSpec sig_d, const RTLIL::SigSpec &sig_q, bool en_polarity = true, bool set_polarity = true, bool clr_polarity = true, const std::string &src = "");
 
@@ -1275,7 +1371,6 @@ public:
 
        RTLIL::SigSpec Not (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, bool is_signed = false, const std::string &src = "");
        RTLIL::SigSpec Pos (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, bool is_signed = false, const std::string &src = "");
-       RTLIL::SigSpec Bu0 (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, bool is_signed = false, const std::string &src = "");
        RTLIL::SigSpec Neg (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, bool is_signed = false, const std::string &src = "");
 
        RTLIL::SigSpec And  (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
@@ -1447,6 +1542,9 @@ public:
 #ifdef WITH_PYTHON
        static std::map<unsigned int, RTLIL::Cell*> *get_all_cells(void);
 #endif
+
+       bool has_memid() const;
+       bool is_mem_cell() const;
 };
 
 struct RTLIL::CaseRule : public RTLIL::AttrObject
@@ -1456,7 +1554,6 @@ struct RTLIL::CaseRule : public RTLIL::AttrObject
        std::vector<RTLIL::SwitchRule*> switches;
 
        ~CaseRule();
-       void optimize();
 
        bool empty() const;
 
@@ -1479,11 +1576,21 @@ struct RTLIL::SwitchRule : public RTLIL::AttrObject
        RTLIL::SwitchRule *clone() const;
 };
 
+struct RTLIL::MemWriteAction : RTLIL::AttrObject
+{
+       RTLIL::IdString memid;
+       RTLIL::SigSpec address;
+       RTLIL::SigSpec data;
+       RTLIL::SigSpec enable;
+       RTLIL::Const priority_mask;
+};
+
 struct RTLIL::SyncRule
 {
        RTLIL::SyncType type;
        RTLIL::SigSpec signal;
        std::vector<RTLIL::SigSig> actions;
+       std::vector<RTLIL::MemWriteAction> mem_write_actions;
 
        template<typename T> void rewrite_sigspecs(T &functor);
        template<typename T> void rewrite_sigspecs2(T &functor);
@@ -1492,12 +1599,21 @@ struct RTLIL::SyncRule
 
 struct RTLIL::Process : public RTLIL::AttrObject
 {
+       unsigned int hashidx_;
+       unsigned int hash() const { return hashidx_; }
+
+protected:
+       // use module->addProcess() and module->remove() to create or destroy processes
+       friend struct RTLIL::Module;
+       Process();
+       ~Process();
+
+public:
        RTLIL::IdString name;
+       RTLIL::Module *module;
        RTLIL::CaseRule root_case;
        std::vector<RTLIL::SyncRule*> syncs;
 
-       ~Process();
-
        template<typename T> void rewrite_sigspecs(T &functor);
        template<typename T> void rewrite_sigspecs2(T &functor);
        RTLIL::Process *clone() const;
@@ -1631,6 +1747,11 @@ void RTLIL::SyncRule::rewrite_sigspecs(T &functor)
                functor(it.first);
                functor(it.second);
        }
+       for (auto &it : mem_write_actions) {
+               functor(it.address);
+               functor(it.data);
+               functor(it.enable);
+       }
 }
 
 template<typename T>
@@ -1640,6 +1761,11 @@ void RTLIL::SyncRule::rewrite_sigspecs2(T &functor)
        for (auto &it : actions) {
                functor(it.first, it.second);
        }
+       for (auto &it : mem_write_actions) {
+               functor(it.address);
+               functor(it.data);
+               functor(it.enable);
+       }
 }
 
 template<typename T>