2013-01-05 04:13:26 -06:00
|
|
|
/*
|
|
|
|
* yosys -- Yosys Open SYnthesis Suite
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef RTLIL_H
|
|
|
|
#define RTLIL_H
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <assert.h>
|
|
|
|
|
2014-07-20 03:36:14 -05:00
|
|
|
// various helpers (unrelated to RTLIL)
|
2013-01-05 04:13:26 -06:00
|
|
|
std::string stringf(const char *fmt, ...);
|
2014-07-20 03:36:14 -05:00
|
|
|
#define SIZE(__obj) int(__obj.size())
|
2013-01-05 04:13:26 -06:00
|
|
|
|
|
|
|
namespace RTLIL
|
|
|
|
{
|
2014-07-26 19:00:04 -05:00
|
|
|
enum State : unsigned char {
|
2013-01-05 04:13:26 -06:00
|
|
|
S0 = 0,
|
|
|
|
S1 = 1,
|
|
|
|
Sx = 2, // undefined value or conflict
|
|
|
|
Sz = 3, // high-impedance / not-connected
|
|
|
|
Sa = 4, // don't care (used only in cases)
|
|
|
|
Sm = 5 // marker (used internally by some passes)
|
|
|
|
};
|
2013-12-04 07:14:05 -06:00
|
|
|
|
2014-07-26 19:00:04 -05:00
|
|
|
enum SyncType : unsigned char {
|
2013-01-05 04:13:26 -06:00
|
|
|
ST0 = 0, // level sensitive: 0
|
|
|
|
ST1 = 1, // level sensitive: 1
|
|
|
|
STp = 2, // edge sensitive: posedge
|
|
|
|
STn = 3, // edge sensitive: negedge
|
|
|
|
STe = 4, // edge sensitive: both edges
|
2013-11-21 06:49:00 -06:00
|
|
|
STa = 5, // always active
|
|
|
|
STi = 6 // init
|
2013-01-05 04:13:26 -06:00
|
|
|
};
|
|
|
|
|
2014-07-26 19:00:04 -05:00
|
|
|
enum ConstFlags : unsigned char {
|
2013-12-04 07:14:05 -06:00
|
|
|
CONST_FLAG_NONE = 0,
|
|
|
|
CONST_FLAG_STRING = 1,
|
2013-12-04 07:24:44 -06:00
|
|
|
CONST_FLAG_SIGNED = 2, // only used for parameters
|
2013-12-04 07:14:05 -06:00
|
|
|
CONST_FLAG_REAL = 4 // unused -- to be used for parameters
|
|
|
|
};
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
extern int autoidx;
|
|
|
|
|
|
|
|
struct Const;
|
|
|
|
struct Selection;
|
|
|
|
struct Design;
|
|
|
|
struct Module;
|
|
|
|
struct Wire;
|
|
|
|
struct Memory;
|
|
|
|
struct Cell;
|
|
|
|
struct SigChunk;
|
2013-11-21 21:07:13 -06:00
|
|
|
struct SigBit;
|
2014-07-22 16:49:26 -05:00
|
|
|
struct SigSpecIterator;
|
2013-01-05 04:13:26 -06:00
|
|
|
struct SigSpec;
|
|
|
|
struct CaseRule;
|
|
|
|
struct SwitchRule;
|
|
|
|
struct SyncRule;
|
|
|
|
struct Process;
|
|
|
|
|
|
|
|
typedef std::pair<SigSpec, SigSpec> SigSig;
|
|
|
|
|
|
|
|
#ifdef NDEBUG
|
|
|
|
typedef std::string IdString;
|
|
|
|
#else
|
|
|
|
struct IdString : public std::string {
|
|
|
|
IdString() { }
|
|
|
|
IdString(std::string str) : std::string(str) {
|
|
|
|
check();
|
|
|
|
}
|
|
|
|
IdString(const char *s) : std::string(s) {
|
|
|
|
check();
|
|
|
|
}
|
|
|
|
IdString &operator=(const std::string &str) {
|
|
|
|
std::string::operator=(str);
|
|
|
|
check();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
IdString &operator=(const char *s) {
|
|
|
|
std::string::operator=(s);
|
|
|
|
check();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
bool operator<(const IdString &rhs) {
|
|
|
|
check(), rhs.check();
|
|
|
|
return std::string(*this) < std::string(rhs);
|
|
|
|
}
|
|
|
|
void check() const {
|
|
|
|
assert(empty() || (size() >= 2 && (at(0) == '$' || at(0) == '\\')));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static IdString escape_id(std::string str) __attribute__((unused));
|
|
|
|
static IdString escape_id(std::string str) {
|
|
|
|
if (str.size() > 0 && str[0] != '\\' && str[0] != '$')
|
|
|
|
return "\\" + str;
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string unescape_id(std::string str) __attribute__((unused));
|
|
|
|
static std::string unescape_id(std::string str) {
|
2013-02-28 18:10:11 -06:00
|
|
|
if (str.size() > 1 && str[0] == '\\' && str[1] != '$')
|
2013-01-05 04:13:26 -06:00
|
|
|
return str.substr(1);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2013-03-01 01:57:58 -06:00
|
|
|
static const char *id2cstr(std::string str) __attribute__((unused));
|
|
|
|
static const char *id2cstr(std::string str) {
|
|
|
|
if (str.size() > 1 && str[0] == '\\' && str[1] != '$')
|
|
|
|
return str.c_str() + 1;
|
|
|
|
return str.c_str();
|
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
static IdString new_id(std::string file, int line, std::string func) __attribute__((unused));
|
|
|
|
static IdString new_id(std::string file, int line, std::string func) {
|
|
|
|
std::string str = "$auto$";
|
|
|
|
size_t pos = file.find_last_of('/');
|
|
|
|
str += pos != std::string::npos ? file.substr(pos+1) : file;
|
|
|
|
str += stringf(":%d:%s$%d", line, func.c_str(), autoidx++);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NEW_ID \
|
|
|
|
RTLIL::new_id(__FILE__, __LINE__, __FUNCTION__)
|
|
|
|
|
2013-08-09 05:42:32 -05:00
|
|
|
template <typename T> struct sort_by_name {
|
|
|
|
bool operator()(T *a, T *b) const {
|
|
|
|
return a->name < b->name;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
// see calc.cc for the implementation of this functions
|
|
|
|
RTLIL::Const const_not (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
RTLIL::Const const_and (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
RTLIL::Const const_or (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
RTLIL::Const const_xor (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
RTLIL::Const const_xnor (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
|
|
|
|
RTLIL::Const const_reduce_and (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
RTLIL::Const const_reduce_or (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
RTLIL::Const const_reduce_xor (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
RTLIL::Const const_reduce_xnor (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
RTLIL::Const const_reduce_bool (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
|
|
|
|
RTLIL::Const const_logic_not (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
RTLIL::Const const_logic_and (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
RTLIL::Const const_logic_or (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
|
|
|
|
RTLIL::Const const_shl (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
RTLIL::Const const_shr (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
RTLIL::Const const_sshl (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
RTLIL::Const const_sshr (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
|
|
|
|
RTLIL::Const const_lt (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
RTLIL::Const const_le (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
RTLIL::Const const_eq (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
RTLIL::Const const_ne (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
2013-12-27 06:50:08 -06:00
|
|
|
RTLIL::Const const_eqx (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
RTLIL::Const const_nex (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::Const const_ge (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
RTLIL::Const const_gt (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
|
|
|
|
RTLIL::Const const_add (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
RTLIL::Const const_sub (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
RTLIL::Const const_mul (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
RTLIL::Const const_div (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
RTLIL::Const const_mod (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
RTLIL::Const const_pow (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
|
|
|
|
|
|
|
RTLIL::Const const_pos (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
2013-12-28 04:54:40 -06:00
|
|
|
RTLIL::Const const_bu0 (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::Const const_neg (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
|
2014-07-27 03:13:22 -05:00
|
|
|
|
|
|
|
|
|
|
|
// This iterator-range-pair is used for Design::modules(), Module::wires() and Module::cells().
|
|
|
|
// It maintains a reference counter that is used to make sure that the container is not modified while being iterated over.
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct ObjIterator
|
|
|
|
{
|
|
|
|
typename std::map<RTLIL::IdString, T>::iterator it;
|
|
|
|
std::map<RTLIL::IdString, T> *list_p;
|
|
|
|
int *refcount_p;
|
|
|
|
|
|
|
|
ObjIterator() : list_p(nullptr), refcount_p(nullptr) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjIterator(decltype(list_p) list_p, int *refcount_p) : list_p(list_p), refcount_p(refcount_p) {
|
|
|
|
if (list_p->empty()) {
|
|
|
|
this->list_p = nullptr;
|
|
|
|
this->refcount_p = nullptr;
|
|
|
|
} else {
|
|
|
|
it = list_p->begin();
|
|
|
|
(*refcount_p)++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjIterator(const RTLIL::ObjIterator<T> &other) {
|
|
|
|
it = other.it;
|
|
|
|
list_p = other.list_p;
|
|
|
|
refcount_p = other.refcount_p;
|
|
|
|
if (refcount_p)
|
|
|
|
(*refcount_p)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjIterator &operator=(const RTLIL::ObjIterator<T> &other) {
|
|
|
|
if (refcount_p)
|
|
|
|
(*refcount_p)--;
|
|
|
|
it = other.it;
|
|
|
|
list_p = other.list_p;
|
|
|
|
refcount_p = other.refcount_p;
|
|
|
|
if (refcount_p)
|
|
|
|
(*refcount_p)++;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
~ObjIterator() {
|
|
|
|
if (refcount_p)
|
|
|
|
(*refcount_p)--;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline T operator*() const {
|
|
|
|
assert(list_p != nullptr);
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator!=(const RTLIL::ObjIterator<T> &other) const {
|
|
|
|
if (list_p == nullptr || other.list_p == nullptr)
|
|
|
|
return list_p != other.list_p;
|
|
|
|
return it != other.it;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void operator++() {
|
|
|
|
assert(list_p != nullptr);
|
|
|
|
if (++it == list_p->end()) {
|
|
|
|
(*refcount_p)--;
|
|
|
|
list_p = nullptr;
|
|
|
|
refcount_p = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct ObjRange
|
|
|
|
{
|
|
|
|
std::map<RTLIL::IdString, T> *list_p;
|
|
|
|
int *refcount_p;
|
|
|
|
|
|
|
|
ObjRange(decltype(list_p) list_p, int *refcount_p) : list_p(list_p), refcount_p(refcount_p) { }
|
|
|
|
RTLIL::ObjIterator<T> begin() { return RTLIL::ObjIterator<T>(list_p, refcount_p); }
|
|
|
|
RTLIL::ObjIterator<T> end() { return RTLIL::ObjIterator<T>(); }
|
2014-07-27 03:41:06 -05:00
|
|
|
|
|
|
|
operator std::set<T>() const {
|
|
|
|
std::set<T> result;
|
|
|
|
for (auto &it : *list_p)
|
|
|
|
result.insert(it.second);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator std::vector<T>() const {
|
|
|
|
std::vector<T> result;
|
|
|
|
result.reserve(list_p->size());
|
|
|
|
for (auto &it : *list_p)
|
|
|
|
result.push_back(it.second);
|
|
|
|
return result;
|
|
|
|
}
|
2014-07-27 03:13:22 -05:00
|
|
|
};
|
2013-01-05 04:13:26 -06:00
|
|
|
};
|
|
|
|
|
2014-07-26 19:00:04 -05:00
|
|
|
struct RTLIL::Const
|
|
|
|
{
|
2013-12-04 07:14:05 -06:00
|
|
|
int flags;
|
2013-01-05 04:13:26 -06:00
|
|
|
std::vector<RTLIL::State> bits;
|
2014-07-26 19:00:04 -05:00
|
|
|
|
2013-12-04 07:14:05 -06:00
|
|
|
Const();
|
|
|
|
Const(std::string str);
|
2013-01-05 04:13:26 -06:00
|
|
|
Const(int val, int width = 32);
|
|
|
|
Const(RTLIL::State bit, int width = 1);
|
2013-12-07 09:56:34 -06:00
|
|
|
Const(std::vector<RTLIL::State> bits) : bits(bits) { flags = CONST_FLAG_NONE; };
|
2014-07-26 19:00:04 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
bool operator <(const RTLIL::Const &other) const;
|
|
|
|
bool operator ==(const RTLIL::Const &other) const;
|
|
|
|
bool operator !=(const RTLIL::Const &other) const;
|
2014-07-26 19:00:04 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
bool as_bool() const;
|
|
|
|
int as_int() const;
|
|
|
|
std::string as_string() const;
|
2014-07-26 19:00:04 -05:00
|
|
|
|
2013-12-04 07:14:05 -06:00
|
|
|
std::string decode_string() const;
|
2013-01-05 04:13:26 -06:00
|
|
|
};
|
|
|
|
|
2014-07-26 19:00:04 -05:00
|
|
|
struct RTLIL::Selection
|
|
|
|
{
|
2013-01-05 04:13:26 -06:00
|
|
|
bool full_selection;
|
|
|
|
std::set<RTLIL::IdString> selected_modules;
|
|
|
|
std::map<RTLIL::IdString, std::set<RTLIL::IdString>> selected_members;
|
2014-07-26 19:00:04 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
Selection(bool full = true) : full_selection(full) { }
|
2014-07-26 19:00:04 -05:00
|
|
|
|
2013-06-02 10:53:30 -05:00
|
|
|
bool selected_module(RTLIL::IdString mod_name) const;
|
|
|
|
bool selected_whole_module(RTLIL::IdString mod_name) const;
|
|
|
|
bool selected_member(RTLIL::IdString mod_name, RTLIL::IdString memb_name) const;
|
2013-01-05 04:13:26 -06:00
|
|
|
void optimize(RTLIL::Design *design);
|
2014-07-26 19:00:04 -05:00
|
|
|
|
2013-11-23 08:58:06 -06:00
|
|
|
template<typename T1> void select(T1 *module) {
|
|
|
|
if (!full_selection && selected_modules.count(module->name) == 0) {
|
|
|
|
selected_modules.insert(module->name);
|
|
|
|
selected_members.erase(module->name);
|
|
|
|
}
|
|
|
|
}
|
2014-07-26 19:00:04 -05:00
|
|
|
|
2013-08-09 08:20:22 -05:00
|
|
|
template<typename T1, typename T2> void select(T1 *module, T2 *member) {
|
|
|
|
if (!full_selection && selected_modules.count(module->name) == 0)
|
|
|
|
selected_members[module->name].insert(member->name);
|
|
|
|
}
|
2014-07-26 19:00:04 -05:00
|
|
|
|
2014-01-17 09:34:50 -06:00
|
|
|
bool empty() const {
|
|
|
|
return !full_selection && selected_modules.empty() && selected_members.empty();
|
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
};
|
|
|
|
|
2014-07-26 19:00:04 -05:00
|
|
|
struct RTLIL::Design
|
|
|
|
{
|
2014-07-27 03:40:31 -05:00
|
|
|
int refcount_modules_;
|
2014-07-27 03:18:00 -05:00
|
|
|
std::map<RTLIL::IdString, RTLIL::Module*> modules_;
|
2014-07-26 19:00:04 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
std::vector<RTLIL::Selection> selection_stack;
|
|
|
|
std::map<RTLIL::IdString, RTLIL::Selection> selection_vars;
|
|
|
|
std::string selected_active_module;
|
2014-07-26 19:00:04 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
~Design();
|
2014-07-26 19:00:04 -05:00
|
|
|
|
2014-07-27 03:40:31 -05:00
|
|
|
RTLIL::ObjRange<RTLIL::Module*> modules() { return RTLIL::ObjRange<RTLIL::Module*>(&modules_, &refcount_modules_); }
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
void check();
|
|
|
|
void optimize();
|
2014-07-26 19:00:04 -05:00
|
|
|
|
2013-06-02 10:53:30 -05:00
|
|
|
bool selected_module(RTLIL::IdString mod_name) const;
|
|
|
|
bool selected_whole_module(RTLIL::IdString mod_name) const;
|
|
|
|
bool selected_member(RTLIL::IdString mod_name, RTLIL::IdString memb_name) const;
|
2014-07-26 19:00:04 -05:00
|
|
|
|
2014-07-27 04:03:56 -05:00
|
|
|
bool selected_module(RTLIL::Module *mod) const;
|
|
|
|
bool selected_whole_module(RTLIL::Module *mod) const;
|
|
|
|
|
2013-10-27 03:30:58 -05:00
|
|
|
bool full_selection() const {
|
|
|
|
return selection_stack.back().full_selection;
|
|
|
|
}
|
2014-07-26 19:00:04 -05:00
|
|
|
|
2013-06-02 10:53:30 -05:00
|
|
|
template<typename T1> bool selected(T1 *module) const {
|
2013-01-05 04:13:26 -06:00
|
|
|
return selected_module(module->name);
|
|
|
|
}
|
2014-07-26 19:00:04 -05:00
|
|
|
|
2013-06-02 10:53:30 -05:00
|
|
|
template<typename T1, typename T2> bool selected(T1 *module, T2 *member) const {
|
2013-01-05 04:13:26 -06:00
|
|
|
return selected_member(module->name, member->name);
|
|
|
|
}
|
2014-07-26 19:00:04 -05:00
|
|
|
|
2013-03-03 13:53:24 -06:00
|
|
|
template<typename T1, typename T2> void select(T1 *module, T2 *member) {
|
|
|
|
if (selection_stack.size() > 0) {
|
|
|
|
RTLIL::Selection &sel = selection_stack.back();
|
2013-08-09 08:20:22 -05:00
|
|
|
sel.select(module, member);
|
2013-03-03 13:53:24 -06:00
|
|
|
}
|
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
};
|
|
|
|
|
2013-10-24 03:59:27 -05:00
|
|
|
#define RTLIL_ATTRIBUTE_MEMBERS \
|
|
|
|
std::map<RTLIL::IdString, RTLIL::Const> attributes; \
|
|
|
|
void set_bool_attribute(RTLIL::IdString id) { \
|
|
|
|
attributes[id] = RTLIL::Const(1); \
|
|
|
|
} \
|
|
|
|
bool get_bool_attribute(RTLIL::IdString id) const { \
|
|
|
|
if (attributes.count(id) == 0) \
|
|
|
|
return false; \
|
|
|
|
return attributes.at(id).as_bool(); \
|
|
|
|
}
|
|
|
|
|
2014-07-25 08:05:18 -05:00
|
|
|
struct RTLIL::Module
|
|
|
|
{
|
2014-07-26 14:16:05 -05:00
|
|
|
protected:
|
|
|
|
void add(RTLIL::Wire *wire);
|
|
|
|
void add(RTLIL::Cell *cell);
|
|
|
|
|
|
|
|
public:
|
2014-07-27 03:13:22 -05:00
|
|
|
int refcount_wires_;
|
|
|
|
int refcount_cells_;
|
|
|
|
|
2014-07-26 19:00:04 -05:00
|
|
|
std::map<RTLIL::IdString, RTLIL::Wire*> wires_;
|
|
|
|
std::map<RTLIL::IdString, RTLIL::Cell*> cells_;
|
|
|
|
std::vector<RTLIL::SigSig> connections_;
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::IdString name;
|
2013-11-24 13:29:07 -06:00
|
|
|
std::set<RTLIL::IdString> avail_parameters;
|
2013-01-05 04:13:26 -06:00
|
|
|
std::map<RTLIL::IdString, RTLIL::Memory*> memories;
|
|
|
|
std::map<RTLIL::IdString, RTLIL::Process*> processes;
|
2013-10-24 03:59:27 -05:00
|
|
|
RTLIL_ATTRIBUTE_MEMBERS
|
2014-07-26 04:58:03 -05:00
|
|
|
|
2014-07-27 03:13:22 -05:00
|
|
|
Module();
|
2013-01-05 04:13:26 -06:00
|
|
|
virtual ~Module();
|
2013-12-04 07:24:44 -06:00
|
|
|
virtual RTLIL::IdString derive(RTLIL::Design *design, std::map<RTLIL::IdString, RTLIL::Const> parameters);
|
2013-01-05 04:13:26 -06:00
|
|
|
virtual size_t count_id(RTLIL::IdString id);
|
|
|
|
virtual void check();
|
|
|
|
virtual void optimize();
|
2014-07-26 04:58:03 -05:00
|
|
|
|
2014-07-26 07:31:47 -05:00
|
|
|
void connect(const RTLIL::SigSig &conn);
|
2014-07-26 04:58:03 -05:00
|
|
|
void connect(const RTLIL::SigSpec &lhs, const RTLIL::SigSpec &rhs);
|
2014-07-26 08:57:27 -05:00
|
|
|
const std::vector<RTLIL::SigSig> &connections() const;
|
2013-06-18 10:11:13 -05:00
|
|
|
void fixup_ports();
|
|
|
|
|
2013-07-27 07:27:51 -05:00
|
|
|
template<typename T> void rewrite_sigspecs(T functor);
|
|
|
|
void cloneInto(RTLIL::Module *new_mod) const;
|
|
|
|
virtual RTLIL::Module *clone() const;
|
2013-10-24 03:59:27 -05:00
|
|
|
|
2014-07-27 04:03:56 -05:00
|
|
|
RTLIL::Wire* wire(RTLIL::IdString id) { return wires_.count(id) ? wires_.at(id) : nullptr; }
|
|
|
|
RTLIL::Cell* cell(RTLIL::IdString id) { return cells_.count(id) ? cells_.at(id) : nullptr; }
|
|
|
|
|
2014-07-27 03:13:22 -05:00
|
|
|
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_); }
|
|
|
|
|
2014-07-26 13:12:50 -05:00
|
|
|
// Removing wires is expensive. If you have to remove wires, remove them all at once.
|
|
|
|
void remove(const std::set<RTLIL::Wire*> &wires);
|
2014-07-21 05:35:06 -05:00
|
|
|
void remove(RTLIL::Cell *cell);
|
|
|
|
|
2014-07-25 08:05:18 -05:00
|
|
|
void rename(RTLIL::Wire *wire, RTLIL::IdString new_name);
|
|
|
|
void rename(RTLIL::Cell *cell, RTLIL::IdString new_name);
|
|
|
|
void rename(RTLIL::IdString old_name, RTLIL::IdString new_name);
|
|
|
|
|
2014-07-21 05:02:55 -05:00
|
|
|
RTLIL::Wire *addWire(RTLIL::IdString name, int width = 1);
|
2014-07-26 14:16:05 -05:00
|
|
|
RTLIL::Wire *addWire(RTLIL::IdString name, const RTLIL::Wire *other);
|
|
|
|
|
2014-07-21 05:02:55 -05:00
|
|
|
RTLIL::Cell *addCell(RTLIL::IdString name, RTLIL::IdString type);
|
2014-07-25 17:38:44 -05:00
|
|
|
RTLIL::Cell *addCell(RTLIL::IdString name, const RTLIL::Cell *other);
|
2014-07-21 05:02:55 -05:00
|
|
|
|
2014-07-18 03:27:06 -05:00
|
|
|
// The add* methods create a cell and return the created cell. All signals must exist in advance.
|
|
|
|
|
2014-03-09 21:02:27 -05:00
|
|
|
RTLIL::Cell* addNot (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
RTLIL::Cell* addPos (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
RTLIL::Cell* addBu0 (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
RTLIL::Cell* addNeg (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
|
|
|
|
RTLIL::Cell* addAnd (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
RTLIL::Cell* addOr (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
RTLIL::Cell* addXor (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
RTLIL::Cell* addXnor (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
|
|
|
|
RTLIL::Cell* addReduceAnd (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
RTLIL::Cell* addReduceOr (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
RTLIL::Cell* addReduceXor (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
RTLIL::Cell* addReduceXnor (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
RTLIL::Cell* addReduceBool (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
|
|
|
|
RTLIL::Cell* addShl (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
RTLIL::Cell* addShr (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
RTLIL::Cell* addSshl (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
RTLIL::Cell* addSshr (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
|
|
|
|
RTLIL::Cell* addLt (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
RTLIL::Cell* addLe (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
RTLIL::Cell* addEq (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
RTLIL::Cell* addNe (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
RTLIL::Cell* addEqx (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
RTLIL::Cell* addNex (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
RTLIL::Cell* addGe (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
RTLIL::Cell* addGt (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
|
|
|
|
RTLIL::Cell* addAdd (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
RTLIL::Cell* addSub (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
RTLIL::Cell* addMul (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
RTLIL::Cell* addDiv (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
RTLIL::Cell* addMod (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
RTLIL::Cell* addPow (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool a_signed = false, bool b_signed = false);
|
|
|
|
|
|
|
|
RTLIL::Cell* addLogicNot (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
RTLIL::Cell* addLogicAnd (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
RTLIL::Cell* addLogicOr (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed = false);
|
|
|
|
|
|
|
|
RTLIL::Cell* addMux (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_s, RTLIL::SigSpec sig_y);
|
|
|
|
RTLIL::Cell* addPmux (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_s, RTLIL::SigSpec sig_y);
|
|
|
|
RTLIL::Cell* addSafePmux (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_s, RTLIL::SigSpec sig_y);
|
|
|
|
|
|
|
|
RTLIL::Cell* addSlice (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_y, RTLIL::Const offset);
|
|
|
|
RTLIL::Cell* addConcat (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y);
|
|
|
|
RTLIL::Cell* addLut (RTLIL::IdString name, RTLIL::SigSpec sig_i, RTLIL::SigSpec sig_o, RTLIL::Const lut);
|
|
|
|
RTLIL::Cell* addAssert (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_en);
|
|
|
|
|
|
|
|
RTLIL::Cell* addSr (RTLIL::IdString name, RTLIL::SigSpec sig_set, RTLIL::SigSpec sig_clr, RTLIL::SigSpec sig_q, bool set_polarity = true, bool clr_polarity = true);
|
|
|
|
RTLIL::Cell* addDff (RTLIL::IdString name, RTLIL::SigSpec sig_clk, RTLIL::SigSpec sig_d, RTLIL::SigSpec sig_q, bool clk_polarity = true);
|
|
|
|
RTLIL::Cell* addDffsr (RTLIL::IdString name, RTLIL::SigSpec sig_clk, RTLIL::SigSpec sig_set, RTLIL::SigSpec sig_clr,
|
|
|
|
RTLIL::SigSpec sig_d, RTLIL::SigSpec sig_q, bool clk_polarity = true, bool set_polarity = true, bool clr_polarity = true);
|
|
|
|
RTLIL::Cell* addAdff (RTLIL::IdString name, RTLIL::SigSpec sig_clk, RTLIL::SigSpec sig_arst, RTLIL::SigSpec sig_d, RTLIL::SigSpec sig_q,
|
|
|
|
RTLIL::Const arst_value, bool clk_polarity = true, bool arst_polarity = true);
|
|
|
|
RTLIL::Cell* addDlatch (RTLIL::IdString name, RTLIL::SigSpec sig_en, RTLIL::SigSpec sig_d, RTLIL::SigSpec sig_q, bool en_polarity = true);
|
2014-03-31 07:14:40 -05:00
|
|
|
RTLIL::Cell* addDlatchsr (RTLIL::IdString name, RTLIL::SigSpec sig_en, RTLIL::SigSpec sig_set, RTLIL::SigSpec sig_clr,
|
|
|
|
RTLIL::SigSpec sig_d, RTLIL::SigSpec sig_q, bool en_polarity = true, bool set_polarity = true, bool clr_polarity = true);
|
2014-03-14 05:45:44 -05:00
|
|
|
|
|
|
|
RTLIL::Cell* addInvGate (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_y);
|
|
|
|
RTLIL::Cell* addAndGate (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y);
|
|
|
|
RTLIL::Cell* addOrGate (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y);
|
|
|
|
RTLIL::Cell* addXorGate (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y);
|
|
|
|
RTLIL::Cell* addMuxGate (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_s, RTLIL::SigSpec sig_y);
|
2014-03-15 08:35:29 -05:00
|
|
|
|
|
|
|
RTLIL::Cell* addDffGate (RTLIL::IdString name, RTLIL::SigSpec sig_clk, RTLIL::SigSpec sig_d, RTLIL::SigSpec sig_q, bool clk_polarity = true);
|
|
|
|
RTLIL::Cell* addDffsrGate (RTLIL::IdString name, RTLIL::SigSpec sig_clk, RTLIL::SigSpec sig_set, RTLIL::SigSpec sig_clr,
|
|
|
|
RTLIL::SigSpec sig_d, RTLIL::SigSpec sig_q, bool clk_polarity = true, bool set_polarity = true, bool clr_polarity = true);
|
|
|
|
RTLIL::Cell* addAdffGate (RTLIL::IdString name, RTLIL::SigSpec sig_clk, RTLIL::SigSpec sig_arst, RTLIL::SigSpec sig_d, RTLIL::SigSpec sig_q,
|
|
|
|
bool arst_value = false, bool clk_polarity = true, bool arst_polarity = true);
|
|
|
|
RTLIL::Cell* addDlatchGate (RTLIL::IdString name, RTLIL::SigSpec sig_en, RTLIL::SigSpec sig_d, RTLIL::SigSpec sig_q, bool en_polarity = true);
|
2014-03-31 07:14:40 -05:00
|
|
|
RTLIL::Cell* addDlatchsrGate (RTLIL::IdString name, RTLIL::SigSpec sig_en, RTLIL::SigSpec sig_set, RTLIL::SigSpec sig_clr,
|
|
|
|
RTLIL::SigSpec sig_d, RTLIL::SigSpec sig_q, bool en_polarity = true, bool set_polarity = true, bool clr_polarity = true);
|
2014-07-18 03:27:06 -05:00
|
|
|
|
|
|
|
// The methods without the add* prefix create a cell and an output signal. They return the newly created output signal.
|
|
|
|
|
|
|
|
RTLIL::SigSpec Not (RTLIL::IdString name, RTLIL::SigSpec sig_a, bool is_signed = false);
|
|
|
|
RTLIL::SigSpec Pos (RTLIL::IdString name, RTLIL::SigSpec sig_a, bool is_signed = false);
|
|
|
|
RTLIL::SigSpec Bu0 (RTLIL::IdString name, RTLIL::SigSpec sig_a, bool is_signed = false);
|
|
|
|
RTLIL::SigSpec Neg (RTLIL::IdString name, RTLIL::SigSpec sig_a, bool is_signed = false);
|
|
|
|
|
|
|
|
RTLIL::SigSpec And (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
|
|
|
|
RTLIL::SigSpec Or (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
|
|
|
|
RTLIL::SigSpec Xor (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
|
|
|
|
RTLIL::SigSpec Xnor (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
|
|
|
|
|
|
|
|
RTLIL::SigSpec ReduceAnd (RTLIL::IdString name, RTLIL::SigSpec sig_a, bool is_signed = false);
|
|
|
|
RTLIL::SigSpec ReduceOr (RTLIL::IdString name, RTLIL::SigSpec sig_a, bool is_signed = false);
|
|
|
|
RTLIL::SigSpec ReduceXor (RTLIL::IdString name, RTLIL::SigSpec sig_a, bool is_signed = false);
|
|
|
|
RTLIL::SigSpec ReduceXnor (RTLIL::IdString name, RTLIL::SigSpec sig_a, bool is_signed = false);
|
|
|
|
RTLIL::SigSpec ReduceBool (RTLIL::IdString name, RTLIL::SigSpec sig_a, bool is_signed = false);
|
|
|
|
|
|
|
|
RTLIL::SigSpec Shl (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
|
|
|
|
RTLIL::SigSpec Shr (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
|
|
|
|
RTLIL::SigSpec Sshl (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
|
|
|
|
RTLIL::SigSpec Sshr (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
|
|
|
|
|
|
|
|
RTLIL::SigSpec Lt (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
|
|
|
|
RTLIL::SigSpec Le (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
|
|
|
|
RTLIL::SigSpec Eq (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
|
|
|
|
RTLIL::SigSpec Ne (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
|
|
|
|
RTLIL::SigSpec Eqx (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
|
|
|
|
RTLIL::SigSpec Nex (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
|
|
|
|
RTLIL::SigSpec Ge (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
|
|
|
|
RTLIL::SigSpec Gt (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
|
|
|
|
|
|
|
|
RTLIL::SigSpec Add (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
|
|
|
|
RTLIL::SigSpec Sub (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
|
|
|
|
RTLIL::SigSpec Mul (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
|
|
|
|
RTLIL::SigSpec Div (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
|
|
|
|
RTLIL::SigSpec Mod (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
|
|
|
|
RTLIL::SigSpec Pow (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool a_signed = false, bool b_signed = false);
|
|
|
|
|
|
|
|
RTLIL::SigSpec LogicNot (RTLIL::IdString name, RTLIL::SigSpec sig_a, bool is_signed = false);
|
|
|
|
RTLIL::SigSpec LogicAnd (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
|
|
|
|
RTLIL::SigSpec LogicOr (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
|
|
|
|
|
|
|
|
RTLIL::SigSpec Mux (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_s);
|
|
|
|
RTLIL::SigSpec Pmux (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_s);
|
|
|
|
RTLIL::SigSpec SafePmux (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_s);
|
|
|
|
|
|
|
|
RTLIL::SigSpec InvGate (RTLIL::IdString name, RTLIL::SigSpec sig_a);
|
|
|
|
RTLIL::SigSpec AndGate (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b);
|
|
|
|
RTLIL::SigSpec OrGate (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b);
|
|
|
|
RTLIL::SigSpec XorGate (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b);
|
|
|
|
RTLIL::SigSpec MuxGate (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_s);
|
2013-01-05 04:13:26 -06:00
|
|
|
};
|
|
|
|
|
2014-07-26 04:58:03 -05:00
|
|
|
struct RTLIL::Wire
|
|
|
|
{
|
2014-07-26 14:16:05 -05:00
|
|
|
protected:
|
2014-07-26 04:58:03 -05:00
|
|
|
// use module->addWire() and module->remove() to create or destroy wires
|
|
|
|
friend struct RTLIL::Module;
|
|
|
|
Wire();
|
|
|
|
~Wire() { };
|
|
|
|
|
|
|
|
public:
|
|
|
|
// do not simply copy wires
|
2014-07-26 14:16:05 -05:00
|
|
|
Wire(RTLIL::Wire &other) = delete;
|
|
|
|
void operator=(RTLIL::Wire &other) = delete;
|
2014-07-26 04:58:03 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::IdString name;
|
|
|
|
int width, start_offset, port_id;
|
2013-11-24 10:29:11 -06:00
|
|
|
bool port_input, port_output;
|
2013-10-24 03:59:27 -05:00
|
|
|
RTLIL_ATTRIBUTE_MEMBERS
|
2013-01-05 04:13:26 -06:00
|
|
|
};
|
|
|
|
|
2014-07-26 04:58:03 -05:00
|
|
|
struct RTLIL::Memory
|
|
|
|
{
|
|
|
|
Memory();
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::IdString name;
|
|
|
|
int width, start_offset, size;
|
2013-10-24 03:59:27 -05:00
|
|
|
RTLIL_ATTRIBUTE_MEMBERS
|
2013-01-05 04:13:26 -06:00
|
|
|
};
|
|
|
|
|
2014-07-25 08:05:18 -05:00
|
|
|
struct RTLIL::Cell
|
|
|
|
{
|
|
|
|
protected:
|
2014-07-26 04:58:03 -05:00
|
|
|
// use module->addCell() and module->remove() to create or destroy cells
|
2014-07-25 08:05:18 -05:00
|
|
|
friend struct RTLIL::Module;
|
|
|
|
Cell() { };
|
|
|
|
~Cell() { };
|
|
|
|
|
|
|
|
public:
|
2014-07-26 04:58:03 -05:00
|
|
|
// do not simply copy cells
|
2014-07-25 08:05:18 -05:00
|
|
|
Cell(RTLIL::Cell &other) = delete;
|
|
|
|
void operator=(RTLIL::Cell &other) = delete;
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::IdString name;
|
|
|
|
RTLIL::IdString type;
|
2014-07-26 04:58:03 -05:00
|
|
|
std::map<RTLIL::IdString, RTLIL::SigSpec> connections_;
|
2013-01-05 04:13:26 -06:00
|
|
|
std::map<RTLIL::IdString, RTLIL::Const> parameters;
|
2013-10-24 03:59:27 -05:00
|
|
|
RTLIL_ATTRIBUTE_MEMBERS
|
2014-07-26 05:22:58 -05:00
|
|
|
|
|
|
|
// access cell ports
|
2014-07-26 09:11:28 -05:00
|
|
|
bool has(RTLIL::IdString portname);
|
2014-07-26 05:22:58 -05:00
|
|
|
void unset(RTLIL::IdString portname);
|
|
|
|
void set(RTLIL::IdString portname, RTLIL::SigSpec signal);
|
2014-07-26 08:57:27 -05:00
|
|
|
const RTLIL::SigSpec &get(RTLIL::IdString portname) const;
|
|
|
|
const std::map<RTLIL::IdString, RTLIL::SigSpec> &connections() const;
|
2014-07-26 05:22:58 -05:00
|
|
|
|
2014-07-21 05:02:55 -05:00
|
|
|
void check();
|
2014-07-26 05:22:58 -05:00
|
|
|
void fixup_parameters(bool set_a_signed = false, bool set_b_signed = false);
|
2013-06-18 10:11:13 -05:00
|
|
|
|
2013-07-27 07:27:51 -05:00
|
|
|
template<typename T> void rewrite_sigspecs(T functor);
|
2013-01-05 04:13:26 -06:00
|
|
|
};
|
|
|
|
|
2014-07-26 19:00:04 -05:00
|
|
|
struct RTLIL::SigChunk
|
|
|
|
{
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::Wire *wire;
|
|
|
|
RTLIL::Const data; // only used if wire == NULL, LSB at index 0
|
|
|
|
int width, offset;
|
2014-07-26 19:00:04 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
SigChunk();
|
2014-07-23 01:59:54 -05:00
|
|
|
SigChunk(const RTLIL::Const &value);
|
2014-07-23 02:00:16 -05:00
|
|
|
SigChunk(RTLIL::Wire *wire);
|
2014-07-23 02:48:26 -05:00
|
|
|
SigChunk(RTLIL::Wire *wire, int offset, int width = 1);
|
2013-01-05 04:13:26 -06:00
|
|
|
SigChunk(const std::string &str);
|
|
|
|
SigChunk(int val, int width = 32);
|
|
|
|
SigChunk(RTLIL::State bit, int width = 1);
|
2013-11-21 21:07:13 -06:00
|
|
|
SigChunk(RTLIL::SigBit bit);
|
2014-07-26 19:00:04 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::SigChunk extract(int offset, int length) const;
|
2014-07-26 19:00:04 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
bool operator <(const RTLIL::SigChunk &other) const;
|
|
|
|
bool operator ==(const RTLIL::SigChunk &other) const;
|
|
|
|
bool operator !=(const RTLIL::SigChunk &other) const;
|
|
|
|
};
|
|
|
|
|
2014-07-26 19:00:04 -05:00
|
|
|
struct RTLIL::SigBit
|
|
|
|
{
|
2013-11-21 21:07:13 -06:00
|
|
|
RTLIL::Wire *wire;
|
|
|
|
RTLIL::State data;
|
|
|
|
int offset;
|
2014-07-26 19:00:04 -05:00
|
|
|
|
2013-11-21 21:07:13 -06:00
|
|
|
SigBit() : wire(NULL), data(RTLIL::State::S0), offset(0) { }
|
|
|
|
SigBit(RTLIL::State bit) : wire(NULL), data(bit), offset(0) { }
|
2014-07-27 04:03:56 -05:00
|
|
|
SigBit(RTLIL::Wire *wire) : wire(wire), data(RTLIL::State::S0), offset(0) { assert(wire && wire->width == 1); }
|
|
|
|
SigBit(RTLIL::Wire *wire, int offset) : wire(wire), data(RTLIL::State::S0), offset(offset) { assert(wire); }
|
2013-11-21 21:07:13 -06:00
|
|
|
SigBit(const RTLIL::SigChunk &chunk) : wire(chunk.wire), data(chunk.wire ? RTLIL::State::S0 : chunk.data.bits[0]), offset(chunk.offset) { assert(chunk.width == 1); }
|
|
|
|
SigBit(const RTLIL::SigChunk &chunk, int index) : wire(chunk.wire), data(chunk.wire ? RTLIL::State::S0 : chunk.data.bits[index]), offset(chunk.wire ? chunk.offset + index : 0) { }
|
|
|
|
SigBit(const RTLIL::SigSpec &sig);
|
2014-07-26 19:00:04 -05:00
|
|
|
|
2013-11-21 21:07:13 -06:00
|
|
|
bool operator <(const RTLIL::SigBit &other) const {
|
|
|
|
return (wire != other.wire) ? (wire < other.wire) : wire ? (offset < other.offset) : (data < other.data);
|
|
|
|
}
|
2014-07-26 19:00:04 -05:00
|
|
|
|
2013-11-21 21:07:13 -06:00
|
|
|
bool operator ==(const RTLIL::SigBit &other) const {
|
|
|
|
return (wire == other.wire) && (wire ? (offset == other.offset) : (data == other.data));
|
|
|
|
}
|
2014-07-26 19:00:04 -05:00
|
|
|
|
2013-11-21 21:07:13 -06:00
|
|
|
bool operator !=(const RTLIL::SigBit &other) const {
|
|
|
|
return (wire != other.wire) || (wire ? (offset != other.offset) : (data != other.data));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-07-26 19:00:04 -05:00
|
|
|
struct RTLIL::SigSpecIterator
|
|
|
|
{
|
2014-07-22 16:49:26 -05:00
|
|
|
RTLIL::SigSpec *sig_p;
|
|
|
|
int index;
|
2014-07-26 19:00:04 -05:00
|
|
|
|
2014-07-22 16:49:26 -05:00
|
|
|
inline RTLIL::SigBit &operator*() const;
|
2014-07-27 03:13:22 -05:00
|
|
|
inline bool operator!=(const RTLIL::SigSpecIterator &other) const { return index != other.index; }
|
2014-07-22 16:49:26 -05:00
|
|
|
inline void operator++() { index++; }
|
|
|
|
};
|
|
|
|
|
2014-07-26 19:00:04 -05:00
|
|
|
struct RTLIL::SigSpec
|
|
|
|
{
|
2014-07-22 13:12:15 -05:00
|
|
|
private:
|
2014-07-23 16:58:03 -05:00
|
|
|
int width_;
|
|
|
|
unsigned long hash_;
|
2014-07-22 13:12:15 -05:00
|
|
|
std::vector<RTLIL::SigChunk> chunks_; // LSB at index 0
|
2014-07-22 14:33:52 -05:00
|
|
|
std::vector<RTLIL::SigBit> bits_; // LSB at index 0
|
2014-07-22 12:56:17 -05:00
|
|
|
|
2014-07-22 14:33:52 -05:00
|
|
|
void pack() const;
|
|
|
|
void unpack() const;
|
2014-07-23 16:58:03 -05:00
|
|
|
void hash() const;
|
|
|
|
|
|
|
|
inline bool packed() const {
|
|
|
|
return bits_.empty();
|
|
|
|
}
|
2014-07-22 13:12:15 -05:00
|
|
|
|
2014-07-22 16:49:26 -05:00
|
|
|
inline void inline_unpack() const {
|
|
|
|
if (!chunks_.empty())
|
|
|
|
unpack();
|
|
|
|
}
|
|
|
|
|
2014-07-22 14:33:52 -05:00
|
|
|
public:
|
2013-01-05 04:13:26 -06:00
|
|
|
SigSpec();
|
2014-07-26 06:59:30 -05:00
|
|
|
SigSpec(const RTLIL::SigSpec &other);
|
|
|
|
const RTLIL::SigSpec &operator=(const RTLIL::SigSpec &other);
|
|
|
|
|
2014-07-23 01:59:54 -05:00
|
|
|
SigSpec(const RTLIL::Const &value);
|
2013-01-05 04:13:26 -06:00
|
|
|
SigSpec(const RTLIL::SigChunk &chunk);
|
2014-07-23 02:00:16 -05:00
|
|
|
SigSpec(RTLIL::Wire *wire);
|
2014-07-23 02:48:26 -05:00
|
|
|
SigSpec(RTLIL::Wire *wire, int offset, int width = 1);
|
2013-01-05 04:13:26 -06:00
|
|
|
SigSpec(const std::string &str);
|
|
|
|
SigSpec(int val, int width = 32);
|
|
|
|
SigSpec(RTLIL::State bit, int width = 1);
|
2013-11-21 21:07:13 -06:00
|
|
|
SigSpec(RTLIL::SigBit bit, int width = 1);
|
2014-07-22 16:49:26 -05:00
|
|
|
SigSpec(std::vector<RTLIL::SigChunk> chunks);
|
2013-11-21 21:07:13 -06:00
|
|
|
SigSpec(std::vector<RTLIL::SigBit> bits);
|
2014-07-20 04:00:09 -05:00
|
|
|
SigSpec(std::set<RTLIL::SigBit> bits);
|
2014-07-22 14:33:52 -05:00
|
|
|
|
2014-07-26 19:11:57 -05:00
|
|
|
SigSpec(RTLIL::SigSpec &&other) {
|
|
|
|
width_ = other.width_;
|
|
|
|
hash_ = other.hash_;
|
2014-07-27 02:20:59 -05:00
|
|
|
chunks_ = std::move(other.chunks_);
|
|
|
|
bits_ = std::move(other.bits_);
|
2014-07-26 19:11:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const RTLIL::SigSpec &operator=(RTLIL::SigSpec &&other) {
|
|
|
|
width_ = other.width_;
|
|
|
|
hash_ = other.hash_;
|
2014-07-27 02:20:59 -05:00
|
|
|
chunks_ = std::move(other.chunks_);
|
|
|
|
bits_ = std::move(other.bits_);
|
2014-07-26 19:11:57 -05:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-07-22 16:49:26 -05:00
|
|
|
inline const std::vector<RTLIL::SigChunk> &chunks() const { pack(); return chunks_; }
|
|
|
|
inline const std::vector<RTLIL::SigBit> &bits() const { inline_unpack(); return bits_; }
|
2014-07-22 14:33:52 -05:00
|
|
|
|
2014-07-22 16:49:26 -05:00
|
|
|
inline int size() const { return width_; }
|
2014-07-22 14:33:52 -05:00
|
|
|
|
2014-07-22 16:49:26 -05:00
|
|
|
inline RTLIL::SigBit &operator[](int index) { inline_unpack(); return bits_.at(index); }
|
|
|
|
inline const RTLIL::SigBit &operator[](int index) const { inline_unpack(); return bits_.at(index); }
|
|
|
|
|
|
|
|
inline RTLIL::SigSpecIterator begin() { RTLIL::SigSpecIterator it; it.sig_p = this; it.index = 0; return it; }
|
|
|
|
inline RTLIL::SigSpecIterator end() { RTLIL::SigSpecIterator it; it.sig_p = this; it.index = width_; return it; }
|
2014-07-22 15:54:03 -05:00
|
|
|
|
2013-03-29 05:19:21 -05:00
|
|
|
void sort();
|
2013-01-05 04:13:26 -06:00
|
|
|
void sort_and_unify();
|
2014-07-22 14:33:52 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
void replace(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec &with);
|
|
|
|
void replace(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec &with, RTLIL::SigSpec *other) const;
|
2014-07-22 14:33:52 -05:00
|
|
|
void replace(int offset, const RTLIL::SigSpec &with);
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
void remove(const RTLIL::SigSpec &pattern);
|
|
|
|
void remove(const RTLIL::SigSpec &pattern, RTLIL::SigSpec *other) const;
|
|
|
|
void remove2(const RTLIL::SigSpec &pattern, RTLIL::SigSpec *other);
|
2014-07-22 14:33:52 -05:00
|
|
|
void remove(int offset, int length = 1);
|
2013-01-05 04:13:26 -06:00
|
|
|
void remove_const();
|
2014-07-22 14:33:52 -05:00
|
|
|
|
2014-07-26 08:57:27 -05:00
|
|
|
RTLIL::SigSpec extract(RTLIL::SigSpec pattern, const RTLIL::SigSpec *other = NULL) const;
|
2014-07-22 15:54:03 -05:00
|
|
|
RTLIL::SigSpec extract(int offset, int length = 1) const;
|
2014-07-22 14:33:52 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
void append(const RTLIL::SigSpec &signal);
|
2013-11-21 21:07:13 -06:00
|
|
|
void append_bit(const RTLIL::SigBit &bit);
|
2014-07-22 14:33:52 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
void extend(int width, bool is_signed = false);
|
2013-11-07 11:17:10 -06:00
|
|
|
void extend_u0(int width, bool is_signed = false);
|
2014-07-22 14:33:52 -05:00
|
|
|
|
2014-07-23 14:34:14 -05:00
|
|
|
RTLIL::SigSpec repeat(int num) const;
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
bool operator <(const RTLIL::SigSpec &other) const;
|
|
|
|
bool operator ==(const RTLIL::SigSpec &other) const;
|
2014-07-23 08:35:09 -05:00
|
|
|
inline bool operator !=(const RTLIL::SigSpec &other) const { return !(*this == other); }
|
2014-07-22 14:33:52 -05:00
|
|
|
|
2014-07-24 15:47:57 -05:00
|
|
|
bool is_wire() const;
|
2014-07-25 07:23:10 -05:00
|
|
|
bool is_chunk() const;
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
bool is_fully_const() const;
|
|
|
|
bool is_fully_def() const;
|
|
|
|
bool is_fully_undef() const;
|
|
|
|
bool has_marked_bits() const;
|
2014-07-22 14:33:52 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
bool as_bool() const;
|
|
|
|
int as_int() const;
|
|
|
|
std::string as_string() const;
|
|
|
|
RTLIL::Const as_const() const;
|
2014-07-24 15:47:57 -05:00
|
|
|
RTLIL::Wire *as_wire() const;
|
2014-07-25 07:23:10 -05:00
|
|
|
RTLIL::SigChunk as_chunk() const;
|
2014-07-22 14:33:52 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
bool match(std::string pattern) const;
|
2014-07-22 14:33:52 -05:00
|
|
|
|
2013-11-21 21:07:13 -06:00
|
|
|
std::set<RTLIL::SigBit> to_sigbit_set() const;
|
|
|
|
std::vector<RTLIL::SigBit> to_sigbit_vector() const;
|
2014-02-02 14:35:26 -06:00
|
|
|
RTLIL::SigBit to_single_sigbit() const;
|
2014-07-22 14:33:52 -05:00
|
|
|
|
2013-06-19 02:30:37 -05:00
|
|
|
static bool parse(RTLIL::SigSpec &sig, RTLIL::Module *module, std::string str);
|
2014-02-06 12:22:46 -06:00
|
|
|
static bool parse_sel(RTLIL::SigSpec &sig, RTLIL::Design *design, RTLIL::Module *module, std::string str);
|
2013-11-09 05:02:27 -06:00
|
|
|
static bool parse_rhs(const RTLIL::SigSpec &lhs, RTLIL::SigSpec &sig, RTLIL::Module *module, std::string str);
|
2014-07-22 14:33:52 -05:00
|
|
|
|
2014-07-23 08:36:09 -05:00
|
|
|
operator std::vector<RTLIL::SigChunk>() const { return chunks(); }
|
|
|
|
operator std::vector<RTLIL::SigBit>() const { return bits(); }
|
2014-07-22 14:33:52 -05:00
|
|
|
|
2014-07-23 21:46:36 -05:00
|
|
|
#ifndef NDEBUG
|
2014-07-22 14:33:52 -05:00
|
|
|
void check() const;
|
2014-07-23 21:46:36 -05:00
|
|
|
#else
|
|
|
|
inline void check() const { }
|
|
|
|
#endif
|
2013-01-05 04:13:26 -06:00
|
|
|
};
|
|
|
|
|
2014-07-22 16:49:26 -05:00
|
|
|
inline RTLIL::SigBit &RTLIL::SigSpecIterator::operator*() const {
|
|
|
|
return (*sig_p)[index];
|
|
|
|
}
|
|
|
|
|
2013-11-21 21:07:13 -06:00
|
|
|
inline RTLIL::SigBit::SigBit(const RTLIL::SigSpec &sig) {
|
2014-07-22 13:15:14 -05:00
|
|
|
assert(sig.size() == 1 && sig.chunks().size() == 1);
|
2014-07-24 15:47:57 -05:00
|
|
|
*this = SigBit(sig.chunks().front());
|
2013-11-21 21:07:13 -06:00
|
|
|
}
|
|
|
|
|
2014-07-26 19:00:04 -05:00
|
|
|
struct RTLIL::CaseRule
|
|
|
|
{
|
2013-01-05 04:13:26 -06:00
|
|
|
std::vector<RTLIL::SigSpec> compare;
|
|
|
|
std::vector<RTLIL::SigSig> actions;
|
|
|
|
std::vector<RTLIL::SwitchRule*> switches;
|
2014-07-26 19:00:04 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
~CaseRule();
|
|
|
|
void optimize();
|
2013-06-18 10:11:13 -05:00
|
|
|
|
2013-07-27 07:27:51 -05:00
|
|
|
template<typename T> void rewrite_sigspecs(T functor);
|
|
|
|
RTLIL::CaseRule *clone() const;
|
2013-01-05 04:13:26 -06:00
|
|
|
};
|
|
|
|
|
2014-07-26 19:00:04 -05:00
|
|
|
struct RTLIL::SwitchRule
|
|
|
|
{
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::SigSpec signal;
|
2013-10-24 04:37:54 -05:00
|
|
|
RTLIL_ATTRIBUTE_MEMBERS
|
2013-01-05 04:13:26 -06:00
|
|
|
std::vector<RTLIL::CaseRule*> cases;
|
2014-07-26 19:00:04 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
~SwitchRule();
|
2013-06-18 10:11:13 -05:00
|
|
|
|
2013-07-27 07:27:51 -05:00
|
|
|
template<typename T> void rewrite_sigspecs(T functor);
|
|
|
|
RTLIL::SwitchRule *clone() const;
|
2013-01-05 04:13:26 -06:00
|
|
|
};
|
|
|
|
|
2014-07-26 19:00:04 -05:00
|
|
|
struct RTLIL::SyncRule
|
|
|
|
{
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::SyncType type;
|
|
|
|
RTLIL::SigSpec signal;
|
|
|
|
std::vector<RTLIL::SigSig> actions;
|
2013-06-18 10:11:13 -05:00
|
|
|
|
2013-07-27 07:27:51 -05:00
|
|
|
template<typename T> void rewrite_sigspecs(T functor);
|
|
|
|
RTLIL::SyncRule *clone() const;
|
2013-01-05 04:13:26 -06:00
|
|
|
};
|
|
|
|
|
2014-07-26 19:00:04 -05:00
|
|
|
struct RTLIL::Process
|
|
|
|
{
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::IdString name;
|
2013-10-24 03:59:27 -05:00
|
|
|
RTLIL_ATTRIBUTE_MEMBERS
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::CaseRule root_case;
|
|
|
|
std::vector<RTLIL::SyncRule*> syncs;
|
2014-07-26 19:00:04 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
~Process();
|
2013-06-18 10:11:13 -05:00
|
|
|
|
2013-07-27 07:27:51 -05:00
|
|
|
template<typename T> void rewrite_sigspecs(T functor);
|
|
|
|
RTLIL::Process *clone() const;
|
2013-01-05 04:13:26 -06:00
|
|
|
};
|
|
|
|
|
2013-06-18 12:54:33 -05:00
|
|
|
template<typename T>
|
|
|
|
void RTLIL::Module::rewrite_sigspecs(T functor)
|
|
|
|
{
|
2014-07-26 18:51:45 -05:00
|
|
|
for (auto &it : cells_)
|
2013-06-18 12:54:33 -05:00
|
|
|
it.second->rewrite_sigspecs(functor);
|
|
|
|
for (auto &it : processes)
|
|
|
|
it.second->rewrite_sigspecs(functor);
|
2014-07-26 04:58:03 -05:00
|
|
|
for (auto &it : connections_) {
|
2013-06-18 12:54:33 -05:00
|
|
|
functor(it.first);
|
|
|
|
functor(it.second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void RTLIL::Cell::rewrite_sigspecs(T functor) {
|
2014-07-26 04:58:03 -05:00
|
|
|
for (auto &it : connections_)
|
2013-06-18 12:54:33 -05:00
|
|
|
functor(it.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void RTLIL::CaseRule::rewrite_sigspecs(T functor) {
|
|
|
|
for (auto &it : compare)
|
|
|
|
functor(it);
|
|
|
|
for (auto &it : actions) {
|
|
|
|
functor(it.first);
|
|
|
|
functor(it.second);
|
|
|
|
}
|
|
|
|
for (auto it : switches)
|
|
|
|
it->rewrite_sigspecs(functor);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void RTLIL::SwitchRule::rewrite_sigspecs(T functor)
|
|
|
|
{
|
|
|
|
functor(signal);
|
|
|
|
for (auto it : cases)
|
|
|
|
it->rewrite_sigspecs(functor);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void RTLIL::SyncRule::rewrite_sigspecs(T functor)
|
|
|
|
{
|
|
|
|
functor(signal);
|
|
|
|
for (auto &it : actions) {
|
|
|
|
functor(it.first);
|
|
|
|
functor(it.second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void RTLIL::Process::rewrite_sigspecs(T functor)
|
|
|
|
{
|
|
|
|
root_case.rewrite_sigspecs(functor);
|
|
|
|
for (auto it : syncs)
|
|
|
|
it->rewrite_sigspecs(functor);
|
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
#endif
|