Change implicit conversions from bool to Sig* to explicit.
[yosys.git] / kernel / rtlil.h
index 6170ea55ea4a207a469e4a44c8a647f6f14392f1..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()) {
@@ -660,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;
@@ -752,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);
@@ -834,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_;
@@ -932,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;
@@ -960,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
 };
 
@@ -1029,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;
 
@@ -1041,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 {
@@ -1048,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);
@@ -1110,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
@@ -1124,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;
@@ -1134,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;
@@ -1189,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);
@@ -1214,6 +1239,7 @@ 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.
@@ -1286,6 +1312,8 @@ public:
        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 = "");
@@ -1323,6 +1351,10 @@ public:
                        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,
@@ -1339,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 = "");
@@ -1511,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
@@ -1520,7 +1554,6 @@ struct RTLIL::CaseRule : public RTLIL::AttrObject
        std::vector<RTLIL::SwitchRule*> switches;
 
        ~CaseRule();
-       void optimize();
 
        bool empty() const;
 
@@ -1543,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);
@@ -1556,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;
@@ -1695,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>
@@ -1704,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>