2013-01-05 04:13:26 -06:00
|
|
|
/*
|
|
|
|
* yosys -- Yosys Open SYnthesis Suite
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2013-01-05 04:13:26 -06:00
|
|
|
* 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.
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2013-01-05 04:13:26 -06:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-07-31 06:19:47 -05:00
|
|
|
#include "kernel/yosys.h"
|
2014-09-06 08:47:46 -05:00
|
|
|
#include "kernel/macc.h"
|
2015-02-07 04:40:19 -06:00
|
|
|
#include "kernel/celltypes.h"
|
2013-06-19 02:30:37 -05:00
|
|
|
#include "frontends/verilog/verilog_frontend.h"
|
2020-03-17 04:34:31 -05:00
|
|
|
#include "frontends/verilog/preproc.h"
|
2013-11-10 16:25:04 -06:00
|
|
|
#include "backends/ilang/ilang_backend.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
2013-01-05 04:13:26 -06:00
|
|
|
#include <algorithm>
|
|
|
|
|
2014-07-31 06:19:47 -05:00
|
|
|
YOSYS_NAMESPACE_BEGIN
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2014-12-11 14:46:36 -06:00
|
|
|
RTLIL::IdString::destruct_guard_t RTLIL::IdString::destruct_guard;
|
2014-08-02 08:44:10 -05:00
|
|
|
std::vector<char*> RTLIL::IdString::global_id_storage_;
|
2014-12-26 14:59:41 -06:00
|
|
|
dict<char*, int, hash_cstr_ops> RTLIL::IdString::global_id_index_;
|
2019-08-11 05:23:16 -05:00
|
|
|
#ifndef YOSYS_NO_IDS_REFCNT
|
|
|
|
std::vector<int> RTLIL::IdString::global_refcount_storage_;
|
2014-08-02 08:11:35 -05:00
|
|
|
std::vector<int> RTLIL::IdString::global_free_idx_list_;
|
2019-08-11 05:23:16 -05:00
|
|
|
#endif
|
2019-08-10 04:41:09 -05:00
|
|
|
#ifdef YOSYS_USE_STICKY_IDS
|
2019-03-11 14:12:28 -05:00
|
|
|
int RTLIL::IdString::last_created_idx_[8];
|
|
|
|
int RTLIL::IdString::last_created_idx_ptr_;
|
2019-08-10 04:41:09 -05:00
|
|
|
#endif
|
2014-08-02 08:11:35 -05:00
|
|
|
|
2020-03-12 14:54:30 -05:00
|
|
|
#define X(_id) IdString RTLIL::ID::_id;
|
2020-04-09 11:14:03 -05:00
|
|
|
#include "kernel/constids.inc"
|
2020-03-12 14:54:30 -05:00
|
|
|
#undef X
|
|
|
|
|
2020-01-07 14:52:03 -06:00
|
|
|
dict<std::string, std::string> RTLIL::constpad;
|
2019-08-10 05:24:16 -05:00
|
|
|
|
2020-04-08 10:36:12 -05:00
|
|
|
const pool<IdString> &RTLIL::builtin_ff_cell_types() {
|
|
|
|
static const pool<IdString> res = {
|
|
|
|
ID($sr),
|
|
|
|
ID($ff),
|
|
|
|
ID($dff),
|
|
|
|
ID($dffe),
|
|
|
|
ID($dffsr),
|
Add new builtin FF types
The new types include:
- FFs with async reset and enable (`$adffe`, `$_DFFE_[NP][NP][01][NP]_`)
- FFs with sync reset (`$sdff`, `$_SDFF_[NP][NP][01]_`)
- FFs with sync reset and enable, reset priority (`$sdffs`, `$_SDFFE_[NP][NP][01][NP]_`)
- FFs with sync reset and enable, enable priority (`$sdffce`, `$_SDFFCE_[NP][NP][01][NP]_`)
- FFs with async reset, set, and enable (`$dffsre`, `$_DFFSRE_[NP][NP][NP][NP]_`)
- latches with reset or set (`$adlatch`, `$_DLATCH_[NP][NP][01]_`)
The new FF types are not actually used anywhere yet (this is left
for future commits).
2020-04-08 14:42:50 -05:00
|
|
|
ID($dffsre),
|
2020-04-08 10:36:12 -05:00
|
|
|
ID($adff),
|
Add new builtin FF types
The new types include:
- FFs with async reset and enable (`$adffe`, `$_DFFE_[NP][NP][01][NP]_`)
- FFs with sync reset (`$sdff`, `$_SDFF_[NP][NP][01]_`)
- FFs with sync reset and enable, reset priority (`$sdffs`, `$_SDFFE_[NP][NP][01][NP]_`)
- FFs with sync reset and enable, enable priority (`$sdffce`, `$_SDFFCE_[NP][NP][01][NP]_`)
- FFs with async reset, set, and enable (`$dffsre`, `$_DFFSRE_[NP][NP][NP][NP]_`)
- latches with reset or set (`$adlatch`, `$_DLATCH_[NP][NP][01]_`)
The new FF types are not actually used anywhere yet (this is left
for future commits).
2020-04-08 14:42:50 -05:00
|
|
|
ID($adffe),
|
|
|
|
ID($sdff),
|
|
|
|
ID($sdffe),
|
|
|
|
ID($sdffce),
|
2020-04-08 10:36:12 -05:00
|
|
|
ID($dlatch),
|
Add new builtin FF types
The new types include:
- FFs with async reset and enable (`$adffe`, `$_DFFE_[NP][NP][01][NP]_`)
- FFs with sync reset (`$sdff`, `$_SDFF_[NP][NP][01]_`)
- FFs with sync reset and enable, reset priority (`$sdffs`, `$_SDFFE_[NP][NP][01][NP]_`)
- FFs with sync reset and enable, enable priority (`$sdffce`, `$_SDFFCE_[NP][NP][01][NP]_`)
- FFs with async reset, set, and enable (`$dffsre`, `$_DFFSRE_[NP][NP][NP][NP]_`)
- latches with reset or set (`$adlatch`, `$_DLATCH_[NP][NP][01]_`)
The new FF types are not actually used anywhere yet (this is left
for future commits).
2020-04-08 14:42:50 -05:00
|
|
|
ID($adlatch),
|
2020-04-08 10:36:12 -05:00
|
|
|
ID($dlatchsr),
|
|
|
|
ID($_DFFE_NN_),
|
|
|
|
ID($_DFFE_NP_),
|
|
|
|
ID($_DFFE_PN_),
|
|
|
|
ID($_DFFE_PP_),
|
|
|
|
ID($_DFFSR_NNN_),
|
|
|
|
ID($_DFFSR_NNP_),
|
|
|
|
ID($_DFFSR_NPN_),
|
|
|
|
ID($_DFFSR_NPP_),
|
|
|
|
ID($_DFFSR_PNN_),
|
|
|
|
ID($_DFFSR_PNP_),
|
|
|
|
ID($_DFFSR_PPN_),
|
|
|
|
ID($_DFFSR_PPP_),
|
Add new builtin FF types
The new types include:
- FFs with async reset and enable (`$adffe`, `$_DFFE_[NP][NP][01][NP]_`)
- FFs with sync reset (`$sdff`, `$_SDFF_[NP][NP][01]_`)
- FFs with sync reset and enable, reset priority (`$sdffs`, `$_SDFFE_[NP][NP][01][NP]_`)
- FFs with sync reset and enable, enable priority (`$sdffce`, `$_SDFFCE_[NP][NP][01][NP]_`)
- FFs with async reset, set, and enable (`$dffsre`, `$_DFFSRE_[NP][NP][NP][NP]_`)
- latches with reset or set (`$adlatch`, `$_DLATCH_[NP][NP][01]_`)
The new FF types are not actually used anywhere yet (this is left
for future commits).
2020-04-08 14:42:50 -05:00
|
|
|
ID($_DFFSRE_NNNN_),
|
|
|
|
ID($_DFFSRE_NNNP_),
|
|
|
|
ID($_DFFSRE_NNPN_),
|
|
|
|
ID($_DFFSRE_NNPP_),
|
|
|
|
ID($_DFFSRE_NPNN_),
|
|
|
|
ID($_DFFSRE_NPNP_),
|
|
|
|
ID($_DFFSRE_NPPN_),
|
|
|
|
ID($_DFFSRE_NPPP_),
|
|
|
|
ID($_DFFSRE_PNNN_),
|
|
|
|
ID($_DFFSRE_PNNP_),
|
|
|
|
ID($_DFFSRE_PNPN_),
|
|
|
|
ID($_DFFSRE_PNPP_),
|
|
|
|
ID($_DFFSRE_PPNN_),
|
|
|
|
ID($_DFFSRE_PPNP_),
|
|
|
|
ID($_DFFSRE_PPPN_),
|
|
|
|
ID($_DFFSRE_PPPP_),
|
|
|
|
ID($_DFF_N_),
|
|
|
|
ID($_DFF_P_),
|
2020-04-08 10:36:12 -05:00
|
|
|
ID($_DFF_NN0_),
|
|
|
|
ID($_DFF_NN1_),
|
|
|
|
ID($_DFF_NP0_),
|
|
|
|
ID($_DFF_NP1_),
|
|
|
|
ID($_DFF_PN0_),
|
|
|
|
ID($_DFF_PN1_),
|
|
|
|
ID($_DFF_PP0_),
|
|
|
|
ID($_DFF_PP1_),
|
Add new builtin FF types
The new types include:
- FFs with async reset and enable (`$adffe`, `$_DFFE_[NP][NP][01][NP]_`)
- FFs with sync reset (`$sdff`, `$_SDFF_[NP][NP][01]_`)
- FFs with sync reset and enable, reset priority (`$sdffs`, `$_SDFFE_[NP][NP][01][NP]_`)
- FFs with sync reset and enable, enable priority (`$sdffce`, `$_SDFFCE_[NP][NP][01][NP]_`)
- FFs with async reset, set, and enable (`$dffsre`, `$_DFFSRE_[NP][NP][NP][NP]_`)
- latches with reset or set (`$adlatch`, `$_DLATCH_[NP][NP][01]_`)
The new FF types are not actually used anywhere yet (this is left
for future commits).
2020-04-08 14:42:50 -05:00
|
|
|
ID($_DFFE_NN0N_),
|
|
|
|
ID($_DFFE_NN0P_),
|
|
|
|
ID($_DFFE_NN1N_),
|
|
|
|
ID($_DFFE_NN1P_),
|
|
|
|
ID($_DFFE_NP0N_),
|
|
|
|
ID($_DFFE_NP0P_),
|
|
|
|
ID($_DFFE_NP1N_),
|
|
|
|
ID($_DFFE_NP1P_),
|
|
|
|
ID($_DFFE_PN0N_),
|
|
|
|
ID($_DFFE_PN0P_),
|
|
|
|
ID($_DFFE_PN1N_),
|
|
|
|
ID($_DFFE_PN1P_),
|
|
|
|
ID($_DFFE_PP0N_),
|
|
|
|
ID($_DFFE_PP0P_),
|
|
|
|
ID($_DFFE_PP1N_),
|
|
|
|
ID($_DFFE_PP1P_),
|
|
|
|
ID($_SDFF_NN0_),
|
|
|
|
ID($_SDFF_NN1_),
|
|
|
|
ID($_SDFF_NP0_),
|
|
|
|
ID($_SDFF_NP1_),
|
|
|
|
ID($_SDFF_PN0_),
|
|
|
|
ID($_SDFF_PN1_),
|
|
|
|
ID($_SDFF_PP0_),
|
|
|
|
ID($_SDFF_PP1_),
|
|
|
|
ID($_SDFFE_NN0N_),
|
|
|
|
ID($_SDFFE_NN0P_),
|
|
|
|
ID($_SDFFE_NN1N_),
|
|
|
|
ID($_SDFFE_NN1P_),
|
|
|
|
ID($_SDFFE_NP0N_),
|
|
|
|
ID($_SDFFE_NP0P_),
|
|
|
|
ID($_SDFFE_NP1N_),
|
|
|
|
ID($_SDFFE_NP1P_),
|
|
|
|
ID($_SDFFE_PN0N_),
|
|
|
|
ID($_SDFFE_PN0P_),
|
|
|
|
ID($_SDFFE_PN1N_),
|
|
|
|
ID($_SDFFE_PN1P_),
|
|
|
|
ID($_SDFFE_PP0N_),
|
|
|
|
ID($_SDFFE_PP0P_),
|
|
|
|
ID($_SDFFE_PP1N_),
|
|
|
|
ID($_SDFFE_PP1P_),
|
|
|
|
ID($_SDFFCE_NN0N_),
|
|
|
|
ID($_SDFFCE_NN0P_),
|
|
|
|
ID($_SDFFCE_NN1N_),
|
|
|
|
ID($_SDFFCE_NN1P_),
|
|
|
|
ID($_SDFFCE_NP0N_),
|
|
|
|
ID($_SDFFCE_NP0P_),
|
|
|
|
ID($_SDFFCE_NP1N_),
|
|
|
|
ID($_SDFFCE_NP1P_),
|
|
|
|
ID($_SDFFCE_PN0N_),
|
|
|
|
ID($_SDFFCE_PN0P_),
|
|
|
|
ID($_SDFFCE_PN1N_),
|
|
|
|
ID($_SDFFCE_PN1P_),
|
|
|
|
ID($_SDFFCE_PP0N_),
|
|
|
|
ID($_SDFFCE_PP0P_),
|
|
|
|
ID($_SDFFCE_PP1N_),
|
|
|
|
ID($_SDFFCE_PP1P_),
|
|
|
|
ID($_SR_NN_),
|
|
|
|
ID($_SR_NP_),
|
|
|
|
ID($_SR_PN_),
|
|
|
|
ID($_SR_PP_),
|
|
|
|
ID($_DLATCH_N_),
|
|
|
|
ID($_DLATCH_P_),
|
|
|
|
ID($_DLATCH_NN0_),
|
|
|
|
ID($_DLATCH_NN1_),
|
|
|
|
ID($_DLATCH_NP0_),
|
|
|
|
ID($_DLATCH_NP1_),
|
|
|
|
ID($_DLATCH_PN0_),
|
|
|
|
ID($_DLATCH_PN1_),
|
|
|
|
ID($_DLATCH_PP0_),
|
|
|
|
ID($_DLATCH_PP1_),
|
2020-04-08 10:36:12 -05:00
|
|
|
ID($_DLATCHSR_NNN_),
|
|
|
|
ID($_DLATCHSR_NNP_),
|
|
|
|
ID($_DLATCHSR_NPN_),
|
|
|
|
ID($_DLATCHSR_NPP_),
|
|
|
|
ID($_DLATCHSR_PNN_),
|
|
|
|
ID($_DLATCHSR_PNP_),
|
|
|
|
ID($_DLATCHSR_PPN_),
|
|
|
|
ID($_DLATCHSR_PPP_),
|
|
|
|
ID($_FF_),
|
|
|
|
};
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2013-12-04 07:14:05 -06:00
|
|
|
RTLIL::Const::Const()
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2013-12-04 07:14:05 -06:00
|
|
|
flags = RTLIL::CONST_FLAG_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::Const::Const(std::string str)
|
|
|
|
{
|
|
|
|
flags = RTLIL::CONST_FLAG_STRING;
|
|
|
|
for (int i = str.size()-1; i >= 0; i--) {
|
2013-01-05 04:13:26 -06:00
|
|
|
unsigned char ch = str[i];
|
|
|
|
for (int j = 0; j < 8; j++) {
|
2019-08-07 13:12:38 -05:00
|
|
|
bits.push_back((ch & 1) != 0 ? State::S1 : State::S0);
|
2013-01-05 04:13:26 -06:00
|
|
|
ch = ch >> 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::Const::Const(int val, int width)
|
|
|
|
{
|
2013-12-04 07:14:05 -06:00
|
|
|
flags = RTLIL::CONST_FLAG_NONE;
|
2013-01-05 04:13:26 -06:00
|
|
|
for (int i = 0; i < width; i++) {
|
2019-08-07 13:12:38 -05:00
|
|
|
bits.push_back((val & 1) != 0 ? State::S1 : State::S0);
|
2013-01-05 04:13:26 -06:00
|
|
|
val = val >> 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::Const::Const(RTLIL::State bit, int width)
|
|
|
|
{
|
2013-12-04 07:14:05 -06:00
|
|
|
flags = RTLIL::CONST_FLAG_NONE;
|
2013-01-05 04:13:26 -06:00
|
|
|
for (int i = 0; i < width; i++)
|
|
|
|
bits.push_back(bit);
|
|
|
|
}
|
|
|
|
|
2014-09-19 08:50:55 -05:00
|
|
|
RTLIL::Const::Const(const std::vector<bool> &bits)
|
|
|
|
{
|
|
|
|
flags = RTLIL::CONST_FLAG_NONE;
|
2020-03-18 10:48:36 -05:00
|
|
|
for (const auto &b : bits)
|
|
|
|
this->bits.emplace_back(b ? State::S1 : State::S0);
|
2014-09-19 08:50:55 -05:00
|
|
|
}
|
|
|
|
|
2018-08-13 08:18:46 -05:00
|
|
|
RTLIL::Const::Const(const RTLIL::Const &c)
|
|
|
|
{
|
|
|
|
flags = c.flags;
|
2020-03-18 10:48:36 -05:00
|
|
|
for (const auto &b : c.bits)
|
2018-08-13 08:18:46 -05:00
|
|
|
this->bits.push_back(b);
|
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
bool RTLIL::Const::operator <(const RTLIL::Const &other) const
|
|
|
|
{
|
|
|
|
if (bits.size() != other.bits.size())
|
|
|
|
return bits.size() < other.bits.size();
|
|
|
|
for (size_t i = 0; i < bits.size(); i++)
|
|
|
|
if (bits[i] != other.bits[i])
|
|
|
|
return bits[i] < other.bits[i];
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RTLIL::Const::operator ==(const RTLIL::Const &other) const
|
|
|
|
{
|
|
|
|
return bits == other.bits;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RTLIL::Const::operator !=(const RTLIL::Const &other) const
|
|
|
|
{
|
|
|
|
return bits != other.bits;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RTLIL::Const::as_bool() const
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < bits.size(); i++)
|
2019-08-07 13:12:38 -05:00
|
|
|
if (bits[i] == State::S1)
|
2013-01-05 04:13:26 -06:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-08-24 08:14:00 -05:00
|
|
|
int RTLIL::Const::as_int(bool is_signed) const
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2014-08-24 08:14:00 -05:00
|
|
|
int32_t ret = 0;
|
2013-01-05 04:13:26 -06:00
|
|
|
for (size_t i = 0; i < bits.size() && i < 32; i++)
|
2019-08-07 13:12:38 -05:00
|
|
|
if (bits[i] == State::S1)
|
2013-01-05 04:13:26 -06:00
|
|
|
ret |= 1 << i;
|
2019-08-07 13:12:38 -05:00
|
|
|
if (is_signed && bits.back() == State::S1)
|
2014-08-24 08:14:00 -05:00
|
|
|
for (size_t i = bits.size(); i < 32; i++)
|
|
|
|
ret |= 1 << i;
|
2013-01-05 04:13:26 -06:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string RTLIL::Const::as_string() const
|
|
|
|
{
|
|
|
|
std::string ret;
|
2020-03-18 10:48:36 -05:00
|
|
|
ret.reserve(bits.size());
|
2013-01-05 04:13:26 -06:00
|
|
|
for (size_t i = bits.size(); i > 0; i--)
|
|
|
|
switch (bits[i-1]) {
|
|
|
|
case S0: ret += "0"; break;
|
|
|
|
case S1: ret += "1"; break;
|
|
|
|
case Sx: ret += "x"; break;
|
|
|
|
case Sz: ret += "z"; break;
|
|
|
|
case Sa: ret += "-"; break;
|
|
|
|
case Sm: ret += "m"; break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Const RTLIL::Const::from_string(const std::string &str)
|
2015-01-31 05:08:20 -06:00
|
|
|
{
|
|
|
|
Const c;
|
2020-03-18 10:48:36 -05:00
|
|
|
c.bits.reserve(str.size());
|
2015-01-31 05:08:20 -06:00
|
|
|
for (auto it = str.rbegin(); it != str.rend(); it++)
|
|
|
|
switch (*it) {
|
|
|
|
case '0': c.bits.push_back(State::S0); break;
|
|
|
|
case '1': c.bits.push_back(State::S1); break;
|
|
|
|
case 'x': c.bits.push_back(State::Sx); break;
|
|
|
|
case 'z': c.bits.push_back(State::Sz); break;
|
|
|
|
case 'm': c.bits.push_back(State::Sm); break;
|
|
|
|
default: c.bits.push_back(State::Sa);
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2013-12-04 07:14:05 -06:00
|
|
|
std::string RTLIL::Const::decode_string() const
|
|
|
|
{
|
|
|
|
std::string string;
|
2020-03-18 10:48:36 -05:00
|
|
|
string.reserve(GetSize(bits)/8);
|
|
|
|
for (int i = 0; i < GetSize(bits); i += 8) {
|
2013-12-04 07:14:05 -06:00
|
|
|
char ch = 0;
|
|
|
|
for (int j = 0; j < 8 && i + j < int (bits.size()); j++)
|
|
|
|
if (bits[i + j] == RTLIL::State::S1)
|
|
|
|
ch |= 1 << j;
|
|
|
|
if (ch != 0)
|
2020-03-18 10:48:36 -05:00
|
|
|
string.append({ch});
|
2013-12-04 07:14:05 -06:00
|
|
|
}
|
2020-03-18 10:48:36 -05:00
|
|
|
std::reverse(string.begin(), string.end());
|
2013-12-04 07:14:05 -06:00
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
2017-08-18 04:40:08 -05:00
|
|
|
bool RTLIL::Const::is_fully_zero() const
|
|
|
|
{
|
|
|
|
cover("kernel.rtlil.const.is_fully_zero");
|
|
|
|
|
2020-03-18 10:48:36 -05:00
|
|
|
for (const auto &bit : bits)
|
2017-08-18 04:40:08 -05:00
|
|
|
if (bit != RTLIL::State::S0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-13 19:06:39 -06:00
|
|
|
bool RTLIL::Const::is_fully_ones() const
|
|
|
|
{
|
|
|
|
cover("kernel.rtlil.const.is_fully_ones");
|
|
|
|
|
2020-03-18 10:48:36 -05:00
|
|
|
for (const auto &bit : bits)
|
2017-12-13 19:06:39 -06:00
|
|
|
if (bit != RTLIL::State::S1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-18 04:40:08 -05:00
|
|
|
bool RTLIL::Const::is_fully_def() const
|
|
|
|
{
|
|
|
|
cover("kernel.rtlil.const.is_fully_def");
|
|
|
|
|
2020-03-18 10:48:36 -05:00
|
|
|
for (const auto &bit : bits)
|
2017-08-18 04:40:08 -05:00
|
|
|
if (bit != RTLIL::State::S0 && bit != RTLIL::State::S1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RTLIL::Const::is_fully_undef() const
|
|
|
|
{
|
|
|
|
cover("kernel.rtlil.const.is_fully_undef");
|
|
|
|
|
2020-03-18 10:48:36 -05:00
|
|
|
for (const auto &bit : bits)
|
2017-08-18 04:40:08 -05:00
|
|
|
if (bit != RTLIL::State::Sx && bit != RTLIL::State::Sz)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-16 16:49:49 -05:00
|
|
|
bool RTLIL::AttrObject::has_attribute(RTLIL::IdString id) const
|
|
|
|
{
|
|
|
|
return attributes.count(id);
|
|
|
|
}
|
|
|
|
|
2019-04-20 04:04:46 -05:00
|
|
|
void RTLIL::AttrObject::set_bool_attribute(RTLIL::IdString id, bool value)
|
2015-04-24 15:04:05 -05:00
|
|
|
{
|
2019-04-20 04:04:46 -05:00
|
|
|
if (value)
|
|
|
|
attributes[id] = RTLIL::Const(1);
|
2020-03-18 10:48:36 -05:00
|
|
|
else
|
|
|
|
attributes.erase(id);
|
2015-04-24 15:04:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RTLIL::AttrObject::get_bool_attribute(RTLIL::IdString id) const
|
|
|
|
{
|
2019-05-07 22:04:28 -05:00
|
|
|
const auto it = attributes.find(id);
|
|
|
|
if (it == attributes.end())
|
2015-04-24 15:04:05 -05:00
|
|
|
return false;
|
2019-05-07 22:04:28 -05:00
|
|
|
return it->second.as_bool();
|
2015-04-24 15:04:05 -05:00
|
|
|
}
|
|
|
|
|
2020-04-16 16:43:03 -05:00
|
|
|
void RTLIL::AttrObject::set_string_attribute(RTLIL::IdString id, string value)
|
|
|
|
{
|
|
|
|
if (value.empty())
|
|
|
|
attributes.erase(id);
|
|
|
|
else
|
|
|
|
attributes[id] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
string RTLIL::AttrObject::get_string_attribute(RTLIL::IdString id) const
|
|
|
|
{
|
|
|
|
std::string value;
|
|
|
|
const auto it = attributes.find(id);
|
|
|
|
if (it != attributes.end())
|
|
|
|
value = it->second.decode_string();
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2015-04-24 15:04:05 -05:00
|
|
|
void RTLIL::AttrObject::set_strpool_attribute(RTLIL::IdString id, const pool<string> &data)
|
|
|
|
{
|
|
|
|
string attrval;
|
2020-03-18 10:48:36 -05:00
|
|
|
for (const auto &s : data) {
|
2015-04-24 15:04:05 -05:00
|
|
|
if (!attrval.empty())
|
|
|
|
attrval += "|";
|
|
|
|
attrval += s;
|
|
|
|
}
|
2020-06-08 14:02:48 -05:00
|
|
|
set_string_attribute(id, attrval);
|
2015-04-24 15:04:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void RTLIL::AttrObject::add_strpool_attribute(RTLIL::IdString id, const pool<string> &data)
|
|
|
|
{
|
|
|
|
pool<string> union_data = get_strpool_attribute(id);
|
|
|
|
union_data.insert(data.begin(), data.end());
|
|
|
|
if (!union_data.empty())
|
|
|
|
set_strpool_attribute(id, union_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
pool<string> RTLIL::AttrObject::get_strpool_attribute(RTLIL::IdString id) const
|
|
|
|
{
|
|
|
|
pool<string> data;
|
|
|
|
if (attributes.count(id) != 0)
|
2020-06-08 14:02:48 -05:00
|
|
|
for (auto s : split_tokens(get_string_attribute(id), "|"))
|
2015-04-24 15:04:05 -05:00
|
|
|
data.insert(s);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2020-06-04 05:46:54 -05:00
|
|
|
void RTLIL::AttrObject::set_hdlname_attribute(const vector<string> &hierarchy)
|
|
|
|
{
|
|
|
|
string attrval;
|
|
|
|
for (const auto &ident : hierarchy) {
|
|
|
|
if (!attrval.empty())
|
|
|
|
attrval += " ";
|
|
|
|
attrval += ident;
|
|
|
|
}
|
|
|
|
set_string_attribute(ID::hdlname, attrval);
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<string> RTLIL::AttrObject::get_hdlname_attribute() const
|
|
|
|
{
|
|
|
|
return split_tokens(get_string_attribute(ID::hdlname), " ");
|
|
|
|
}
|
|
|
|
|
2013-06-02 10:53:30 -05:00
|
|
|
bool RTLIL::Selection::selected_module(RTLIL::IdString mod_name) const
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
|
|
|
if (full_selection)
|
|
|
|
return true;
|
|
|
|
if (selected_modules.count(mod_name) > 0)
|
|
|
|
return true;
|
|
|
|
if (selected_members.count(mod_name) > 0)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-02 10:53:30 -05:00
|
|
|
bool RTLIL::Selection::selected_whole_module(RTLIL::IdString mod_name) const
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
|
|
|
if (full_selection)
|
|
|
|
return true;
|
|
|
|
if (selected_modules.count(mod_name) > 0)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-02 10:53:30 -05:00
|
|
|
bool RTLIL::Selection::selected_member(RTLIL::IdString mod_name, RTLIL::IdString memb_name) const
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
|
|
|
if (full_selection)
|
|
|
|
return true;
|
|
|
|
if (selected_modules.count(mod_name) > 0)
|
|
|
|
return true;
|
|
|
|
if (selected_members.count(mod_name) > 0)
|
2013-06-02 10:53:30 -05:00
|
|
|
if (selected_members.at(mod_name).count(memb_name) > 0)
|
2013-01-05 04:13:26 -06:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RTLIL::Selection::optimize(RTLIL::Design *design)
|
|
|
|
{
|
|
|
|
if (full_selection) {
|
|
|
|
selected_modules.clear();
|
|
|
|
selected_members.clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<RTLIL::IdString> del_list, add_list;
|
|
|
|
|
|
|
|
del_list.clear();
|
|
|
|
for (auto mod_name : selected_modules) {
|
2014-07-27 03:18:00 -05:00
|
|
|
if (design->modules_.count(mod_name) == 0)
|
2013-01-05 04:13:26 -06:00
|
|
|
del_list.push_back(mod_name);
|
|
|
|
selected_members.erase(mod_name);
|
|
|
|
}
|
|
|
|
for (auto mod_name : del_list)
|
|
|
|
selected_modules.erase(mod_name);
|
|
|
|
|
|
|
|
del_list.clear();
|
|
|
|
for (auto &it : selected_members)
|
2014-07-27 03:18:00 -05:00
|
|
|
if (design->modules_.count(it.first) == 0)
|
2013-01-05 04:13:26 -06:00
|
|
|
del_list.push_back(it.first);
|
|
|
|
for (auto mod_name : del_list)
|
|
|
|
selected_members.erase(mod_name);
|
|
|
|
|
|
|
|
for (auto &it : selected_members) {
|
|
|
|
del_list.clear();
|
|
|
|
for (auto memb_name : it.second)
|
2014-07-27 03:18:00 -05:00
|
|
|
if (design->modules_[it.first]->count_id(memb_name) == 0)
|
2013-01-05 04:13:26 -06:00
|
|
|
del_list.push_back(memb_name);
|
|
|
|
for (auto memb_name : del_list)
|
|
|
|
it.second.erase(memb_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
del_list.clear();
|
|
|
|
add_list.clear();
|
|
|
|
for (auto &it : selected_members)
|
|
|
|
if (it.second.size() == 0)
|
|
|
|
del_list.push_back(it.first);
|
2014-07-27 03:18:00 -05:00
|
|
|
else if (it.second.size() == design->modules_[it.first]->wires_.size() + design->modules_[it.first]->memories.size() +
|
|
|
|
design->modules_[it.first]->cells_.size() + design->modules_[it.first]->processes.size())
|
2013-01-05 04:13:26 -06:00
|
|
|
add_list.push_back(it.first);
|
|
|
|
for (auto mod_name : del_list)
|
|
|
|
selected_members.erase(mod_name);
|
|
|
|
for (auto mod_name : add_list) {
|
|
|
|
selected_members.erase(mod_name);
|
|
|
|
selected_modules.insert(mod_name);
|
|
|
|
}
|
|
|
|
|
2014-07-27 03:18:00 -05:00
|
|
|
if (selected_modules.size() == design->modules_.size()) {
|
2013-01-05 04:13:26 -06:00
|
|
|
full_selection = true;
|
|
|
|
selected_modules.clear();
|
|
|
|
selected_members.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-29 09:06:27 -05:00
|
|
|
RTLIL::Design::Design()
|
2020-03-17 04:34:31 -05:00
|
|
|
: verilog_defines (new define_map_t)
|
2014-07-29 09:06:27 -05:00
|
|
|
{
|
2014-12-28 17:12:36 -06:00
|
|
|
static unsigned int hashidx_count = 123456789;
|
|
|
|
hashidx_count = mkhash_xorshift(hashidx_count);
|
|
|
|
hashidx_ = hashidx_count;
|
2014-12-28 10:51:16 -06:00
|
|
|
|
2014-07-29 09:06:27 -05:00
|
|
|
refcount_modules_ = 0;
|
2014-09-02 15:49:24 -05:00
|
|
|
selection_stack.push_back(RTLIL::Selection());
|
2018-07-09 08:48:06 -05:00
|
|
|
|
|
|
|
#ifdef WITH_PYTHON
|
|
|
|
RTLIL::Design::get_all_designs()->insert(std::pair<unsigned int, RTLIL::Design*>(hashidx_, this));
|
|
|
|
#endif
|
2014-07-29 09:06:27 -05:00
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::Design::~Design()
|
|
|
|
{
|
2014-12-26 14:35:22 -06:00
|
|
|
for (auto it = modules_.begin(); it != modules_.end(); ++it)
|
2013-01-05 04:13:26 -06:00
|
|
|
delete it->second;
|
2016-06-18 07:13:36 -05:00
|
|
|
for (auto n : verilog_packages)
|
2016-06-18 03:24:21 -05:00
|
|
|
delete n;
|
2016-11-15 05:42:43 -06:00
|
|
|
for (auto n : verilog_globals)
|
|
|
|
delete n;
|
2018-07-09 08:48:06 -05:00
|
|
|
#ifdef WITH_PYTHON
|
|
|
|
RTLIL::Design::get_all_designs()->erase(hashidx_);
|
|
|
|
#endif
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2018-07-09 08:48:06 -05:00
|
|
|
#ifdef WITH_PYTHON
|
2019-04-03 07:27:39 -05:00
|
|
|
static std::map<unsigned int, RTLIL::Design*> all_designs;
|
2018-07-09 08:48:06 -05:00
|
|
|
std::map<unsigned int, RTLIL::Design*> *RTLIL::Design::get_all_designs(void)
|
|
|
|
{
|
2019-04-03 07:27:39 -05:00
|
|
|
return &all_designs;
|
2018-07-09 08:48:06 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-07-27 14:12:09 -05:00
|
|
|
RTLIL::ObjRange<RTLIL::Module*> RTLIL::Design::modules()
|
|
|
|
{
|
|
|
|
return RTLIL::ObjRange<RTLIL::Module*>(&modules_, &refcount_modules_);
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::Module *RTLIL::Design::module(RTLIL::IdString name)
|
|
|
|
{
|
|
|
|
return modules_.count(name) ? modules_.at(name) : NULL;
|
|
|
|
}
|
|
|
|
|
2015-06-17 02:38:56 -05:00
|
|
|
RTLIL::Module *RTLIL::Design::top_module()
|
|
|
|
{
|
|
|
|
RTLIL::Module *module = nullptr;
|
|
|
|
int module_count = 0;
|
|
|
|
|
|
|
|
for (auto mod : selected_modules()) {
|
2020-04-02 11:51:32 -05:00
|
|
|
if (mod->get_bool_attribute(ID::top))
|
2015-06-17 02:38:56 -05:00
|
|
|
return mod;
|
|
|
|
module_count++;
|
|
|
|
module = mod;
|
|
|
|
}
|
|
|
|
|
|
|
|
return module_count == 1 ? module : nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-27 14:12:09 -05:00
|
|
|
void RTLIL::Design::add(RTLIL::Module *module)
|
|
|
|
{
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(modules_.count(module->name) == 0);
|
|
|
|
log_assert(refcount_modules_ == 0);
|
2014-07-27 14:12:09 -05:00
|
|
|
modules_[module->name] = module;
|
2014-07-31 07:11:39 -05:00
|
|
|
module->design = this;
|
2014-07-31 07:34:12 -05:00
|
|
|
|
|
|
|
for (auto mon : monitors)
|
|
|
|
mon->notify_module_add(module);
|
2014-12-29 06:33:33 -06:00
|
|
|
|
|
|
|
if (yosys_xtrace) {
|
|
|
|
log("#X# New Module: %s\n", log_id(module));
|
|
|
|
log_backtrace("-X- ", yosys_xtrace-1);
|
|
|
|
}
|
2014-07-27 14:12:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::Module *RTLIL::Design::addModule(RTLIL::IdString name)
|
|
|
|
{
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(modules_.count(name) == 0);
|
|
|
|
log_assert(refcount_modules_ == 0);
|
2014-07-31 07:34:12 -05:00
|
|
|
|
|
|
|
RTLIL::Module *module = new RTLIL::Module;
|
|
|
|
modules_[name] = module;
|
|
|
|
module->design = this;
|
|
|
|
module->name = name;
|
|
|
|
|
|
|
|
for (auto mon : monitors)
|
|
|
|
mon->notify_module_add(module);
|
|
|
|
|
2014-12-29 06:33:33 -06:00
|
|
|
if (yosys_xtrace) {
|
|
|
|
log("#X# New Module: %s\n", log_id(module));
|
|
|
|
log_backtrace("-X- ", yosys_xtrace-1);
|
|
|
|
}
|
|
|
|
|
2014-07-31 07:34:12 -05:00
|
|
|
return module;
|
2014-07-27 14:12:09 -05:00
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
void RTLIL::Design::scratchpad_unset(const std::string &varname)
|
2014-08-30 12:37:12 -05:00
|
|
|
{
|
|
|
|
scratchpad.erase(varname);
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
void RTLIL::Design::scratchpad_set_int(const std::string &varname, int value)
|
2014-08-30 12:37:12 -05:00
|
|
|
{
|
|
|
|
scratchpad[varname] = stringf("%d", value);
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
void RTLIL::Design::scratchpad_set_bool(const std::string &varname, bool value)
|
2014-08-30 12:37:12 -05:00
|
|
|
{
|
|
|
|
scratchpad[varname] = value ? "true" : "false";
|
|
|
|
}
|
|
|
|
|
2020-03-27 14:21:09 -05:00
|
|
|
void RTLIL::Design::scratchpad_set_string(const std::string &varname, std::string value)
|
2014-08-30 12:37:12 -05:00
|
|
|
{
|
2020-03-27 14:21:09 -05:00
|
|
|
scratchpad[varname] = std::move(value);
|
2014-08-30 12:37:12 -05:00
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
int RTLIL::Design::scratchpad_get_int(const std::string &varname, int default_value) const
|
2014-08-30 12:37:12 -05:00
|
|
|
{
|
2020-03-18 13:21:53 -05:00
|
|
|
auto it = scratchpad.find(varname);
|
|
|
|
if (it == scratchpad.end())
|
2014-08-30 12:37:12 -05:00
|
|
|
return default_value;
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
const std::string &str = it->second;
|
2014-08-30 12:37:12 -05:00
|
|
|
|
|
|
|
if (str == "0" || str == "false")
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (str == "1" || str == "true")
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
char *endptr = nullptr;
|
|
|
|
long int parsed_value = strtol(str.c_str(), &endptr, 10);
|
|
|
|
return *endptr ? default_value : parsed_value;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
bool RTLIL::Design::scratchpad_get_bool(const std::string &varname, bool default_value) const
|
2014-08-30 12:37:12 -05:00
|
|
|
{
|
2020-03-18 13:21:53 -05:00
|
|
|
auto it = scratchpad.find(varname);
|
|
|
|
if (it == scratchpad.end())
|
2014-08-30 12:37:12 -05:00
|
|
|
return default_value;
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
const std::string &str = it->second;
|
2014-08-30 12:37:12 -05:00
|
|
|
|
|
|
|
if (str == "0" || str == "false")
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (str == "1" || str == "true")
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return default_value;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
std::string RTLIL::Design::scratchpad_get_string(const std::string &varname, const std::string &default_value) const
|
2014-08-30 12:37:12 -05:00
|
|
|
{
|
2020-03-18 13:21:53 -05:00
|
|
|
auto it = scratchpad.find(varname);
|
|
|
|
if (it == scratchpad.end())
|
2014-08-30 12:37:12 -05:00
|
|
|
return default_value;
|
2020-03-18 13:21:53 -05:00
|
|
|
|
|
|
|
return it->second;
|
2014-08-30 12:37:12 -05:00
|
|
|
}
|
|
|
|
|
2014-07-27 14:12:09 -05:00
|
|
|
void RTLIL::Design::remove(RTLIL::Module *module)
|
|
|
|
{
|
2014-07-31 07:34:12 -05:00
|
|
|
for (auto mon : monitors)
|
|
|
|
mon->notify_module_del(module);
|
|
|
|
|
2014-12-29 06:33:33 -06:00
|
|
|
if (yosys_xtrace) {
|
|
|
|
log("#X# Remove Module: %s\n", log_id(module));
|
|
|
|
log_backtrace("-X- ", yosys_xtrace-1);
|
|
|
|
}
|
|
|
|
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(modules_.at(module->name) == module);
|
2020-04-14 11:31:06 -05:00
|
|
|
log_assert(refcount_modules_ == 0);
|
2014-07-27 14:12:09 -05:00
|
|
|
modules_.erase(module->name);
|
|
|
|
delete module;
|
|
|
|
}
|
|
|
|
|
2015-06-29 18:37:59 -05:00
|
|
|
void RTLIL::Design::rename(RTLIL::Module *module, RTLIL::IdString new_name)
|
|
|
|
{
|
|
|
|
modules_.erase(module->name);
|
|
|
|
module->name = new_name;
|
|
|
|
add(module);
|
|
|
|
}
|
|
|
|
|
2015-01-23 17:13:27 -06:00
|
|
|
void RTLIL::Design::sort()
|
|
|
|
{
|
|
|
|
scratchpad.sort();
|
|
|
|
modules_.sort(sort_by_id_str());
|
|
|
|
for (auto &it : modules_)
|
|
|
|
it.second->sort();
|
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
void RTLIL::Design::check()
|
|
|
|
{
|
|
|
|
#ifndef NDEBUG
|
2014-07-27 03:18:00 -05:00
|
|
|
for (auto &it : modules_) {
|
2014-07-31 07:11:39 -05:00
|
|
|
log_assert(this == it.second->design);
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(it.first == it.second->name);
|
2014-08-02 11:58:40 -05:00
|
|
|
log_assert(!it.first.empty());
|
2013-01-05 04:13:26 -06:00
|
|
|
it.second->check();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void RTLIL::Design::optimize()
|
|
|
|
{
|
2014-07-27 03:18:00 -05:00
|
|
|
for (auto &it : modules_)
|
2013-01-05 04:13:26 -06:00
|
|
|
it.second->optimize();
|
|
|
|
for (auto &it : selection_stack)
|
|
|
|
it.optimize(this);
|
|
|
|
for (auto &it : selection_vars)
|
|
|
|
it.second.optimize(this);
|
|
|
|
}
|
|
|
|
|
2013-06-02 10:53:30 -05:00
|
|
|
bool RTLIL::Design::selected_module(RTLIL::IdString mod_name) const
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
|
|
|
if (!selected_active_module.empty() && mod_name != selected_active_module)
|
|
|
|
return false;
|
|
|
|
if (selection_stack.size() == 0)
|
|
|
|
return true;
|
|
|
|
return selection_stack.back().selected_module(mod_name);
|
|
|
|
}
|
|
|
|
|
2013-06-02 10:53:30 -05:00
|
|
|
bool RTLIL::Design::selected_whole_module(RTLIL::IdString mod_name) const
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
|
|
|
if (!selected_active_module.empty() && mod_name != selected_active_module)
|
|
|
|
return false;
|
|
|
|
if (selection_stack.size() == 0)
|
|
|
|
return true;
|
|
|
|
return selection_stack.back().selected_whole_module(mod_name);
|
|
|
|
}
|
|
|
|
|
2013-06-02 10:53:30 -05:00
|
|
|
bool RTLIL::Design::selected_member(RTLIL::IdString mod_name, RTLIL::IdString memb_name) const
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
|
|
|
if (!selected_active_module.empty() && mod_name != selected_active_module)
|
|
|
|
return false;
|
|
|
|
if (selection_stack.size() == 0)
|
|
|
|
return true;
|
|
|
|
return selection_stack.back().selected_member(mod_name, memb_name);
|
|
|
|
}
|
|
|
|
|
2014-07-27 04:03:56 -05:00
|
|
|
bool RTLIL::Design::selected_module(RTLIL::Module *mod) const
|
|
|
|
{
|
|
|
|
return selected_module(mod->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RTLIL::Design::selected_whole_module(RTLIL::Module *mod) const
|
|
|
|
{
|
|
|
|
return selected_whole_module(mod->name);
|
|
|
|
}
|
|
|
|
|
2014-07-31 07:11:39 -05:00
|
|
|
std::vector<RTLIL::Module*> RTLIL::Design::selected_modules() const
|
|
|
|
{
|
|
|
|
std::vector<RTLIL::Module*> result;
|
|
|
|
result.reserve(modules_.size());
|
|
|
|
for (auto &it : modules_)
|
2019-04-18 10:42:12 -05:00
|
|
|
if (selected_module(it.first) && !it.second->get_blackbox_attribute())
|
2014-07-31 07:11:39 -05:00
|
|
|
result.push_back(it.second);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<RTLIL::Module*> RTLIL::Design::selected_whole_modules() const
|
|
|
|
{
|
|
|
|
std::vector<RTLIL::Module*> result;
|
|
|
|
result.reserve(modules_.size());
|
|
|
|
for (auto &it : modules_)
|
2019-04-18 10:42:12 -05:00
|
|
|
if (selected_whole_module(it.first) && !it.second->get_blackbox_attribute())
|
2014-07-31 07:11:39 -05:00
|
|
|
result.push_back(it.second);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<RTLIL::Module*> RTLIL::Design::selected_whole_modules_warn() const
|
|
|
|
{
|
|
|
|
std::vector<RTLIL::Module*> result;
|
|
|
|
result.reserve(modules_.size());
|
|
|
|
for (auto &it : modules_)
|
2019-04-18 10:42:12 -05:00
|
|
|
if (it.second->get_blackbox_attribute())
|
2015-02-03 16:11:57 -06:00
|
|
|
continue;
|
|
|
|
else if (selected_whole_module(it.first))
|
2014-07-31 07:11:39 -05:00
|
|
|
result.push_back(it.second);
|
|
|
|
else if (selected_module(it.first))
|
2014-11-09 03:44:23 -06:00
|
|
|
log_warning("Ignoring partially selected module %s.\n", log_id(it.first));
|
2014-07-31 07:11:39 -05:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-07-27 03:13:22 -05:00
|
|
|
RTLIL::Module::Module()
|
|
|
|
{
|
2014-12-28 17:12:36 -06:00
|
|
|
static unsigned int hashidx_count = 123456789;
|
|
|
|
hashidx_count = mkhash_xorshift(hashidx_count);
|
|
|
|
hashidx_ = hashidx_count;
|
2014-12-28 10:51:16 -06:00
|
|
|
|
2014-07-31 07:34:12 -05:00
|
|
|
design = nullptr;
|
2014-07-27 03:13:22 -05:00
|
|
|
refcount_wires_ = 0;
|
|
|
|
refcount_cells_ = 0;
|
2018-07-09 08:48:06 -05:00
|
|
|
|
|
|
|
#ifdef WITH_PYTHON
|
|
|
|
RTLIL::Module::get_all_modules()->insert(std::pair<unsigned int, RTLIL::Module*>(hashidx_, this));
|
|
|
|
#endif
|
2014-07-27 03:13:22 -05:00
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::Module::~Module()
|
|
|
|
{
|
2014-12-26 14:35:22 -06:00
|
|
|
for (auto it = wires_.begin(); it != wires_.end(); ++it)
|
2013-01-05 04:13:26 -06:00
|
|
|
delete it->second;
|
2014-12-26 14:35:22 -06:00
|
|
|
for (auto it = memories.begin(); it != memories.end(); ++it)
|
2013-01-05 04:13:26 -06:00
|
|
|
delete it->second;
|
2014-12-26 14:35:22 -06:00
|
|
|
for (auto it = cells_.begin(); it != cells_.end(); ++it)
|
2013-01-05 04:13:26 -06:00
|
|
|
delete it->second;
|
2014-12-26 14:35:22 -06:00
|
|
|
for (auto it = processes.begin(); it != processes.end(); ++it)
|
2013-01-05 04:13:26 -06:00
|
|
|
delete it->second;
|
2018-07-09 08:48:06 -05:00
|
|
|
#ifdef WITH_PYTHON
|
|
|
|
RTLIL::Module::get_all_modules()->erase(hashidx_);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef WITH_PYTHON
|
2019-04-03 07:27:39 -05:00
|
|
|
static std::map<unsigned int, RTLIL::Module*> all_modules;
|
2018-07-09 08:48:06 -05:00
|
|
|
std::map<unsigned int, RTLIL::Module*> *RTLIL::Module::get_all_modules(void)
|
|
|
|
{
|
2019-04-03 07:27:39 -05:00
|
|
|
return &all_modules;
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
2018-07-09 08:48:06 -05:00
|
|
|
#endif
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2019-04-05 10:31:49 -05:00
|
|
|
void RTLIL::Module::makeblackbox()
|
|
|
|
{
|
|
|
|
pool<RTLIL::Wire*> delwires;
|
|
|
|
|
|
|
|
for (auto it = wires_.begin(); it != wires_.end(); ++it)
|
|
|
|
if (!it->second->port_input && !it->second->port_output)
|
|
|
|
delwires.insert(it->second);
|
|
|
|
|
|
|
|
for (auto it = memories.begin(); it != memories.end(); ++it)
|
|
|
|
delete it->second;
|
|
|
|
memories.clear();
|
|
|
|
|
|
|
|
for (auto it = cells_.begin(); it != cells_.end(); ++it)
|
|
|
|
delete it->second;
|
|
|
|
cells_.clear();
|
|
|
|
|
|
|
|
for (auto it = processes.begin(); it != processes.end(); ++it)
|
|
|
|
delete it->second;
|
|
|
|
processes.clear();
|
|
|
|
|
2020-04-13 22:37:22 -05:00
|
|
|
connections_.clear();
|
|
|
|
|
2019-04-05 10:31:49 -05:00
|
|
|
remove(delwires);
|
2019-08-15 16:50:10 -05:00
|
|
|
set_bool_attribute(ID::blackbox);
|
2019-04-05 10:31:49 -05:00
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
void RTLIL::Module::reprocess_module(RTLIL::Design *, const dict<RTLIL::IdString, RTLIL::Module *> &)
|
2018-10-11 16:33:31 -05:00
|
|
|
{
|
|
|
|
log_error("Cannot reprocess_module module `%s' !\n", id2cstr(name));
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::IdString RTLIL::Module::derive(RTLIL::Design*, const dict<RTLIL::IdString, RTLIL::Const> &, bool mayfail)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2018-01-05 06:28:45 -06:00
|
|
|
if (mayfail)
|
|
|
|
return RTLIL::IdString();
|
2013-03-26 13:27:49 -05:00
|
|
|
log_error("Module `%s' is used with parameters but is not parametric!\n", id2cstr(name));
|
2018-10-11 16:33:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::IdString RTLIL::Module::derive(RTLIL::Design*, const dict<RTLIL::IdString, RTLIL::Const> &, const dict<RTLIL::IdString, RTLIL::Module*> &, const dict<RTLIL::IdString, RTLIL::IdString> &, bool mayfail)
|
2018-10-11 16:33:31 -05:00
|
|
|
{
|
|
|
|
if (mayfail)
|
|
|
|
return RTLIL::IdString();
|
|
|
|
log_error("Module `%s' is used with parameters but is not parametric!\n", id2cstr(name));
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t RTLIL::Module::count_id(RTLIL::IdString id)
|
|
|
|
{
|
2014-07-26 18:51:45 -05:00
|
|
|
return wires_.count(id) + memories.count(id) + cells_.count(id) + processes.count(id);
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2013-11-10 16:25:04 -06:00
|
|
|
#ifndef NDEBUG
|
|
|
|
namespace {
|
|
|
|
struct InternalCellChecker
|
|
|
|
{
|
|
|
|
RTLIL::Module *module;
|
|
|
|
RTLIL::Cell *cell;
|
2014-12-26 14:59:41 -06:00
|
|
|
pool<RTLIL::IdString> expected_params, expected_ports;
|
2013-11-10 16:25:04 -06:00
|
|
|
|
|
|
|
InternalCellChecker(RTLIL::Module *module, RTLIL::Cell *cell) : module(module), cell(cell) { }
|
|
|
|
|
|
|
|
void error(int linenr)
|
|
|
|
{
|
2014-08-23 06:54:21 -05:00
|
|
|
std::stringstream buf;
|
|
|
|
ILANG_BACKEND::dump_cell(buf, " ", cell);
|
2013-11-10 16:25:04 -06:00
|
|
|
|
2014-07-21 05:02:55 -05:00
|
|
|
log_error("Found error in internal cell %s%s%s (%s) at %s:%d:\n%s",
|
|
|
|
module ? module->name.c_str() : "", module ? "." : "",
|
2014-08-23 06:54:21 -05:00
|
|
|
cell->name.c_str(), cell->type.c_str(), __FILE__, linenr, buf.str().c_str());
|
2013-11-10 16:25:04 -06:00
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
int param(RTLIL::IdString name)
|
2013-11-10 16:25:04 -06:00
|
|
|
{
|
2020-03-18 13:21:53 -05:00
|
|
|
auto it = cell->parameters.find(name);
|
|
|
|
if (it == cell->parameters.end())
|
2013-11-10 16:25:04 -06:00
|
|
|
error(__LINE__);
|
|
|
|
expected_params.insert(name);
|
2020-03-18 13:21:53 -05:00
|
|
|
return it->second.as_int();
|
2013-11-10 16:25:04 -06:00
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
int param_bool(RTLIL::IdString name)
|
2014-02-07 10:39:35 -06:00
|
|
|
{
|
|
|
|
int v = param(name);
|
2020-03-18 13:21:53 -05:00
|
|
|
if (GetSize(cell->parameters.at(name)) > 32)
|
2014-02-08 12:13:49 -06:00
|
|
|
error(__LINE__);
|
2014-02-07 10:39:35 -06:00
|
|
|
if (v != 0 && v != 1)
|
|
|
|
error(__LINE__);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2019-12-04 05:59:36 -06:00
|
|
|
int param_bool(RTLIL::IdString name, bool expected)
|
|
|
|
{
|
|
|
|
int v = param_bool(name);
|
|
|
|
if (v != expected)
|
|
|
|
error(__LINE__);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
void param_bits(RTLIL::IdString name, int width)
|
2014-02-08 12:13:49 -06:00
|
|
|
{
|
|
|
|
param(name);
|
2020-03-18 13:21:53 -05:00
|
|
|
if (GetSize(cell->parameters.at(name).bits) != width)
|
2014-02-08 12:13:49 -06:00
|
|
|
error(__LINE__);
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
void port(RTLIL::IdString name, int width)
|
2013-11-10 16:25:04 -06:00
|
|
|
{
|
2020-03-18 13:21:53 -05:00
|
|
|
auto it = cell->connections_.find(name);
|
|
|
|
if (it == cell->connections_.end())
|
2013-11-10 16:25:04 -06:00
|
|
|
error(__LINE__);
|
2020-03-18 13:21:53 -05:00
|
|
|
if (GetSize(it->second) != width)
|
2013-11-10 16:25:04 -06:00
|
|
|
error(__LINE__);
|
|
|
|
expected_ports.insert(name);
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
void check_expected(bool check_matched_sign = false)
|
2013-11-10 16:25:04 -06:00
|
|
|
{
|
|
|
|
for (auto ¶ : cell->parameters)
|
|
|
|
if (expected_params.count(para.first) == 0)
|
|
|
|
error(__LINE__);
|
2014-07-26 07:32:50 -05:00
|
|
|
for (auto &conn : cell->connections())
|
2013-11-10 16:25:04 -06:00
|
|
|
if (expected_ports.count(conn.first) == 0)
|
|
|
|
error(__LINE__);
|
2013-12-31 07:54:06 -06:00
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
if (check_matched_sign) {
|
2020-04-02 11:51:32 -05:00
|
|
|
log_assert(expected_params.count(ID::A_SIGNED) != 0 && expected_params.count(ID::B_SIGNED) != 0);
|
|
|
|
bool a_is_signed = cell->parameters.at(ID::A_SIGNED).as_bool();
|
|
|
|
bool b_is_signed = cell->parameters.at(ID::B_SIGNED).as_bool();
|
2013-12-31 07:54:06 -06:00
|
|
|
if (a_is_signed != b_is_signed)
|
|
|
|
error(__LINE__);
|
|
|
|
}
|
2013-11-10 16:25:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void check()
|
|
|
|
{
|
2019-08-06 21:07:45 -05:00
|
|
|
if (!cell->type.begins_with("$") || cell->type.begins_with("$__") || cell->type.begins_with("$paramod") || cell->type.begins_with("$fmcombine") ||
|
2019-08-06 18:42:25 -05:00
|
|
|
cell->type.begins_with("$verific$") || cell->type.begins_with("$array:") || cell->type.begins_with("$extern:"))
|
2014-07-21 05:02:55 -05:00
|
|
|
return;
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type.in(ID($not), ID($pos), ID($neg))) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param_bool(ID::A_SIGNED);
|
|
|
|
port(ID::A, param(ID::A_WIDTH));
|
|
|
|
port(ID::Y, param(ID::Y_WIDTH));
|
2013-11-10 16:25:04 -06:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type.in(ID($and), ID($or), ID($xor), ID($xnor))) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param_bool(ID::A_SIGNED);
|
|
|
|
param_bool(ID::B_SIGNED);
|
|
|
|
port(ID::A, param(ID::A_WIDTH));
|
|
|
|
port(ID::B, param(ID::B_WIDTH));
|
|
|
|
port(ID::Y, param(ID::Y_WIDTH));
|
2020-03-18 13:21:53 -05:00
|
|
|
check_expected(true);
|
2013-11-10 16:25:04 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type.in(ID($reduce_and), ID($reduce_or), ID($reduce_xor), ID($reduce_xnor), ID($reduce_bool))) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param_bool(ID::A_SIGNED);
|
|
|
|
port(ID::A, param(ID::A_WIDTH));
|
|
|
|
port(ID::Y, param(ID::Y_WIDTH));
|
2013-11-10 16:25:04 -06:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-04 05:59:36 -06:00
|
|
|
if (cell->type.in(ID($shl), ID($shr), ID($sshl), ID($sshr))) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param_bool(ID::A_SIGNED);
|
|
|
|
param_bool(ID::B_SIGNED, /*expected=*/false);
|
|
|
|
port(ID::A, param(ID::A_WIDTH));
|
|
|
|
port(ID::B, param(ID::B_WIDTH));
|
|
|
|
port(ID::Y, param(ID::Y_WIDTH));
|
2019-12-04 05:59:36 -06:00
|
|
|
check_expected(/*check_matched_sign=*/false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cell->type.in(ID($shift), ID($shiftx))) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param_bool(ID::A_SIGNED);
|
|
|
|
param_bool(ID::B_SIGNED);
|
|
|
|
port(ID::A, param(ID::A_WIDTH));
|
|
|
|
port(ID::B, param(ID::B_WIDTH));
|
|
|
|
port(ID::Y, param(ID::Y_WIDTH));
|
2019-12-04 05:59:36 -06:00
|
|
|
check_expected(/*check_matched_sign=*/false);
|
2013-11-10 16:25:04 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type.in(ID($lt), ID($le), ID($eq), ID($ne), ID($eqx), ID($nex), ID($ge), ID($gt))) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param_bool(ID::A_SIGNED);
|
|
|
|
param_bool(ID::B_SIGNED);
|
|
|
|
port(ID::A, param(ID::A_WIDTH));
|
|
|
|
port(ID::B, param(ID::B_WIDTH));
|
|
|
|
port(ID::Y, param(ID::Y_WIDTH));
|
2020-03-18 13:21:53 -05:00
|
|
|
check_expected(true);
|
2013-11-10 16:25:04 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-21 05:51:58 -05:00
|
|
|
if (cell->type.in(ID($add), ID($sub), ID($mul), ID($div), ID($mod), ID($divfloor), ID($modfloor), ID($pow))) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param_bool(ID::A_SIGNED);
|
|
|
|
param_bool(ID::B_SIGNED);
|
|
|
|
port(ID::A, param(ID::A_WIDTH));
|
|
|
|
port(ID::B, param(ID::B_WIDTH));
|
|
|
|
port(ID::Y, param(ID::Y_WIDTH));
|
2019-08-10 05:24:16 -05:00
|
|
|
check_expected(cell->type != ID($pow));
|
2013-11-10 16:25:04 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($fa)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
port(ID::A, param(ID::WIDTH));
|
|
|
|
port(ID::B, param(ID::WIDTH));
|
|
|
|
port(ID::C, param(ID::WIDTH));
|
|
|
|
port(ID::X, param(ID::WIDTH));
|
|
|
|
port(ID::Y, param(ID::WIDTH));
|
2014-09-08 05:15:39 -05:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($lcu)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
port(ID::P, param(ID::WIDTH));
|
|
|
|
port(ID::G, param(ID::WIDTH));
|
|
|
|
port(ID::CI, 1);
|
|
|
|
port(ID::CO, param(ID::WIDTH));
|
2014-09-08 06:28:23 -05:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($alu)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param_bool(ID::A_SIGNED);
|
|
|
|
param_bool(ID::B_SIGNED);
|
|
|
|
port(ID::A, param(ID::A_WIDTH));
|
|
|
|
port(ID::B, param(ID::B_WIDTH));
|
|
|
|
port(ID::CI, 1);
|
|
|
|
port(ID::BI, 1);
|
|
|
|
port(ID::X, param(ID::Y_WIDTH));
|
|
|
|
port(ID::Y, param(ID::Y_WIDTH));
|
|
|
|
port(ID::CO, param(ID::Y_WIDTH));
|
2020-03-18 13:21:53 -05:00
|
|
|
check_expected(true);
|
2014-08-30 11:59:05 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($macc)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param(ID::CONFIG);
|
|
|
|
param(ID::CONFIG_WIDTH);
|
|
|
|
port(ID::A, param(ID::A_WIDTH));
|
|
|
|
port(ID::B, param(ID::B_WIDTH));
|
|
|
|
port(ID::Y, param(ID::Y_WIDTH));
|
2014-09-06 08:47:46 -05:00
|
|
|
check_expected();
|
|
|
|
Macc().from_cell(cell);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($logic_not)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param_bool(ID::A_SIGNED);
|
|
|
|
port(ID::A, param(ID::A_WIDTH));
|
|
|
|
port(ID::Y, param(ID::Y_WIDTH));
|
2013-11-10 16:25:04 -06:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type.in(ID($logic_and), ID($logic_or))) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param_bool(ID::A_SIGNED);
|
|
|
|
param_bool(ID::B_SIGNED);
|
|
|
|
port(ID::A, param(ID::A_WIDTH));
|
|
|
|
port(ID::B, param(ID::B_WIDTH));
|
|
|
|
port(ID::Y, param(ID::Y_WIDTH));
|
2019-12-04 05:59:36 -06:00
|
|
|
check_expected(/*check_matched_sign=*/false);
|
2013-11-10 16:25:04 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($slice)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param(ID::OFFSET);
|
|
|
|
port(ID::A, param(ID::A_WIDTH));
|
|
|
|
port(ID::Y, param(ID::Y_WIDTH));
|
|
|
|
if (param(ID::OFFSET) + param(ID::Y_WIDTH) > param(ID::A_WIDTH))
|
2014-02-07 10:44:57 -06:00
|
|
|
error(__LINE__);
|
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($concat)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
port(ID::A, param(ID::A_WIDTH));
|
|
|
|
port(ID::B, param(ID::B_WIDTH));
|
|
|
|
port(ID::Y, param(ID::A_WIDTH) + param(ID::B_WIDTH));
|
2014-02-07 10:44:57 -06:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($mux)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
port(ID::A, param(ID::WIDTH));
|
|
|
|
port(ID::B, param(ID::WIDTH));
|
|
|
|
port(ID::S, 1);
|
|
|
|
port(ID::Y, param(ID::WIDTH));
|
2013-11-10 16:25:04 -06:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($pmux)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
port(ID::A, param(ID::WIDTH));
|
|
|
|
port(ID::B, param(ID::WIDTH) * param(ID::S_WIDTH));
|
|
|
|
port(ID::S, param(ID::S_WIDTH));
|
|
|
|
port(ID::Y, param(ID::WIDTH));
|
2013-11-10 16:25:04 -06:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($lut)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param(ID::LUT);
|
|
|
|
port(ID::A, param(ID::WIDTH));
|
2019-08-15 16:50:10 -05:00
|
|
|
port(ID::Y, 1);
|
2013-11-10 16:25:04 -06:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($sop)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param(ID::DEPTH);
|
|
|
|
param(ID::TABLE);
|
|
|
|
port(ID::A, param(ID::WIDTH));
|
2019-08-15 16:50:10 -05:00
|
|
|
port(ID::Y, 1);
|
2016-06-17 06:46:01 -05:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($sr)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param_bool(ID::SET_POLARITY);
|
|
|
|
param_bool(ID::CLR_POLARITY);
|
|
|
|
port(ID::SET, param(ID::WIDTH));
|
|
|
|
port(ID::CLR, param(ID::WIDTH));
|
|
|
|
port(ID::Q, param(ID::WIDTH));
|
2013-11-10 16:25:04 -06:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($ff)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
port(ID::D, param(ID::WIDTH));
|
|
|
|
port(ID::Q, param(ID::WIDTH));
|
2016-10-11 18:18:39 -05:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($dff)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param_bool(ID::CLK_POLARITY);
|
|
|
|
port(ID::CLK, 1);
|
|
|
|
port(ID::D, param(ID::WIDTH));
|
|
|
|
port(ID::Q, param(ID::WIDTH));
|
2013-11-10 16:25:04 -06:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($dffe)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param_bool(ID::CLK_POLARITY);
|
|
|
|
param_bool(ID::EN_POLARITY);
|
|
|
|
port(ID::CLK, 1);
|
|
|
|
port(ID::EN, 1);
|
|
|
|
port(ID::D, param(ID::WIDTH));
|
|
|
|
port(ID::Q, param(ID::WIDTH));
|
2014-12-08 03:50:19 -06:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($dffsr)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param_bool(ID::CLK_POLARITY);
|
|
|
|
param_bool(ID::SET_POLARITY);
|
|
|
|
param_bool(ID::CLR_POLARITY);
|
|
|
|
port(ID::CLK, 1);
|
|
|
|
port(ID::SET, param(ID::WIDTH));
|
|
|
|
port(ID::CLR, param(ID::WIDTH));
|
|
|
|
port(ID::D, param(ID::WIDTH));
|
|
|
|
port(ID::Q, param(ID::WIDTH));
|
2013-11-10 16:25:04 -06:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Add new builtin FF types
The new types include:
- FFs with async reset and enable (`$adffe`, `$_DFFE_[NP][NP][01][NP]_`)
- FFs with sync reset (`$sdff`, `$_SDFF_[NP][NP][01]_`)
- FFs with sync reset and enable, reset priority (`$sdffs`, `$_SDFFE_[NP][NP][01][NP]_`)
- FFs with sync reset and enable, enable priority (`$sdffce`, `$_SDFFCE_[NP][NP][01][NP]_`)
- FFs with async reset, set, and enable (`$dffsre`, `$_DFFSRE_[NP][NP][NP][NP]_`)
- latches with reset or set (`$adlatch`, `$_DLATCH_[NP][NP][01]_`)
The new FF types are not actually used anywhere yet (this is left
for future commits).
2020-04-08 14:42:50 -05:00
|
|
|
if (cell->type == ID($dffsre)) {
|
|
|
|
param_bool(ID::CLK_POLARITY);
|
|
|
|
param_bool(ID::SET_POLARITY);
|
|
|
|
param_bool(ID::CLR_POLARITY);
|
|
|
|
param_bool(ID::EN_POLARITY);
|
|
|
|
port(ID::CLK, 1);
|
|
|
|
port(ID::EN, 1);
|
|
|
|
port(ID::SET, param(ID::WIDTH));
|
|
|
|
port(ID::CLR, param(ID::WIDTH));
|
|
|
|
port(ID::D, param(ID::WIDTH));
|
|
|
|
port(ID::Q, param(ID::WIDTH));
|
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($adff)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param_bool(ID::CLK_POLARITY);
|
|
|
|
param_bool(ID::ARST_POLARITY);
|
|
|
|
param_bits(ID::ARST_VALUE, param(ID::WIDTH));
|
|
|
|
port(ID::CLK, 1);
|
|
|
|
port(ID::ARST, 1);
|
|
|
|
port(ID::D, param(ID::WIDTH));
|
|
|
|
port(ID::Q, param(ID::WIDTH));
|
2013-11-10 16:25:04 -06:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Add new builtin FF types
The new types include:
- FFs with async reset and enable (`$adffe`, `$_DFFE_[NP][NP][01][NP]_`)
- FFs with sync reset (`$sdff`, `$_SDFF_[NP][NP][01]_`)
- FFs with sync reset and enable, reset priority (`$sdffs`, `$_SDFFE_[NP][NP][01][NP]_`)
- FFs with sync reset and enable, enable priority (`$sdffce`, `$_SDFFCE_[NP][NP][01][NP]_`)
- FFs with async reset, set, and enable (`$dffsre`, `$_DFFSRE_[NP][NP][NP][NP]_`)
- latches with reset or set (`$adlatch`, `$_DLATCH_[NP][NP][01]_`)
The new FF types are not actually used anywhere yet (this is left
for future commits).
2020-04-08 14:42:50 -05:00
|
|
|
if (cell->type == ID($sdff)) {
|
|
|
|
param_bool(ID::CLK_POLARITY);
|
|
|
|
param_bool(ID::SRST_POLARITY);
|
|
|
|
param_bits(ID::SRST_VALUE, param(ID::WIDTH));
|
|
|
|
port(ID::CLK, 1);
|
|
|
|
port(ID::SRST, 1);
|
|
|
|
port(ID::D, param(ID::WIDTH));
|
|
|
|
port(ID::Q, param(ID::WIDTH));
|
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cell->type.in(ID($sdffe), ID($sdffce))) {
|
|
|
|
param_bool(ID::CLK_POLARITY);
|
|
|
|
param_bool(ID::EN_POLARITY);
|
|
|
|
param_bool(ID::SRST_POLARITY);
|
|
|
|
param_bits(ID::SRST_VALUE, param(ID::WIDTH));
|
|
|
|
port(ID::CLK, 1);
|
|
|
|
port(ID::EN, 1);
|
|
|
|
port(ID::SRST, 1);
|
|
|
|
port(ID::D, param(ID::WIDTH));
|
|
|
|
port(ID::Q, param(ID::WIDTH));
|
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cell->type == ID($adffe)) {
|
|
|
|
param_bool(ID::CLK_POLARITY);
|
|
|
|
param_bool(ID::EN_POLARITY);
|
|
|
|
param_bool(ID::ARST_POLARITY);
|
|
|
|
param_bits(ID::ARST_VALUE, param(ID::WIDTH));
|
|
|
|
port(ID::CLK, 1);
|
|
|
|
port(ID::EN, 1);
|
|
|
|
port(ID::ARST, 1);
|
|
|
|
port(ID::D, param(ID::WIDTH));
|
|
|
|
port(ID::Q, param(ID::WIDTH));
|
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($dlatch)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param_bool(ID::EN_POLARITY);
|
|
|
|
port(ID::EN, 1);
|
|
|
|
port(ID::D, param(ID::WIDTH));
|
|
|
|
port(ID::Q, param(ID::WIDTH));
|
2013-11-10 16:25:04 -06:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Add new builtin FF types
The new types include:
- FFs with async reset and enable (`$adffe`, `$_DFFE_[NP][NP][01][NP]_`)
- FFs with sync reset (`$sdff`, `$_SDFF_[NP][NP][01]_`)
- FFs with sync reset and enable, reset priority (`$sdffs`, `$_SDFFE_[NP][NP][01][NP]_`)
- FFs with sync reset and enable, enable priority (`$sdffce`, `$_SDFFCE_[NP][NP][01][NP]_`)
- FFs with async reset, set, and enable (`$dffsre`, `$_DFFSRE_[NP][NP][NP][NP]_`)
- latches with reset or set (`$adlatch`, `$_DLATCH_[NP][NP][01]_`)
The new FF types are not actually used anywhere yet (this is left
for future commits).
2020-04-08 14:42:50 -05:00
|
|
|
if (cell->type == ID($adlatch)) {
|
|
|
|
param_bool(ID::EN_POLARITY);
|
|
|
|
param_bool(ID::ARST_POLARITY);
|
|
|
|
param_bits(ID::ARST_VALUE, param(ID::WIDTH));
|
|
|
|
port(ID::EN, 1);
|
|
|
|
port(ID::ARST, 1);
|
|
|
|
port(ID::D, param(ID::WIDTH));
|
|
|
|
port(ID::Q, param(ID::WIDTH));
|
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($dlatchsr)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param_bool(ID::EN_POLARITY);
|
|
|
|
param_bool(ID::SET_POLARITY);
|
|
|
|
param_bool(ID::CLR_POLARITY);
|
|
|
|
port(ID::EN, 1);
|
|
|
|
port(ID::SET, param(ID::WIDTH));
|
|
|
|
port(ID::CLR, param(ID::WIDTH));
|
|
|
|
port(ID::D, param(ID::WIDTH));
|
|
|
|
port(ID::Q, param(ID::WIDTH));
|
2014-03-31 07:14:40 -05:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($fsm)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param(ID::NAME);
|
|
|
|
param_bool(ID::CLK_POLARITY);
|
|
|
|
param_bool(ID::ARST_POLARITY);
|
|
|
|
param(ID::STATE_BITS);
|
|
|
|
param(ID::STATE_NUM);
|
|
|
|
param(ID::STATE_NUM_LOG2);
|
|
|
|
param(ID::STATE_RST);
|
|
|
|
param_bits(ID::STATE_TABLE, param(ID::STATE_BITS) * param(ID::STATE_NUM));
|
|
|
|
param(ID::TRANS_NUM);
|
|
|
|
param_bits(ID::TRANS_TABLE, param(ID::TRANS_NUM) * (2*param(ID::STATE_NUM_LOG2) + param(ID::CTRL_IN_WIDTH) + param(ID::CTRL_OUT_WIDTH)));
|
|
|
|
port(ID::CLK, 1);
|
|
|
|
port(ID::ARST, 1);
|
|
|
|
port(ID::CTRL_IN, param(ID::CTRL_IN_WIDTH));
|
|
|
|
port(ID::CTRL_OUT, param(ID::CTRL_OUT_WIDTH));
|
2013-11-10 16:25:04 -06:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($memrd)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param(ID::MEMID);
|
|
|
|
param_bool(ID::CLK_ENABLE);
|
|
|
|
param_bool(ID::CLK_POLARITY);
|
|
|
|
param_bool(ID::TRANSPARENT);
|
|
|
|
port(ID::CLK, 1);
|
|
|
|
port(ID::EN, 1);
|
|
|
|
port(ID::ADDR, param(ID::ABITS));
|
|
|
|
port(ID::DATA, param(ID::WIDTH));
|
2013-11-10 16:25:04 -06:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($memwr)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param(ID::MEMID);
|
|
|
|
param_bool(ID::CLK_ENABLE);
|
|
|
|
param_bool(ID::CLK_POLARITY);
|
|
|
|
param(ID::PRIORITY);
|
|
|
|
port(ID::CLK, 1);
|
|
|
|
port(ID::EN, param(ID::WIDTH));
|
|
|
|
port(ID::ADDR, param(ID::ABITS));
|
|
|
|
port(ID::DATA, param(ID::WIDTH));
|
2013-11-10 16:25:04 -06:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($meminit)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param(ID::MEMID);
|
|
|
|
param(ID::PRIORITY);
|
|
|
|
port(ID::ADDR, param(ID::ABITS));
|
|
|
|
port(ID::DATA, param(ID::WIDTH) * param(ID::WORDS));
|
2015-02-14 03:23:03 -06:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($mem)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param(ID::MEMID);
|
|
|
|
param(ID::SIZE);
|
|
|
|
param(ID::OFFSET);
|
|
|
|
param(ID::INIT);
|
|
|
|
param_bits(ID::RD_CLK_ENABLE, max(1, param(ID::RD_PORTS)));
|
|
|
|
param_bits(ID::RD_CLK_POLARITY, max(1, param(ID::RD_PORTS)));
|
|
|
|
param_bits(ID::RD_TRANSPARENT, max(1, param(ID::RD_PORTS)));
|
|
|
|
param_bits(ID::WR_CLK_ENABLE, max(1, param(ID::WR_PORTS)));
|
|
|
|
param_bits(ID::WR_CLK_POLARITY, max(1, param(ID::WR_PORTS)));
|
|
|
|
port(ID::RD_CLK, param(ID::RD_PORTS));
|
|
|
|
port(ID::RD_EN, param(ID::RD_PORTS));
|
|
|
|
port(ID::RD_ADDR, param(ID::RD_PORTS) * param(ID::ABITS));
|
|
|
|
port(ID::RD_DATA, param(ID::RD_PORTS) * param(ID::WIDTH));
|
|
|
|
port(ID::WR_CLK, param(ID::WR_PORTS));
|
|
|
|
port(ID::WR_EN, param(ID::WR_PORTS) * param(ID::WIDTH));
|
|
|
|
port(ID::WR_ADDR, param(ID::WR_PORTS) * param(ID::ABITS));
|
|
|
|
port(ID::WR_DATA, param(ID::WR_PORTS) * param(ID::WIDTH));
|
2013-11-10 16:25:04 -06:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($tribuf)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
port(ID::A, param(ID::WIDTH));
|
|
|
|
port(ID::Y, param(ID::WIDTH));
|
|
|
|
port(ID::EN, 1);
|
2015-08-16 05:54:52 -05:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type.in(ID($assert), ID($assume), ID($live), ID($fair), ID($cover))) {
|
2019-08-15 16:50:10 -05:00
|
|
|
port(ID::A, 1);
|
2020-04-02 11:51:32 -05:00
|
|
|
port(ID::EN, 1);
|
2015-02-26 11:04:10 -06:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($initstate)) {
|
2019-08-15 16:50:10 -05:00
|
|
|
port(ID::Y, 1);
|
2016-07-21 07:23:22 -05:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type.in(ID($anyconst), ID($anyseq), ID($allconst), ID($allseq))) {
|
2020-04-02 11:51:32 -05:00
|
|
|
port(ID::Y, param(ID::WIDTH));
|
2016-07-27 08:41:22 -05:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($equiv)) {
|
2019-08-15 16:50:10 -05:00
|
|
|
port(ID::A, 1);
|
|
|
|
port(ID::B, 1);
|
|
|
|
port(ID::Y, 1);
|
2015-01-19 04:55:05 -06:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type.in(ID($specify2), ID($specify3))) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param_bool(ID::FULL);
|
|
|
|
param_bool(ID::SRC_DST_PEN);
|
|
|
|
param_bool(ID::SRC_DST_POL);
|
|
|
|
param(ID::T_RISE_MIN);
|
|
|
|
param(ID::T_RISE_TYP);
|
|
|
|
param(ID::T_RISE_MAX);
|
|
|
|
param(ID::T_FALL_MIN);
|
|
|
|
param(ID::T_FALL_TYP);
|
|
|
|
param(ID::T_FALL_MAX);
|
|
|
|
port(ID::EN, 1);
|
|
|
|
port(ID::SRC, param(ID::SRC_WIDTH));
|
|
|
|
port(ID::DST, param(ID::DST_WIDTH));
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($specify3)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param_bool(ID::EDGE_EN);
|
|
|
|
param_bool(ID::EDGE_POL);
|
|
|
|
param_bool(ID::DAT_DST_PEN);
|
|
|
|
param_bool(ID::DAT_DST_POL);
|
|
|
|
port(ID::DAT, param(ID::DST_WIDTH));
|
2019-04-22 02:26:20 -05:00
|
|
|
}
|
|
|
|
check_expected();
|
2019-04-21 14:58:57 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (cell->type == ID($specrule)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
param(ID::TYPE);
|
|
|
|
param_bool(ID::SRC_PEN);
|
|
|
|
param_bool(ID::SRC_POL);
|
|
|
|
param_bool(ID::DST_PEN);
|
|
|
|
param_bool(ID::DST_POL);
|
|
|
|
param(ID::T_LIMIT_MIN);
|
|
|
|
param(ID::T_LIMIT_TYP);
|
|
|
|
param(ID::T_LIMIT_MAX);
|
|
|
|
param(ID::T_LIMIT2_MIN);
|
|
|
|
param(ID::T_LIMIT2_TYP);
|
|
|
|
param(ID::T_LIMIT2_MAX);
|
|
|
|
port(ID::SRC_EN, 1);
|
|
|
|
port(ID::DST_EN, 1);
|
|
|
|
port(ID::SRC, param(ID::SRC_WIDTH));
|
|
|
|
port(ID::DST, param(ID::DST_WIDTH));
|
2019-04-23 08:46:40 -05:00
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
if (cell->type == ID($_BUF_)) { port(ID::A,1); port(ID::Y,1); check_expected(); return; }
|
|
|
|
if (cell->type == ID($_NOT_)) { port(ID::A,1); port(ID::Y,1); check_expected(); return; }
|
|
|
|
if (cell->type == ID($_AND_)) { port(ID::A,1); port(ID::B,1); port(ID::Y,1); check_expected(); return; }
|
|
|
|
if (cell->type == ID($_NAND_)) { port(ID::A,1); port(ID::B,1); port(ID::Y,1); check_expected(); return; }
|
|
|
|
if (cell->type == ID($_OR_)) { port(ID::A,1); port(ID::B,1); port(ID::Y,1); check_expected(); return; }
|
|
|
|
if (cell->type == ID($_NOR_)) { port(ID::A,1); port(ID::B,1); port(ID::Y,1); check_expected(); return; }
|
|
|
|
if (cell->type == ID($_XOR_)) { port(ID::A,1); port(ID::B,1); port(ID::Y,1); check_expected(); return; }
|
|
|
|
if (cell->type == ID($_XNOR_)) { port(ID::A,1); port(ID::B,1); port(ID::Y,1); check_expected(); return; }
|
|
|
|
if (cell->type == ID($_ANDNOT_)) { port(ID::A,1); port(ID::B,1); port(ID::Y,1); check_expected(); return; }
|
|
|
|
if (cell->type == ID($_ORNOT_)) { port(ID::A,1); port(ID::B,1); port(ID::Y,1); check_expected(); return; }
|
2020-04-02 11:51:32 -05:00
|
|
|
if (cell->type == ID($_MUX_)) { port(ID::A,1); port(ID::B,1); port(ID::S,1); port(ID::Y,1); check_expected(); return; }
|
|
|
|
if (cell->type == ID($_NMUX_)) { port(ID::A,1); port(ID::B,1); port(ID::S,1); port(ID::Y,1); check_expected(); return; }
|
|
|
|
if (cell->type == ID($_AOI3_)) { port(ID::A,1); port(ID::B,1); port(ID::C,1); port(ID::Y,1); check_expected(); return; }
|
|
|
|
if (cell->type == ID($_OAI3_)) { port(ID::A,1); port(ID::B,1); port(ID::C,1); port(ID::Y,1); check_expected(); return; }
|
|
|
|
if (cell->type == ID($_AOI4_)) { port(ID::A,1); port(ID::B,1); port(ID::C,1); port(ID::D,1); port(ID::Y,1); check_expected(); return; }
|
|
|
|
if (cell->type == ID($_OAI4_)) { port(ID::A,1); port(ID::B,1); port(ID::C,1); port(ID::D,1); port(ID::Y,1); check_expected(); return; }
|
|
|
|
|
|
|
|
if (cell->type == ID($_TBUF_)) { port(ID::A,1); port(ID::Y,1); port(ID::E,1); check_expected(); return; }
|
|
|
|
|
|
|
|
if (cell->type == ID($_MUX4_)) { port(ID::A,1); port(ID::B,1); port(ID::C,1); port(ID::D,1); port(ID::S,1); port(ID::T,1); port(ID::Y,1); check_expected(); return; }
|
|
|
|
if (cell->type == ID($_MUX8_)) { port(ID::A,1); port(ID::B,1); port(ID::C,1); port(ID::D,1); port(ID::E,1); port(ID::F,1); port(ID::G,1); port(ID::H,1); port(ID::S,1); port(ID::T,1); port(ID::U,1); port(ID::Y,1); check_expected(); return; }
|
|
|
|
if (cell->type == ID($_MUX16_)) { port(ID::A,1); port(ID::B,1); port(ID::C,1); port(ID::D,1); port(ID::E,1); port(ID::F,1); port(ID::G,1); port(ID::H,1); port(ID::I,1); port(ID::J,1); port(ID::K,1); port(ID::L,1); port(ID::M,1); port(ID::N,1); port(ID::O,1); port(ID::P,1); port(ID::S,1); port(ID::T,1); port(ID::U,1); port(ID::V,1); port(ID::Y,1); check_expected(); return; }
|
|
|
|
|
Add new builtin FF types
The new types include:
- FFs with async reset and enable (`$adffe`, `$_DFFE_[NP][NP][01][NP]_`)
- FFs with sync reset (`$sdff`, `$_SDFF_[NP][NP][01]_`)
- FFs with sync reset and enable, reset priority (`$sdffs`, `$_SDFFE_[NP][NP][01][NP]_`)
- FFs with sync reset and enable, enable priority (`$sdffce`, `$_SDFFCE_[NP][NP][01][NP]_`)
- FFs with async reset, set, and enable (`$dffsre`, `$_DFFSRE_[NP][NP][NP][NP]_`)
- latches with reset or set (`$adlatch`, `$_DLATCH_[NP][NP][01]_`)
The new FF types are not actually used anywhere yet (this is left
for future commits).
2020-04-08 14:42:50 -05:00
|
|
|
if (cell->type.in(ID($_SR_NN_), ID($_SR_NP_), ID($_SR_PN_), ID($_SR_PP_)))
|
|
|
|
{ port(ID::S,1); port(ID::R,1); port(ID::Q,1); check_expected(); return; }
|
|
|
|
|
|
|
|
if (cell->type == ID($_FF_)) { port(ID::D,1); port(ID::Q,1); check_expected(); return; }
|
|
|
|
|
|
|
|
if (cell->type.in(ID($_DFF_N_), ID($_DFF_P_)))
|
|
|
|
{ port(ID::D,1); port(ID::Q,1); port(ID::C,1); check_expected(); return; }
|
|
|
|
|
|
|
|
if (cell->type.in(ID($_DFFE_NN_), ID($_DFFE_NP_), ID($_DFFE_PN_), ID($_DFFE_PP_)))
|
|
|
|
{ port(ID::D,1); port(ID::Q,1); port(ID::C,1); port(ID::E,1); check_expected(); return; }
|
|
|
|
|
|
|
|
if (cell->type.in(
|
|
|
|
ID($_DFF_NN0_), ID($_DFF_NN1_), ID($_DFF_NP0_), ID($_DFF_NP1_),
|
|
|
|
ID($_DFF_PN0_), ID($_DFF_PN1_), ID($_DFF_PP0_), ID($_DFF_PP1_)))
|
|
|
|
{ port(ID::D,1); port(ID::Q,1); port(ID::C,1); port(ID::R,1); check_expected(); return; }
|
|
|
|
|
|
|
|
if (cell->type.in(
|
|
|
|
ID($_DFFE_NN0N_), ID($_DFFE_NN0P_), ID($_DFFE_NN1N_), ID($_DFFE_NN1P_),
|
|
|
|
ID($_DFFE_NP0N_), ID($_DFFE_NP0P_), ID($_DFFE_NP1N_), ID($_DFFE_NP1P_),
|
|
|
|
ID($_DFFE_PN0N_), ID($_DFFE_PN0P_), ID($_DFFE_PN1N_), ID($_DFFE_PN1P_),
|
|
|
|
ID($_DFFE_PP0N_), ID($_DFFE_PP0P_), ID($_DFFE_PP1N_), ID($_DFFE_PP1P_)))
|
|
|
|
{ port(ID::D,1); port(ID::Q,1); port(ID::C,1); port(ID::R,1); port(ID::E,1); check_expected(); return; }
|
|
|
|
|
|
|
|
if (cell->type.in(
|
|
|
|
ID($_DFFSR_NNN_), ID($_DFFSR_NNP_), ID($_DFFSR_NPN_), ID($_DFFSR_NPP_),
|
|
|
|
ID($_DFFSR_PNN_), ID($_DFFSR_PNP_), ID($_DFFSR_PPN_), ID($_DFFSR_PPP_)))
|
|
|
|
{ port(ID::C,1); port(ID::S,1); port(ID::R,1); port(ID::D,1); port(ID::Q,1); check_expected(); return; }
|
|
|
|
|
|
|
|
if (cell->type.in(
|
|
|
|
ID($_DFFSRE_NNNN_), ID($_DFFSRE_NNNP_), ID($_DFFSRE_NNPN_), ID($_DFFSRE_NNPP_),
|
|
|
|
ID($_DFFSRE_NPNN_), ID($_DFFSRE_NPNP_), ID($_DFFSRE_NPPN_), ID($_DFFSRE_NPPP_),
|
|
|
|
ID($_DFFSRE_PNNN_), ID($_DFFSRE_PNNP_), ID($_DFFSRE_PNPN_), ID($_DFFSRE_PNPP_),
|
|
|
|
ID($_DFFSRE_PPNN_), ID($_DFFSRE_PPNP_), ID($_DFFSRE_PPPN_), ID($_DFFSRE_PPPP_)))
|
|
|
|
{ port(ID::C,1); port(ID::S,1); port(ID::R,1); port(ID::D,1); port(ID::E,1); port(ID::Q,1); check_expected(); return; }
|
|
|
|
|
|
|
|
if (cell->type.in(
|
|
|
|
ID($_SDFF_NN0_), ID($_SDFF_NN1_), ID($_SDFF_NP0_), ID($_SDFF_NP1_),
|
|
|
|
ID($_SDFF_PN0_), ID($_SDFF_PN1_), ID($_SDFF_PP0_), ID($_SDFF_PP1_)))
|
|
|
|
{ port(ID::D,1); port(ID::Q,1); port(ID::C,1); port(ID::R,1); check_expected(); return; }
|
|
|
|
|
|
|
|
if (cell->type.in(
|
|
|
|
ID($_SDFFE_NN0N_), ID($_SDFFE_NN0P_), ID($_SDFFE_NN1N_), ID($_SDFFE_NN1P_),
|
|
|
|
ID($_SDFFE_NP0N_), ID($_SDFFE_NP0P_), ID($_SDFFE_NP1N_), ID($_SDFFE_NP1P_),
|
|
|
|
ID($_SDFFE_PN0N_), ID($_SDFFE_PN0P_), ID($_SDFFE_PN1N_), ID($_SDFFE_PN1P_),
|
|
|
|
ID($_SDFFE_PP0N_), ID($_SDFFE_PP0P_), ID($_SDFFE_PP1N_), ID($_SDFFE_PP1P_),
|
|
|
|
ID($_SDFFCE_NN0N_), ID($_SDFFCE_NN0P_), ID($_SDFFCE_NN1N_), ID($_SDFFCE_NN1P_),
|
|
|
|
ID($_SDFFCE_NP0N_), ID($_SDFFCE_NP0P_), ID($_SDFFCE_NP1N_), ID($_SDFFCE_NP1P_),
|
|
|
|
ID($_SDFFCE_PN0N_), ID($_SDFFCE_PN0P_), ID($_SDFFCE_PN1N_), ID($_SDFFCE_PN1P_),
|
|
|
|
ID($_SDFFCE_PP0N_), ID($_SDFFCE_PP0P_), ID($_SDFFCE_PP1N_), ID($_SDFFCE_PP1P_)))
|
|
|
|
{ port(ID::D,1); port(ID::Q,1); port(ID::C,1); port(ID::R,1); port(ID::E,1); check_expected(); return; }
|
|
|
|
|
|
|
|
if (cell->type.in(ID($_DLATCH_N_), ID($_DLATCH_P_)))
|
|
|
|
{ port(ID::E,1); port(ID::D,1); port(ID::Q,1); check_expected(); return; }
|
|
|
|
|
|
|
|
if (cell->type.in(
|
|
|
|
ID($_DLATCH_NN0_), ID($_DLATCH_NN1_), ID($_DLATCH_NP0_), ID($_DLATCH_NP1_),
|
|
|
|
ID($_DLATCH_PN0_), ID($_DLATCH_PN1_), ID($_DLATCH_PP0_), ID($_DLATCH_PP1_)))
|
|
|
|
{ port(ID::E,1); port(ID::R,1); port(ID::D,1); port(ID::Q,1); check_expected(); return; }
|
|
|
|
|
|
|
|
if (cell->type.in(
|
|
|
|
ID($_DLATCHSR_NNN_), ID($_DLATCHSR_NNP_), ID($_DLATCHSR_NPN_), ID($_DLATCHSR_NPP_),
|
|
|
|
ID($_DLATCHSR_PNN_), ID($_DLATCHSR_PNP_), ID($_DLATCHSR_PPN_), ID($_DLATCHSR_PPP_)))
|
|
|
|
{ port(ID::E,1); port(ID::S,1); port(ID::R,1); port(ID::D,1); port(ID::Q,1); check_expected(); return; }
|
2014-03-31 07:14:40 -05:00
|
|
|
|
2013-11-10 16:25:04 -06:00
|
|
|
error(__LINE__);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-01-23 17:13:27 -06:00
|
|
|
void RTLIL::Module::sort()
|
|
|
|
{
|
|
|
|
wires_.sort(sort_by_id_str());
|
|
|
|
cells_.sort(sort_by_id_str());
|
2020-04-16 08:51:03 -05:00
|
|
|
parameter_default_values.sort(sort_by_id_str());
|
2015-01-23 17:13:27 -06:00
|
|
|
memories.sort(sort_by_id_str());
|
|
|
|
processes.sort(sort_by_id_str());
|
|
|
|
for (auto &it : cells_)
|
|
|
|
it.second->sort();
|
|
|
|
for (auto &it : wires_)
|
|
|
|
it.second->attributes.sort(sort_by_id_str());
|
|
|
|
for (auto &it : memories)
|
|
|
|
it.second->attributes.sort(sort_by_id_str());
|
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
void RTLIL::Module::check()
|
|
|
|
{
|
|
|
|
#ifndef NDEBUG
|
2014-08-02 13:54:30 -05:00
|
|
|
std::vector<bool> ports_declared;
|
2014-07-26 18:49:51 -05:00
|
|
|
for (auto &it : wires_) {
|
2014-07-31 07:11:39 -05:00
|
|
|
log_assert(this == it.second->module);
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(it.first == it.second->name);
|
2014-08-02 11:58:40 -05:00
|
|
|
log_assert(!it.first.empty());
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(it.second->width >= 0);
|
|
|
|
log_assert(it.second->port_id >= 0);
|
2014-08-02 13:54:30 -05:00
|
|
|
for (auto &it2 : it.second->attributes)
|
2014-08-02 11:58:40 -05:00
|
|
|
log_assert(!it2.first.empty());
|
2014-08-02 13:54:30 -05:00
|
|
|
if (it.second->port_id) {
|
2014-10-10 09:59:44 -05:00
|
|
|
log_assert(GetSize(ports) >= it.second->port_id);
|
2014-08-14 09:13:42 -05:00
|
|
|
log_assert(ports.at(it.second->port_id-1) == it.first);
|
2014-08-02 13:54:30 -05:00
|
|
|
log_assert(it.second->port_input || it.second->port_output);
|
2014-10-10 09:59:44 -05:00
|
|
|
if (GetSize(ports_declared) < it.second->port_id)
|
2014-08-02 13:54:30 -05:00
|
|
|
ports_declared.resize(it.second->port_id);
|
|
|
|
log_assert(ports_declared[it.second->port_id-1] == false);
|
|
|
|
ports_declared[it.second->port_id-1] = true;
|
|
|
|
} else
|
|
|
|
log_assert(!it.second->port_input && !it.second->port_output);
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
2014-08-02 13:54:30 -05:00
|
|
|
for (auto port_declared : ports_declared)
|
|
|
|
log_assert(port_declared == true);
|
2014-10-10 09:59:44 -05:00
|
|
|
log_assert(GetSize(ports) == GetSize(ports_declared));
|
2013-01-05 04:13:26 -06:00
|
|
|
|
|
|
|
for (auto &it : memories) {
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(it.first == it.second->name);
|
2014-08-02 11:58:40 -05:00
|
|
|
log_assert(!it.first.empty());
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(it.second->width >= 0);
|
|
|
|
log_assert(it.second->size >= 0);
|
2014-08-02 13:54:30 -05:00
|
|
|
for (auto &it2 : it.second->attributes)
|
2014-08-02 11:58:40 -05:00
|
|
|
log_assert(!it2.first.empty());
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2014-07-26 18:51:45 -05:00
|
|
|
for (auto &it : cells_) {
|
2014-07-31 07:11:39 -05:00
|
|
|
log_assert(this == it.second->module);
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(it.first == it.second->name);
|
2014-08-02 11:58:40 -05:00
|
|
|
log_assert(!it.first.empty());
|
|
|
|
log_assert(!it.second->type.empty());
|
2014-07-26 07:32:50 -05:00
|
|
|
for (auto &it2 : it.second->connections()) {
|
2014-08-02 11:58:40 -05:00
|
|
|
log_assert(!it2.first.empty());
|
2013-01-05 04:13:26 -06:00
|
|
|
it2.second.check();
|
|
|
|
}
|
2014-08-02 13:54:30 -05:00
|
|
|
for (auto &it2 : it.second->attributes)
|
2014-08-02 11:58:40 -05:00
|
|
|
log_assert(!it2.first.empty());
|
2014-08-02 13:54:30 -05:00
|
|
|
for (auto &it2 : it.second->parameters)
|
2014-08-02 11:58:40 -05:00
|
|
|
log_assert(!it2.first.empty());
|
2014-07-21 05:02:55 -05:00
|
|
|
InternalCellChecker checker(this, it.second);
|
|
|
|
checker.check();
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &it : processes) {
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(it.first == it.second->name);
|
2014-08-02 11:58:40 -05:00
|
|
|
log_assert(!it.first.empty());
|
2019-06-19 00:22:13 -05:00
|
|
|
log_assert(it.second->root_case.compare.empty());
|
|
|
|
std::vector<CaseRule*> all_cases = {&it.second->root_case};
|
|
|
|
for (size_t i = 0; i < all_cases.size(); i++) {
|
|
|
|
for (auto &switch_it : all_cases[i]->switches) {
|
|
|
|
for (auto &case_it : switch_it->cases) {
|
|
|
|
for (auto &compare_it : case_it->compare) {
|
|
|
|
log_assert(switch_it->signal.size() == compare_it.size());
|
|
|
|
}
|
|
|
|
all_cases.push_back(case_it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (auto &sync_it : it.second->syncs) {
|
|
|
|
switch (sync_it->type) {
|
|
|
|
case SyncType::ST0:
|
|
|
|
case SyncType::ST1:
|
|
|
|
case SyncType::STp:
|
|
|
|
case SyncType::STn:
|
|
|
|
case SyncType::STe:
|
|
|
|
log_assert(!sync_it->signal.empty());
|
|
|
|
break;
|
|
|
|
case SyncType::STa:
|
|
|
|
case SyncType::STg:
|
|
|
|
case SyncType::STi:
|
|
|
|
log_assert(sync_it->signal.empty());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2014-07-26 04:58:03 -05:00
|
|
|
for (auto &it : connections_) {
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(it.first.size() == it.second.size());
|
2015-02-07 17:01:51 -06:00
|
|
|
log_assert(!it.first.has_const());
|
2013-01-05 04:13:26 -06:00
|
|
|
it.first.check();
|
|
|
|
it.second.check();
|
|
|
|
}
|
|
|
|
|
2014-08-02 13:54:30 -05:00
|
|
|
for (auto &it : attributes)
|
2014-08-02 11:58:40 -05:00
|
|
|
log_assert(!it.first.empty());
|
2013-01-05 04:13:26 -06:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void RTLIL::Module::optimize()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-07-27 07:27:51 -05:00
|
|
|
void RTLIL::Module::cloneInto(RTLIL::Module *new_mod) const
|
|
|
|
{
|
2014-07-27 03:13:22 -05:00
|
|
|
log_assert(new_mod->refcount_wires_ == 0);
|
|
|
|
log_assert(new_mod->refcount_cells_ == 0);
|
|
|
|
|
2015-06-08 07:49:34 -05:00
|
|
|
new_mod->avail_parameters = avail_parameters;
|
2020-04-16 08:51:03 -05:00
|
|
|
new_mod->parameter_default_values = parameter_default_values;
|
2015-06-08 07:49:34 -05:00
|
|
|
|
2015-01-21 17:59:58 -06:00
|
|
|
for (auto &conn : connections_)
|
|
|
|
new_mod->connect(conn);
|
|
|
|
|
|
|
|
for (auto &attr : attributes)
|
|
|
|
new_mod->attributes[attr.first] = attr.second;
|
2013-07-27 07:27:51 -05:00
|
|
|
|
2014-07-26 18:49:51 -05:00
|
|
|
for (auto &it : wires_)
|
2014-07-26 14:16:05 -05:00
|
|
|
new_mod->addWire(it.first, it.second);
|
2013-07-27 07:27:51 -05:00
|
|
|
|
|
|
|
for (auto &it : memories)
|
2020-06-09 04:55:48 -05:00
|
|
|
new_mod->addMemory(it.first, it.second);
|
2013-07-27 07:27:51 -05:00
|
|
|
|
2014-07-26 18:51:45 -05:00
|
|
|
for (auto &it : cells_)
|
2014-07-25 17:38:44 -05:00
|
|
|
new_mod->addCell(it.first, it.second);
|
2013-07-27 07:27:51 -05:00
|
|
|
|
|
|
|
for (auto &it : processes)
|
2020-06-09 04:55:48 -05:00
|
|
|
new_mod->addProcess(it.first, it.second);
|
2013-07-27 07:27:51 -05:00
|
|
|
|
|
|
|
struct RewriteSigSpecWorker
|
|
|
|
{
|
|
|
|
RTLIL::Module *mod;
|
|
|
|
void operator()(RTLIL::SigSpec &sig)
|
|
|
|
{
|
2020-03-18 10:48:36 -05:00
|
|
|
sig.pack();
|
|
|
|
for (auto &c : sig.chunks_)
|
2013-07-27 07:27:51 -05:00
|
|
|
if (c.wire != NULL)
|
2014-07-26 18:49:51 -05:00
|
|
|
c.wire = mod->wires_.at(c.wire->name);
|
2013-07-27 07:27:51 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
RewriteSigSpecWorker rewriteSigSpecWorker;
|
|
|
|
rewriteSigSpecWorker.mod = new_mod;
|
|
|
|
new_mod->rewrite_sigspecs(rewriteSigSpecWorker);
|
2014-08-14 09:13:42 -05:00
|
|
|
new_mod->fixup_ports();
|
2013-07-27 07:27:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::Module *RTLIL::Module::clone() const
|
|
|
|
{
|
|
|
|
RTLIL::Module *new_mod = new RTLIL::Module;
|
2014-07-27 14:12:09 -05:00
|
|
|
new_mod->name = name;
|
2013-07-27 07:27:51 -05:00
|
|
|
cloneInto(new_mod);
|
|
|
|
return new_mod;
|
|
|
|
}
|
|
|
|
|
2014-07-31 07:11:39 -05:00
|
|
|
bool RTLIL::Module::has_memories() const
|
|
|
|
{
|
|
|
|
return !memories.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RTLIL::Module::has_processes() const
|
|
|
|
{
|
|
|
|
return !processes.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RTLIL::Module::has_memories_warn() const
|
|
|
|
{
|
|
|
|
if (!memories.empty())
|
2014-11-09 03:44:23 -06:00
|
|
|
log_warning("Ignoring module %s because it contains memories (run 'memory' command first).\n", log_id(this));
|
2014-07-31 07:11:39 -05:00
|
|
|
return !memories.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RTLIL::Module::has_processes_warn() const
|
|
|
|
{
|
|
|
|
if (!processes.empty())
|
2014-11-09 03:44:23 -06:00
|
|
|
log_warning("Ignoring module %s because it contains processes (run 'proc' command first).\n", log_id(this));
|
2014-07-31 07:11:39 -05:00
|
|
|
return !processes.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<RTLIL::Wire*> RTLIL::Module::selected_wires() const
|
|
|
|
{
|
|
|
|
std::vector<RTLIL::Wire*> result;
|
|
|
|
result.reserve(wires_.size());
|
|
|
|
for (auto &it : wires_)
|
|
|
|
if (design->selected(this, it.second))
|
|
|
|
result.push_back(it.second);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<RTLIL::Cell*> RTLIL::Module::selected_cells() const
|
|
|
|
{
|
|
|
|
std::vector<RTLIL::Cell*> result;
|
2019-09-27 19:00:19 -05:00
|
|
|
result.reserve(cells_.size());
|
2014-07-31 07:11:39 -05:00
|
|
|
for (auto &it : cells_)
|
|
|
|
if (design->selected(this, it.second))
|
|
|
|
result.push_back(it.second);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-06-18 10:11:13 -05:00
|
|
|
void RTLIL::Module::add(RTLIL::Wire *wire)
|
|
|
|
{
|
2014-07-27 03:13:22 -05:00
|
|
|
log_assert(!wire->name.empty());
|
|
|
|
log_assert(count_id(wire->name) == 0);
|
|
|
|
log_assert(refcount_wires_ == 0);
|
2014-07-26 18:49:51 -05:00
|
|
|
wires_[wire->name] = wire;
|
2014-07-31 07:11:39 -05:00
|
|
|
wire->module = this;
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2013-06-18 10:11:13 -05:00
|
|
|
void RTLIL::Module::add(RTLIL::Cell *cell)
|
|
|
|
{
|
2014-07-27 03:13:22 -05:00
|
|
|
log_assert(!cell->name.empty());
|
|
|
|
log_assert(count_id(cell->name) == 0);
|
|
|
|
log_assert(refcount_cells_ == 0);
|
2014-07-26 18:51:45 -05:00
|
|
|
cells_[cell->name] = cell;
|
2014-07-31 07:11:39 -05:00
|
|
|
cell->module = this;
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2019-05-15 09:01:00 -05:00
|
|
|
void RTLIL::Module::remove(const pool<RTLIL::Wire*> &wires)
|
|
|
|
{
|
|
|
|
log_assert(refcount_wires_ == 0);
|
|
|
|
|
2014-07-26 13:12:50 -05:00
|
|
|
struct DeleteWireWorker
|
|
|
|
{
|
|
|
|
RTLIL::Module *module;
|
2014-12-28 10:51:16 -06:00
|
|
|
const pool<RTLIL::Wire*> *wires_p;
|
2014-07-26 13:12:50 -05:00
|
|
|
|
|
|
|
void operator()(RTLIL::SigSpec &sig) {
|
2020-03-17 12:22:16 -05:00
|
|
|
sig.pack();
|
2020-03-12 17:55:54 -05:00
|
|
|
for (auto &c : sig.chunks_)
|
2014-07-26 13:12:50 -05:00
|
|
|
if (c.wire != NULL && wires_p->count(c.wire)) {
|
|
|
|
c.wire = module->addWire(NEW_ID, c.width);
|
|
|
|
c.offset = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-15 09:01:00 -05:00
|
|
|
void operator()(RTLIL::SigSpec &lhs, RTLIL::SigSpec &rhs) {
|
|
|
|
log_assert(GetSize(lhs) == GetSize(rhs));
|
2020-03-12 17:55:54 -05:00
|
|
|
lhs.unpack();
|
|
|
|
rhs.unpack();
|
2019-05-15 09:01:00 -05:00
|
|
|
for (int i = 0; i < GetSize(lhs); i++) {
|
2020-03-12 17:55:54 -05:00
|
|
|
RTLIL::SigBit &lhs_bit = lhs.bits_[i];
|
|
|
|
RTLIL::SigBit &rhs_bit = rhs.bits_[i];
|
2020-03-17 12:22:16 -05:00
|
|
|
if ((lhs_bit.wire != nullptr && wires_p->count(lhs_bit.wire)) || (rhs_bit.wire != nullptr && wires_p->count(rhs_bit.wire))) {
|
|
|
|
lhs_bit = State::Sx;
|
|
|
|
rhs_bit = State::Sx;
|
2020-03-13 10:17:39 -05:00
|
|
|
}
|
2019-05-15 09:01:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2014-07-27 03:13:22 -05:00
|
|
|
|
2014-07-26 13:12:50 -05:00
|
|
|
DeleteWireWorker delete_wire_worker;
|
|
|
|
delete_wire_worker.module = this;
|
|
|
|
delete_wire_worker.wires_p = &wires;
|
2019-05-15 09:01:00 -05:00
|
|
|
rewrite_sigspecs2(delete_wire_worker);
|
2014-07-26 13:12:50 -05:00
|
|
|
|
|
|
|
for (auto &it : wires) {
|
2014-07-27 03:13:22 -05:00
|
|
|
log_assert(wires_.count(it->name) != 0);
|
|
|
|
wires_.erase(it->name);
|
2014-07-26 13:12:50 -05:00
|
|
|
delete it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-21 05:02:55 -05:00
|
|
|
void RTLIL::Module::remove(RTLIL::Cell *cell)
|
|
|
|
{
|
2014-09-14 10:04:39 -05:00
|
|
|
while (!cell->connections_.empty())
|
|
|
|
cell->unsetPort(cell->connections_.begin()->first);
|
|
|
|
|
2014-07-27 03:13:22 -05:00
|
|
|
log_assert(cells_.count(cell->name) != 0);
|
|
|
|
log_assert(refcount_cells_ == 0);
|
2014-07-26 18:51:45 -05:00
|
|
|
cells_.erase(cell->name);
|
2014-07-21 05:02:55 -05:00
|
|
|
delete cell;
|
|
|
|
}
|
|
|
|
|
2014-07-25 08:05:18 -05:00
|
|
|
void RTLIL::Module::rename(RTLIL::Wire *wire, RTLIL::IdString new_name)
|
|
|
|
{
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(wires_[wire->name] == wire);
|
2014-07-27 03:13:22 -05:00
|
|
|
log_assert(refcount_wires_ == 0);
|
2014-07-26 18:49:51 -05:00
|
|
|
wires_.erase(wire->name);
|
2014-07-25 08:05:18 -05:00
|
|
|
wire->name = new_name;
|
|
|
|
add(wire);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RTLIL::Module::rename(RTLIL::Cell *cell, RTLIL::IdString new_name)
|
|
|
|
{
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(cells_[cell->name] == cell);
|
2014-07-27 03:13:22 -05:00
|
|
|
log_assert(refcount_wires_ == 0);
|
2014-07-26 18:51:45 -05:00
|
|
|
cells_.erase(cell->name);
|
2014-07-25 08:05:18 -05:00
|
|
|
cell->name = new_name;
|
|
|
|
add(cell);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RTLIL::Module::rename(RTLIL::IdString old_name, RTLIL::IdString new_name)
|
|
|
|
{
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(count_id(old_name) != 0);
|
2014-07-26 18:49:51 -05:00
|
|
|
if (wires_.count(old_name))
|
|
|
|
rename(wires_.at(old_name), new_name);
|
2014-07-26 18:51:45 -05:00
|
|
|
else if (cells_.count(old_name))
|
|
|
|
rename(cells_.at(old_name), new_name);
|
2014-07-25 08:05:18 -05:00
|
|
|
else
|
|
|
|
log_abort();
|
|
|
|
}
|
|
|
|
|
2014-08-05 07:47:03 -05:00
|
|
|
void RTLIL::Module::swap_names(RTLIL::Wire *w1, RTLIL::Wire *w2)
|
|
|
|
{
|
|
|
|
log_assert(wires_[w1->name] == w1);
|
|
|
|
log_assert(wires_[w2->name] == w2);
|
|
|
|
log_assert(refcount_wires_ == 0);
|
|
|
|
|
|
|
|
wires_.erase(w1->name);
|
|
|
|
wires_.erase(w2->name);
|
|
|
|
|
|
|
|
std::swap(w1->name, w2->name);
|
|
|
|
|
|
|
|
wires_[w1->name] = w1;
|
|
|
|
wires_[w2->name] = w2;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RTLIL::Module::swap_names(RTLIL::Cell *c1, RTLIL::Cell *c2)
|
|
|
|
{
|
|
|
|
log_assert(cells_[c1->name] == c1);
|
|
|
|
log_assert(cells_[c2->name] == c2);
|
|
|
|
log_assert(refcount_cells_ == 0);
|
|
|
|
|
|
|
|
cells_.erase(c1->name);
|
|
|
|
cells_.erase(c2->name);
|
|
|
|
|
|
|
|
std::swap(c1->name, c2->name);
|
|
|
|
|
|
|
|
cells_[c1->name] = c1;
|
|
|
|
cells_[c2->name] = c2;
|
|
|
|
}
|
|
|
|
|
2014-08-16 16:50:36 -05:00
|
|
|
RTLIL::IdString RTLIL::Module::uniquify(RTLIL::IdString name)
|
|
|
|
{
|
|
|
|
int index = 0;
|
|
|
|
return uniquify(name, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::IdString RTLIL::Module::uniquify(RTLIL::IdString name, int &index)
|
|
|
|
{
|
|
|
|
if (index == 0) {
|
|
|
|
if (count_id(name) == 0)
|
|
|
|
return name;
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
RTLIL::IdString new_name = stringf("%s_%d", name.c_str(), index);
|
|
|
|
if (count_id(new_name) == 0)
|
|
|
|
return new_name;
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-18 10:11:13 -05:00
|
|
|
static bool fixup_ports_compare(const RTLIL::Wire *a, const RTLIL::Wire *b)
|
|
|
|
{
|
|
|
|
if (a->port_id && !b->port_id)
|
|
|
|
return true;
|
|
|
|
if (!a->port_id && b->port_id)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (a->port_id == b->port_id)
|
|
|
|
return a->name < b->name;
|
|
|
|
return a->port_id < b->port_id;
|
|
|
|
}
|
|
|
|
|
2014-07-26 07:31:47 -05:00
|
|
|
void RTLIL::Module::connect(const RTLIL::SigSig &conn)
|
|
|
|
{
|
2014-07-31 07:34:12 -05:00
|
|
|
for (auto mon : monitors)
|
|
|
|
mon->notify_connect(this, conn);
|
|
|
|
|
|
|
|
if (design)
|
|
|
|
for (auto mon : design->monitors)
|
|
|
|
mon->notify_connect(this, conn);
|
|
|
|
|
2015-10-24 12:23:30 -05:00
|
|
|
// ignore all attempts to assign constants to other constants
|
|
|
|
if (conn.first.has_const()) {
|
|
|
|
RTLIL::SigSig new_conn;
|
|
|
|
for (int i = 0; i < GetSize(conn.first); i++)
|
|
|
|
if (conn.first[i].wire) {
|
|
|
|
new_conn.first.append(conn.first[i]);
|
|
|
|
new_conn.second.append(conn.second[i]);
|
|
|
|
}
|
|
|
|
if (GetSize(new_conn.first))
|
|
|
|
connect(new_conn);
|
|
|
|
return;
|
|
|
|
}
|
2015-10-24 06:44:35 -05:00
|
|
|
|
2014-12-29 06:33:33 -06:00
|
|
|
if (yosys_xtrace) {
|
|
|
|
log("#X# Connect (SigSig) in %s: %s = %s (%d bits)\n", log_id(this), log_signal(conn.first), log_signal(conn.second), GetSize(conn.first));
|
|
|
|
log_backtrace("-X- ", yosys_xtrace-1);
|
|
|
|
}
|
|
|
|
|
2016-08-27 10:06:22 -05:00
|
|
|
log_assert(GetSize(conn.first) == GetSize(conn.second));
|
2014-07-26 07:31:47 -05:00
|
|
|
connections_.push_back(conn);
|
|
|
|
}
|
|
|
|
|
2014-07-26 04:58:03 -05:00
|
|
|
void RTLIL::Module::connect(const RTLIL::SigSpec &lhs, const RTLIL::SigSpec &rhs)
|
|
|
|
{
|
2014-07-31 07:34:12 -05:00
|
|
|
connect(RTLIL::SigSig(lhs, rhs));
|
|
|
|
}
|
|
|
|
|
|
|
|
void RTLIL::Module::new_connections(const std::vector<RTLIL::SigSig> &new_conn)
|
|
|
|
{
|
|
|
|
for (auto mon : monitors)
|
2014-08-01 09:53:15 -05:00
|
|
|
mon->notify_connect(this, new_conn);
|
2014-07-31 07:34:12 -05:00
|
|
|
|
|
|
|
if (design)
|
|
|
|
for (auto mon : design->monitors)
|
2014-08-01 09:53:15 -05:00
|
|
|
mon->notify_connect(this, new_conn);
|
2014-07-31 07:34:12 -05:00
|
|
|
|
2014-12-29 06:33:33 -06:00
|
|
|
if (yosys_xtrace) {
|
|
|
|
log("#X# New connections vector in %s:\n", log_id(this));
|
|
|
|
for (auto &conn: new_conn)
|
|
|
|
log("#X# %s = %s (%d bits)\n", log_signal(conn.first), log_signal(conn.second), GetSize(conn.first));
|
|
|
|
log_backtrace("-X- ", yosys_xtrace-1);
|
|
|
|
}
|
|
|
|
|
2014-07-31 07:34:12 -05:00
|
|
|
connections_ = new_conn;
|
2014-07-26 04:58:03 -05:00
|
|
|
}
|
|
|
|
|
2014-07-26 08:57:27 -05:00
|
|
|
const std::vector<RTLIL::SigSig> &RTLIL::Module::connections() const
|
2014-07-26 07:38:33 -05:00
|
|
|
{
|
|
|
|
return connections_;
|
|
|
|
}
|
|
|
|
|
2013-06-18 10:11:13 -05:00
|
|
|
void RTLIL::Module::fixup_ports()
|
|
|
|
{
|
|
|
|
std::vector<RTLIL::Wire*> all_ports;
|
|
|
|
|
2014-07-26 18:49:51 -05:00
|
|
|
for (auto &w : wires_)
|
2013-06-18 10:11:13 -05:00
|
|
|
if (w.second->port_input || w.second->port_output)
|
|
|
|
all_ports.push_back(w.second);
|
|
|
|
else
|
|
|
|
w.second->port_id = 0;
|
|
|
|
|
|
|
|
std::sort(all_ports.begin(), all_ports.end(), fixup_ports_compare);
|
2014-08-14 09:13:42 -05:00
|
|
|
|
|
|
|
ports.clear();
|
|
|
|
for (size_t i = 0; i < all_ports.size(); i++) {
|
|
|
|
ports.push_back(all_ports[i]->name);
|
2013-06-18 10:11:13 -05:00
|
|
|
all_ports[i]->port_id = i+1;
|
2014-08-14 09:13:42 -05:00
|
|
|
}
|
2013-06-18 10:11:13 -05:00
|
|
|
}
|
|
|
|
|
2014-07-21 05:02:55 -05:00
|
|
|
RTLIL::Wire *RTLIL::Module::addWire(RTLIL::IdString name, int width)
|
|
|
|
{
|
|
|
|
RTLIL::Wire *wire = new RTLIL::Wire;
|
|
|
|
wire->name = name;
|
|
|
|
wire->width = width;
|
|
|
|
add(wire);
|
|
|
|
return wire;
|
|
|
|
}
|
|
|
|
|
2014-07-26 14:16:05 -05:00
|
|
|
RTLIL::Wire *RTLIL::Module::addWire(RTLIL::IdString name, const RTLIL::Wire *other)
|
|
|
|
{
|
|
|
|
RTLIL::Wire *wire = addWire(name);
|
|
|
|
wire->width = other->width;
|
|
|
|
wire->start_offset = other->start_offset;
|
|
|
|
wire->port_id = other->port_id;
|
|
|
|
wire->port_input = other->port_input;
|
|
|
|
wire->port_output = other->port_output;
|
2014-07-28 05:12:13 -05:00
|
|
|
wire->upto = other->upto;
|
2020-04-27 11:44:24 -05:00
|
|
|
wire->is_signed = other->is_signed;
|
2014-07-26 14:16:05 -05:00
|
|
|
wire->attributes = other->attributes;
|
|
|
|
return wire;
|
|
|
|
}
|
|
|
|
|
2014-07-21 05:02:55 -05:00
|
|
|
RTLIL::Cell *RTLIL::Module::addCell(RTLIL::IdString name, RTLIL::IdString type)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = new RTLIL::Cell;
|
|
|
|
cell->name = name;
|
|
|
|
cell->type = type;
|
|
|
|
add(cell);
|
|
|
|
return cell;
|
|
|
|
}
|
2014-03-09 21:02:27 -05:00
|
|
|
|
2014-07-25 17:38:44 -05:00
|
|
|
RTLIL::Cell *RTLIL::Module::addCell(RTLIL::IdString name, const RTLIL::Cell *other)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = addCell(name, other->type);
|
2014-07-26 08:57:57 -05:00
|
|
|
cell->connections_ = other->connections_;
|
2014-07-25 17:38:44 -05:00
|
|
|
cell->parameters = other->parameters;
|
|
|
|
cell->attributes = other->attributes;
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-06-03 09:35:27 -05:00
|
|
|
RTLIL::Memory *RTLIL::Module::addMemory(RTLIL::IdString name, const RTLIL::Memory *other)
|
|
|
|
{
|
|
|
|
RTLIL::Memory *mem = new RTLIL::Memory;
|
|
|
|
mem->name = name;
|
|
|
|
mem->width = other->width;
|
|
|
|
mem->start_offset = other->start_offset;
|
|
|
|
mem->size = other->size;
|
|
|
|
mem->attributes = other->attributes;
|
|
|
|
memories[mem->name] = mem;
|
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
|
2020-06-09 04:55:48 -05:00
|
|
|
RTLIL::Process *RTLIL::Module::addProcess(RTLIL::IdString name, const RTLIL::Process *other)
|
|
|
|
{
|
|
|
|
RTLIL::Process *proc = other->clone();
|
|
|
|
proc->name = name;
|
|
|
|
processes[name] = proc;
|
|
|
|
return proc;
|
|
|
|
}
|
|
|
|
|
2014-07-18 03:27:06 -05:00
|
|
|
#define DEF_METHOD(_func, _y_size, _type) \
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_y, bool is_signed, const std::string &src) { \
|
2014-07-31 07:34:12 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, _type); \
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->parameters[ID::A_SIGNED] = is_signed; \
|
|
|
|
cell->parameters[ID::A_WIDTH] = sig_a.size(); \
|
|
|
|
cell->parameters[ID::Y_WIDTH] = sig_y.size(); \
|
2019-08-15 16:50:10 -05:00
|
|
|
cell->setPort(ID::A, sig_a); \
|
|
|
|
cell->setPort(ID::Y, sig_y); \
|
2017-09-01 05:26:55 -05:00
|
|
|
cell->set_src_attribute(src); \
|
2014-03-09 21:02:27 -05:00
|
|
|
return cell; \
|
2014-07-18 03:27:06 -05:00
|
|
|
} \
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::SigSpec RTLIL::Module::_func(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, bool is_signed, const std::string &src) { \
|
2014-07-21 05:35:06 -05:00
|
|
|
RTLIL::SigSpec sig_y = addWire(NEW_ID, _y_size); \
|
2017-08-29 15:46:35 -05:00
|
|
|
add ## _func(name, sig_a, sig_y, is_signed, src); \
|
2014-07-18 03:27:06 -05:00
|
|
|
return sig_y; \
|
2014-03-09 21:02:27 -05:00
|
|
|
}
|
2019-08-10 05:24:16 -05:00
|
|
|
DEF_METHOD(Not, sig_a.size(), ID($not))
|
|
|
|
DEF_METHOD(Pos, sig_a.size(), ID($pos))
|
|
|
|
DEF_METHOD(Neg, sig_a.size(), ID($neg))
|
|
|
|
DEF_METHOD(ReduceAnd, 1, ID($reduce_and))
|
|
|
|
DEF_METHOD(ReduceOr, 1, ID($reduce_or))
|
|
|
|
DEF_METHOD(ReduceXor, 1, ID($reduce_xor))
|
|
|
|
DEF_METHOD(ReduceXnor, 1, ID($reduce_xnor))
|
|
|
|
DEF_METHOD(ReduceBool, 1, ID($reduce_bool))
|
|
|
|
DEF_METHOD(LogicNot, 1, ID($logic_not))
|
2014-03-09 21:02:27 -05:00
|
|
|
#undef DEF_METHOD
|
|
|
|
|
2014-07-18 03:27:06 -05:00
|
|
|
#define DEF_METHOD(_func, _y_size, _type) \
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed, const std::string &src) { \
|
2014-07-31 07:34:12 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, _type); \
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->parameters[ID::A_SIGNED] = is_signed; \
|
|
|
|
cell->parameters[ID::B_SIGNED] = is_signed; \
|
|
|
|
cell->parameters[ID::A_WIDTH] = sig_a.size(); \
|
|
|
|
cell->parameters[ID::B_WIDTH] = sig_b.size(); \
|
|
|
|
cell->parameters[ID::Y_WIDTH] = sig_y.size(); \
|
2019-08-15 16:50:10 -05:00
|
|
|
cell->setPort(ID::A, sig_a); \
|
|
|
|
cell->setPort(ID::B, sig_b); \
|
|
|
|
cell->setPort(ID::Y, sig_y); \
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src); \
|
2014-03-09 21:02:27 -05:00
|
|
|
return cell; \
|
2014-07-18 03:27:06 -05:00
|
|
|
} \
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::SigSpec RTLIL::Module::_func(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed, const std::string &src) { \
|
2017-09-09 03:16:48 -05:00
|
|
|
RTLIL::SigSpec sig_y = addWire(NEW_ID, _y_size); \
|
|
|
|
add ## _func(name, sig_a, sig_b, sig_y, is_signed, src); \
|
|
|
|
return sig_y; \
|
2014-03-09 21:02:27 -05:00
|
|
|
}
|
2019-08-10 05:24:16 -05:00
|
|
|
DEF_METHOD(And, max(sig_a.size(), sig_b.size()), ID($and))
|
|
|
|
DEF_METHOD(Or, max(sig_a.size(), sig_b.size()), ID($or))
|
|
|
|
DEF_METHOD(Xor, max(sig_a.size(), sig_b.size()), ID($xor))
|
|
|
|
DEF_METHOD(Xnor, max(sig_a.size(), sig_b.size()), ID($xnor))
|
|
|
|
DEF_METHOD(Shift, sig_a.size(), ID($shift))
|
|
|
|
DEF_METHOD(Shiftx, sig_a.size(), ID($shiftx))
|
|
|
|
DEF_METHOD(Lt, 1, ID($lt))
|
|
|
|
DEF_METHOD(Le, 1, ID($le))
|
|
|
|
DEF_METHOD(Eq, 1, ID($eq))
|
|
|
|
DEF_METHOD(Ne, 1, ID($ne))
|
|
|
|
DEF_METHOD(Eqx, 1, ID($eqx))
|
|
|
|
DEF_METHOD(Nex, 1, ID($nex))
|
|
|
|
DEF_METHOD(Ge, 1, ID($ge))
|
|
|
|
DEF_METHOD(Gt, 1, ID($gt))
|
|
|
|
DEF_METHOD(Add, max(sig_a.size(), sig_b.size()), ID($add))
|
|
|
|
DEF_METHOD(Sub, max(sig_a.size(), sig_b.size()), ID($sub))
|
|
|
|
DEF_METHOD(Mul, max(sig_a.size(), sig_b.size()), ID($mul))
|
|
|
|
DEF_METHOD(Div, max(sig_a.size(), sig_b.size()), ID($div))
|
|
|
|
DEF_METHOD(Mod, max(sig_a.size(), sig_b.size()), ID($mod))
|
2020-04-21 05:51:58 -05:00
|
|
|
DEF_METHOD(DivFloor, max(sig_a.size(), sig_b.size()), ID($divfloor))
|
2020-04-08 12:30:47 -05:00
|
|
|
DEF_METHOD(ModFloor, max(sig_a.size(), sig_b.size()), ID($modfloor))
|
2019-08-10 05:24:16 -05:00
|
|
|
DEF_METHOD(LogicAnd, 1, ID($logic_and))
|
|
|
|
DEF_METHOD(LogicOr, 1, ID($logic_or))
|
2014-03-09 21:02:27 -05:00
|
|
|
#undef DEF_METHOD
|
|
|
|
|
2020-01-02 11:58:45 -06:00
|
|
|
#define DEF_METHOD(_func, _y_size, _type) \
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed, const std::string &src) { \
|
2020-01-02 11:58:45 -06:00
|
|
|
RTLIL::Cell *cell = addCell(name, _type); \
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->parameters[ID::A_SIGNED] = is_signed; \
|
|
|
|
cell->parameters[ID::B_SIGNED] = false; \
|
|
|
|
cell->parameters[ID::A_WIDTH] = sig_a.size(); \
|
|
|
|
cell->parameters[ID::B_WIDTH] = sig_b.size(); \
|
|
|
|
cell->parameters[ID::Y_WIDTH] = sig_y.size(); \
|
2020-01-02 11:58:45 -06:00
|
|
|
cell->setPort(ID::A, sig_a); \
|
|
|
|
cell->setPort(ID::B, sig_b); \
|
|
|
|
cell->setPort(ID::Y, sig_y); \
|
|
|
|
cell->set_src_attribute(src); \
|
|
|
|
return cell; \
|
|
|
|
} \
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::SigSpec RTLIL::Module::_func(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed, const std::string &src) { \
|
2020-01-02 11:58:45 -06:00
|
|
|
RTLIL::SigSpec sig_y = addWire(NEW_ID, _y_size); \
|
|
|
|
add ## _func(name, sig_a, sig_b, sig_y, is_signed, src); \
|
|
|
|
return sig_y; \
|
|
|
|
}
|
|
|
|
DEF_METHOD(Shl, sig_a.size(), ID($shl))
|
|
|
|
DEF_METHOD(Shr, sig_a.size(), ID($shr))
|
|
|
|
DEF_METHOD(Sshl, sig_a.size(), ID($sshl))
|
|
|
|
DEF_METHOD(Sshr, sig_a.size(), ID($sshr))
|
|
|
|
#undef DEF_METHOD
|
|
|
|
|
2014-03-09 21:02:27 -05:00
|
|
|
#define DEF_METHOD(_func, _type, _pmux) \
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_s, const RTLIL::SigSpec &sig_y, const std::string &src) { \
|
2014-08-19 06:44:56 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, _type); \
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->parameters[ID::WIDTH] = sig_a.size(); \
|
|
|
|
if (_pmux) cell->parameters[ID::S_WIDTH] = sig_s.size(); \
|
2019-08-15 16:50:10 -05:00
|
|
|
cell->setPort(ID::A, sig_a); \
|
|
|
|
cell->setPort(ID::B, sig_b); \
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->setPort(ID::S, sig_s); \
|
2019-08-15 16:50:10 -05:00
|
|
|
cell->setPort(ID::Y, sig_y); \
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src); \
|
2014-08-19 06:44:56 -05:00
|
|
|
return cell; \
|
2014-07-18 03:27:06 -05:00
|
|
|
} \
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::SigSpec RTLIL::Module::_func(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_s, const std::string &src) { \
|
2014-07-22 13:15:14 -05:00
|
|
|
RTLIL::SigSpec sig_y = addWire(NEW_ID, sig_a.size()); \
|
2017-09-09 03:16:48 -05:00
|
|
|
add ## _func(name, sig_a, sig_b, sig_s, sig_y, src); \
|
2014-08-19 06:44:56 -05:00
|
|
|
return sig_y; \
|
2014-03-09 21:02:27 -05:00
|
|
|
}
|
2019-08-10 05:24:16 -05:00
|
|
|
DEF_METHOD(Mux, ID($mux), 0)
|
|
|
|
DEF_METHOD(Pmux, ID($pmux), 1)
|
2014-03-09 21:02:27 -05:00
|
|
|
#undef DEF_METHOD
|
|
|
|
|
2014-03-14 05:45:44 -05:00
|
|
|
#define DEF_METHOD_2(_func, _type, _P1, _P2) \
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, const RTLIL::SigBit &sig1, const RTLIL::SigBit &sig2, const std::string &src) { \
|
2014-08-19 06:44:56 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, _type); \
|
|
|
|
cell->setPort("\\" #_P1, sig1); \
|
|
|
|
cell->setPort("\\" #_P2, sig2); \
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src); \
|
2014-08-19 06:44:56 -05:00
|
|
|
return cell; \
|
2014-07-18 03:27:06 -05:00
|
|
|
} \
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::SigBit RTLIL::Module::_func(RTLIL::IdString name, const RTLIL::SigBit &sig1, const std::string &src) { \
|
2017-09-09 03:16:48 -05:00
|
|
|
RTLIL::SigBit sig2 = addWire(NEW_ID); \
|
|
|
|
add ## _func(name, sig1, sig2, src); \
|
2014-08-19 06:44:56 -05:00
|
|
|
return sig2; \
|
2014-03-14 05:45:44 -05:00
|
|
|
}
|
|
|
|
#define DEF_METHOD_3(_func, _type, _P1, _P2, _P3) \
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, const RTLIL::SigBit &sig1, const RTLIL::SigBit &sig2, const RTLIL::SigBit &sig3, const std::string &src) { \
|
2014-08-19 06:44:56 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, _type); \
|
|
|
|
cell->setPort("\\" #_P1, sig1); \
|
|
|
|
cell->setPort("\\" #_P2, sig2); \
|
|
|
|
cell->setPort("\\" #_P3, sig3); \
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src); \
|
2014-08-19 06:44:56 -05:00
|
|
|
return cell; \
|
2014-07-18 03:27:06 -05:00
|
|
|
} \
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::SigBit RTLIL::Module::_func(RTLIL::IdString name, const RTLIL::SigBit &sig1, const RTLIL::SigBit &sig2, const std::string &src) { \
|
2017-09-09 03:16:48 -05:00
|
|
|
RTLIL::SigBit sig3 = addWire(NEW_ID); \
|
|
|
|
add ## _func(name, sig1, sig2, sig3, src); \
|
2014-08-19 06:44:56 -05:00
|
|
|
return sig3; \
|
2014-03-14 05:45:44 -05:00
|
|
|
}
|
|
|
|
#define DEF_METHOD_4(_func, _type, _P1, _P2, _P3, _P4) \
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, const RTLIL::SigBit &sig1, const RTLIL::SigBit &sig2, const RTLIL::SigBit &sig3, const RTLIL::SigBit &sig4, const std::string &src) { \
|
2014-08-19 06:44:56 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, _type); \
|
|
|
|
cell->setPort("\\" #_P1, sig1); \
|
|
|
|
cell->setPort("\\" #_P2, sig2); \
|
|
|
|
cell->setPort("\\" #_P3, sig3); \
|
|
|
|
cell->setPort("\\" #_P4, sig4); \
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src); \
|
2014-08-19 06:44:56 -05:00
|
|
|
return cell; \
|
|
|
|
} \
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::SigBit RTLIL::Module::_func(RTLIL::IdString name, const RTLIL::SigBit &sig1, const RTLIL::SigBit &sig2, const RTLIL::SigBit &sig3, const std::string &src) { \
|
2017-09-09 03:16:48 -05:00
|
|
|
RTLIL::SigBit sig4 = addWire(NEW_ID); \
|
|
|
|
add ## _func(name, sig1, sig2, sig3, sig4, src); \
|
2014-08-19 06:44:56 -05:00
|
|
|
return sig4; \
|
|
|
|
}
|
|
|
|
#define DEF_METHOD_5(_func, _type, _P1, _P2, _P3, _P4, _P5) \
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, const RTLIL::SigBit &sig1, const RTLIL::SigBit &sig2, const RTLIL::SigBit &sig3, const RTLIL::SigBit &sig4, const RTLIL::SigBit &sig5, const std::string &src) { \
|
2014-08-19 06:44:56 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, _type); \
|
|
|
|
cell->setPort("\\" #_P1, sig1); \
|
|
|
|
cell->setPort("\\" #_P2, sig2); \
|
|
|
|
cell->setPort("\\" #_P3, sig3); \
|
|
|
|
cell->setPort("\\" #_P4, sig4); \
|
|
|
|
cell->setPort("\\" #_P5, sig5); \
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src); \
|
2014-08-19 06:44:56 -05:00
|
|
|
return cell; \
|
2014-07-18 03:27:06 -05:00
|
|
|
} \
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::SigBit RTLIL::Module::_func(RTLIL::IdString name, const RTLIL::SigBit &sig1, const RTLIL::SigBit &sig2, const RTLIL::SigBit &sig3, const RTLIL::SigBit &sig4, const std::string &src) { \
|
2017-09-09 03:16:48 -05:00
|
|
|
RTLIL::SigBit sig5 = addWire(NEW_ID); \
|
|
|
|
add ## _func(name, sig1, sig2, sig3, sig4, sig5, src); \
|
|
|
|
return sig5; \
|
2014-03-14 05:45:44 -05:00
|
|
|
}
|
2019-08-10 05:24:16 -05:00
|
|
|
DEF_METHOD_2(BufGate, ID($_BUF_), A, Y)
|
|
|
|
DEF_METHOD_2(NotGate, ID($_NOT_), A, Y)
|
|
|
|
DEF_METHOD_3(AndGate, ID($_AND_), A, B, Y)
|
|
|
|
DEF_METHOD_3(NandGate, ID($_NAND_), A, B, Y)
|
|
|
|
DEF_METHOD_3(OrGate, ID($_OR_), A, B, Y)
|
|
|
|
DEF_METHOD_3(NorGate, ID($_NOR_), A, B, Y)
|
|
|
|
DEF_METHOD_3(XorGate, ID($_XOR_), A, B, Y)
|
|
|
|
DEF_METHOD_3(XnorGate, ID($_XNOR_), A, B, Y)
|
|
|
|
DEF_METHOD_3(AndnotGate, ID($_ANDNOT_), A, B, Y)
|
|
|
|
DEF_METHOD_3(OrnotGate, ID($_ORNOT_), A, B, Y)
|
|
|
|
DEF_METHOD_4(MuxGate, ID($_MUX_), A, B, S, Y)
|
|
|
|
DEF_METHOD_4(NmuxGate, ID($_NMUX_), A, B, S, Y)
|
|
|
|
DEF_METHOD_4(Aoi3Gate, ID($_AOI3_), A, B, C, Y)
|
|
|
|
DEF_METHOD_4(Oai3Gate, ID($_OAI3_), A, B, C, Y)
|
|
|
|
DEF_METHOD_5(Aoi4Gate, ID($_AOI4_), A, B, C, D, Y)
|
|
|
|
DEF_METHOD_5(Oai4Gate, ID($_OAI4_), A, B, C, D, Y)
|
2014-03-14 05:45:44 -05:00
|
|
|
#undef DEF_METHOD_2
|
|
|
|
#undef DEF_METHOD_3
|
|
|
|
#undef DEF_METHOD_4
|
2014-08-19 06:44:56 -05:00
|
|
|
#undef DEF_METHOD_5
|
2014-03-14 05:45:44 -05:00
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::addPow(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool a_signed, bool b_signed, const std::string &src)
|
2014-03-09 21:02:27 -05:00
|
|
|
{
|
2019-08-10 05:24:16 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, ID($pow));
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->parameters[ID::A_SIGNED] = a_signed;
|
|
|
|
cell->parameters[ID::B_SIGNED] = b_signed;
|
|
|
|
cell->parameters[ID::A_WIDTH] = sig_a.size();
|
|
|
|
cell->parameters[ID::B_WIDTH] = sig_b.size();
|
|
|
|
cell->parameters[ID::Y_WIDTH] = sig_y.size();
|
2019-08-15 16:50:10 -05:00
|
|
|
cell->setPort(ID::A, sig_a);
|
|
|
|
cell->setPort(ID::B, sig_b);
|
|
|
|
cell->setPort(ID::Y, sig_y);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2014-03-09 21:02:27 -05:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::addSlice(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_y, RTLIL::Const offset, const std::string &src)
|
2014-03-09 21:02:27 -05:00
|
|
|
{
|
2019-08-10 05:24:16 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, ID($slice));
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->parameters[ID::A_WIDTH] = sig_a.size();
|
|
|
|
cell->parameters[ID::Y_WIDTH] = sig_y.size();
|
|
|
|
cell->parameters[ID::OFFSET] = offset;
|
2019-08-15 16:50:10 -05:00
|
|
|
cell->setPort(ID::A, sig_a);
|
|
|
|
cell->setPort(ID::Y, sig_y);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2014-03-09 21:02:27 -05:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::addConcat(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, const std::string &src)
|
2014-03-09 21:02:27 -05:00
|
|
|
{
|
2019-08-10 05:24:16 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, ID($concat));
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->parameters[ID::A_WIDTH] = sig_a.size();
|
|
|
|
cell->parameters[ID::B_WIDTH] = sig_b.size();
|
2019-08-15 16:50:10 -05:00
|
|
|
cell->setPort(ID::A, sig_a);
|
|
|
|
cell->setPort(ID::B, sig_b);
|
|
|
|
cell->setPort(ID::Y, sig_y);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2014-03-09 21:02:27 -05:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::addLut(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_y, RTLIL::Const lut, const std::string &src)
|
2014-03-09 21:02:27 -05:00
|
|
|
{
|
2019-08-10 05:24:16 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, ID($lut));
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->parameters[ID::LUT] = lut;
|
|
|
|
cell->parameters[ID::WIDTH] = sig_a.size();
|
2019-08-15 16:50:10 -05:00
|
|
|
cell->setPort(ID::A, sig_a);
|
|
|
|
cell->setPort(ID::Y, sig_y);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2014-03-09 21:02:27 -05:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::addTribuf(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_y, const std::string &src)
|
2015-08-16 05:54:52 -05:00
|
|
|
{
|
2019-08-10 05:24:16 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, ID($tribuf));
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->parameters[ID::WIDTH] = sig_a.size();
|
2019-08-15 16:50:10 -05:00
|
|
|
cell->setPort(ID::A, sig_a);
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->setPort(ID::EN, sig_en);
|
2019-08-15 16:50:10 -05:00
|
|
|
cell->setPort(ID::Y, sig_y);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2015-08-16 05:54:52 -05:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::addAssert(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_en, const std::string &src)
|
2014-03-09 21:02:27 -05:00
|
|
|
{
|
2019-08-10 05:24:16 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, ID($assert));
|
2019-08-15 16:50:10 -05:00
|
|
|
cell->setPort(ID::A, sig_a);
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->setPort(ID::EN, sig_en);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2014-03-09 21:02:27 -05:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::addAssume(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_en, const std::string &src)
|
2016-07-13 09:56:17 -05:00
|
|
|
{
|
2019-08-10 05:24:16 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, ID($assume));
|
2019-08-15 16:50:10 -05:00
|
|
|
cell->setPort(ID::A, sig_a);
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->setPort(ID::EN, sig_en);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2016-07-13 09:56:17 -05:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::addLive(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_en, const std::string &src)
|
2017-02-25 03:36:39 -06:00
|
|
|
{
|
2019-08-10 05:24:16 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, ID($live));
|
2019-08-15 16:50:10 -05:00
|
|
|
cell->setPort(ID::A, sig_a);
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->setPort(ID::EN, sig_en);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2017-02-25 03:36:39 -06:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::addFair(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_en, const std::string &src)
|
2017-02-25 03:36:39 -06:00
|
|
|
{
|
2019-08-10 05:24:16 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, ID($fair));
|
2019-08-15 16:50:10 -05:00
|
|
|
cell->setPort(ID::A, sig_a);
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->setPort(ID::EN, sig_en);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2017-02-25 03:36:39 -06:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::addCover(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_en, const std::string &src)
|
2017-02-04 07:14:26 -06:00
|
|
|
{
|
2019-08-10 05:24:16 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, ID($cover));
|
2019-08-15 16:50:10 -05:00
|
|
|
cell->setPort(ID::A, sig_a);
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->setPort(ID::EN, sig_en);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2017-02-04 07:14:26 -06:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::addEquiv(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, const std::string &src)
|
2015-01-19 06:59:08 -06:00
|
|
|
{
|
2019-08-10 05:24:16 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, ID($equiv));
|
2019-08-15 16:50:10 -05:00
|
|
|
cell->setPort(ID::A, sig_a);
|
|
|
|
cell->setPort(ID::B, sig_b);
|
|
|
|
cell->setPort(ID::Y, sig_y);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2015-01-19 06:59:08 -06:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::addSr(RTLIL::IdString name, const RTLIL::SigSpec &sig_set, const RTLIL::SigSpec &sig_clr, const RTLIL::SigSpec &sig_q, bool set_polarity, bool clr_polarity, const std::string &src)
|
2014-03-09 21:02:27 -05:00
|
|
|
{
|
2019-08-10 05:24:16 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, ID($sr));
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->parameters[ID::SET_POLARITY] = set_polarity;
|
|
|
|
cell->parameters[ID::CLR_POLARITY] = clr_polarity;
|
|
|
|
cell->parameters[ID::WIDTH] = sig_q.size();
|
|
|
|
cell->setPort(ID::SET, sig_set);
|
|
|
|
cell->setPort(ID::CLR, sig_clr);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2014-03-09 21:02:27 -05:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::addFf(RTLIL::IdString name, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, const std::string &src)
|
2016-10-11 18:18:39 -05:00
|
|
|
{
|
2019-08-10 05:24:16 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, ID($ff));
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->parameters[ID::WIDTH] = sig_q.size();
|
|
|
|
cell->setPort(ID::D, sig_d);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2016-10-11 18:18:39 -05:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::addDff(RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, bool clk_polarity, const std::string &src)
|
2014-03-09 21:02:27 -05:00
|
|
|
{
|
2019-08-10 05:24:16 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, ID($dff));
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->parameters[ID::CLK_POLARITY] = clk_polarity;
|
|
|
|
cell->parameters[ID::WIDTH] = sig_q.size();
|
|
|
|
cell->setPort(ID::CLK, sig_clk);
|
|
|
|
cell->setPort(ID::D, sig_d);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2014-03-09 21:02:27 -05:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::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, bool en_polarity, const std::string &src)
|
2014-12-08 07:59:38 -06:00
|
|
|
{
|
2019-08-10 05:24:16 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, ID($dffe));
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->parameters[ID::CLK_POLARITY] = clk_polarity;
|
|
|
|
cell->parameters[ID::EN_POLARITY] = en_polarity;
|
|
|
|
cell->parameters[ID::WIDTH] = sig_q.size();
|
|
|
|
cell->setPort(ID::CLK, sig_clk);
|
|
|
|
cell->setPort(ID::EN, sig_en);
|
|
|
|
cell->setPort(ID::D, sig_d);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2014-12-08 07:59:38 -06:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::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, bool set_polarity, bool clr_polarity, const std::string &src)
|
2014-03-09 21:02:27 -05:00
|
|
|
{
|
2019-08-10 05:24:16 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, ID($dffsr));
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->parameters[ID::CLK_POLARITY] = clk_polarity;
|
|
|
|
cell->parameters[ID::SET_POLARITY] = set_polarity;
|
|
|
|
cell->parameters[ID::CLR_POLARITY] = clr_polarity;
|
|
|
|
cell->parameters[ID::WIDTH] = sig_q.size();
|
|
|
|
cell->setPort(ID::CLK, sig_clk);
|
|
|
|
cell->setPort(ID::SET, sig_set);
|
|
|
|
cell->setPort(ID::CLR, sig_clr);
|
|
|
|
cell->setPort(ID::D, sig_d);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2014-03-09 21:02:27 -05:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-06-23 08:39:25 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::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, bool en_polarity, bool set_polarity, bool clr_polarity, const std::string &src)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = addCell(name, ID($dffsre));
|
|
|
|
cell->parameters[ID::CLK_POLARITY] = clk_polarity;
|
|
|
|
cell->parameters[ID::EN_POLARITY] = en_polarity;
|
|
|
|
cell->parameters[ID::SET_POLARITY] = set_polarity;
|
|
|
|
cell->parameters[ID::CLR_POLARITY] = clr_polarity;
|
|
|
|
cell->parameters[ID::WIDTH] = sig_q.size();
|
|
|
|
cell->setPort(ID::CLK, sig_clk);
|
|
|
|
cell->setPort(ID::EN, sig_en);
|
|
|
|
cell->setPort(ID::SET, sig_set);
|
|
|
|
cell->setPort(ID::CLR, sig_clr);
|
|
|
|
cell->setPort(ID::D, sig_d);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
|
|
|
cell->set_src_attribute(src);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::addAdff(RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_arst, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q,
|
2017-09-09 03:16:48 -05:00
|
|
|
RTLIL::Const arst_value, bool clk_polarity, bool arst_polarity, const std::string &src)
|
2014-03-09 21:02:27 -05:00
|
|
|
{
|
2019-08-10 05:24:16 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, ID($adff));
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->parameters[ID::CLK_POLARITY] = clk_polarity;
|
|
|
|
cell->parameters[ID::ARST_POLARITY] = arst_polarity;
|
|
|
|
cell->parameters[ID::ARST_VALUE] = arst_value;
|
|
|
|
cell->parameters[ID::WIDTH] = sig_q.size();
|
|
|
|
cell->setPort(ID::CLK, sig_clk);
|
|
|
|
cell->setPort(ID::ARST, sig_arst);
|
|
|
|
cell->setPort(ID::D, sig_d);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2014-03-09 21:02:27 -05:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-06-23 08:39:25 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::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, bool en_polarity, bool arst_polarity, const std::string &src)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = addCell(name, ID($adffe));
|
|
|
|
cell->parameters[ID::CLK_POLARITY] = clk_polarity;
|
|
|
|
cell->parameters[ID::EN_POLARITY] = en_polarity;
|
|
|
|
cell->parameters[ID::ARST_POLARITY] = arst_polarity;
|
|
|
|
cell->parameters[ID::ARST_VALUE] = arst_value;
|
|
|
|
cell->parameters[ID::WIDTH] = sig_q.size();
|
|
|
|
cell->setPort(ID::CLK, sig_clk);
|
|
|
|
cell->setPort(ID::EN, sig_en);
|
|
|
|
cell->setPort(ID::ARST, sig_arst);
|
|
|
|
cell->setPort(ID::D, sig_d);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
|
|
|
cell->set_src_attribute(src);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::Cell* RTLIL::Module::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, bool srst_polarity, const std::string &src)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = addCell(name, ID($sdff));
|
|
|
|
cell->parameters[ID::CLK_POLARITY] = clk_polarity;
|
|
|
|
cell->parameters[ID::SRST_POLARITY] = srst_polarity;
|
|
|
|
cell->parameters[ID::SRST_VALUE] = srst_value;
|
|
|
|
cell->parameters[ID::WIDTH] = sig_q.size();
|
|
|
|
cell->setPort(ID::CLK, sig_clk);
|
|
|
|
cell->setPort(ID::SRST, sig_srst);
|
|
|
|
cell->setPort(ID::D, sig_d);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
|
|
|
cell->set_src_attribute(src);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::Cell* RTLIL::Module::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, bool en_polarity, bool srst_polarity, const std::string &src)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = addCell(name, ID($sdffe));
|
|
|
|
cell->parameters[ID::CLK_POLARITY] = clk_polarity;
|
|
|
|
cell->parameters[ID::EN_POLARITY] = en_polarity;
|
|
|
|
cell->parameters[ID::SRST_POLARITY] = srst_polarity;
|
|
|
|
cell->parameters[ID::SRST_VALUE] = srst_value;
|
|
|
|
cell->parameters[ID::WIDTH] = sig_q.size();
|
|
|
|
cell->setPort(ID::CLK, sig_clk);
|
|
|
|
cell->setPort(ID::EN, sig_en);
|
|
|
|
cell->setPort(ID::SRST, sig_srst);
|
|
|
|
cell->setPort(ID::D, sig_d);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
|
|
|
cell->set_src_attribute(src);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::Cell* RTLIL::Module::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, bool en_polarity, bool srst_polarity, const std::string &src)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = addCell(name, ID($sdffce));
|
|
|
|
cell->parameters[ID::CLK_POLARITY] = clk_polarity;
|
|
|
|
cell->parameters[ID::EN_POLARITY] = en_polarity;
|
|
|
|
cell->parameters[ID::SRST_POLARITY] = srst_polarity;
|
|
|
|
cell->parameters[ID::SRST_VALUE] = srst_value;
|
|
|
|
cell->parameters[ID::WIDTH] = sig_q.size();
|
|
|
|
cell->setPort(ID::CLK, sig_clk);
|
|
|
|
cell->setPort(ID::EN, sig_en);
|
|
|
|
cell->setPort(ID::SRST, sig_srst);
|
|
|
|
cell->setPort(ID::D, sig_d);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
|
|
|
cell->set_src_attribute(src);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::addDlatch(RTLIL::IdString name, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, bool en_polarity, const std::string &src)
|
2014-03-09 21:02:27 -05:00
|
|
|
{
|
2019-08-10 05:24:16 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, ID($dlatch));
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->parameters[ID::EN_POLARITY] = en_polarity;
|
|
|
|
cell->parameters[ID::WIDTH] = sig_q.size();
|
|
|
|
cell->setPort(ID::EN, sig_en);
|
|
|
|
cell->setPort(ID::D, sig_d);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2014-03-09 21:02:27 -05:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-06-23 08:39:25 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::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, bool arst_polarity, const std::string &src)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = addCell(name, ID($adlatch));
|
|
|
|
cell->parameters[ID::EN_POLARITY] = en_polarity;
|
|
|
|
cell->parameters[ID::ARST_POLARITY] = arst_polarity;
|
|
|
|
cell->parameters[ID::ARST_VALUE] = arst_value;
|
|
|
|
cell->parameters[ID::WIDTH] = sig_q.size();
|
|
|
|
cell->setPort(ID::EN, sig_en);
|
|
|
|
cell->setPort(ID::ARST, sig_arst);
|
|
|
|
cell->setPort(ID::D, sig_d);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
|
|
|
cell->set_src_attribute(src);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::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, bool set_polarity, bool clr_polarity, const std::string &src)
|
2014-03-31 07:14:40 -05:00
|
|
|
{
|
2019-08-10 05:24:16 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, ID($dlatchsr));
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->parameters[ID::EN_POLARITY] = en_polarity;
|
|
|
|
cell->parameters[ID::SET_POLARITY] = set_polarity;
|
|
|
|
cell->parameters[ID::CLR_POLARITY] = clr_polarity;
|
|
|
|
cell->parameters[ID::WIDTH] = sig_q.size();
|
|
|
|
cell->setPort(ID::EN, sig_en);
|
|
|
|
cell->setPort(ID::SET, sig_set);
|
|
|
|
cell->setPort(ID::CLR, sig_clr);
|
|
|
|
cell->setPort(ID::D, sig_d);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2016-10-11 18:18:39 -05:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-06-23 08:39:25 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::addSrGate(RTLIL::IdString name, const RTLIL::SigSpec &sig_set, const RTLIL::SigSpec &sig_clr,
|
|
|
|
const RTLIL::SigSpec &sig_q, bool set_polarity, bool clr_polarity, const std::string &src)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = addCell(name, stringf("$_SR_%c%c_", set_polarity ? 'P' : 'N', clr_polarity ? 'P' : 'N'));
|
|
|
|
cell->setPort(ID::S, sig_set);
|
|
|
|
cell->setPort(ID::R, sig_clr);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
|
|
|
cell->set_src_attribute(src);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::addFfGate(RTLIL::IdString name, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, const std::string &src)
|
2016-10-11 18:18:39 -05:00
|
|
|
{
|
2019-08-10 05:24:16 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, ID($_FF_));
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->setPort(ID::D, sig_d);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2014-03-31 07:14:40 -05:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::addDffGate(RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, bool clk_polarity, const std::string &src)
|
2014-03-15 08:35:29 -05:00
|
|
|
{
|
2014-07-31 07:34:12 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, stringf("$_DFF_%c_", clk_polarity ? 'P' : 'N'));
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->setPort(ID::C, sig_clk);
|
|
|
|
cell->setPort(ID::D, sig_d);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2014-03-15 08:35:29 -05:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::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, bool en_polarity, const std::string &src)
|
2014-12-08 07:59:38 -06:00
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = addCell(name, stringf("$_DFFE_%c%c_", clk_polarity ? 'P' : 'N', en_polarity ? 'P' : 'N'));
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->setPort(ID::C, sig_clk);
|
|
|
|
cell->setPort(ID::E, sig_en);
|
|
|
|
cell->setPort(ID::D, sig_d);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2014-12-08 07:59:38 -06:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::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, bool set_polarity, bool clr_polarity, const std::string &src)
|
2014-03-15 08:35:29 -05:00
|
|
|
{
|
2014-07-31 07:34:12 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, stringf("$_DFFSR_%c%c%c_", clk_polarity ? 'P' : 'N', set_polarity ? 'P' : 'N', clr_polarity ? 'P' : 'N'));
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->setPort(ID::C, sig_clk);
|
|
|
|
cell->setPort(ID::S, sig_set);
|
|
|
|
cell->setPort(ID::R, sig_clr);
|
|
|
|
cell->setPort(ID::D, sig_d);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2014-03-15 08:35:29 -05:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-06-23 08:39:25 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::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, bool en_polarity, bool set_polarity, bool clr_polarity, const std::string &src)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = addCell(name, stringf("$_DFFSRE_%c%c%c%c_", clk_polarity ? 'P' : 'N', set_polarity ? 'P' : 'N', clr_polarity ? 'P' : 'N', en_polarity ? 'P' : 'N'));
|
|
|
|
cell->setPort(ID::C, sig_clk);
|
|
|
|
cell->setPort(ID::S, sig_set);
|
|
|
|
cell->setPort(ID::R, sig_clr);
|
|
|
|
cell->setPort(ID::E, sig_en);
|
|
|
|
cell->setPort(ID::D, sig_d);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
|
|
|
cell->set_src_attribute(src);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::addAdffGate(RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_arst, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q,
|
2017-09-09 03:16:48 -05:00
|
|
|
bool arst_value, bool clk_polarity, bool arst_polarity, const std::string &src)
|
2014-03-15 08:35:29 -05:00
|
|
|
{
|
2014-07-31 07:34:12 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, stringf("$_DFF_%c%c%c_", clk_polarity ? 'P' : 'N', arst_polarity ? 'P' : 'N', arst_value ? '1' : '0'));
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->setPort(ID::C, sig_clk);
|
|
|
|
cell->setPort(ID::R, sig_arst);
|
|
|
|
cell->setPort(ID::D, sig_d);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2014-03-15 08:35:29 -05:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-06-23 08:39:25 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::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, bool clk_polarity, bool en_polarity, bool arst_polarity, const std::string &src)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = addCell(name, stringf("$_DFFE_%c%c%c%c_", clk_polarity ? 'P' : 'N', arst_polarity ? 'P' : 'N', arst_value ? '1' : '0', en_polarity ? 'P' : 'N'));
|
|
|
|
cell->setPort(ID::C, sig_clk);
|
|
|
|
cell->setPort(ID::R, sig_arst);
|
|
|
|
cell->setPort(ID::E, sig_en);
|
|
|
|
cell->setPort(ID::D, sig_d);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
|
|
|
cell->set_src_attribute(src);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::Cell* RTLIL::Module::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, bool clk_polarity, bool srst_polarity, const std::string &src)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = addCell(name, stringf("$_SDFF_%c%c%c_", clk_polarity ? 'P' : 'N', srst_polarity ? 'P' : 'N', srst_value ? '1' : '0'));
|
|
|
|
cell->setPort(ID::C, sig_clk);
|
|
|
|
cell->setPort(ID::R, sig_srst);
|
|
|
|
cell->setPort(ID::D, sig_d);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
|
|
|
cell->set_src_attribute(src);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::Cell* RTLIL::Module::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, bool clk_polarity, bool en_polarity, bool srst_polarity, const std::string &src)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = addCell(name, stringf("$_SDFFE_%c%c%c%c_", clk_polarity ? 'P' : 'N', srst_polarity ? 'P' : 'N', srst_value ? '1' : '0', en_polarity ? 'P' : 'N'));
|
|
|
|
cell->setPort(ID::C, sig_clk);
|
|
|
|
cell->setPort(ID::R, sig_srst);
|
|
|
|
cell->setPort(ID::E, sig_en);
|
|
|
|
cell->setPort(ID::D, sig_d);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
|
|
|
cell->set_src_attribute(src);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::Cell* RTLIL::Module::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, bool clk_polarity, bool en_polarity, bool srst_polarity, const std::string &src)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = addCell(name, stringf("$_SDFFCE_%c%c%c%c_", clk_polarity ? 'P' : 'N', srst_polarity ? 'P' : 'N', srst_value ? '1' : '0', en_polarity ? 'P' : 'N'));
|
|
|
|
cell->setPort(ID::C, sig_clk);
|
|
|
|
cell->setPort(ID::R, sig_srst);
|
|
|
|
cell->setPort(ID::E, sig_en);
|
|
|
|
cell->setPort(ID::D, sig_d);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
|
|
|
cell->set_src_attribute(src);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::addDlatchGate(RTLIL::IdString name, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, bool en_polarity, const std::string &src)
|
2014-03-15 08:35:29 -05:00
|
|
|
{
|
2014-07-31 07:34:12 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, stringf("$_DLATCH_%c_", en_polarity ? 'P' : 'N'));
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->setPort(ID::E, sig_en);
|
|
|
|
cell->setPort(ID::D, sig_d);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2014-03-15 08:35:29 -05:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-06-23 08:39:25 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::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, bool en_polarity, bool arst_polarity, const std::string &src)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = addCell(name, stringf("$_DLATCH_%c%c%c_", en_polarity ? 'P' : 'N', arst_polarity ? 'P' : 'N', arst_value ? '1' : '0'));
|
|
|
|
cell->setPort(ID::E, sig_en);
|
|
|
|
cell->setPort(ID::R, sig_arst);
|
|
|
|
cell->setPort(ID::D, sig_d);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
|
|
|
cell->set_src_attribute(src);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::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, bool set_polarity, bool clr_polarity, const std::string &src)
|
2014-03-31 07:14:40 -05:00
|
|
|
{
|
2014-07-31 07:34:12 -05:00
|
|
|
RTLIL::Cell *cell = addCell(name, stringf("$_DLATCHSR_%c%c%c_", en_polarity ? 'P' : 'N', set_polarity ? 'P' : 'N', clr_polarity ? 'P' : 'N'));
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->setPort(ID::E, sig_en);
|
|
|
|
cell->setPort(ID::S, sig_set);
|
|
|
|
cell->setPort(ID::R, sig_clr);
|
|
|
|
cell->setPort(ID::D, sig_d);
|
|
|
|
cell->setPort(ID::Q, sig_q);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2014-03-31 07:14:40 -05:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2017-09-09 03:16:48 -05:00
|
|
|
RTLIL::SigSpec RTLIL::Module::Anyconst(RTLIL::IdString name, int width, const std::string &src)
|
2016-09-07 05:42:16 -05:00
|
|
|
{
|
|
|
|
RTLIL::SigSpec sig = addWire(NEW_ID, width);
|
2019-08-10 05:24:16 -05:00
|
|
|
Cell *cell = addCell(name, ID($anyconst));
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->setParam(ID::WIDTH, width);
|
2019-08-15 16:50:10 -05:00
|
|
|
cell->setPort(ID::Y, sig);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2016-09-07 05:42:16 -05:00
|
|
|
return sig;
|
|
|
|
}
|
|
|
|
|
2017-09-09 03:16:48 -05:00
|
|
|
RTLIL::SigSpec RTLIL::Module::Anyseq(RTLIL::IdString name, int width, const std::string &src)
|
2016-10-14 08:24:03 -05:00
|
|
|
{
|
|
|
|
RTLIL::SigSpec sig = addWire(NEW_ID, width);
|
2019-08-10 05:24:16 -05:00
|
|
|
Cell *cell = addCell(name, ID($anyseq));
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->setParam(ID::WIDTH, width);
|
2019-08-15 16:50:10 -05:00
|
|
|
cell->setPort(ID::Y, sig);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2016-10-14 08:24:03 -05:00
|
|
|
return sig;
|
|
|
|
}
|
|
|
|
|
2018-02-23 06:14:47 -06:00
|
|
|
RTLIL::SigSpec RTLIL::Module::Allconst(RTLIL::IdString name, int width, const std::string &src)
|
|
|
|
{
|
|
|
|
RTLIL::SigSpec sig = addWire(NEW_ID, width);
|
2019-08-10 05:24:16 -05:00
|
|
|
Cell *cell = addCell(name, ID($allconst));
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->setParam(ID::WIDTH, width);
|
2019-08-15 16:50:10 -05:00
|
|
|
cell->setPort(ID::Y, sig);
|
2018-02-23 06:14:47 -06:00
|
|
|
cell->set_src_attribute(src);
|
|
|
|
return sig;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::SigSpec RTLIL::Module::Allseq(RTLIL::IdString name, int width, const std::string &src)
|
|
|
|
{
|
|
|
|
RTLIL::SigSpec sig = addWire(NEW_ID, width);
|
2019-08-10 05:24:16 -05:00
|
|
|
Cell *cell = addCell(name, ID($allseq));
|
2020-04-02 11:51:32 -05:00
|
|
|
cell->setParam(ID::WIDTH, width);
|
2019-08-15 16:50:10 -05:00
|
|
|
cell->setPort(ID::Y, sig);
|
2018-02-23 06:14:47 -06:00
|
|
|
cell->set_src_attribute(src);
|
|
|
|
return sig;
|
|
|
|
}
|
|
|
|
|
2017-09-09 03:16:48 -05:00
|
|
|
RTLIL::SigSpec RTLIL::Module::Initstate(RTLIL::IdString name, const std::string &src)
|
2016-09-07 05:42:16 -05:00
|
|
|
{
|
|
|
|
RTLIL::SigSpec sig = addWire(NEW_ID);
|
2019-08-10 05:24:16 -05:00
|
|
|
Cell *cell = addCell(name, ID($initstate));
|
2019-08-15 16:50:10 -05:00
|
|
|
cell->setPort(ID::Y, sig);
|
2017-09-09 03:16:48 -05:00
|
|
|
cell->set_src_attribute(src);
|
2016-09-07 05:42:16 -05:00
|
|
|
return sig;
|
|
|
|
}
|
2014-03-31 07:14:40 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::Wire::Wire()
|
|
|
|
{
|
2014-12-28 17:12:36 -06:00
|
|
|
static unsigned int hashidx_count = 123456789;
|
|
|
|
hashidx_count = mkhash_xorshift(hashidx_count);
|
|
|
|
hashidx_ = hashidx_count;
|
2014-12-28 10:51:16 -06:00
|
|
|
|
2014-07-31 07:34:12 -05:00
|
|
|
module = nullptr;
|
2013-01-05 04:13:26 -06:00
|
|
|
width = 1;
|
|
|
|
start_offset = 0;
|
|
|
|
port_id = 0;
|
|
|
|
port_input = false;
|
|
|
|
port_output = false;
|
2014-07-28 05:12:13 -05:00
|
|
|
upto = false;
|
2020-04-27 11:44:24 -05:00
|
|
|
is_signed = false;
|
2018-07-09 08:48:06 -05:00
|
|
|
|
|
|
|
#ifdef WITH_PYTHON
|
|
|
|
RTLIL::Wire::get_all_wires()->insert(std::pair<unsigned int, RTLIL::Wire*>(hashidx_, this));
|
|
|
|
#endif
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2018-07-10 01:52:36 -05:00
|
|
|
RTLIL::Wire::~Wire()
|
|
|
|
{
|
|
|
|
#ifdef WITH_PYTHON
|
|
|
|
RTLIL::Wire::get_all_wires()->erase(hashidx_);
|
|
|
|
#endif
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2018-07-09 08:48:06 -05:00
|
|
|
#ifdef WITH_PYTHON
|
2019-04-03 07:27:39 -05:00
|
|
|
static std::map<unsigned int, RTLIL::Wire*> all_wires;
|
2018-07-09 08:48:06 -05:00
|
|
|
std::map<unsigned int, RTLIL::Wire*> *RTLIL::Wire::get_all_wires(void)
|
|
|
|
{
|
2019-04-03 07:27:39 -05:00
|
|
|
return &all_wires;
|
2018-07-09 08:48:06 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::Memory::Memory()
|
|
|
|
{
|
2014-12-28 17:12:36 -06:00
|
|
|
static unsigned int hashidx_count = 123456789;
|
|
|
|
hashidx_count = mkhash_xorshift(hashidx_count);
|
|
|
|
hashidx_ = hashidx_count;
|
2014-12-28 10:51:16 -06:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
width = 1;
|
2017-01-25 10:00:59 -06:00
|
|
|
start_offset = 0;
|
2013-01-05 04:13:26 -06:00
|
|
|
size = 0;
|
2018-08-13 08:18:46 -05:00
|
|
|
#ifdef WITH_PYTHON
|
|
|
|
RTLIL::Memory::get_all_memorys()->insert(std::pair<unsigned int, RTLIL::Memory*>(hashidx_, this));
|
|
|
|
#endif
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2014-08-22 09:09:13 -05:00
|
|
|
RTLIL::Cell::Cell() : module(nullptr)
|
|
|
|
{
|
2014-12-28 17:12:36 -06:00
|
|
|
static unsigned int hashidx_count = 123456789;
|
|
|
|
hashidx_count = mkhash_xorshift(hashidx_count);
|
|
|
|
hashidx_ = hashidx_count;
|
2014-12-28 14:27:51 -06:00
|
|
|
|
|
|
|
// log("#memtrace# %p\n", this);
|
|
|
|
memhasher();
|
2018-07-09 08:48:06 -05:00
|
|
|
|
|
|
|
#ifdef WITH_PYTHON
|
|
|
|
RTLIL::Cell::get_all_cells()->insert(std::pair<unsigned int, RTLIL::Cell*>(hashidx_, this));
|
|
|
|
#endif
|
2014-08-22 09:09:13 -05:00
|
|
|
}
|
|
|
|
|
2018-07-10 01:52:36 -05:00
|
|
|
RTLIL::Cell::~Cell()
|
|
|
|
{
|
|
|
|
#ifdef WITH_PYTHON
|
|
|
|
RTLIL::Cell::get_all_cells()->erase(hashidx_);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-07-09 08:48:06 -05:00
|
|
|
#ifdef WITH_PYTHON
|
2019-04-03 07:27:39 -05:00
|
|
|
static std::map<unsigned int, RTLIL::Cell*> all_cells;
|
2018-07-09 08:48:06 -05:00
|
|
|
std::map<unsigned int, RTLIL::Cell*> *RTLIL::Cell::get_all_cells(void)
|
|
|
|
{
|
2019-04-03 07:27:39 -05:00
|
|
|
return &all_cells;
|
2014-08-22 09:09:13 -05:00
|
|
|
}
|
2018-07-09 08:48:06 -05:00
|
|
|
#endif
|
2014-08-22 09:09:13 -05:00
|
|
|
|
2014-07-31 09:38:54 -05:00
|
|
|
bool RTLIL::Cell::hasPort(RTLIL::IdString portname) const
|
2014-07-26 09:11:28 -05:00
|
|
|
{
|
|
|
|
return connections_.count(portname) != 0;
|
|
|
|
}
|
|
|
|
|
2014-07-31 09:38:54 -05:00
|
|
|
void RTLIL::Cell::unsetPort(RTLIL::IdString portname)
|
2014-07-26 05:22:58 -05:00
|
|
|
{
|
2014-08-01 09:53:15 -05:00
|
|
|
RTLIL::SigSpec signal;
|
|
|
|
auto conn_it = connections_.find(portname);
|
2014-07-31 07:34:12 -05:00
|
|
|
|
2014-08-01 09:53:15 -05:00
|
|
|
if (conn_it != connections_.end())
|
|
|
|
{
|
|
|
|
for (auto mon : module->monitors)
|
|
|
|
mon->notify_connect(this, conn_it->first, conn_it->second, signal);
|
2014-07-31 07:34:12 -05:00
|
|
|
|
2014-08-01 09:53:15 -05:00
|
|
|
if (module->design)
|
|
|
|
for (auto mon : module->design->monitors)
|
|
|
|
mon->notify_connect(this, conn_it->first, conn_it->second, signal);
|
2014-07-31 07:34:12 -05:00
|
|
|
|
2014-12-29 06:33:33 -06:00
|
|
|
if (yosys_xtrace) {
|
|
|
|
log("#X# Unconnect %s.%s.%s\n", log_id(this->module), log_id(this), log_id(portname));
|
|
|
|
log_backtrace("-X- ", yosys_xtrace-1);
|
|
|
|
}
|
|
|
|
|
2014-08-01 09:53:15 -05:00
|
|
|
connections_.erase(conn_it);
|
|
|
|
}
|
2014-07-26 05:22:58 -05:00
|
|
|
}
|
|
|
|
|
2014-07-31 09:38:54 -05:00
|
|
|
void RTLIL::Cell::setPort(RTLIL::IdString portname, RTLIL::SigSpec signal)
|
2014-07-26 05:22:58 -05:00
|
|
|
{
|
2020-03-18 10:48:36 -05:00
|
|
|
auto r = connections_.insert(portname);
|
|
|
|
auto conn_it = r.first;
|
2020-03-26 16:33:06 -05:00
|
|
|
if (!r.second && conn_it->second == signal)
|
2015-01-17 05:04:40 -06:00
|
|
|
return;
|
2014-07-31 07:34:12 -05:00
|
|
|
|
|
|
|
for (auto mon : module->monitors)
|
2014-08-01 09:53:15 -05:00
|
|
|
mon->notify_connect(this, conn_it->first, conn_it->second, signal);
|
2014-07-31 07:34:12 -05:00
|
|
|
|
|
|
|
if (module->design)
|
|
|
|
for (auto mon : module->design->monitors)
|
2014-08-01 09:53:15 -05:00
|
|
|
mon->notify_connect(this, conn_it->first, conn_it->second, signal);
|
2014-07-31 07:34:12 -05:00
|
|
|
|
2014-12-29 06:33:33 -06:00
|
|
|
if (yosys_xtrace) {
|
|
|
|
log("#X# Connect %s.%s.%s = %s (%d)\n", log_id(this->module), log_id(this), log_id(portname), log_signal(signal), GetSize(signal));
|
|
|
|
log_backtrace("-X- ", yosys_xtrace-1);
|
|
|
|
}
|
|
|
|
|
2020-03-26 16:33:06 -05:00
|
|
|
conn_it->second = std::move(signal);
|
2014-07-26 05:22:58 -05:00
|
|
|
}
|
|
|
|
|
2014-07-31 09:38:54 -05:00
|
|
|
const RTLIL::SigSpec &RTLIL::Cell::getPort(RTLIL::IdString portname) const
|
2014-07-26 05:22:58 -05:00
|
|
|
{
|
|
|
|
return connections_.at(portname);
|
|
|
|
}
|
|
|
|
|
2014-12-26 03:53:21 -06:00
|
|
|
const dict<RTLIL::IdString, RTLIL::SigSpec> &RTLIL::Cell::connections() const
|
2014-07-26 05:22:58 -05:00
|
|
|
{
|
|
|
|
return connections_;
|
|
|
|
}
|
|
|
|
|
2015-02-07 04:40:19 -06:00
|
|
|
bool RTLIL::Cell::known() const
|
|
|
|
{
|
|
|
|
if (yosys_celltypes.cell_known(type))
|
|
|
|
return true;
|
|
|
|
if (module && module->design && module->design->module(type))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RTLIL::Cell::input(RTLIL::IdString portname) const
|
|
|
|
{
|
|
|
|
if (yosys_celltypes.cell_known(type))
|
|
|
|
return yosys_celltypes.cell_input(type, portname);
|
|
|
|
if (module && module->design) {
|
|
|
|
RTLIL::Module *m = module->design->module(type);
|
|
|
|
RTLIL::Wire *w = m ? m->wire(portname) : nullptr;
|
|
|
|
return w && w->port_input;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RTLIL::Cell::output(RTLIL::IdString portname) const
|
|
|
|
{
|
|
|
|
if (yosys_celltypes.cell_known(type))
|
|
|
|
return yosys_celltypes.cell_output(type, portname);
|
|
|
|
if (module && module->design) {
|
|
|
|
RTLIL::Module *m = module->design->module(type);
|
|
|
|
RTLIL::Wire *w = m ? m->wire(portname) : nullptr;
|
|
|
|
return w && w->port_output;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-31 09:38:54 -05:00
|
|
|
bool RTLIL::Cell::hasParam(RTLIL::IdString paramname) const
|
|
|
|
{
|
2014-10-18 08:20:38 -05:00
|
|
|
return parameters.count(paramname) != 0;
|
2014-07-31 09:38:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void RTLIL::Cell::unsetParam(RTLIL::IdString paramname)
|
|
|
|
{
|
|
|
|
parameters.erase(paramname);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RTLIL::Cell::setParam(RTLIL::IdString paramname, RTLIL::Const value)
|
|
|
|
{
|
2020-03-26 16:33:06 -05:00
|
|
|
parameters[paramname] = std::move(value);
|
2014-07-31 09:38:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const RTLIL::Const &RTLIL::Cell::getParam(RTLIL::IdString paramname) const
|
|
|
|
{
|
2020-04-16 14:48:21 -05:00
|
|
|
const auto &it = parameters.find(paramname);
|
|
|
|
if (it != parameters.end())
|
|
|
|
return it->second;
|
|
|
|
if (module && module->design) {
|
|
|
|
RTLIL::Module *m = module->design->module(type);
|
|
|
|
if (m)
|
2020-04-22 14:07:08 -05:00
|
|
|
return m->parameter_default_values.at(paramname);
|
2020-04-16 14:48:21 -05:00
|
|
|
}
|
2020-04-22 14:07:08 -05:00
|
|
|
throw std::out_of_range("Cell::getParam()");
|
2014-07-31 09:38:54 -05:00
|
|
|
}
|
|
|
|
|
2015-01-23 17:13:27 -06:00
|
|
|
void RTLIL::Cell::sort()
|
|
|
|
{
|
|
|
|
connections_.sort(sort_by_id_str());
|
|
|
|
parameters.sort(sort_by_id_str());
|
|
|
|
attributes.sort(sort_by_id_str());
|
|
|
|
}
|
|
|
|
|
2014-07-21 05:02:55 -05:00
|
|
|
void RTLIL::Cell::check()
|
|
|
|
{
|
2014-07-23 14:38:18 -05:00
|
|
|
#ifndef NDEBUG
|
2014-07-21 05:02:55 -05:00
|
|
|
InternalCellChecker checker(NULL, this);
|
|
|
|
checker.check();
|
2014-07-23 14:38:18 -05:00
|
|
|
#endif
|
2014-07-21 05:02:55 -05:00
|
|
|
}
|
|
|
|
|
2014-07-26 05:22:58 -05:00
|
|
|
void RTLIL::Cell::fixup_parameters(bool set_a_signed, bool set_b_signed)
|
|
|
|
{
|
2019-08-06 21:07:45 -05:00
|
|
|
if (!type.begins_with("$") || type.begins_with("$_") || type.begins_with("$paramod") || type.begins_with("$fmcombine") ||
|
2019-08-06 18:42:25 -05:00
|
|
|
type.begins_with("$verific$") || type.begins_with("$array:") || type.begins_with("$extern:"))
|
2014-07-26 05:22:58 -05:00
|
|
|
return;
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (type == ID($mux) || type == ID($pmux)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
parameters[ID::WIDTH] = GetSize(connections_[ID::Y]);
|
2019-08-10 05:24:16 -05:00
|
|
|
if (type == ID($pmux))
|
2020-04-02 11:51:32 -05:00
|
|
|
parameters[ID::S_WIDTH] = GetSize(connections_[ID::S]);
|
2014-07-26 05:22:58 -05:00
|
|
|
check();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (type == ID($lut) || type == ID($sop)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
parameters[ID::WIDTH] = GetSize(connections_[ID::A]);
|
2014-08-31 10:06:36 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (type == ID($fa)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
parameters[ID::WIDTH] = GetSize(connections_[ID::Y]);
|
2014-09-08 05:15:39 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
if (type == ID($lcu)) {
|
2020-04-02 11:51:32 -05:00
|
|
|
parameters[ID::WIDTH] = GetSize(connections_[ID::CO]);
|
2014-09-08 06:28:23 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:24:16 -05:00
|
|
|
bool signedness_ab = !type.in(ID($slice), ID($concat), ID($macc));
|
2014-07-26 05:22:58 -05:00
|
|
|
|
2019-08-15 16:50:10 -05:00
|
|
|
if (connections_.count(ID::A)) {
|
2014-07-26 05:22:58 -05:00
|
|
|
if (signedness_ab) {
|
|
|
|
if (set_a_signed)
|
2020-04-02 11:51:32 -05:00
|
|
|
parameters[ID::A_SIGNED] = true;
|
|
|
|
else if (parameters.count(ID::A_SIGNED) == 0)
|
|
|
|
parameters[ID::A_SIGNED] = false;
|
2014-07-26 05:22:58 -05:00
|
|
|
}
|
2020-04-02 11:51:32 -05:00
|
|
|
parameters[ID::A_WIDTH] = GetSize(connections_[ID::A]);
|
2014-07-26 05:22:58 -05:00
|
|
|
}
|
|
|
|
|
2019-08-15 16:50:10 -05:00
|
|
|
if (connections_.count(ID::B)) {
|
2014-07-26 05:22:58 -05:00
|
|
|
if (signedness_ab) {
|
|
|
|
if (set_b_signed)
|
2020-04-02 11:51:32 -05:00
|
|
|
parameters[ID::B_SIGNED] = true;
|
|
|
|
else if (parameters.count(ID::B_SIGNED) == 0)
|
|
|
|
parameters[ID::B_SIGNED] = false;
|
2014-07-26 05:22:58 -05:00
|
|
|
}
|
2020-04-02 11:51:32 -05:00
|
|
|
parameters[ID::B_WIDTH] = GetSize(connections_[ID::B]);
|
2014-07-26 05:22:58 -05:00
|
|
|
}
|
|
|
|
|
2019-08-15 16:50:10 -05:00
|
|
|
if (connections_.count(ID::Y))
|
2020-04-02 11:51:32 -05:00
|
|
|
parameters[ID::Y_WIDTH] = GetSize(connections_[ID::Y]);
|
2014-07-26 05:22:58 -05:00
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (connections_.count(ID::Q))
|
|
|
|
parameters[ID::WIDTH] = GetSize(connections_[ID::Q]);
|
2019-02-20 09:36:42 -06:00
|
|
|
|
2014-07-26 05:22:58 -05:00
|
|
|
check();
|
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::SigChunk::SigChunk()
|
|
|
|
{
|
|
|
|
wire = NULL;
|
|
|
|
width = 0;
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
|
2014-07-23 01:59:54 -05:00
|
|
|
RTLIL::SigChunk::SigChunk(const RTLIL::Const &value)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
|
|
|
wire = NULL;
|
2014-09-01 04:36:02 -05:00
|
|
|
data = value.bits;
|
2014-10-10 09:59:44 -05:00
|
|
|
width = GetSize(data);
|
2013-01-05 04:13:26 -06:00
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
|
2014-07-23 02:00:16 -05:00
|
|
|
RTLIL::SigChunk::SigChunk(RTLIL::Wire *wire)
|
|
|
|
{
|
2014-07-27 04:03:56 -05:00
|
|
|
log_assert(wire != nullptr);
|
2014-07-23 02:00:16 -05:00
|
|
|
this->wire = wire;
|
|
|
|
this->width = wire->width;
|
|
|
|
this->offset = 0;
|
|
|
|
}
|
|
|
|
|
2014-07-23 02:48:26 -05:00
|
|
|
RTLIL::SigChunk::SigChunk(RTLIL::Wire *wire, int offset, int width)
|
2014-07-23 02:00:16 -05:00
|
|
|
{
|
2014-07-27 04:03:56 -05:00
|
|
|
log_assert(wire != nullptr);
|
2014-07-23 02:48:26 -05:00
|
|
|
this->wire = wire;
|
|
|
|
this->width = width;
|
|
|
|
this->offset = offset;
|
2014-07-23 02:00:16 -05:00
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::SigChunk::SigChunk(const std::string &str)
|
|
|
|
{
|
|
|
|
wire = NULL;
|
2014-09-01 04:36:02 -05:00
|
|
|
data = RTLIL::Const(str).bits;
|
2014-10-10 09:59:44 -05:00
|
|
|
width = GetSize(data);
|
2013-01-05 04:13:26 -06:00
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::SigChunk::SigChunk(int val, int width)
|
|
|
|
{
|
|
|
|
wire = NULL;
|
2014-09-01 04:36:02 -05:00
|
|
|
data = RTLIL::Const(val, width).bits;
|
2014-10-10 09:59:44 -05:00
|
|
|
this->width = GetSize(data);
|
2013-01-05 04:13:26 -06:00
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::SigChunk::SigChunk(RTLIL::State bit, int width)
|
|
|
|
{
|
|
|
|
wire = NULL;
|
2014-09-01 04:36:02 -05:00
|
|
|
data = RTLIL::Const(bit, width).bits;
|
2014-10-10 09:59:44 -05:00
|
|
|
this->width = GetSize(data);
|
2013-01-05 04:13:26 -06:00
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::SigChunk::SigChunk(const RTLIL::SigBit &bit)
|
2013-11-21 21:07:13 -06:00
|
|
|
{
|
|
|
|
wire = bit.wire;
|
2014-08-01 08:25:42 -05:00
|
|
|
offset = 0;
|
2013-11-21 21:07:13 -06:00
|
|
|
if (wire == NULL)
|
2014-09-01 04:36:02 -05:00
|
|
|
data = RTLIL::Const(bit.data).bits;
|
2014-08-01 08:25:42 -05:00
|
|
|
else
|
|
|
|
offset = bit.offset;
|
2013-11-21 21:07:13 -06:00
|
|
|
width = 1;
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
RTLIL::SigChunk::SigChunk(const RTLIL::SigChunk &sigchunk)
|
2018-08-13 08:18:46 -05:00
|
|
|
{
|
2020-03-18 13:51:00 -05:00
|
|
|
*this = sigchunk;
|
2018-08-13 08:18:46 -05:00
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::SigChunk RTLIL::SigChunk::extract(int offset, int length) const
|
|
|
|
{
|
|
|
|
RTLIL::SigChunk ret;
|
|
|
|
if (wire) {
|
|
|
|
ret.wire = wire;
|
|
|
|
ret.offset = this->offset + offset;
|
|
|
|
ret.width = length;
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < length; i++)
|
2014-09-01 04:36:02 -05:00
|
|
|
ret.data.push_back(data[offset+i]);
|
2013-01-05 04:13:26 -06:00
|
|
|
ret.width = length;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RTLIL::SigChunk::operator <(const RTLIL::SigChunk &other) const
|
|
|
|
{
|
|
|
|
if (wire && other.wire)
|
|
|
|
if (wire->name != other.wire->name)
|
|
|
|
return wire->name < other.wire->name;
|
2014-07-22 14:40:52 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
if (wire != other.wire)
|
|
|
|
return wire < other.wire;
|
|
|
|
|
|
|
|
if (offset != other.offset)
|
|
|
|
return offset < other.offset;
|
|
|
|
|
|
|
|
if (width != other.width)
|
|
|
|
return width < other.width;
|
|
|
|
|
2014-09-01 04:36:02 -05:00
|
|
|
return data < other.data;
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RTLIL::SigChunk::operator ==(const RTLIL::SigChunk &other) const
|
|
|
|
{
|
2014-09-01 04:36:02 -05:00
|
|
|
return wire == other.wire && width == other.width && offset == other.offset && data == other.data;
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RTLIL::SigChunk::operator !=(const RTLIL::SigChunk &other) const
|
|
|
|
{
|
|
|
|
if (*this == other)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::SigSpec::SigSpec()
|
|
|
|
{
|
2014-07-22 13:12:15 -05:00
|
|
|
width_ = 0;
|
2014-07-23 16:58:03 -05:00
|
|
|
hash_ = 0;
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2014-07-26 06:59:30 -05:00
|
|
|
RTLIL::SigSpec::SigSpec(const RTLIL::SigSpec &other)
|
|
|
|
{
|
|
|
|
*this = other;
|
|
|
|
}
|
|
|
|
|
2014-07-28 03:52:58 -05:00
|
|
|
RTLIL::SigSpec::SigSpec(std::initializer_list<RTLIL::SigSpec> parts)
|
|
|
|
{
|
|
|
|
cover("kernel.rtlil.sigspec.init.list");
|
|
|
|
|
|
|
|
width_ = 0;
|
|
|
|
hash_ = 0;
|
|
|
|
|
2020-03-13 10:17:39 -05:00
|
|
|
log_assert(parts.size() > 0);
|
|
|
|
auto ie = parts.begin();
|
|
|
|
auto it = ie + parts.size() - 1;
|
|
|
|
while (it >= ie)
|
|
|
|
append(*it--);
|
2014-07-28 03:52:58 -05:00
|
|
|
}
|
|
|
|
|
2020-03-18 13:51:00 -05:00
|
|
|
RTLIL::SigSpec &RTLIL::SigSpec::operator=(const RTLIL::SigSpec &other)
|
2014-07-26 06:59:30 -05:00
|
|
|
{
|
|
|
|
cover("kernel.rtlil.sigspec.assign");
|
|
|
|
|
|
|
|
width_ = other.width_;
|
|
|
|
hash_ = other.hash_;
|
|
|
|
chunks_ = other.chunks_;
|
2020-03-18 13:51:00 -05:00
|
|
|
bits_ = other.bits_;
|
2014-07-26 06:59:30 -05:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-07-23 01:59:54 -05:00
|
|
|
RTLIL::SigSpec::SigSpec(const RTLIL::Const &value)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2014-07-28 03:52:30 -05:00
|
|
|
cover("kernel.rtlil.sigspec.init.const");
|
|
|
|
|
2020-03-13 10:17:39 -05:00
|
|
|
chunks_.emplace_back(value);
|
2014-07-22 13:12:15 -05:00
|
|
|
width_ = chunks_.back().width;
|
2014-07-23 16:58:03 -05:00
|
|
|
hash_ = 0;
|
2013-01-05 04:13:26 -06:00
|
|
|
check();
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::SigSpec::SigSpec(const RTLIL::SigChunk &chunk)
|
|
|
|
{
|
2014-07-28 03:52:30 -05:00
|
|
|
cover("kernel.rtlil.sigspec.init.chunk");
|
|
|
|
|
2020-03-13 10:17:39 -05:00
|
|
|
chunks_.emplace_back(chunk);
|
2014-07-22 13:12:15 -05:00
|
|
|
width_ = chunks_.back().width;
|
2014-07-23 16:58:03 -05:00
|
|
|
hash_ = 0;
|
2013-01-05 04:13:26 -06:00
|
|
|
check();
|
|
|
|
}
|
|
|
|
|
2014-07-23 02:00:16 -05:00
|
|
|
RTLIL::SigSpec::SigSpec(RTLIL::Wire *wire)
|
|
|
|
{
|
2014-07-28 03:52:30 -05:00
|
|
|
cover("kernel.rtlil.sigspec.init.wire");
|
|
|
|
|
2020-03-13 10:17:39 -05:00
|
|
|
chunks_.emplace_back(wire);
|
2014-07-23 02:00:16 -05:00
|
|
|
width_ = chunks_.back().width;
|
2014-07-23 16:58:03 -05:00
|
|
|
hash_ = 0;
|
2014-07-23 02:00:16 -05:00
|
|
|
check();
|
|
|
|
}
|
|
|
|
|
2014-07-23 02:48:26 -05:00
|
|
|
RTLIL::SigSpec::SigSpec(RTLIL::Wire *wire, int offset, int width)
|
2014-07-23 02:00:16 -05:00
|
|
|
{
|
2014-07-28 03:52:30 -05:00
|
|
|
cover("kernel.rtlil.sigspec.init.wire_part");
|
|
|
|
|
2020-03-13 10:17:39 -05:00
|
|
|
chunks_.emplace_back(wire, offset, width);
|
2014-07-23 02:48:26 -05:00
|
|
|
width_ = chunks_.back().width;
|
2014-07-23 16:58:03 -05:00
|
|
|
hash_ = 0;
|
2014-07-23 02:48:26 -05:00
|
|
|
check();
|
2014-07-23 02:00:16 -05:00
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::SigSpec::SigSpec(const std::string &str)
|
|
|
|
{
|
2014-07-28 03:52:30 -05:00
|
|
|
cover("kernel.rtlil.sigspec.init.str");
|
|
|
|
|
2020-03-13 10:17:39 -05:00
|
|
|
chunks_.emplace_back(str);
|
2014-07-22 13:12:15 -05:00
|
|
|
width_ = chunks_.back().width;
|
2014-07-23 16:58:03 -05:00
|
|
|
hash_ = 0;
|
2013-01-05 04:13:26 -06:00
|
|
|
check();
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::SigSpec::SigSpec(int val, int width)
|
|
|
|
{
|
2014-07-28 03:52:30 -05:00
|
|
|
cover("kernel.rtlil.sigspec.init.int");
|
|
|
|
|
2020-03-13 10:17:39 -05:00
|
|
|
chunks_.emplace_back(val, width);
|
2014-07-22 13:12:15 -05:00
|
|
|
width_ = width;
|
2014-07-23 16:58:03 -05:00
|
|
|
hash_ = 0;
|
2013-01-05 04:13:26 -06:00
|
|
|
check();
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::SigSpec::SigSpec(RTLIL::State bit, int width)
|
|
|
|
{
|
2014-07-28 03:52:30 -05:00
|
|
|
cover("kernel.rtlil.sigspec.init.state");
|
|
|
|
|
2020-03-13 10:17:39 -05:00
|
|
|
chunks_.emplace_back(bit, width);
|
2014-07-22 13:12:15 -05:00
|
|
|
width_ = width;
|
2014-07-23 16:58:03 -05:00
|
|
|
hash_ = 0;
|
2013-11-21 21:07:13 -06:00
|
|
|
check();
|
|
|
|
}
|
|
|
|
|
2020-03-13 10:17:39 -05:00
|
|
|
RTLIL::SigSpec::SigSpec(const RTLIL::SigBit &bit, int width)
|
2013-11-21 21:07:13 -06:00
|
|
|
{
|
2014-07-28 03:52:30 -05:00
|
|
|
cover("kernel.rtlil.sigspec.init.bit");
|
|
|
|
|
2013-11-21 21:07:13 -06:00
|
|
|
if (bit.wire == NULL)
|
2020-03-13 10:17:39 -05:00
|
|
|
chunks_.emplace_back(bit.data, width);
|
2013-11-21 21:07:13 -06:00
|
|
|
else
|
|
|
|
for (int i = 0; i < width; i++)
|
2014-07-22 13:12:15 -05:00
|
|
|
chunks_.push_back(bit);
|
|
|
|
width_ = width;
|
2014-07-23 16:58:03 -05:00
|
|
|
hash_ = 0;
|
2013-11-21 21:07:13 -06:00
|
|
|
check();
|
|
|
|
}
|
|
|
|
|
2020-03-13 10:17:39 -05:00
|
|
|
RTLIL::SigSpec::SigSpec(const std::vector<RTLIL::SigChunk> &chunks)
|
2014-07-22 16:50:21 -05:00
|
|
|
{
|
2014-07-28 03:52:30 -05:00
|
|
|
cover("kernel.rtlil.sigspec.init.stdvec_chunks");
|
|
|
|
|
2014-07-22 16:50:21 -05:00
|
|
|
width_ = 0;
|
2014-07-23 16:58:03 -05:00
|
|
|
hash_ = 0;
|
2020-03-13 10:17:39 -05:00
|
|
|
for (const auto &c : chunks)
|
2014-07-22 16:50:21 -05:00
|
|
|
append(c);
|
|
|
|
check();
|
|
|
|
}
|
|
|
|
|
2020-03-13 10:17:39 -05:00
|
|
|
RTLIL::SigSpec::SigSpec(const std::vector<RTLIL::SigBit> &bits)
|
2013-11-21 21:07:13 -06:00
|
|
|
{
|
2014-07-28 03:52:30 -05:00
|
|
|
cover("kernel.rtlil.sigspec.init.stdvec_bits");
|
|
|
|
|
2014-07-22 13:12:15 -05:00
|
|
|
width_ = 0;
|
2014-07-23 16:58:03 -05:00
|
|
|
hash_ = 0;
|
2020-03-13 10:17:39 -05:00
|
|
|
for (const auto &bit : bits)
|
|
|
|
append(bit);
|
2014-07-20 04:00:09 -05:00
|
|
|
check();
|
|
|
|
}
|
|
|
|
|
2020-03-13 10:17:39 -05:00
|
|
|
RTLIL::SigSpec::SigSpec(const pool<RTLIL::SigBit> &bits)
|
2014-12-26 03:53:21 -06:00
|
|
|
{
|
2014-12-26 14:59:41 -06:00
|
|
|
cover("kernel.rtlil.sigspec.init.pool_bits");
|
2014-12-26 03:53:21 -06:00
|
|
|
|
|
|
|
width_ = 0;
|
|
|
|
hash_ = 0;
|
2020-03-13 10:17:39 -05:00
|
|
|
for (const auto &bit : bits)
|
|
|
|
append(bit);
|
2014-12-26 03:53:21 -06:00
|
|
|
check();
|
|
|
|
}
|
|
|
|
|
2020-03-13 10:17:39 -05:00
|
|
|
RTLIL::SigSpec::SigSpec(const std::set<RTLIL::SigBit> &bits)
|
2014-07-20 04:00:09 -05:00
|
|
|
{
|
2014-07-28 03:52:30 -05:00
|
|
|
cover("kernel.rtlil.sigspec.init.stdset_bits");
|
|
|
|
|
2014-07-22 13:12:15 -05:00
|
|
|
width_ = 0;
|
2014-07-23 16:58:03 -05:00
|
|
|
hash_ = 0;
|
2020-03-13 10:17:39 -05:00
|
|
|
for (const auto &bit : bits)
|
|
|
|
append(bit);
|
2013-01-05 04:13:26 -06:00
|
|
|
check();
|
|
|
|
}
|
|
|
|
|
2014-12-08 08:08:02 -06:00
|
|
|
RTLIL::SigSpec::SigSpec(bool bit)
|
|
|
|
{
|
|
|
|
cover("kernel.rtlil.sigspec.init.bool");
|
|
|
|
|
|
|
|
width_ = 0;
|
|
|
|
hash_ = 0;
|
2020-03-13 10:17:39 -05:00
|
|
|
append(SigBit(bit));
|
2014-12-08 08:08:02 -06:00
|
|
|
check();
|
|
|
|
}
|
|
|
|
|
2014-07-22 14:33:52 -05:00
|
|
|
void RTLIL::SigSpec::pack() const
|
|
|
|
{
|
|
|
|
RTLIL::SigSpec *that = (RTLIL::SigSpec*)this;
|
|
|
|
|
|
|
|
if (that->bits_.empty())
|
|
|
|
return;
|
|
|
|
|
2014-07-24 08:05:41 -05:00
|
|
|
cover("kernel.rtlil.sigspec.convert.pack");
|
2014-07-22 14:33:52 -05:00
|
|
|
log_assert(that->chunks_.empty());
|
|
|
|
|
|
|
|
std::vector<RTLIL::SigBit> old_bits;
|
|
|
|
old_bits.swap(that->bits_);
|
|
|
|
|
2014-07-26 06:59:30 -05:00
|
|
|
RTLIL::SigChunk *last = NULL;
|
|
|
|
int last_end_offset = 0;
|
|
|
|
|
|
|
|
for (auto &bit : old_bits) {
|
|
|
|
if (last && bit.wire == last->wire) {
|
|
|
|
if (bit.wire == NULL) {
|
2014-09-01 04:36:02 -05:00
|
|
|
last->data.push_back(bit.data);
|
2014-07-26 06:59:30 -05:00
|
|
|
last->width++;
|
|
|
|
continue;
|
|
|
|
} else if (last_end_offset == bit.offset) {
|
|
|
|
last_end_offset++;
|
|
|
|
last->width++;
|
|
|
|
continue;
|
|
|
|
}
|
2014-07-24 08:05:41 -05:00
|
|
|
}
|
2014-07-26 06:59:30 -05:00
|
|
|
that->chunks_.push_back(bit);
|
|
|
|
last = &that->chunks_.back();
|
|
|
|
last_end_offset = bit.offset + 1;
|
|
|
|
}
|
2014-07-24 08:05:41 -05:00
|
|
|
|
|
|
|
check();
|
2014-07-22 14:33:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void RTLIL::SigSpec::unpack() const
|
|
|
|
{
|
|
|
|
RTLIL::SigSpec *that = (RTLIL::SigSpec*)this;
|
|
|
|
|
|
|
|
if (that->chunks_.empty())
|
|
|
|
return;
|
|
|
|
|
2014-07-24 08:05:41 -05:00
|
|
|
cover("kernel.rtlil.sigspec.convert.unpack");
|
2014-07-22 14:33:52 -05:00
|
|
|
log_assert(that->bits_.empty());
|
|
|
|
|
|
|
|
that->bits_.reserve(that->width_);
|
|
|
|
for (auto &c : that->chunks_)
|
|
|
|
for (int i = 0; i < c.width; i++)
|
2020-03-18 13:51:00 -05:00
|
|
|
that->bits_.emplace_back(c, i);
|
2014-07-22 14:33:52 -05:00
|
|
|
|
|
|
|
that->chunks_.clear();
|
2014-07-23 16:58:03 -05:00
|
|
|
that->hash_ = 0;
|
2014-07-22 14:33:52 -05:00
|
|
|
}
|
|
|
|
|
2014-12-26 14:35:22 -06:00
|
|
|
void RTLIL::SigSpec::updhash() const
|
2014-07-22 14:33:52 -05:00
|
|
|
{
|
2014-07-23 16:58:03 -05:00
|
|
|
RTLIL::SigSpec *that = (RTLIL::SigSpec*)this;
|
|
|
|
|
|
|
|
if (that->hash_ != 0)
|
|
|
|
return;
|
|
|
|
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.hash");
|
2014-07-23 16:58:03 -05:00
|
|
|
that->pack();
|
|
|
|
|
2014-12-30 11:51:24 -06:00
|
|
|
that->hash_ = mkhash_init;
|
2014-07-23 16:58:03 -05:00
|
|
|
for (auto &c : that->chunks_)
|
|
|
|
if (c.wire == NULL) {
|
2014-09-01 04:36:02 -05:00
|
|
|
for (auto &v : c.data)
|
2014-12-27 05:02:57 -06:00
|
|
|
that->hash_ = mkhash(that->hash_, v);
|
2014-07-23 16:58:03 -05:00
|
|
|
} else {
|
2014-12-27 05:02:57 -06:00
|
|
|
that->hash_ = mkhash(that->hash_, c.wire->name.index_);
|
|
|
|
that->hash_ = mkhash(that->hash_, c.offset);
|
|
|
|
that->hash_ = mkhash(that->hash_, c.width);
|
2014-07-23 16:58:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (that->hash_ == 0)
|
|
|
|
that->hash_ = 1;
|
2014-07-22 14:33:52 -05:00
|
|
|
}
|
|
|
|
|
2013-03-29 05:19:21 -05:00
|
|
|
void RTLIL::SigSpec::sort()
|
|
|
|
{
|
2014-07-22 15:26:30 -05:00
|
|
|
unpack();
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.sort");
|
2014-07-22 15:26:30 -05:00
|
|
|
std::sort(bits_.begin(), bits_.end());
|
2013-03-29 05:19:21 -05:00
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
void RTLIL::SigSpec::sort_and_unify()
|
|
|
|
{
|
2016-01-31 10:55:49 -06:00
|
|
|
unpack();
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.sort_and_unify");
|
2016-01-31 10:55:49 -06:00
|
|
|
|
|
|
|
// A copy of the bits vector is used to prevent duplicating the logic from
|
|
|
|
// SigSpec::SigSpec(std::vector<SigBit>). This incurrs an extra copy but
|
|
|
|
// that isn't showing up as significant in profiles.
|
|
|
|
std::vector<SigBit> unique_bits = bits_;
|
|
|
|
std::sort(unique_bits.begin(), unique_bits.end());
|
|
|
|
auto last = std::unique(unique_bits.begin(), unique_bits.end());
|
|
|
|
unique_bits.erase(last, unique_bits.end());
|
|
|
|
|
|
|
|
*this = unique_bits;
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void RTLIL::SigSpec::replace(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec &with)
|
|
|
|
{
|
|
|
|
replace(pattern, with, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RTLIL::SigSpec::replace(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec &with, RTLIL::SigSpec *other) const
|
|
|
|
{
|
2016-01-30 21:43:29 -06:00
|
|
|
log_assert(other != NULL);
|
|
|
|
log_assert(width_ == other->width_);
|
2014-08-14 15:32:18 -05:00
|
|
|
log_assert(pattern.width_ == with.width_);
|
2014-07-23 20:50:28 -05:00
|
|
|
|
2014-07-22 15:26:30 -05:00
|
|
|
pattern.unpack();
|
|
|
|
with.unpack();
|
2016-01-30 21:43:29 -06:00
|
|
|
unpack();
|
|
|
|
other->unpack();
|
2014-07-22 14:33:52 -05:00
|
|
|
|
2016-01-30 21:43:29 -06:00
|
|
|
for (int i = 0; i < GetSize(pattern.bits_); i++) {
|
|
|
|
if (pattern.bits_[i].wire != NULL) {
|
|
|
|
for (int j = 0; j < GetSize(bits_); j++) {
|
|
|
|
if (bits_[j] == pattern.bits_[i]) {
|
|
|
|
other->bits_[j] = with.bits_[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-14 15:32:18 -05:00
|
|
|
|
2016-01-30 21:43:29 -06:00
|
|
|
other->check();
|
2014-08-14 15:32:18 -05:00
|
|
|
}
|
|
|
|
|
2014-12-26 03:53:21 -06:00
|
|
|
void RTLIL::SigSpec::replace(const dict<RTLIL::SigBit, RTLIL::SigBit> &rules)
|
|
|
|
{
|
|
|
|
replace(rules, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RTLIL::SigSpec::replace(const dict<RTLIL::SigBit, RTLIL::SigBit> &rules, RTLIL::SigSpec *other) const
|
|
|
|
{
|
|
|
|
cover("kernel.rtlil.sigspec.replace_dict");
|
|
|
|
|
|
|
|
log_assert(other != NULL);
|
|
|
|
log_assert(width_ == other->width_);
|
|
|
|
|
2019-09-29 02:17:40 -05:00
|
|
|
if (rules.empty()) return;
|
2014-12-26 03:53:21 -06:00
|
|
|
unpack();
|
|
|
|
other->unpack();
|
|
|
|
|
|
|
|
for (int i = 0; i < GetSize(bits_); i++) {
|
|
|
|
auto it = rules.find(bits_[i]);
|
|
|
|
if (it != rules.end())
|
|
|
|
other->bits_[i] = it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
other->check();
|
|
|
|
}
|
|
|
|
|
2014-08-14 15:32:18 -05:00
|
|
|
void RTLIL::SigSpec::replace(const std::map<RTLIL::SigBit, RTLIL::SigBit> &rules)
|
|
|
|
{
|
|
|
|
replace(rules, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RTLIL::SigSpec::replace(const std::map<RTLIL::SigBit, RTLIL::SigBit> &rules, RTLIL::SigSpec *other) const
|
|
|
|
{
|
2014-12-26 03:53:21 -06:00
|
|
|
cover("kernel.rtlil.sigspec.replace_map");
|
2014-08-14 15:32:18 -05:00
|
|
|
|
|
|
|
log_assert(other != NULL);
|
|
|
|
log_assert(width_ == other->width_);
|
|
|
|
|
2019-09-29 02:17:40 -05:00
|
|
|
if (rules.empty()) return;
|
2014-08-14 15:32:18 -05:00
|
|
|
unpack();
|
|
|
|
other->unpack();
|
2014-07-22 15:26:30 -05:00
|
|
|
|
2014-10-10 09:59:44 -05:00
|
|
|
for (int i = 0; i < GetSize(bits_); i++) {
|
2014-08-14 15:32:18 -05:00
|
|
|
auto it = rules.find(bits_[i]);
|
|
|
|
if (it != rules.end())
|
|
|
|
other->bits_[i] = it->second;
|
|
|
|
}
|
2014-07-22 15:26:30 -05:00
|
|
|
|
|
|
|
other->check();
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void RTLIL::SigSpec::remove(const RTLIL::SigSpec &pattern)
|
|
|
|
{
|
|
|
|
remove2(pattern, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RTLIL::SigSpec::remove(const RTLIL::SigSpec &pattern, RTLIL::SigSpec *other) const
|
|
|
|
{
|
|
|
|
RTLIL::SigSpec tmp = *this;
|
|
|
|
tmp.remove2(pattern, other);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RTLIL::SigSpec::remove2(const RTLIL::SigSpec &pattern, RTLIL::SigSpec *other)
|
2014-08-14 15:32:18 -05:00
|
|
|
{
|
2016-01-30 21:25:35 -06:00
|
|
|
if (other)
|
|
|
|
cover("kernel.rtlil.sigspec.remove_other");
|
|
|
|
else
|
|
|
|
cover("kernel.rtlil.sigspec.remove");
|
|
|
|
|
|
|
|
unpack();
|
|
|
|
if (other != NULL) {
|
|
|
|
log_assert(width_ == other->width_);
|
|
|
|
other->unpack();
|
|
|
|
}
|
|
|
|
|
2016-12-31 09:14:42 -06:00
|
|
|
for (int i = GetSize(bits_) - 1; i >= 0; i--)
|
|
|
|
{
|
2016-01-30 21:25:35 -06:00
|
|
|
if (bits_[i].wire == NULL) continue;
|
|
|
|
|
2016-12-31 09:14:42 -06:00
|
|
|
for (auto &pattern_chunk : pattern.chunks())
|
2016-01-30 21:25:35 -06:00
|
|
|
if (bits_[i].wire == pattern_chunk.wire &&
|
|
|
|
bits_[i].offset >= pattern_chunk.offset &&
|
|
|
|
bits_[i].offset < pattern_chunk.offset + pattern_chunk.width) {
|
|
|
|
bits_.erase(bits_.begin() + i);
|
|
|
|
width_--;
|
|
|
|
if (other != NULL) {
|
|
|
|
other->bits_.erase(other->bits_.begin() + i);
|
|
|
|
other->width_--;
|
|
|
|
}
|
2016-12-31 09:14:42 -06:00
|
|
|
break;
|
2016-01-30 21:25:35 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
check();
|
2014-08-14 15:32:18 -05:00
|
|
|
}
|
|
|
|
|
2014-12-26 14:59:41 -06:00
|
|
|
void RTLIL::SigSpec::remove(const pool<RTLIL::SigBit> &pattern)
|
2014-08-14 15:32:18 -05:00
|
|
|
{
|
|
|
|
remove2(pattern, NULL);
|
|
|
|
}
|
|
|
|
|
2014-12-26 14:59:41 -06:00
|
|
|
void RTLIL::SigSpec::remove(const pool<RTLIL::SigBit> &pattern, RTLIL::SigSpec *other) const
|
2014-08-14 15:32:18 -05:00
|
|
|
{
|
|
|
|
RTLIL::SigSpec tmp = *this;
|
|
|
|
tmp.remove2(pattern, other);
|
|
|
|
}
|
|
|
|
|
2014-12-26 14:59:41 -06:00
|
|
|
void RTLIL::SigSpec::remove2(const pool<RTLIL::SigBit> &pattern, RTLIL::SigSpec *other)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2014-07-23 20:50:28 -05:00
|
|
|
if (other)
|
|
|
|
cover("kernel.rtlil.sigspec.remove_other");
|
|
|
|
else
|
|
|
|
cover("kernel.rtlil.sigspec.remove");
|
|
|
|
|
2014-07-22 15:26:30 -05:00
|
|
|
unpack();
|
2014-07-22 14:33:52 -05:00
|
|
|
|
2014-07-22 15:26:30 -05:00
|
|
|
if (other != NULL) {
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(width_ == other->width_);
|
2014-07-22 15:26:30 -05:00
|
|
|
other->unpack();
|
|
|
|
}
|
2014-07-22 14:33:52 -05:00
|
|
|
|
2016-01-30 00:40:45 -06:00
|
|
|
for (int i = GetSize(bits_) - 1; i >= 0; i--) {
|
|
|
|
if (bits_[i].wire != NULL && pattern.count(bits_[i])) {
|
|
|
|
bits_.erase(bits_.begin() + i);
|
|
|
|
width_--;
|
|
|
|
if (other != NULL) {
|
|
|
|
other->bits_.erase(other->bits_.begin() + i);
|
|
|
|
other->width_--;
|
|
|
|
}
|
|
|
|
}
|
2014-07-22 15:26:30 -05:00
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
check();
|
|
|
|
}
|
|
|
|
|
2016-01-30 00:03:12 -06:00
|
|
|
void RTLIL::SigSpec::remove2(const std::set<RTLIL::SigBit> &pattern, RTLIL::SigSpec *other)
|
|
|
|
{
|
|
|
|
if (other)
|
|
|
|
cover("kernel.rtlil.sigspec.remove_other");
|
|
|
|
else
|
|
|
|
cover("kernel.rtlil.sigspec.remove");
|
|
|
|
|
|
|
|
unpack();
|
|
|
|
|
|
|
|
if (other != NULL) {
|
|
|
|
log_assert(width_ == other->width_);
|
|
|
|
other->unpack();
|
|
|
|
}
|
|
|
|
|
2016-01-30 00:40:45 -06:00
|
|
|
for (int i = GetSize(bits_) - 1; i >= 0; i--) {
|
|
|
|
if (bits_[i].wire != NULL && pattern.count(bits_[i])) {
|
|
|
|
bits_.erase(bits_.begin() + i);
|
|
|
|
width_--;
|
|
|
|
if (other != NULL) {
|
|
|
|
other->bits_.erase(other->bits_.begin() + i);
|
|
|
|
other->width_--;
|
|
|
|
}
|
|
|
|
}
|
2016-01-30 00:03:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
check();
|
|
|
|
}
|
|
|
|
|
2014-08-14 15:32:18 -05:00
|
|
|
RTLIL::SigSpec RTLIL::SigSpec::extract(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec *other) const
|
|
|
|
{
|
2016-01-31 11:07:21 -06:00
|
|
|
if (other)
|
|
|
|
cover("kernel.rtlil.sigspec.extract_other");
|
|
|
|
else
|
|
|
|
cover("kernel.rtlil.sigspec.extract");
|
|
|
|
|
|
|
|
log_assert(other == NULL || width_ == other->width_);
|
|
|
|
|
|
|
|
RTLIL::SigSpec ret;
|
|
|
|
std::vector<RTLIL::SigBit> bits_match = to_sigbit_vector();
|
|
|
|
|
|
|
|
for (auto& pattern_chunk : pattern.chunks()) {
|
|
|
|
if (other) {
|
|
|
|
std::vector<RTLIL::SigBit> bits_other = other->to_sigbit_vector();
|
|
|
|
for (int i = 0; i < width_; i++)
|
|
|
|
if (bits_match[i].wire &&
|
|
|
|
bits_match[i].wire == pattern_chunk.wire &&
|
|
|
|
bits_match[i].offset >= pattern_chunk.offset &&
|
|
|
|
bits_match[i].offset < pattern_chunk.offset + pattern_chunk.width)
|
2020-03-13 10:17:39 -05:00
|
|
|
ret.append(bits_other[i]);
|
2016-01-31 11:07:21 -06:00
|
|
|
} else {
|
|
|
|
for (int i = 0; i < width_; i++)
|
|
|
|
if (bits_match[i].wire &&
|
|
|
|
bits_match[i].wire == pattern_chunk.wire &&
|
|
|
|
bits_match[i].offset >= pattern_chunk.offset &&
|
|
|
|
bits_match[i].offset < pattern_chunk.offset + pattern_chunk.width)
|
2020-03-13 10:17:39 -05:00
|
|
|
ret.append(bits_match[i]);
|
2016-01-31 11:07:21 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret.check();
|
|
|
|
return ret;
|
2014-08-14 15:32:18 -05:00
|
|
|
}
|
|
|
|
|
2014-12-26 14:59:41 -06:00
|
|
|
RTLIL::SigSpec RTLIL::SigSpec::extract(const pool<RTLIL::SigBit> &pattern, const RTLIL::SigSpec *other) const
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2014-07-23 20:50:28 -05:00
|
|
|
if (other)
|
|
|
|
cover("kernel.rtlil.sigspec.extract_other");
|
|
|
|
else
|
|
|
|
cover("kernel.rtlil.sigspec.extract");
|
|
|
|
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(other == NULL || width_ == other->width_);
|
2013-11-21 21:07:13 -06:00
|
|
|
|
|
|
|
std::vector<RTLIL::SigBit> bits_match = to_sigbit_vector();
|
|
|
|
RTLIL::SigSpec ret;
|
|
|
|
|
|
|
|
if (other) {
|
2014-07-26 08:57:27 -05:00
|
|
|
std::vector<RTLIL::SigBit> bits_other = other->to_sigbit_vector();
|
2014-07-22 13:12:15 -05:00
|
|
|
for (int i = 0; i < width_; i++)
|
2014-08-14 15:32:18 -05:00
|
|
|
if (bits_match[i].wire && pattern.count(bits_match[i]))
|
2020-03-13 10:17:39 -05:00
|
|
|
ret.append(bits_other[i]);
|
2013-11-21 21:07:13 -06:00
|
|
|
} else {
|
2014-07-22 13:12:15 -05:00
|
|
|
for (int i = 0; i < width_; i++)
|
2014-08-14 15:32:18 -05:00
|
|
|
if (bits_match[i].wire && pattern.count(bits_match[i]))
|
2020-03-13 10:17:39 -05:00
|
|
|
ret.append(bits_match[i]);
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
2013-11-21 21:07:13 -06:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
ret.check();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RTLIL::SigSpec::replace(int offset, const RTLIL::SigSpec &with)
|
|
|
|
{
|
2014-07-24 08:05:41 -05:00
|
|
|
cover("kernel.rtlil.sigspec.replace_pos");
|
2014-07-23 20:50:28 -05:00
|
|
|
|
2014-07-22 15:26:30 -05:00
|
|
|
unpack();
|
|
|
|
with.unpack();
|
2014-07-22 14:33:52 -05:00
|
|
|
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(offset >= 0);
|
|
|
|
log_assert(with.width_ >= 0);
|
|
|
|
log_assert(offset+with.width_ <= width_);
|
2014-07-22 15:26:30 -05:00
|
|
|
|
|
|
|
for (int i = 0; i < with.width_; i++)
|
|
|
|
bits_.at(offset + i) = with.bits_.at(i);
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
check();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RTLIL::SigSpec::remove_const()
|
|
|
|
{
|
2014-07-27 07:47:48 -05:00
|
|
|
if (packed())
|
|
|
|
{
|
|
|
|
cover("kernel.rtlil.sigspec.remove_const.packed");
|
2014-07-23 20:50:28 -05:00
|
|
|
|
2014-07-27 07:47:48 -05:00
|
|
|
std::vector<RTLIL::SigChunk> new_chunks;
|
2014-10-10 09:59:44 -05:00
|
|
|
new_chunks.reserve(GetSize(chunks_));
|
2014-07-22 15:26:30 -05:00
|
|
|
|
2014-07-27 07:47:48 -05:00
|
|
|
width_ = 0;
|
|
|
|
for (auto &chunk : chunks_)
|
|
|
|
if (chunk.wire != NULL) {
|
|
|
|
new_chunks.push_back(chunk);
|
|
|
|
width_ += chunk.width;
|
|
|
|
}
|
2014-07-22 15:26:30 -05:00
|
|
|
|
2014-07-27 07:47:48 -05:00
|
|
|
chunks_.swap(new_chunks);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cover("kernel.rtlil.sigspec.remove_const.unpacked");
|
2014-07-22 15:26:30 -05:00
|
|
|
|
2014-07-27 07:47:48 -05:00
|
|
|
std::vector<RTLIL::SigBit> new_bits;
|
|
|
|
new_bits.reserve(width_);
|
|
|
|
|
|
|
|
for (auto &bit : bits_)
|
|
|
|
if (bit.wire != NULL)
|
|
|
|
new_bits.push_back(bit);
|
|
|
|
|
|
|
|
bits_.swap(new_bits);
|
|
|
|
width_ = bits_.size();
|
|
|
|
}
|
2014-07-22 15:26:30 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
check();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RTLIL::SigSpec::remove(int offset, int length)
|
|
|
|
{
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.remove_pos");
|
|
|
|
|
2014-07-22 15:26:30 -05:00
|
|
|
unpack();
|
|
|
|
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(offset >= 0);
|
|
|
|
log_assert(length >= 0);
|
|
|
|
log_assert(offset + length <= width_);
|
2014-07-22 15:26:30 -05:00
|
|
|
|
|
|
|
bits_.erase(bits_.begin() + offset, bits_.begin() + offset + length);
|
|
|
|
width_ = bits_.size();
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
check();
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::SigSpec RTLIL::SigSpec::extract(int offset, int length) const
|
|
|
|
{
|
2014-07-22 15:26:30 -05:00
|
|
|
unpack();
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.extract_pos");
|
2014-07-22 15:26:30 -05:00
|
|
|
return std::vector<RTLIL::SigBit>(bits_.begin() + offset, bits_.begin() + offset + length);
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void RTLIL::SigSpec::append(const RTLIL::SigSpec &signal)
|
|
|
|
{
|
2014-07-23 13:11:55 -05:00
|
|
|
if (signal.width_ == 0)
|
|
|
|
return;
|
2014-07-22 14:33:52 -05:00
|
|
|
|
2014-07-23 13:11:55 -05:00
|
|
|
if (width_ == 0) {
|
|
|
|
*this = signal;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.append");
|
|
|
|
|
2014-07-23 13:11:55 -05:00
|
|
|
if (packed() != signal.packed()) {
|
|
|
|
pack();
|
|
|
|
signal.pack();
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
2014-07-22 15:26:30 -05:00
|
|
|
|
2014-07-23 13:11:55 -05:00
|
|
|
if (packed())
|
|
|
|
for (auto &other_c : signal.chunks_)
|
|
|
|
{
|
|
|
|
auto &my_last_c = chunks_.back();
|
|
|
|
if (my_last_c.wire == NULL && other_c.wire == NULL) {
|
2014-09-01 04:36:02 -05:00
|
|
|
auto &this_data = my_last_c.data;
|
|
|
|
auto &other_data = other_c.data;
|
2014-07-23 13:11:55 -05:00
|
|
|
this_data.insert(this_data.end(), other_data.begin(), other_data.end());
|
|
|
|
my_last_c.width += other_c.width;
|
|
|
|
} else
|
|
|
|
if (my_last_c.wire == other_c.wire && my_last_c.offset + my_last_c.width == other_c.offset) {
|
|
|
|
my_last_c.width += other_c.width;
|
|
|
|
} else
|
|
|
|
chunks_.push_back(other_c);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bits_.insert(bits_.end(), signal.bits_.begin(), signal.bits_.end());
|
|
|
|
|
|
|
|
width_ += signal.width_;
|
2014-07-24 08:05:41 -05:00
|
|
|
check();
|
2013-11-21 21:07:13 -06:00
|
|
|
}
|
|
|
|
|
2020-03-13 10:17:39 -05:00
|
|
|
void RTLIL::SigSpec::append(const RTLIL::SigBit &bit)
|
2013-11-21 21:07:13 -06:00
|
|
|
{
|
2014-07-22 15:26:30 -05:00
|
|
|
if (packed())
|
|
|
|
{
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.append_bit.packed");
|
|
|
|
|
2014-07-22 15:26:30 -05:00
|
|
|
if (chunks_.size() == 0)
|
|
|
|
chunks_.push_back(bit);
|
2013-11-21 21:07:13 -06:00
|
|
|
else
|
2014-07-22 15:26:30 -05:00
|
|
|
if (bit.wire == NULL)
|
|
|
|
if (chunks_.back().wire == NULL) {
|
2014-09-01 04:36:02 -05:00
|
|
|
chunks_.back().data.push_back(bit.data);
|
2014-07-22 15:26:30 -05:00
|
|
|
chunks_.back().width++;
|
|
|
|
} else
|
|
|
|
chunks_.push_back(bit);
|
2013-11-21 21:07:13 -06:00
|
|
|
else
|
2014-07-22 15:26:30 -05:00
|
|
|
if (chunks_.back().wire == bit.wire && chunks_.back().offset + chunks_.back().width == bit.offset)
|
|
|
|
chunks_.back().width++;
|
|
|
|
else
|
|
|
|
chunks_.push_back(bit);
|
|
|
|
}
|
|
|
|
else
|
2014-07-23 20:50:28 -05:00
|
|
|
{
|
|
|
|
cover("kernel.rtlil.sigspec.append_bit.unpacked");
|
2014-07-22 15:26:30 -05:00
|
|
|
bits_.push_back(bit);
|
2014-07-23 20:50:28 -05:00
|
|
|
}
|
2014-07-22 15:26:30 -05:00
|
|
|
|
2014-07-22 13:12:15 -05:00
|
|
|
width_++;
|
2014-07-24 08:05:41 -05:00
|
|
|
check();
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2013-11-07 11:17:10 -06:00
|
|
|
void RTLIL::SigSpec::extend_u0(int width, bool is_signed)
|
2013-11-07 09:53:28 -06:00
|
|
|
{
|
2014-07-24 20:17:35 -05:00
|
|
|
cover("kernel.rtlil.sigspec.extend_u0");
|
2014-07-23 20:50:28 -05:00
|
|
|
|
2014-07-22 14:33:52 -05:00
|
|
|
pack();
|
|
|
|
|
2014-07-22 13:12:15 -05:00
|
|
|
if (width_ > width)
|
|
|
|
remove(width, width_ - width);
|
2015-07-02 04:14:30 -05:00
|
|
|
|
2014-07-22 13:12:15 -05:00
|
|
|
if (width_ < width) {
|
2019-03-23 08:38:48 -05:00
|
|
|
RTLIL::SigBit padding = width_ > 0 ? (*this)[width_ - 1] : RTLIL::State::Sx;
|
2013-11-07 09:53:28 -06:00
|
|
|
if (!is_signed)
|
2014-12-24 02:51:17 -06:00
|
|
|
padding = RTLIL::State::S0;
|
2014-07-22 13:12:15 -05:00
|
|
|
while (width_ < width)
|
2013-11-07 09:53:28 -06:00
|
|
|
append(padding);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-07-23 14:34:14 -05:00
|
|
|
RTLIL::SigSpec RTLIL::SigSpec::repeat(int num) const
|
|
|
|
{
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.repeat");
|
|
|
|
|
2014-07-23 14:34:14 -05:00
|
|
|
RTLIL::SigSpec sig;
|
|
|
|
for (int i = 0; i < num; i++)
|
|
|
|
sig.append(*this);
|
|
|
|
return sig;
|
|
|
|
}
|
|
|
|
|
2014-07-23 21:46:36 -05:00
|
|
|
#ifndef NDEBUG
|
2013-01-05 04:13:26 -06:00
|
|
|
void RTLIL::SigSpec::check() const
|
|
|
|
{
|
2014-07-24 08:05:41 -05:00
|
|
|
if (width_ > 64)
|
|
|
|
{
|
|
|
|
cover("kernel.rtlil.sigspec.check.skip");
|
|
|
|
}
|
|
|
|
else if (packed())
|
2014-07-22 15:26:30 -05:00
|
|
|
{
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.check.packed");
|
|
|
|
|
2014-07-22 15:26:30 -05:00
|
|
|
int w = 0;
|
|
|
|
for (size_t i = 0; i < chunks_.size(); i++) {
|
2020-03-18 13:21:53 -05:00
|
|
|
const RTLIL::SigChunk &chunk = chunks_[i];
|
2014-07-22 15:26:30 -05:00
|
|
|
if (chunk.wire == NULL) {
|
2014-07-23 13:11:55 -05:00
|
|
|
if (i > 0)
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(chunks_[i-1].wire != NULL);
|
|
|
|
log_assert(chunk.offset == 0);
|
2014-09-01 04:36:02 -05:00
|
|
|
log_assert(chunk.data.size() == (size_t)chunk.width);
|
2014-07-22 15:26:30 -05:00
|
|
|
} else {
|
2014-07-23 13:11:55 -05:00
|
|
|
if (i > 0 && chunks_[i-1].wire == chunk.wire)
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(chunk.offset != chunks_[i-1].offset + chunks_[i-1].width);
|
|
|
|
log_assert(chunk.offset >= 0);
|
|
|
|
log_assert(chunk.width >= 0);
|
|
|
|
log_assert(chunk.offset + chunk.width <= chunk.wire->width);
|
2014-09-01 04:36:02 -05:00
|
|
|
log_assert(chunk.data.size() == 0);
|
2014-07-22 15:26:30 -05:00
|
|
|
}
|
|
|
|
w += chunk.width;
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(w == width_);
|
|
|
|
log_assert(bits_.empty());
|
2014-07-22 15:26:30 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.check.unpacked");
|
|
|
|
|
2014-10-10 09:59:44 -05:00
|
|
|
log_assert(width_ == GetSize(bits_));
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(chunks_.empty());
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
}
|
2014-07-23 21:46:36 -05:00
|
|
|
#endif
|
2013-01-05 04:13:26 -06:00
|
|
|
|
|
|
|
bool RTLIL::SigSpec::operator <(const RTLIL::SigSpec &other) const
|
|
|
|
{
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.comp_lt");
|
|
|
|
|
2014-07-23 16:58:03 -05:00
|
|
|
if (this == &other)
|
|
|
|
return false;
|
2014-07-22 14:33:52 -05:00
|
|
|
|
2014-07-22 13:12:15 -05:00
|
|
|
if (width_ != other.width_)
|
|
|
|
return width_ < other.width_;
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2014-07-23 16:58:03 -05:00
|
|
|
pack();
|
|
|
|
other.pack();
|
|
|
|
|
|
|
|
if (chunks_.size() != other.chunks_.size())
|
|
|
|
return chunks_.size() < other.chunks_.size();
|
|
|
|
|
2014-12-26 14:35:22 -06:00
|
|
|
updhash();
|
|
|
|
other.updhash();
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2014-07-23 16:58:03 -05:00
|
|
|
if (hash_ != other.hash_)
|
|
|
|
return hash_ < other.hash_;
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2014-07-23 16:58:03 -05:00
|
|
|
for (size_t i = 0; i < chunks_.size(); i++)
|
2014-07-23 20:50:28 -05:00
|
|
|
if (chunks_[i] != other.chunks_[i]) {
|
|
|
|
cover("kernel.rtlil.sigspec.comp_lt.hash_collision");
|
2014-07-23 16:58:03 -05:00
|
|
|
return chunks_[i] < other.chunks_[i];
|
2014-07-23 20:50:28 -05:00
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2014-07-23 21:16:32 -05:00
|
|
|
cover("kernel.rtlil.sigspec.comp_lt.equal");
|
2013-01-05 04:13:26 -06:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RTLIL::SigSpec::operator ==(const RTLIL::SigSpec &other) const
|
|
|
|
{
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.comp_eq");
|
|
|
|
|
2014-07-23 16:58:03 -05:00
|
|
|
if (this == &other)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (width_ != other.width_)
|
|
|
|
return false;
|
|
|
|
|
2019-10-04 18:45:36 -05:00
|
|
|
// Without this, SigSpec() == SigSpec(State::S0, 0) will fail
|
|
|
|
// since the RHS will contain one SigChunk of width 0 causing
|
|
|
|
// the size check below to fail
|
|
|
|
if (width_ == 0)
|
|
|
|
return true;
|
|
|
|
|
2014-07-22 14:33:52 -05:00
|
|
|
pack();
|
|
|
|
other.pack();
|
|
|
|
|
2019-04-30 08:19:04 -05:00
|
|
|
if (chunks_.size() != other.chunks_.size())
|
2013-01-05 04:13:26 -06:00
|
|
|
return false;
|
|
|
|
|
2014-12-26 14:35:22 -06:00
|
|
|
updhash();
|
|
|
|
other.updhash();
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2014-07-23 16:58:03 -05:00
|
|
|
if (hash_ != other.hash_)
|
2013-01-05 04:13:26 -06:00
|
|
|
return false;
|
|
|
|
|
2014-07-23 16:58:03 -05:00
|
|
|
for (size_t i = 0; i < chunks_.size(); i++)
|
2014-07-23 20:50:28 -05:00
|
|
|
if (chunks_[i] != other.chunks_[i]) {
|
|
|
|
cover("kernel.rtlil.sigspec.comp_eq.hash_collision");
|
2013-01-05 04:13:26 -06:00
|
|
|
return false;
|
2014-07-23 20:50:28 -05:00
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2014-07-23 21:16:32 -05:00
|
|
|
cover("kernel.rtlil.sigspec.comp_eq.equal");
|
2013-01-05 04:13:26 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-24 15:47:57 -05:00
|
|
|
bool RTLIL::SigSpec::is_wire() const
|
|
|
|
{
|
|
|
|
cover("kernel.rtlil.sigspec.is_wire");
|
|
|
|
|
|
|
|
pack();
|
2014-10-10 09:59:44 -05:00
|
|
|
return GetSize(chunks_) == 1 && chunks_[0].wire && chunks_[0].wire->width == width_;
|
2014-07-24 15:47:57 -05:00
|
|
|
}
|
|
|
|
|
2014-07-25 07:23:10 -05:00
|
|
|
bool RTLIL::SigSpec::is_chunk() const
|
|
|
|
{
|
|
|
|
cover("kernel.rtlil.sigspec.is_chunk");
|
|
|
|
|
|
|
|
pack();
|
2014-10-10 09:59:44 -05:00
|
|
|
return GetSize(chunks_) == 1;
|
2014-07-25 07:23:10 -05:00
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
bool RTLIL::SigSpec::is_fully_const() const
|
|
|
|
{
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.is_fully_const");
|
|
|
|
|
2014-07-22 14:33:52 -05:00
|
|
|
pack();
|
2014-07-22 13:12:15 -05:00
|
|
|
for (auto it = chunks_.begin(); it != chunks_.end(); it++)
|
2013-01-05 04:13:26 -06:00
|
|
|
if (it->width > 0 && it->wire != NULL)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-29 00:28:15 -05:00
|
|
|
bool RTLIL::SigSpec::is_fully_zero() const
|
|
|
|
{
|
|
|
|
cover("kernel.rtlil.sigspec.is_fully_zero");
|
|
|
|
|
|
|
|
pack();
|
|
|
|
for (auto it = chunks_.begin(); it != chunks_.end(); it++) {
|
|
|
|
if (it->width > 0 && it->wire != NULL)
|
|
|
|
return false;
|
|
|
|
for (size_t i = 0; i < it->data.size(); i++)
|
|
|
|
if (it->data[i] != RTLIL::State::S0)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-12 14:48:31 -06:00
|
|
|
bool RTLIL::SigSpec::is_fully_ones() const
|
|
|
|
{
|
|
|
|
cover("kernel.rtlil.sigspec.is_fully_ones");
|
|
|
|
|
|
|
|
pack();
|
|
|
|
for (auto it = chunks_.begin(); it != chunks_.end(); it++) {
|
|
|
|
if (it->width > 0 && it->wire != NULL)
|
|
|
|
return false;
|
|
|
|
for (size_t i = 0; i < it->data.size(); i++)
|
|
|
|
if (it->data[i] != RTLIL::State::S1)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
bool RTLIL::SigSpec::is_fully_def() const
|
|
|
|
{
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.is_fully_def");
|
|
|
|
|
2014-07-22 14:33:52 -05:00
|
|
|
pack();
|
2014-07-22 13:12:15 -05:00
|
|
|
for (auto it = chunks_.begin(); it != chunks_.end(); it++) {
|
2013-01-05 04:13:26 -06:00
|
|
|
if (it->width > 0 && it->wire != NULL)
|
|
|
|
return false;
|
2014-09-01 04:36:02 -05:00
|
|
|
for (size_t i = 0; i < it->data.size(); i++)
|
|
|
|
if (it->data[i] != RTLIL::State::S0 && it->data[i] != RTLIL::State::S1)
|
2013-01-05 04:13:26 -06:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RTLIL::SigSpec::is_fully_undef() const
|
|
|
|
{
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.is_fully_undef");
|
|
|
|
|
2014-07-22 14:33:52 -05:00
|
|
|
pack();
|
2014-07-22 13:12:15 -05:00
|
|
|
for (auto it = chunks_.begin(); it != chunks_.end(); it++) {
|
2013-01-05 04:13:26 -06:00
|
|
|
if (it->width > 0 && it->wire != NULL)
|
|
|
|
return false;
|
2014-09-01 04:36:02 -05:00
|
|
|
for (size_t i = 0; i < it->data.size(); i++)
|
|
|
|
if (it->data[i] != RTLIL::State::Sx && it->data[i] != RTLIL::State::Sz)
|
2013-01-05 04:13:26 -06:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-07 17:01:51 -06:00
|
|
|
bool RTLIL::SigSpec::has_const() const
|
|
|
|
{
|
|
|
|
cover("kernel.rtlil.sigspec.has_const");
|
|
|
|
|
|
|
|
pack();
|
|
|
|
for (auto it = chunks_.begin(); it != chunks_.end(); it++)
|
|
|
|
if (it->width > 0 && it->wire == NULL)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
bool RTLIL::SigSpec::has_marked_bits() const
|
|
|
|
{
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.has_marked_bits");
|
|
|
|
|
2014-07-22 14:33:52 -05:00
|
|
|
pack();
|
2014-07-22 13:12:15 -05:00
|
|
|
for (auto it = chunks_.begin(); it != chunks_.end(); it++)
|
2013-01-05 04:13:26 -06:00
|
|
|
if (it->width > 0 && it->wire == NULL) {
|
2014-09-01 04:36:02 -05:00
|
|
|
for (size_t i = 0; i < it->data.size(); i++)
|
|
|
|
if (it->data[i] == RTLIL::State::Sm)
|
2013-01-05 04:13:26 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RTLIL::SigSpec::as_bool() const
|
|
|
|
{
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.as_bool");
|
|
|
|
|
2014-07-22 14:33:52 -05:00
|
|
|
pack();
|
2014-10-10 09:59:44 -05:00
|
|
|
log_assert(is_fully_const() && GetSize(chunks_) <= 1);
|
2014-07-23 13:32:28 -05:00
|
|
|
if (width_)
|
2014-09-01 04:36:02 -05:00
|
|
|
return RTLIL::Const(chunks_[0].data).as_bool();
|
2013-01-05 04:13:26 -06:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-08-24 08:14:00 -05:00
|
|
|
int RTLIL::SigSpec::as_int(bool is_signed) const
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.as_int");
|
|
|
|
|
2014-07-22 14:33:52 -05:00
|
|
|
pack();
|
2014-10-10 09:59:44 -05:00
|
|
|
log_assert(is_fully_const() && GetSize(chunks_) <= 1);
|
2014-07-23 13:32:28 -05:00
|
|
|
if (width_)
|
2014-09-01 04:36:02 -05:00
|
|
|
return RTLIL::Const(chunks_[0].data).as_int(is_signed);
|
2013-01-05 04:13:26 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string RTLIL::SigSpec::as_string() const
|
|
|
|
{
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.as_string");
|
|
|
|
|
2014-07-22 14:33:52 -05:00
|
|
|
pack();
|
2013-01-05 04:13:26 -06:00
|
|
|
std::string str;
|
2020-03-18 13:21:53 -05:00
|
|
|
str.reserve(size());
|
2014-07-22 13:12:15 -05:00
|
|
|
for (size_t i = chunks_.size(); i > 0; i--) {
|
|
|
|
const RTLIL::SigChunk &chunk = chunks_[i-1];
|
2013-01-05 04:13:26 -06:00
|
|
|
if (chunk.wire != NULL)
|
2020-03-18 13:21:53 -05:00
|
|
|
str.append(chunk.width, '?');
|
2013-01-05 04:13:26 -06:00
|
|
|
else
|
2014-09-01 04:36:02 -05:00
|
|
|
str += RTLIL::Const(chunk.data).as_string();
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::Const RTLIL::SigSpec::as_const() const
|
|
|
|
{
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.as_const");
|
|
|
|
|
2014-07-22 14:33:52 -05:00
|
|
|
pack();
|
2014-10-10 09:59:44 -05:00
|
|
|
log_assert(is_fully_const() && GetSize(chunks_) <= 1);
|
2014-07-23 13:32:28 -05:00
|
|
|
if (width_)
|
|
|
|
return chunks_[0].data;
|
2013-01-05 04:13:26 -06:00
|
|
|
return RTLIL::Const();
|
|
|
|
}
|
|
|
|
|
2014-07-24 15:47:57 -05:00
|
|
|
RTLIL::Wire *RTLIL::SigSpec::as_wire() const
|
|
|
|
{
|
|
|
|
cover("kernel.rtlil.sigspec.as_wire");
|
|
|
|
|
|
|
|
pack();
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(is_wire());
|
2014-07-24 15:47:57 -05:00
|
|
|
return chunks_[0].wire;
|
|
|
|
}
|
|
|
|
|
2014-07-25 07:23:10 -05:00
|
|
|
RTLIL::SigChunk RTLIL::SigSpec::as_chunk() const
|
|
|
|
{
|
|
|
|
cover("kernel.rtlil.sigspec.as_chunk");
|
|
|
|
|
|
|
|
pack();
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(is_chunk());
|
2014-07-25 07:23:10 -05:00
|
|
|
return chunks_[0];
|
|
|
|
}
|
|
|
|
|
2015-10-24 15:56:40 -05:00
|
|
|
RTLIL::SigBit RTLIL::SigSpec::as_bit() const
|
|
|
|
{
|
|
|
|
cover("kernel.rtlil.sigspec.as_bit");
|
|
|
|
|
|
|
|
log_assert(width_ == 1);
|
|
|
|
if (packed())
|
|
|
|
return RTLIL::SigBit(*chunks_.begin());
|
|
|
|
else
|
|
|
|
return bits_[0];
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
bool RTLIL::SigSpec::match(const char* pattern) const
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.match");
|
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
unpack();
|
|
|
|
log_assert(int(strlen(pattern)) == GetSize(bits_));
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2020-03-18 13:21:53 -05:00
|
|
|
for (auto it = bits_.rbegin(); it != bits_.rend(); it++, pattern++) {
|
|
|
|
if (*pattern == ' ')
|
2013-01-05 04:13:26 -06:00
|
|
|
continue;
|
2020-03-18 13:21:53 -05:00
|
|
|
if (*pattern == '*') {
|
|
|
|
if (*it != State::Sz && *it != State::Sx)
|
2013-01-05 04:13:26 -06:00
|
|
|
return false;
|
|
|
|
continue;
|
|
|
|
}
|
2020-03-18 13:21:53 -05:00
|
|
|
if (*pattern == '0') {
|
|
|
|
if (*it != State::S0)
|
|
|
|
return false;
|
|
|
|
} else
|
|
|
|
if (*pattern == '1') {
|
|
|
|
if (*it != State::S1)
|
|
|
|
return false;
|
|
|
|
} else
|
|
|
|
log_abort();
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-21 21:07:13 -06:00
|
|
|
std::set<RTLIL::SigBit> RTLIL::SigSpec::to_sigbit_set() const
|
|
|
|
{
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.to_sigbit_set");
|
|
|
|
|
2014-07-22 14:33:52 -05:00
|
|
|
pack();
|
2013-11-21 21:07:13 -06:00
|
|
|
std::set<RTLIL::SigBit> sigbits;
|
2014-07-22 13:12:15 -05:00
|
|
|
for (auto &c : chunks_)
|
2013-11-21 21:07:13 -06:00
|
|
|
for (int i = 0; i < c.width; i++)
|
|
|
|
sigbits.insert(RTLIL::SigBit(c, i));
|
|
|
|
return sigbits;
|
|
|
|
}
|
|
|
|
|
2014-12-27 05:02:57 -06:00
|
|
|
pool<RTLIL::SigBit> RTLIL::SigSpec::to_sigbit_pool() const
|
2014-12-26 03:53:21 -06:00
|
|
|
{
|
2014-12-26 14:59:41 -06:00
|
|
|
cover("kernel.rtlil.sigspec.to_sigbit_pool");
|
2014-12-26 03:53:21 -06:00
|
|
|
|
|
|
|
pack();
|
2014-12-26 14:59:41 -06:00
|
|
|
pool<RTLIL::SigBit> sigbits;
|
2020-03-18 13:21:53 -05:00
|
|
|
sigbits.reserve(size());
|
2014-12-26 03:53:21 -06:00
|
|
|
for (auto &c : chunks_)
|
|
|
|
for (int i = 0; i < c.width; i++)
|
|
|
|
sigbits.insert(RTLIL::SigBit(c, i));
|
|
|
|
return sigbits;
|
|
|
|
}
|
|
|
|
|
2013-11-21 21:07:13 -06:00
|
|
|
std::vector<RTLIL::SigBit> RTLIL::SigSpec::to_sigbit_vector() const
|
|
|
|
{
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.to_sigbit_vector");
|
|
|
|
|
2014-07-22 14:33:52 -05:00
|
|
|
unpack();
|
|
|
|
return bits_;
|
2013-11-21 21:07:13 -06:00
|
|
|
}
|
|
|
|
|
2014-08-14 16:14:47 -05:00
|
|
|
std::map<RTLIL::SigBit, RTLIL::SigBit> RTLIL::SigSpec::to_sigbit_map(const RTLIL::SigSpec &other) const
|
|
|
|
{
|
|
|
|
cover("kernel.rtlil.sigspec.to_sigbit_map");
|
|
|
|
|
|
|
|
unpack();
|
|
|
|
other.unpack();
|
|
|
|
|
|
|
|
log_assert(width_ == other.width_);
|
|
|
|
|
|
|
|
std::map<RTLIL::SigBit, RTLIL::SigBit> new_map;
|
|
|
|
for (int i = 0; i < width_; i++)
|
|
|
|
new_map[bits_[i]] = other.bits_[i];
|
|
|
|
|
|
|
|
return new_map;
|
|
|
|
}
|
|
|
|
|
2014-12-26 03:53:21 -06:00
|
|
|
dict<RTLIL::SigBit, RTLIL::SigBit> RTLIL::SigSpec::to_sigbit_dict(const RTLIL::SigSpec &other) const
|
|
|
|
{
|
|
|
|
cover("kernel.rtlil.sigspec.to_sigbit_dict");
|
|
|
|
|
|
|
|
unpack();
|
|
|
|
other.unpack();
|
|
|
|
|
|
|
|
log_assert(width_ == other.width_);
|
|
|
|
|
|
|
|
dict<RTLIL::SigBit, RTLIL::SigBit> new_map;
|
2020-03-18 13:21:53 -05:00
|
|
|
new_map.reserve(size());
|
2014-12-26 03:53:21 -06:00
|
|
|
for (int i = 0; i < width_; i++)
|
|
|
|
new_map[bits_[i]] = other.bits_[i];
|
|
|
|
|
|
|
|
return new_map;
|
|
|
|
}
|
|
|
|
|
2013-06-19 02:30:37 -05:00
|
|
|
static void sigspec_parse_split(std::vector<std::string> &tokens, const std::string &text, char sep)
|
|
|
|
{
|
|
|
|
size_t start = 0, end = 0;
|
|
|
|
while ((end = text.find(sep, start)) != std::string::npos) {
|
|
|
|
tokens.push_back(text.substr(start, end - start));
|
|
|
|
start = end + 1;
|
|
|
|
}
|
|
|
|
tokens.push_back(text.substr(start));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sigspec_parse_get_dummy_line_num()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RTLIL::SigSpec::parse(RTLIL::SigSpec &sig, RTLIL::Module *module, std::string str)
|
|
|
|
{
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.parse");
|
|
|
|
|
2015-08-11 04:32:37 -05:00
|
|
|
AST::current_filename = "input";
|
|
|
|
|
2013-06-19 02:30:37 -05:00
|
|
|
std::vector<std::string> tokens;
|
|
|
|
sigspec_parse_split(tokens, str, ',');
|
|
|
|
|
|
|
|
sig = RTLIL::SigSpec();
|
2013-12-07 04:57:29 -06:00
|
|
|
for (int tokidx = int(tokens.size())-1; tokidx >= 0; tokidx--)
|
2013-06-19 02:30:37 -05:00
|
|
|
{
|
2013-12-07 04:57:29 -06:00
|
|
|
std::string netname = tokens[tokidx];
|
2013-06-19 02:30:37 -05:00
|
|
|
std::string indices;
|
|
|
|
|
|
|
|
if (netname.size() == 0)
|
|
|
|
continue;
|
|
|
|
|
2014-10-26 14:33:10 -05:00
|
|
|
if (('0' <= netname[0] && netname[0] <= '9') || netname[0] == '\'') {
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.parse.const");
|
2013-06-19 02:30:37 -05:00
|
|
|
AST::get_line_num = sigspec_parse_get_dummy_line_num;
|
|
|
|
AST::AstNode *ast = VERILOG_FRONTEND::const2ast(netname);
|
|
|
|
if (ast == NULL)
|
|
|
|
return false;
|
|
|
|
sig.append(RTLIL::Const(ast->bits));
|
|
|
|
delete ast;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-11-05 21:14:56 -06:00
|
|
|
if (module == NULL)
|
|
|
|
return false;
|
|
|
|
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.parse.net");
|
|
|
|
|
2013-06-19 02:30:37 -05:00
|
|
|
if (netname[0] != '$' && netname[0] != '\\')
|
|
|
|
netname = "\\" + netname;
|
|
|
|
|
2014-07-26 18:49:51 -05:00
|
|
|
if (module->wires_.count(netname) == 0) {
|
2013-06-19 02:30:37 -05:00
|
|
|
size_t indices_pos = netname.size()-1;
|
|
|
|
if (indices_pos > 2 && netname[indices_pos] == ']')
|
|
|
|
{
|
|
|
|
indices_pos--;
|
|
|
|
while (indices_pos > 0 && ('0' <= netname[indices_pos] && netname[indices_pos] <= '9')) indices_pos--;
|
|
|
|
if (indices_pos > 0 && netname[indices_pos] == ':') {
|
|
|
|
indices_pos--;
|
|
|
|
while (indices_pos > 0 && ('0' <= netname[indices_pos] && netname[indices_pos] <= '9')) indices_pos--;
|
|
|
|
}
|
|
|
|
if (indices_pos > 0 && netname[indices_pos] == '[') {
|
|
|
|
indices = netname.substr(indices_pos);
|
|
|
|
netname = netname.substr(0, indices_pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-26 18:49:51 -05:00
|
|
|
if (module->wires_.count(netname) == 0)
|
2013-06-19 02:30:37 -05:00
|
|
|
return false;
|
|
|
|
|
2014-07-26 18:49:51 -05:00
|
|
|
RTLIL::Wire *wire = module->wires_.at(netname);
|
2013-06-19 02:30:37 -05:00
|
|
|
if (!indices.empty()) {
|
|
|
|
std::vector<std::string> index_tokens;
|
|
|
|
sigspec_parse_split(index_tokens, indices.substr(1, indices.size()-2), ':');
|
2014-07-23 20:50:28 -05:00
|
|
|
if (index_tokens.size() == 1) {
|
|
|
|
cover("kernel.rtlil.sigspec.parse.bit_sel");
|
2019-08-07 13:09:17 -05:00
|
|
|
int a = atoi(index_tokens.at(0).c_str());
|
2014-10-15 17:54:14 -05:00
|
|
|
if (a < 0 || a >= wire->width)
|
|
|
|
return false;
|
|
|
|
sig.append(RTLIL::SigSpec(wire, a));
|
2014-07-23 20:50:28 -05:00
|
|
|
} else {
|
|
|
|
cover("kernel.rtlil.sigspec.parse.part_sel");
|
2019-08-07 13:09:17 -05:00
|
|
|
int a = atoi(index_tokens.at(0).c_str());
|
|
|
|
int b = atoi(index_tokens.at(1).c_str());
|
2013-06-19 02:30:37 -05:00
|
|
|
if (a > b) {
|
|
|
|
int tmp = a;
|
|
|
|
a = b, b = tmp;
|
|
|
|
}
|
2014-10-15 17:54:14 -05:00
|
|
|
if (a < 0 || a >= wire->width)
|
|
|
|
return false;
|
|
|
|
if (b < 0 || b >= wire->width)
|
|
|
|
return false;
|
2014-07-23 02:48:26 -05:00
|
|
|
sig.append(RTLIL::SigSpec(wire, a, b-a+1));
|
2013-06-19 02:30:37 -05:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
sig.append(wire);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-06 12:22:46 -06:00
|
|
|
bool RTLIL::SigSpec::parse_sel(RTLIL::SigSpec &sig, RTLIL::Design *design, RTLIL::Module *module, std::string str)
|
|
|
|
{
|
|
|
|
if (str.empty() || str[0] != '@')
|
|
|
|
return parse(sig, module, str);
|
|
|
|
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.parse.sel");
|
|
|
|
|
2014-02-06 12:22:46 -06:00
|
|
|
str = RTLIL::escape_id(str.substr(1));
|
|
|
|
if (design->selection_vars.count(str) == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
sig = RTLIL::SigSpec();
|
|
|
|
RTLIL::Selection &sel = design->selection_vars.at(str);
|
2014-07-26 18:49:51 -05:00
|
|
|
for (auto &it : module->wires_)
|
2014-02-06 12:22:46 -06:00
|
|
|
if (sel.selected_member(module->name, it.first))
|
|
|
|
sig.append(it.second);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-09 05:02:27 -06:00
|
|
|
bool RTLIL::SigSpec::parse_rhs(const RTLIL::SigSpec &lhs, RTLIL::SigSpec &sig, RTLIL::Module *module, std::string str)
|
|
|
|
{
|
2013-12-07 04:57:29 -06:00
|
|
|
if (str == "0") {
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.parse.rhs_zeros");
|
2014-07-22 13:12:15 -05:00
|
|
|
sig = RTLIL::SigSpec(RTLIL::State::S0, lhs.width_);
|
2013-12-07 04:57:29 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (str == "~0") {
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.parse.rhs_ones");
|
2014-07-22 13:12:15 -05:00
|
|
|
sig = RTLIL::SigSpec(RTLIL::State::S1, lhs.width_);
|
2013-12-07 04:57:29 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-22 13:12:15 -05:00
|
|
|
if (lhs.chunks_.size() == 1) {
|
2013-11-09 05:02:27 -06:00
|
|
|
char *p = (char*)str.c_str(), *endptr;
|
2014-10-18 08:20:38 -05:00
|
|
|
long int val = strtol(p, &endptr, 10);
|
2013-11-09 05:02:27 -06:00
|
|
|
if (endptr && endptr != p && *endptr == 0) {
|
2014-07-22 13:12:15 -05:00
|
|
|
sig = RTLIL::SigSpec(val, lhs.width_);
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.parse.rhs_dec");
|
2013-11-09 05:02:27 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return parse(sig, module, str);
|
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::CaseRule::~CaseRule()
|
|
|
|
{
|
|
|
|
for (auto it = switches.begin(); it != switches.end(); it++)
|
|
|
|
delete *it;
|
|
|
|
}
|
|
|
|
|
2018-12-23 03:04:23 -06:00
|
|
|
bool RTLIL::CaseRule::empty() const
|
|
|
|
{
|
|
|
|
return actions.empty() && switches.empty();
|
|
|
|
}
|
|
|
|
|
2013-07-27 07:27:51 -05:00
|
|
|
RTLIL::CaseRule *RTLIL::CaseRule::clone() const
|
|
|
|
{
|
|
|
|
RTLIL::CaseRule *new_caserule = new RTLIL::CaseRule;
|
|
|
|
new_caserule->compare = compare;
|
|
|
|
new_caserule->actions = actions;
|
|
|
|
for (auto &it : switches)
|
|
|
|
new_caserule->switches.push_back(it->clone());
|
|
|
|
return new_caserule;
|
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::SwitchRule::~SwitchRule()
|
|
|
|
{
|
|
|
|
for (auto it = cases.begin(); it != cases.end(); it++)
|
|
|
|
delete *it;
|
|
|
|
}
|
|
|
|
|
2018-12-23 03:04:23 -06:00
|
|
|
bool RTLIL::SwitchRule::empty() const
|
|
|
|
{
|
|
|
|
return cases.empty();
|
|
|
|
}
|
|
|
|
|
2013-07-27 07:27:51 -05:00
|
|
|
RTLIL::SwitchRule *RTLIL::SwitchRule::clone() const
|
|
|
|
{
|
|
|
|
RTLIL::SwitchRule *new_switchrule = new RTLIL::SwitchRule;
|
|
|
|
new_switchrule->signal = signal;
|
|
|
|
new_switchrule->attributes = attributes;
|
|
|
|
for (auto &it : cases)
|
|
|
|
new_switchrule->cases.push_back(it->clone());
|
|
|
|
return new_switchrule;
|
2015-07-02 04:14:30 -05:00
|
|
|
|
2013-07-27 07:27:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::SyncRule *RTLIL::SyncRule::clone() const
|
|
|
|
{
|
|
|
|
RTLIL::SyncRule *new_syncrule = new RTLIL::SyncRule;
|
|
|
|
new_syncrule->type = type;
|
|
|
|
new_syncrule->signal = signal;
|
|
|
|
new_syncrule->actions = actions;
|
|
|
|
return new_syncrule;
|
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::Process::~Process()
|
|
|
|
{
|
|
|
|
for (auto it = syncs.begin(); it != syncs.end(); it++)
|
|
|
|
delete *it;
|
|
|
|
}
|
|
|
|
|
2013-07-27 07:27:51 -05:00
|
|
|
RTLIL::Process *RTLIL::Process::clone() const
|
|
|
|
{
|
|
|
|
RTLIL::Process *new_proc = new RTLIL::Process;
|
|
|
|
|
|
|
|
new_proc->name = name;
|
|
|
|
new_proc->attributes = attributes;
|
|
|
|
|
|
|
|
RTLIL::CaseRule *rc_ptr = root_case.clone();
|
|
|
|
new_proc->root_case = *rc_ptr;
|
|
|
|
rc_ptr->switches.clear();
|
|
|
|
delete rc_ptr;
|
|
|
|
|
|
|
|
for (auto &it : syncs)
|
|
|
|
new_proc->syncs.push_back(it->clone());
|
2015-07-02 04:14:30 -05:00
|
|
|
|
2013-07-27 07:27:51 -05:00
|
|
|
return new_proc;
|
|
|
|
}
|
|
|
|
|
2018-08-20 09:04:43 -05:00
|
|
|
#ifdef WITH_PYTHON
|
2018-08-13 08:18:46 -05:00
|
|
|
RTLIL::Memory::~Memory()
|
|
|
|
{
|
|
|
|
RTLIL::Memory::get_all_memorys()->erase(hashidx_);
|
|
|
|
}
|
2019-04-03 07:27:39 -05:00
|
|
|
static std::map<unsigned int, RTLIL::Memory*> all_memorys;
|
2018-08-13 08:18:46 -05:00
|
|
|
std::map<unsigned int, RTLIL::Memory*> *RTLIL::Memory::get_all_memorys(void)
|
|
|
|
{
|
2019-04-03 07:27:39 -05:00
|
|
|
return &all_memorys;
|
2018-08-13 08:18:46 -05:00
|
|
|
}
|
|
|
|
#endif
|
2014-07-31 06:19:47 -05:00
|
|
|
YOSYS_NAMESPACE_END
|