2013-01-05 04:13:26 -06:00
|
|
|
/*
|
|
|
|
* yosys -- Yosys Open SYnthesis Suite
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-07-31 06:19:47 -05:00
|
|
|
#include "kernel/yosys.h"
|
2013-06-19 02:30:37 -05:00
|
|
|
#include "frontends/verilog/verilog_frontend.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
|
|
|
|
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++) {
|
|
|
|
bits.push_back((ch & 1) != 0 ? RTLIL::S1 : RTLIL::S0);
|
|
|
|
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++) {
|
|
|
|
bits.push_back((val & 1) != 0 ? RTLIL::S1 : RTLIL::S0);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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++)
|
|
|
|
if (bits[i] == RTLIL::S1)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int RTLIL::Const::as_int() const
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
for (size_t i = 0; i < bits.size() && i < 32; i++)
|
|
|
|
if (bits[i] == RTLIL::S1)
|
|
|
|
ret |= 1 << i;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string RTLIL::Const::as_string() const
|
|
|
|
{
|
|
|
|
std::string ret;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-12-04 07:14:05 -06:00
|
|
|
std::string RTLIL::Const::decode_string() const
|
|
|
|
{
|
|
|
|
std::string string;
|
|
|
|
std::vector <char> string_chars;
|
|
|
|
for (int i = 0; i < int (bits.size()); i += 8) {
|
|
|
|
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)
|
|
|
|
string_chars.push_back(ch);
|
|
|
|
}
|
|
|
|
for (int i = int (string_chars.size()) - 1; i >= 0; i--)
|
|
|
|
string += string_chars[i];
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
refcount_modules_ = 0;
|
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::Design::~Design()
|
|
|
|
{
|
2014-07-27 03:18:00 -05:00
|
|
|
for (auto it = modules_.begin(); it != modules_.end(); it++)
|
2013-01-05 04:13:26 -06:00
|
|
|
delete it->second;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-27 14:12:09 -05:00
|
|
|
modules_[name] = new RTLIL::Module;
|
|
|
|
modules_[name]->name = name;
|
|
|
|
return modules_[name];
|
|
|
|
}
|
|
|
|
|
|
|
|
void RTLIL::Design::remove(RTLIL::Module *module)
|
|
|
|
{
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(modules_.at(module->name) == module);
|
2014-07-27 14:12:09 -05:00
|
|
|
modules_.erase(module->name);
|
|
|
|
delete module;
|
|
|
|
}
|
|
|
|
|
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-28 04:08:55 -05:00
|
|
|
log_assert(it.first == it.second->name);
|
|
|
|
log_assert(it.first.size() > 0 && (it.first[0] == '\\' || it.first[0] == '$'));
|
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-27 03:13:22 -05:00
|
|
|
RTLIL::Module::Module()
|
|
|
|
{
|
|
|
|
refcount_wires_ = 0;
|
|
|
|
refcount_cells_ = 0;
|
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::Module::~Module()
|
|
|
|
{
|
2014-07-26 18:49:51 -05:00
|
|
|
for (auto it = wires_.begin(); it != wires_.end(); it++)
|
2013-01-05 04:13:26 -06:00
|
|
|
delete it->second;
|
|
|
|
for (auto it = memories.begin(); it != memories.end(); it++)
|
|
|
|
delete it->second;
|
2014-07-26 18:51:45 -05:00
|
|
|
for (auto it = cells_.begin(); it != cells_.end(); it++)
|
2013-01-05 04:13:26 -06:00
|
|
|
delete it->second;
|
|
|
|
for (auto it = processes.begin(); it != processes.end(); it++)
|
|
|
|
delete it->second;
|
|
|
|
}
|
|
|
|
|
2013-12-04 07:24:44 -06:00
|
|
|
RTLIL::IdString RTLIL::Module::derive(RTLIL::Design*, std::map<RTLIL::IdString, RTLIL::Const>)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2013-03-26 13:27:49 -05:00
|
|
|
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;
|
|
|
|
std::set<RTLIL::IdString> expected_params, expected_ports;
|
|
|
|
|
|
|
|
InternalCellChecker(RTLIL::Module *module, RTLIL::Cell *cell) : module(module), cell(cell) { }
|
|
|
|
|
|
|
|
void error(int linenr)
|
|
|
|
{
|
|
|
|
char *ptr;
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
FILE *f = open_memstream(&ptr, &size);
|
|
|
|
ILANG_BACKEND::dump_cell(f, " ", cell);
|
|
|
|
fputc(0, f);
|
|
|
|
fclose(f);
|
|
|
|
|
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 ? "." : "",
|
|
|
|
cell->name.c_str(), cell->type.c_str(), __FILE__, linenr, ptr);
|
2013-11-10 16:25:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
int param(const char *name)
|
|
|
|
{
|
|
|
|
if (cell->parameters.count(name) == 0)
|
|
|
|
error(__LINE__);
|
|
|
|
expected_params.insert(name);
|
|
|
|
return cell->parameters.at(name).as_int();
|
|
|
|
}
|
|
|
|
|
2014-02-07 10:39:35 -06:00
|
|
|
int param_bool(const char *name)
|
|
|
|
{
|
|
|
|
int v = param(name);
|
2014-02-08 12:13:49 -06:00
|
|
|
if (cell->parameters.at(name).bits.size() > 32)
|
|
|
|
error(__LINE__);
|
2014-02-07 10:39:35 -06:00
|
|
|
if (v != 0 && v != 1)
|
|
|
|
error(__LINE__);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2014-02-08 12:13:49 -06:00
|
|
|
void param_bits(const char *name, int width)
|
|
|
|
{
|
|
|
|
param(name);
|
|
|
|
if (int(cell->parameters.at(name).bits.size()) != width)
|
|
|
|
error(__LINE__);
|
|
|
|
}
|
|
|
|
|
2013-11-10 16:25:04 -06:00
|
|
|
void port(const char *name, int width)
|
|
|
|
{
|
2014-07-26 09:11:28 -05:00
|
|
|
if (!cell->has(name))
|
2013-11-10 16:25:04 -06:00
|
|
|
error(__LINE__);
|
2014-07-26 09:11:28 -05:00
|
|
|
if (cell->get(name).size() != width)
|
2013-11-10 16:25:04 -06:00
|
|
|
error(__LINE__);
|
|
|
|
expected_ports.insert(name);
|
|
|
|
}
|
|
|
|
|
2013-12-31 07:54:06 -06:00
|
|
|
void check_expected(bool check_matched_sign = true)
|
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
|
|
|
|
|
|
|
if (expected_params.count("\\A_SIGNED") != 0 && expected_params.count("\\B_SIGNED") && check_matched_sign) {
|
|
|
|
bool a_is_signed = param("\\A_SIGNED") != 0;
|
|
|
|
bool b_is_signed = param("\\B_SIGNED") != 0;
|
|
|
|
if (a_is_signed != b_is_signed)
|
|
|
|
error(__LINE__);
|
|
|
|
}
|
2013-11-10 16:25:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void check_gate(const char *ports)
|
|
|
|
{
|
|
|
|
if (cell->parameters.size() != 0)
|
|
|
|
error(__LINE__);
|
|
|
|
|
|
|
|
for (const char *p = ports; *p; p++) {
|
|
|
|
char portname[3] = { '\\', *p, 0 };
|
2014-07-26 09:11:28 -05:00
|
|
|
if (!cell->has(portname))
|
2013-11-10 16:25:04 -06:00
|
|
|
error(__LINE__);
|
2014-07-26 09:11:28 -05:00
|
|
|
if (cell->get(portname).size() != 1)
|
2013-11-10 16:25:04 -06:00
|
|
|
error(__LINE__);
|
|
|
|
}
|
|
|
|
|
2014-07-26 07:32:50 -05:00
|
|
|
for (auto &conn : cell->connections()) {
|
2013-11-10 16:25:04 -06:00
|
|
|
if (conn.first.size() != 2 || conn.first.at(0) != '\\')
|
|
|
|
error(__LINE__);
|
|
|
|
if (strchr(ports, conn.first.at(1)) == NULL)
|
|
|
|
error(__LINE__);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void check()
|
|
|
|
{
|
2014-07-21 05:02:55 -05:00
|
|
|
if (cell->type[0] != '$' || cell->type.substr(0, 3) == "$__" || cell->type.substr(0, 8) == "$paramod" ||
|
2014-07-27 14:12:09 -05:00
|
|
|
cell->type.substr(0, 9) == "$verific$" || cell->type.substr(0, 7) == "$array:" || cell->type.substr(0, 8) == "$extern:")
|
2014-07-21 05:02:55 -05:00
|
|
|
return;
|
|
|
|
|
2013-12-28 04:54:40 -06:00
|
|
|
if (cell->type == "$not" || cell->type == "$pos" || cell->type == "$bu0" || cell->type == "$neg") {
|
2014-02-07 10:39:35 -06:00
|
|
|
param_bool("\\A_SIGNED");
|
2013-11-10 16:25:04 -06:00
|
|
|
port("\\A", param("\\A_WIDTH"));
|
|
|
|
port("\\Y", param("\\Y_WIDTH"));
|
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cell->type == "$and" || cell->type == "$or" || cell->type == "$xor" || cell->type == "$xnor") {
|
2014-02-07 10:39:35 -06:00
|
|
|
param_bool("\\A_SIGNED");
|
|
|
|
param_bool("\\B_SIGNED");
|
2013-11-10 16:25:04 -06:00
|
|
|
port("\\A", param("\\A_WIDTH"));
|
|
|
|
port("\\B", param("\\B_WIDTH"));
|
|
|
|
port("\\Y", param("\\Y_WIDTH"));
|
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cell->type == "$reduce_and" || cell->type == "$reduce_or" || cell->type == "$reduce_xor" ||
|
|
|
|
cell->type == "$reduce_xnor" || cell->type == "$reduce_bool") {
|
2014-02-07 10:39:35 -06:00
|
|
|
param_bool("\\A_SIGNED");
|
2013-11-10 16:25:04 -06:00
|
|
|
port("\\A", param("\\A_WIDTH"));
|
|
|
|
port("\\Y", param("\\Y_WIDTH"));
|
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-29 07:42:33 -05:00
|
|
|
if (cell->type == "$shl" || cell->type == "$shr" || cell->type == "$sshl" || cell->type == "$sshr" ||
|
|
|
|
cell->type == "$shift" || cell->type == "$shiftx") {
|
2014-02-07 10:39:35 -06:00
|
|
|
param_bool("\\A_SIGNED");
|
|
|
|
param_bool("\\B_SIGNED");
|
2013-11-10 16:25:04 -06:00
|
|
|
port("\\A", param("\\A_WIDTH"));
|
|
|
|
port("\\B", param("\\B_WIDTH"));
|
|
|
|
port("\\Y", param("\\Y_WIDTH"));
|
2013-12-31 07:54:06 -06:00
|
|
|
check_expected(false);
|
2013-11-10 16:25:04 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cell->type == "$lt" || cell->type == "$le" || cell->type == "$eq" || cell->type == "$ne" ||
|
2013-12-27 07:20:15 -06:00
|
|
|
cell->type == "$eqx" || cell->type == "$nex" || cell->type == "$ge" || cell->type == "$gt") {
|
2014-02-07 10:39:35 -06:00
|
|
|
param_bool("\\A_SIGNED");
|
|
|
|
param_bool("\\B_SIGNED");
|
2013-11-10 16:25:04 -06:00
|
|
|
port("\\A", param("\\A_WIDTH"));
|
|
|
|
port("\\B", param("\\B_WIDTH"));
|
|
|
|
port("\\Y", param("\\Y_WIDTH"));
|
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cell->type == "$add" || cell->type == "$sub" || cell->type == "$mul" || cell->type == "$div" ||
|
|
|
|
cell->type == "$mod" || cell->type == "$pow") {
|
2014-02-07 10:39:35 -06:00
|
|
|
param_bool("\\A_SIGNED");
|
|
|
|
param_bool("\\B_SIGNED");
|
2013-11-10 16:25:04 -06:00
|
|
|
port("\\A", param("\\A_WIDTH"));
|
|
|
|
port("\\B", param("\\B_WIDTH"));
|
|
|
|
port("\\Y", param("\\Y_WIDTH"));
|
2013-12-31 07:54:06 -06:00
|
|
|
check_expected(cell->type != "$pow");
|
2013-11-10 16:25:04 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cell->type == "$logic_not") {
|
2014-02-07 10:39:35 -06:00
|
|
|
param_bool("\\A_SIGNED");
|
2013-11-10 16:25:04 -06:00
|
|
|
port("\\A", param("\\A_WIDTH"));
|
|
|
|
port("\\Y", param("\\Y_WIDTH"));
|
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cell->type == "$logic_and" || cell->type == "$logic_or") {
|
2014-02-07 10:39:35 -06:00
|
|
|
param_bool("\\A_SIGNED");
|
|
|
|
param_bool("\\B_SIGNED");
|
2013-11-10 16:25:04 -06:00
|
|
|
port("\\A", param("\\A_WIDTH"));
|
|
|
|
port("\\B", param("\\B_WIDTH"));
|
|
|
|
port("\\Y", param("\\Y_WIDTH"));
|
2013-12-31 07:54:06 -06:00
|
|
|
check_expected(false);
|
2013-11-10 16:25:04 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-07 10:44:57 -06:00
|
|
|
if (cell->type == "$slice") {
|
|
|
|
param("\\OFFSET");
|
|
|
|
port("\\A", param("\\A_WIDTH"));
|
|
|
|
port("\\Y", param("\\Y_WIDTH"));
|
|
|
|
if (param("\\OFFSET") + param("\\Y_WIDTH") > param("\\A_WIDTH"))
|
|
|
|
error(__LINE__);
|
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cell->type == "$concat") {
|
|
|
|
port("\\A", param("\\A_WIDTH"));
|
|
|
|
port("\\B", param("\\B_WIDTH"));
|
|
|
|
port("\\Y", param("\\A_WIDTH") + param("\\B_WIDTH"));
|
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-10 16:25:04 -06:00
|
|
|
if (cell->type == "$mux") {
|
|
|
|
port("\\A", param("\\WIDTH"));
|
|
|
|
port("\\B", param("\\WIDTH"));
|
|
|
|
port("\\S", 1);
|
|
|
|
port("\\Y", param("\\WIDTH"));
|
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cell->type == "$pmux" || cell->type == "$safe_pmux") {
|
|
|
|
port("\\A", param("\\WIDTH"));
|
|
|
|
port("\\B", param("\\WIDTH") * param("\\S_WIDTH"));
|
|
|
|
port("\\S", param("\\S_WIDTH"));
|
|
|
|
port("\\Y", param("\\WIDTH"));
|
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cell->type == "$lut") {
|
|
|
|
param("\\LUT");
|
|
|
|
port("\\I", param("\\WIDTH"));
|
|
|
|
port("\\O", 1);
|
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cell->type == "$sr") {
|
2014-02-07 10:39:35 -06:00
|
|
|
param_bool("\\SET_POLARITY");
|
|
|
|
param_bool("\\CLR_POLARITY");
|
2013-11-10 16:25:04 -06:00
|
|
|
port("\\SET", param("\\WIDTH"));
|
|
|
|
port("\\CLR", param("\\WIDTH"));
|
|
|
|
port("\\Q", param("\\WIDTH"));
|
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cell->type == "$dff") {
|
2014-02-07 10:39:35 -06:00
|
|
|
param_bool("\\CLK_POLARITY");
|
2013-11-10 16:25:04 -06:00
|
|
|
port("\\CLK", 1);
|
|
|
|
port("\\D", param("\\WIDTH"));
|
|
|
|
port("\\Q", param("\\WIDTH"));
|
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cell->type == "$dffsr") {
|
2014-02-07 10:39:35 -06:00
|
|
|
param_bool("\\CLK_POLARITY");
|
|
|
|
param_bool("\\SET_POLARITY");
|
|
|
|
param_bool("\\CLR_POLARITY");
|
2013-11-10 16:25:04 -06:00
|
|
|
port("\\CLK", 1);
|
|
|
|
port("\\SET", param("\\WIDTH"));
|
|
|
|
port("\\CLR", param("\\WIDTH"));
|
|
|
|
port("\\D", param("\\WIDTH"));
|
|
|
|
port("\\Q", param("\\WIDTH"));
|
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cell->type == "$adff") {
|
2014-02-07 10:39:35 -06:00
|
|
|
param_bool("\\CLK_POLARITY");
|
|
|
|
param_bool("\\ARST_POLARITY");
|
2014-02-08 12:13:49 -06:00
|
|
|
param_bits("\\ARST_VALUE", param("\\WIDTH"));
|
2013-11-10 16:25:04 -06:00
|
|
|
port("\\CLK", 1);
|
|
|
|
port("\\ARST", 1);
|
|
|
|
port("\\D", param("\\WIDTH"));
|
|
|
|
port("\\Q", param("\\WIDTH"));
|
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cell->type == "$dlatch") {
|
2014-02-07 10:39:35 -06:00
|
|
|
param_bool("\\EN_POLARITY");
|
2013-11-10 16:25:04 -06:00
|
|
|
port("\\EN", 1);
|
|
|
|
port("\\D", param("\\WIDTH"));
|
|
|
|
port("\\Q", param("\\WIDTH"));
|
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-31 07:14:40 -05:00
|
|
|
if (cell->type == "$dlatchsr") {
|
|
|
|
param_bool("\\EN_POLARITY");
|
|
|
|
param_bool("\\SET_POLARITY");
|
|
|
|
param_bool("\\CLR_POLARITY");
|
|
|
|
port("\\EN", 1);
|
|
|
|
port("\\SET", param("\\WIDTH"));
|
|
|
|
port("\\CLR", param("\\WIDTH"));
|
|
|
|
port("\\D", param("\\WIDTH"));
|
|
|
|
port("\\Q", param("\\WIDTH"));
|
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-10 16:25:04 -06:00
|
|
|
if (cell->type == "$fsm") {
|
|
|
|
param("\\NAME");
|
2014-02-07 10:39:35 -06:00
|
|
|
param_bool("\\CLK_POLARITY");
|
|
|
|
param_bool("\\ARST_POLARITY");
|
2013-11-10 16:25:04 -06:00
|
|
|
param("\\STATE_BITS");
|
|
|
|
param("\\STATE_NUM");
|
|
|
|
param("\\STATE_NUM_LOG2");
|
|
|
|
param("\\STATE_RST");
|
2014-02-08 12:13:49 -06:00
|
|
|
param_bits("\\STATE_TABLE", param("\\STATE_BITS") * param("\\STATE_NUM"));
|
2013-11-10 16:25:04 -06:00
|
|
|
param("\\TRANS_NUM");
|
2014-02-08 12:13:49 -06:00
|
|
|
param_bits("\\TRANS_TABLE", param("\\TRANS_NUM") * (2*param("\\STATE_NUM_LOG2") + param("\\CTRL_IN_WIDTH") + param("\\CTRL_OUT_WIDTH")));
|
2013-11-10 16:25:04 -06:00
|
|
|
port("\\CLK", 1);
|
|
|
|
port("\\ARST", 1);
|
|
|
|
port("\\CTRL_IN", param("\\CTRL_IN_WIDTH"));
|
|
|
|
port("\\CTRL_OUT", param("\\CTRL_OUT_WIDTH"));
|
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cell->type == "$memrd") {
|
|
|
|
param("\\MEMID");
|
2014-02-07 10:39:35 -06:00
|
|
|
param_bool("\\CLK_ENABLE");
|
|
|
|
param_bool("\\CLK_POLARITY");
|
|
|
|
param_bool("\\TRANSPARENT");
|
2013-11-10 16:25:04 -06:00
|
|
|
port("\\CLK", 1);
|
|
|
|
port("\\ADDR", param("\\ABITS"));
|
|
|
|
port("\\DATA", param("\\WIDTH"));
|
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cell->type == "$memwr") {
|
|
|
|
param("\\MEMID");
|
2014-02-07 10:39:35 -06:00
|
|
|
param_bool("\\CLK_ENABLE");
|
|
|
|
param_bool("\\CLK_POLARITY");
|
2014-01-02 17:22:17 -06:00
|
|
|
param("\\PRIORITY");
|
2013-11-10 16:25:04 -06:00
|
|
|
port("\\CLK", 1);
|
2014-07-16 04:38:02 -05:00
|
|
|
port("\\EN", param("\\WIDTH"));
|
2013-11-10 16:25:04 -06:00
|
|
|
port("\\ADDR", param("\\ABITS"));
|
|
|
|
port("\\DATA", param("\\WIDTH"));
|
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cell->type == "$mem") {
|
|
|
|
param("\\MEMID");
|
|
|
|
param("\\SIZE");
|
|
|
|
param("\\OFFSET");
|
2014-02-08 12:13:49 -06:00
|
|
|
param_bits("\\RD_CLK_ENABLE", param("\\RD_PORTS"));
|
|
|
|
param_bits("\\RD_CLK_POLARITY", param("\\RD_PORTS"));
|
|
|
|
param_bits("\\RD_TRANSPARENT", param("\\RD_PORTS"));
|
|
|
|
param_bits("\\WR_CLK_ENABLE", param("\\WR_PORTS"));
|
|
|
|
param_bits("\\WR_CLK_POLARITY", param("\\WR_PORTS"));
|
2013-11-10 16:25:04 -06:00
|
|
|
port("\\RD_CLK", param("\\RD_PORTS"));
|
|
|
|
port("\\RD_ADDR", param("\\RD_PORTS") * param("\\ABITS"));
|
|
|
|
port("\\RD_DATA", param("\\RD_PORTS") * param("\\WIDTH"));
|
|
|
|
port("\\WR_CLK", param("\\WR_PORTS"));
|
2014-07-16 04:38:02 -05:00
|
|
|
port("\\WR_EN", param("\\WR_PORTS") * param("\\WIDTH"));
|
2013-11-10 16:25:04 -06:00
|
|
|
port("\\WR_ADDR", param("\\WR_PORTS") * param("\\ABITS"));
|
|
|
|
port("\\WR_DATA", param("\\WR_PORTS") * param("\\WIDTH"));
|
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-19 07:03:40 -06:00
|
|
|
if (cell->type == "$assert") {
|
|
|
|
port("\\A", 1);
|
|
|
|
port("\\EN", 1);
|
|
|
|
check_expected();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-10 16:25:04 -06:00
|
|
|
if (cell->type == "$_INV_") { check_gate("AY"); return; }
|
|
|
|
if (cell->type == "$_AND_") { check_gate("ABY"); return; }
|
|
|
|
if (cell->type == "$_OR_") { check_gate("ABY"); return; }
|
|
|
|
if (cell->type == "$_XOR_") { check_gate("ABY"); return; }
|
|
|
|
if (cell->type == "$_MUX_") { check_gate("ABSY"); return; }
|
|
|
|
|
|
|
|
if (cell->type == "$_SR_NN_") { check_gate("SRQ"); return; }
|
|
|
|
if (cell->type == "$_SR_NP_") { check_gate("SRQ"); return; }
|
|
|
|
if (cell->type == "$_SR_PN_") { check_gate("SRQ"); return; }
|
|
|
|
if (cell->type == "$_SR_PP_") { check_gate("SRQ"); return; }
|
|
|
|
|
|
|
|
if (cell->type == "$_DFF_N_") { check_gate("DQC"); return; }
|
|
|
|
if (cell->type == "$_DFF_P_") { check_gate("DQC"); return; }
|
|
|
|
|
|
|
|
if (cell->type == "$_DFF_NN0_") { check_gate("DQCR"); return; }
|
|
|
|
if (cell->type == "$_DFF_NN1_") { check_gate("DQCR"); return; }
|
|
|
|
if (cell->type == "$_DFF_NP0_") { check_gate("DQCR"); return; }
|
|
|
|
if (cell->type == "$_DFF_NP1_") { check_gate("DQCR"); return; }
|
|
|
|
if (cell->type == "$_DFF_PN0_") { check_gate("DQCR"); return; }
|
|
|
|
if (cell->type == "$_DFF_PN1_") { check_gate("DQCR"); return; }
|
|
|
|
if (cell->type == "$_DFF_PP0_") { check_gate("DQCR"); return; }
|
|
|
|
if (cell->type == "$_DFF_PP1_") { check_gate("DQCR"); return; }
|
|
|
|
|
|
|
|
if (cell->type == "$_DFFSR_NNN_") { check_gate("CSRDQ"); return; }
|
|
|
|
if (cell->type == "$_DFFSR_NNP_") { check_gate("CSRDQ"); return; }
|
|
|
|
if (cell->type == "$_DFFSR_NPN_") { check_gate("CSRDQ"); return; }
|
|
|
|
if (cell->type == "$_DFFSR_NPP_") { check_gate("CSRDQ"); return; }
|
|
|
|
if (cell->type == "$_DFFSR_PNN_") { check_gate("CSRDQ"); return; }
|
|
|
|
if (cell->type == "$_DFFSR_PNP_") { check_gate("CSRDQ"); return; }
|
|
|
|
if (cell->type == "$_DFFSR_PPN_") { check_gate("CSRDQ"); return; }
|
|
|
|
if (cell->type == "$_DFFSR_PPP_") { check_gate("CSRDQ"); return; }
|
|
|
|
|
|
|
|
if (cell->type == "$_DLATCH_N_") { check_gate("EDQ"); return; }
|
|
|
|
if (cell->type == "$_DLATCH_P_") { check_gate("EDQ"); return; }
|
|
|
|
|
2014-03-31 07:14:40 -05:00
|
|
|
if (cell->type == "$_DLATCHSR_NNN_") { check_gate("ESRDQ"); return; }
|
|
|
|
if (cell->type == "$_DLATCHSR_NNP_") { check_gate("ESRDQ"); return; }
|
|
|
|
if (cell->type == "$_DLATCHSR_NPN_") { check_gate("ESRDQ"); return; }
|
|
|
|
if (cell->type == "$_DLATCHSR_NPP_") { check_gate("ESRDQ"); return; }
|
|
|
|
if (cell->type == "$_DLATCHSR_PNN_") { check_gate("ESRDQ"); return; }
|
|
|
|
if (cell->type == "$_DLATCHSR_PNP_") { check_gate("ESRDQ"); return; }
|
|
|
|
if (cell->type == "$_DLATCHSR_PPN_") { check_gate("ESRDQ"); return; }
|
|
|
|
if (cell->type == "$_DLATCHSR_PPP_") { check_gate("ESRDQ"); return; }
|
|
|
|
|
2013-11-10 16:25:04 -06:00
|
|
|
error(__LINE__);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
void RTLIL::Module::check()
|
|
|
|
{
|
|
|
|
#ifndef NDEBUG
|
2014-07-26 18:49:51 -05:00
|
|
|
for (auto &it : wires_) {
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(it.first == it.second->name);
|
|
|
|
log_assert(it.first.size() > 0 && (it.first[0] == '\\' || it.first[0] == '$'));
|
|
|
|
log_assert(it.second->width >= 0);
|
|
|
|
log_assert(it.second->port_id >= 0);
|
2013-01-05 04:13:26 -06:00
|
|
|
for (auto &it2 : it.second->attributes) {
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(it2.first.size() > 0 && (it2.first[0] == '\\' || it2.first[0] == '$'));
|
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);
|
|
|
|
log_assert(it.first.size() > 0 && (it.first[0] == '\\' || it.first[0] == '$'));
|
|
|
|
log_assert(it.second->width >= 0);
|
|
|
|
log_assert(it.second->size >= 0);
|
2013-01-05 04:13:26 -06:00
|
|
|
for (auto &it2 : it.second->attributes) {
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(it2.first.size() > 0 && (it2.first[0] == '\\' || it2.first[0] == '$'));
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-26 18:51:45 -05:00
|
|
|
for (auto &it : cells_) {
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(it.first == it.second->name);
|
|
|
|
log_assert(it.first.size() > 0 && (it.first[0] == '\\' || it.first[0] == '$'));
|
|
|
|
log_assert(it.second->type.size() > 0 && (it.second->type[0] == '\\' || it.second->type[0] == '$'));
|
2014-07-26 07:32:50 -05:00
|
|
|
for (auto &it2 : it.second->connections()) {
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(it2.first.size() > 0 && (it2.first[0] == '\\' || it2.first[0] == '$'));
|
2013-01-05 04:13:26 -06:00
|
|
|
it2.second.check();
|
|
|
|
}
|
|
|
|
for (auto &it2 : it.second->attributes) {
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(it2.first.size() > 0 && (it2.first[0] == '\\' || it2.first[0] == '$'));
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
for (auto &it2 : it.second->parameters) {
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(it2.first.size() > 0 && (it2.first[0] == '\\' || it2.first[0] == '$'));
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
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);
|
|
|
|
log_assert(it.first.size() > 0 && (it.first[0] == '\\' || it.first[0] == '$'));
|
2013-01-05 04:13:26 -06:00
|
|
|
// FIXME: More checks here..
|
|
|
|
}
|
|
|
|
|
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());
|
2013-01-05 04:13:26 -06:00
|
|
|
it.first.check();
|
|
|
|
it.second.check();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &it : attributes) {
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(it.first.size() > 0 && (it.first[0] == '\\' || it.first[0] == '$'));
|
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);
|
|
|
|
|
2014-07-26 08:57:57 -05:00
|
|
|
new_mod->connections_ = connections_;
|
2013-07-27 07:27:51 -05:00
|
|
|
new_mod->attributes = attributes;
|
|
|
|
|
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)
|
|
|
|
new_mod->memories[it.first] = new RTLIL::Memory(*it.second);
|
|
|
|
|
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)
|
|
|
|
new_mod->processes[it.first] = it.second->clone();
|
|
|
|
|
|
|
|
struct RewriteSigSpecWorker
|
|
|
|
{
|
|
|
|
RTLIL::Module *mod;
|
|
|
|
void operator()(RTLIL::SigSpec &sig)
|
|
|
|
{
|
2014-07-22 16:50:21 -05:00
|
|
|
std::vector<RTLIL::SigChunk> chunks = sig.chunks();
|
|
|
|
for (auto &c : 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);
|
2014-07-22 16:50:21 -05:00
|
|
|
sig = chunks;
|
2013-07-27 07:27:51 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
RewriteSigSpecWorker rewriteSigSpecWorker;
|
|
|
|
rewriteSigSpecWorker.mod = new_mod;
|
|
|
|
new_mod->rewrite_sigspecs(rewriteSigSpecWorker);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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;
|
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;
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2014-07-26 13:12:50 -05:00
|
|
|
namespace {
|
|
|
|
struct DeleteWireWorker
|
|
|
|
{
|
|
|
|
RTLIL::Module *module;
|
|
|
|
const std::set<RTLIL::Wire*> *wires_p;
|
|
|
|
|
|
|
|
void operator()(RTLIL::SigSpec &sig) {
|
|
|
|
std::vector<RTLIL::SigChunk> chunks = sig;
|
|
|
|
for (auto &c : chunks)
|
|
|
|
if (c.wire != NULL && wires_p->count(c.wire)) {
|
|
|
|
c.wire = module->addWire(NEW_ID, c.width);
|
|
|
|
c.offset = 0;
|
|
|
|
}
|
|
|
|
sig = chunks;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
void RTLIL::Module::remove(RTLIL::Wire *wire)
|
|
|
|
{
|
2014-07-26 18:49:51 -05:00
|
|
|
std::set<RTLIL::Wire*> wires_;
|
|
|
|
wires_.insert(wire);
|
|
|
|
remove(wires_);
|
2014-07-26 13:12:50 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void RTLIL::Module::remove(const std::set<RTLIL::Wire*> &wires)
|
|
|
|
{
|
2014-07-27 03:13:22 -05:00
|
|
|
log_assert(refcount_wires_ == 0);
|
|
|
|
|
2014-07-26 13:12:50 -05:00
|
|
|
DeleteWireWorker delete_wire_worker;
|
|
|
|
delete_wire_worker.module = this;
|
|
|
|
delete_wire_worker.wires_p = &wires;
|
|
|
|
rewrite_sigspecs(delete_wire_worker);
|
|
|
|
|
|
|
|
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-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();
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
connections_.push_back(conn);
|
|
|
|
}
|
|
|
|
|
2014-07-26 04:58:03 -05:00
|
|
|
void RTLIL::Module::connect(const RTLIL::SigSpec &lhs, const RTLIL::SigSpec &rhs)
|
|
|
|
{
|
|
|
|
connections_.push_back(RTLIL::SigSig(lhs, rhs));
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
for (size_t i = 0; i < all_ports.size(); i++)
|
|
|
|
all_ports[i]->port_id = i+1;
|
|
|
|
}
|
|
|
|
|
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;
|
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;
|
|
|
|
}
|
|
|
|
|
2014-07-18 03:27:06 -05:00
|
|
|
#define DEF_METHOD(_func, _y_size, _type) \
|
|
|
|
RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_y, bool is_signed) { \
|
2014-03-09 21:02:27 -05:00
|
|
|
RTLIL::Cell *cell = new RTLIL::Cell; \
|
|
|
|
cell->name = name; \
|
|
|
|
cell->type = _type; \
|
|
|
|
cell->parameters["\\A_SIGNED"] = is_signed; \
|
2014-07-22 13:15:14 -05:00
|
|
|
cell->parameters["\\A_WIDTH"] = sig_a.size(); \
|
|
|
|
cell->parameters["\\Y_WIDTH"] = sig_y.size(); \
|
2014-07-26 07:32:50 -05:00
|
|
|
cell->set("\\A", sig_a); \
|
|
|
|
cell->set("\\Y", sig_y); \
|
2014-03-09 21:02:27 -05:00
|
|
|
add(cell); \
|
|
|
|
return cell; \
|
2014-07-18 03:27:06 -05:00
|
|
|
} \
|
|
|
|
RTLIL::SigSpec RTLIL::Module::_func(RTLIL::IdString name, RTLIL::SigSpec sig_a, bool is_signed) { \
|
2014-07-21 05:35:06 -05:00
|
|
|
RTLIL::SigSpec sig_y = addWire(NEW_ID, _y_size); \
|
2014-07-18 03:27:06 -05:00
|
|
|
add ## _func(name, sig_a, sig_y, is_signed); \
|
|
|
|
return sig_y; \
|
2014-03-09 21:02:27 -05:00
|
|
|
}
|
2014-07-22 13:15:14 -05:00
|
|
|
DEF_METHOD(Not, sig_a.size(), "$not")
|
|
|
|
DEF_METHOD(Pos, sig_a.size(), "$pos")
|
|
|
|
DEF_METHOD(Bu0, sig_a.size(), "$bu0")
|
|
|
|
DEF_METHOD(Neg, sig_a.size(), "$neg")
|
2014-07-18 03:27:06 -05:00
|
|
|
DEF_METHOD(ReduceAnd, 1, "$reduce_and")
|
|
|
|
DEF_METHOD(ReduceOr, 1, "$reduce_or")
|
|
|
|
DEF_METHOD(ReduceXor, 1, "$reduce_xor")
|
|
|
|
DEF_METHOD(ReduceXnor, 1, "$reduce_xnor")
|
|
|
|
DEF_METHOD(ReduceBool, 1, "$reduce_bool")
|
|
|
|
DEF_METHOD(LogicNot, 1, "$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) \
|
|
|
|
RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed) { \
|
2014-03-09 21:02:27 -05:00
|
|
|
RTLIL::Cell *cell = new RTLIL::Cell; \
|
|
|
|
cell->name = name; \
|
|
|
|
cell->type = _type; \
|
|
|
|
cell->parameters["\\A_SIGNED"] = is_signed; \
|
|
|
|
cell->parameters["\\B_SIGNED"] = is_signed; \
|
2014-07-22 13:15:14 -05:00
|
|
|
cell->parameters["\\A_WIDTH"] = sig_a.size(); \
|
|
|
|
cell->parameters["\\B_WIDTH"] = sig_b.size(); \
|
|
|
|
cell->parameters["\\Y_WIDTH"] = sig_y.size(); \
|
2014-07-26 07:32:50 -05:00
|
|
|
cell->set("\\A", sig_a); \
|
|
|
|
cell->set("\\B", sig_b); \
|
|
|
|
cell->set("\\Y", sig_y); \
|
2014-03-09 21:02:27 -05:00
|
|
|
add(cell); \
|
|
|
|
return cell; \
|
2014-07-18 03:27:06 -05:00
|
|
|
} \
|
|
|
|
RTLIL::SigSpec RTLIL::Module::_func(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed) { \
|
2014-07-21 05:35:06 -05:00
|
|
|
RTLIL::SigSpec sig_y = addWire(NEW_ID, _y_size); \
|
2014-07-18 03:27:06 -05:00
|
|
|
add ## _func(name, sig_a, sig_b, sig_y, is_signed); \
|
|
|
|
return sig_y; \
|
2014-03-09 21:02:27 -05:00
|
|
|
}
|
2014-07-22 13:15:14 -05:00
|
|
|
DEF_METHOD(And, std::max(sig_a.size(), sig_b.size()), "$and")
|
|
|
|
DEF_METHOD(Or, std::max(sig_a.size(), sig_b.size()), "$or")
|
|
|
|
DEF_METHOD(Xor, std::max(sig_a.size(), sig_b.size()), "$xor")
|
|
|
|
DEF_METHOD(Xnor, std::max(sig_a.size(), sig_b.size()), "$xnor")
|
|
|
|
DEF_METHOD(Shl, sig_a.size(), "$shl")
|
|
|
|
DEF_METHOD(Shr, sig_a.size(), "$shr")
|
|
|
|
DEF_METHOD(Sshl, sig_a.size(), "$sshl")
|
|
|
|
DEF_METHOD(Sshr, sig_a.size(), "$sshr")
|
2014-07-29 07:42:33 -05:00
|
|
|
DEF_METHOD(Shift, sig_a.size(), "$shift")
|
|
|
|
DEF_METHOD(Shiftx, sig_a.size(), "$shiftx")
|
2014-07-18 03:27:06 -05:00
|
|
|
DEF_METHOD(Lt, 1, "$lt")
|
|
|
|
DEF_METHOD(Le, 1, "$le")
|
|
|
|
DEF_METHOD(Eq, 1, "$eq")
|
|
|
|
DEF_METHOD(Ne, 1, "$ne")
|
|
|
|
DEF_METHOD(Eqx, 1, "$eqx")
|
|
|
|
DEF_METHOD(Nex, 1, "$nex")
|
|
|
|
DEF_METHOD(Ge, 1, "$ge")
|
|
|
|
DEF_METHOD(Gt, 1, "$gt")
|
2014-07-22 13:15:14 -05:00
|
|
|
DEF_METHOD(Add, std::max(sig_a.size(), sig_b.size()), "$add")
|
|
|
|
DEF_METHOD(Sub, std::max(sig_a.size(), sig_b.size()), "$sub")
|
|
|
|
DEF_METHOD(Mul, std::max(sig_a.size(), sig_b.size()), "$mul")
|
|
|
|
DEF_METHOD(Div, std::max(sig_a.size(), sig_b.size()), "$div")
|
|
|
|
DEF_METHOD(Mod, std::max(sig_a.size(), sig_b.size()), "$mod")
|
2014-07-18 03:27:06 -05:00
|
|
|
DEF_METHOD(LogicAnd, 1, "$logic_and")
|
|
|
|
DEF_METHOD(LogicOr, 1, "$logic_or")
|
2014-03-09 21:02:27 -05:00
|
|
|
#undef DEF_METHOD
|
|
|
|
|
|
|
|
#define DEF_METHOD(_func, _type, _pmux) \
|
2014-07-18 03:27:06 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_s, RTLIL::SigSpec sig_y) { \
|
2014-03-09 21:02:27 -05:00
|
|
|
RTLIL::Cell *cell = new RTLIL::Cell; \
|
|
|
|
cell->name = name; \
|
|
|
|
cell->type = _type; \
|
2014-07-22 13:15:14 -05:00
|
|
|
cell->parameters["\\WIDTH"] = sig_a.size(); \
|
|
|
|
cell->parameters["\\WIDTH"] = sig_b.size(); \
|
|
|
|
if (_pmux) cell->parameters["\\S_WIDTH"] = sig_s.size(); \
|
2014-07-26 07:32:50 -05:00
|
|
|
cell->set("\\A", sig_a); \
|
|
|
|
cell->set("\\B", sig_b); \
|
|
|
|
cell->set("\\S", sig_s); \
|
|
|
|
cell->set("\\Y", sig_y); \
|
2014-03-09 21:02:27 -05:00
|
|
|
add(cell); \
|
|
|
|
return cell; \
|
2014-07-18 03:27:06 -05:00
|
|
|
} \
|
|
|
|
RTLIL::SigSpec RTLIL::Module::_func(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_s) { \
|
2014-07-22 13:15:14 -05:00
|
|
|
RTLIL::SigSpec sig_y = addWire(NEW_ID, sig_a.size()); \
|
2014-07-18 03:27:06 -05:00
|
|
|
add ## _func(name, sig_a, sig_b, sig_s, sig_y); \
|
|
|
|
return sig_y; \
|
2014-03-09 21:02:27 -05:00
|
|
|
}
|
2014-07-18 03:27:06 -05:00
|
|
|
DEF_METHOD(Mux, "$mux", 0)
|
|
|
|
DEF_METHOD(Pmux, "$pmux", 1)
|
|
|
|
DEF_METHOD(SafePmux, "$safe_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) \
|
2014-07-18 03:27:06 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, RTLIL::SigSpec sig1, RTLIL::SigSpec sig2) { \
|
|
|
|
RTLIL::Cell *cell = new RTLIL::Cell; \
|
|
|
|
cell->name = name; \
|
|
|
|
cell->type = _type; \
|
2014-07-26 08:57:57 -05:00
|
|
|
cell->set("\\" #_P1, sig1); \
|
|
|
|
cell->set("\\" #_P2, sig2); \
|
2014-07-18 03:27:06 -05:00
|
|
|
add(cell); \
|
|
|
|
return cell; \
|
|
|
|
} \
|
|
|
|
RTLIL::SigSpec RTLIL::Module::_func(RTLIL::IdString name, RTLIL::SigSpec sig1) { \
|
2014-07-21 05:35:06 -05:00
|
|
|
RTLIL::SigSpec sig2 = addWire(NEW_ID); \
|
2014-07-18 03:27:06 -05:00
|
|
|
add ## _func(name, sig1, sig2); \
|
|
|
|
return sig2; \
|
2014-03-14 05:45:44 -05:00
|
|
|
}
|
|
|
|
#define DEF_METHOD_3(_func, _type, _P1, _P2, _P3) \
|
2014-07-18 03:27:06 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, RTLIL::SigSpec sig1, RTLIL::SigSpec sig2, RTLIL::SigSpec sig3) { \
|
|
|
|
RTLIL::Cell *cell = new RTLIL::Cell; \
|
|
|
|
cell->name = name; \
|
|
|
|
cell->type = _type; \
|
2014-07-26 08:57:57 -05:00
|
|
|
cell->set("\\" #_P1, sig1); \
|
|
|
|
cell->set("\\" #_P2, sig2); \
|
|
|
|
cell->set("\\" #_P3, sig3); \
|
2014-07-18 03:27:06 -05:00
|
|
|
add(cell); \
|
|
|
|
return cell; \
|
|
|
|
} \
|
|
|
|
RTLIL::SigSpec RTLIL::Module::_func(RTLIL::IdString name, RTLIL::SigSpec sig1, RTLIL::SigSpec sig2) { \
|
2014-07-21 05:35:06 -05:00
|
|
|
RTLIL::SigSpec sig3 = addWire(NEW_ID); \
|
2014-07-18 03:27:06 -05:00
|
|
|
add ## _func(name, sig1, sig2, sig3); \
|
|
|
|
return sig3; \
|
2014-03-14 05:45:44 -05:00
|
|
|
}
|
|
|
|
#define DEF_METHOD_4(_func, _type, _P1, _P2, _P3, _P4) \
|
2014-07-18 03:27:06 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, RTLIL::SigSpec sig1, RTLIL::SigSpec sig2, RTLIL::SigSpec sig3, RTLIL::SigSpec sig4) { \
|
|
|
|
RTLIL::Cell *cell = new RTLIL::Cell; \
|
|
|
|
cell->name = name; \
|
|
|
|
cell->type = _type; \
|
2014-07-26 08:57:57 -05:00
|
|
|
cell->set("\\" #_P1, sig1); \
|
|
|
|
cell->set("\\" #_P2, sig2); \
|
|
|
|
cell->set("\\" #_P3, sig3); \
|
|
|
|
cell->set("\\" #_P4, sig4); \
|
2014-07-18 03:27:06 -05:00
|
|
|
add(cell); \
|
|
|
|
return cell; \
|
|
|
|
} \
|
|
|
|
RTLIL::SigSpec RTLIL::Module::_func(RTLIL::IdString name, RTLIL::SigSpec sig1, RTLIL::SigSpec sig2, RTLIL::SigSpec sig3) { \
|
2014-07-21 05:35:06 -05:00
|
|
|
RTLIL::SigSpec sig4 = addWire(NEW_ID); \
|
2014-07-18 03:27:06 -05:00
|
|
|
add ## _func(name, sig1, sig2, sig3, sig4); \
|
|
|
|
return sig4; \
|
2014-03-14 05:45:44 -05:00
|
|
|
}
|
2014-07-18 03:27:06 -05:00
|
|
|
DEF_METHOD_2(InvGate, "$_INV_", A, Y)
|
|
|
|
DEF_METHOD_3(AndGate, "$_AND_", A, B, Y)
|
|
|
|
DEF_METHOD_3(OrGate, "$_OR_", A, B, Y)
|
|
|
|
DEF_METHOD_3(XorGate, "$_XOR_", A, B, Y)
|
|
|
|
DEF_METHOD_4(MuxGate, "$_MUX_", A, B, S, Y)
|
2014-03-14 05:45:44 -05:00
|
|
|
#undef DEF_METHOD_2
|
|
|
|
#undef DEF_METHOD_3
|
|
|
|
#undef DEF_METHOD_4
|
|
|
|
|
2014-03-09 21:02:27 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::addPow(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool a_signed, bool b_signed)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = new RTLIL::Cell;
|
|
|
|
cell->name = name;
|
|
|
|
cell->type = "$pow";
|
|
|
|
cell->parameters["\\A_SIGNED"] = a_signed;
|
|
|
|
cell->parameters["\\B_SIGNED"] = b_signed;
|
2014-07-22 13:15:14 -05:00
|
|
|
cell->parameters["\\A_WIDTH"] = sig_a.size();
|
|
|
|
cell->parameters["\\B_WIDTH"] = sig_b.size();
|
|
|
|
cell->parameters["\\Y_WIDTH"] = sig_y.size();
|
2014-07-26 07:32:50 -05:00
|
|
|
cell->set("\\A", sig_a);
|
|
|
|
cell->set("\\B", sig_b);
|
|
|
|
cell->set("\\Y", sig_y);
|
2014-03-09 21:02:27 -05:00
|
|
|
add(cell);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::Cell* RTLIL::Module::addSlice(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_y, RTLIL::Const offset)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = new RTLIL::Cell;
|
|
|
|
cell->name = name;
|
|
|
|
cell->type = "$slice";
|
2014-07-22 13:15:14 -05:00
|
|
|
cell->parameters["\\A_WIDTH"] = sig_a.size();
|
|
|
|
cell->parameters["\\Y_WIDTH"] = sig_y.size();
|
2014-03-09 21:02:27 -05:00
|
|
|
cell->parameters["\\OFFSET"] = offset;
|
2014-07-26 07:32:50 -05:00
|
|
|
cell->set("\\A", sig_a);
|
|
|
|
cell->set("\\Y", sig_y);
|
2014-03-09 21:02:27 -05:00
|
|
|
add(cell);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::Cell* RTLIL::Module::addConcat(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = new RTLIL::Cell;
|
|
|
|
cell->name = name;
|
|
|
|
cell->type = "$concat";
|
2014-07-22 13:15:14 -05:00
|
|
|
cell->parameters["\\A_WIDTH"] = sig_a.size();
|
|
|
|
cell->parameters["\\B_WIDTH"] = sig_b.size();
|
2014-07-26 07:32:50 -05:00
|
|
|
cell->set("\\A", sig_a);
|
|
|
|
cell->set("\\B", sig_b);
|
|
|
|
cell->set("\\Y", sig_y);
|
2014-03-09 21:02:27 -05:00
|
|
|
add(cell);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::Cell* RTLIL::Module::addLut(RTLIL::IdString name, RTLIL::SigSpec sig_i, RTLIL::SigSpec sig_o, RTLIL::Const lut)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = new RTLIL::Cell;
|
|
|
|
cell->name = name;
|
|
|
|
cell->type = "$lut";
|
|
|
|
cell->parameters["\\LUT"] = lut;
|
2014-07-22 13:15:14 -05:00
|
|
|
cell->parameters["\\WIDTH"] = sig_i.size();
|
2014-07-26 07:32:50 -05:00
|
|
|
cell->set("\\I", sig_i);
|
|
|
|
cell->set("\\O", sig_o);
|
2014-03-09 21:02:27 -05:00
|
|
|
add(cell);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::Cell* RTLIL::Module::addAssert(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_en)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = new RTLIL::Cell;
|
|
|
|
cell->name = name;
|
|
|
|
cell->type = "$assert";
|
2014-07-26 07:32:50 -05:00
|
|
|
cell->set("\\A", sig_a);
|
|
|
|
cell->set("\\EN", sig_en);
|
2014-03-09 21:02:27 -05:00
|
|
|
add(cell);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::Cell* RTLIL::Module::addSr(RTLIL::IdString name, RTLIL::SigSpec sig_set, RTLIL::SigSpec sig_clr, RTLIL::SigSpec sig_q, bool set_polarity, bool clr_polarity)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = new RTLIL::Cell;
|
|
|
|
cell->name = name;
|
|
|
|
cell->type = "$sr";
|
|
|
|
cell->parameters["\\SET_POLARITY"] = set_polarity;
|
|
|
|
cell->parameters["\\CLR_POLARITY"] = clr_polarity;
|
2014-07-22 13:15:14 -05:00
|
|
|
cell->parameters["\\WIDTH"] = sig_q.size();
|
2014-07-26 07:32:50 -05:00
|
|
|
cell->set("\\SET", sig_set);
|
|
|
|
cell->set("\\CLR", sig_clr);
|
|
|
|
cell->set("\\Q", sig_q);
|
2014-03-09 21:02:27 -05:00
|
|
|
add(cell);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::Cell* RTLIL::Module::addDff(RTLIL::IdString name, RTLIL::SigSpec sig_clk, RTLIL::SigSpec sig_d, RTLIL::SigSpec sig_q, bool clk_polarity)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = new RTLIL::Cell;
|
|
|
|
cell->name = name;
|
|
|
|
cell->type = "$dff";
|
|
|
|
cell->parameters["\\CLK_POLARITY"] = clk_polarity;
|
2014-07-22 13:15:14 -05:00
|
|
|
cell->parameters["\\WIDTH"] = sig_q.size();
|
2014-07-26 07:32:50 -05:00
|
|
|
cell->set("\\CLK", sig_clk);
|
|
|
|
cell->set("\\D", sig_d);
|
|
|
|
cell->set("\\Q", sig_q);
|
2014-03-09 21:02:27 -05:00
|
|
|
add(cell);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::Cell* RTLIL::Module::addDffsr(RTLIL::IdString name, RTLIL::SigSpec sig_clk, RTLIL::SigSpec sig_set, RTLIL::SigSpec sig_clr,
|
|
|
|
RTLIL::SigSpec sig_d, RTLIL::SigSpec sig_q, bool clk_polarity, bool set_polarity, bool clr_polarity)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = new RTLIL::Cell;
|
|
|
|
cell->name = name;
|
|
|
|
cell->type = "$dffsr";
|
|
|
|
cell->parameters["\\CLK_POLARITY"] = clk_polarity;
|
|
|
|
cell->parameters["\\SET_POLARITY"] = set_polarity;
|
|
|
|
cell->parameters["\\CLR_POLARITY"] = clr_polarity;
|
2014-07-22 13:15:14 -05:00
|
|
|
cell->parameters["\\WIDTH"] = sig_q.size();
|
2014-07-26 07:32:50 -05:00
|
|
|
cell->set("\\CLK", sig_clk);
|
|
|
|
cell->set("\\SET", sig_set);
|
|
|
|
cell->set("\\CLR", sig_clr);
|
|
|
|
cell->set("\\D", sig_d);
|
|
|
|
cell->set("\\Q", sig_q);
|
2014-03-09 21:02:27 -05:00
|
|
|
add(cell);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::Cell* RTLIL::Module::addAdff(RTLIL::IdString name, RTLIL::SigSpec sig_clk, RTLIL::SigSpec sig_arst, RTLIL::SigSpec sig_d, RTLIL::SigSpec sig_q,
|
|
|
|
RTLIL::Const arst_value, bool clk_polarity, bool arst_polarity)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = new RTLIL::Cell;
|
|
|
|
cell->name = name;
|
2014-03-17 08:41:41 -05:00
|
|
|
cell->type = "$adff";
|
2014-03-09 21:02:27 -05:00
|
|
|
cell->parameters["\\CLK_POLARITY"] = clk_polarity;
|
|
|
|
cell->parameters["\\ARST_POLARITY"] = arst_polarity;
|
|
|
|
cell->parameters["\\ARST_VALUE"] = arst_value;
|
2014-07-22 13:15:14 -05:00
|
|
|
cell->parameters["\\WIDTH"] = sig_q.size();
|
2014-07-26 07:32:50 -05:00
|
|
|
cell->set("\\CLK", sig_clk);
|
|
|
|
cell->set("\\ARST", sig_arst);
|
|
|
|
cell->set("\\D", sig_d);
|
|
|
|
cell->set("\\Q", sig_q);
|
2014-03-09 21:02:27 -05:00
|
|
|
add(cell);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2014-03-15 08:35:29 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::addDlatch(RTLIL::IdString name, RTLIL::SigSpec sig_en, RTLIL::SigSpec sig_d, RTLIL::SigSpec sig_q, bool en_polarity)
|
2014-03-09 21:02:27 -05:00
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = new RTLIL::Cell;
|
|
|
|
cell->name = name;
|
2014-03-31 07:14:40 -05:00
|
|
|
cell->type = "$dlatch";
|
2014-03-09 21:02:27 -05:00
|
|
|
cell->parameters["\\EN_POLARITY"] = en_polarity;
|
2014-07-22 13:15:14 -05:00
|
|
|
cell->parameters["\\WIDTH"] = sig_q.size();
|
2014-07-26 07:32:50 -05:00
|
|
|
cell->set("\\EN", sig_en);
|
|
|
|
cell->set("\\D", sig_d);
|
|
|
|
cell->set("\\Q", sig_q);
|
2014-03-09 21:02:27 -05:00
|
|
|
add(cell);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2014-03-31 07:14:40 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::addDlatchsr(RTLIL::IdString name, RTLIL::SigSpec sig_en, RTLIL::SigSpec sig_set, RTLIL::SigSpec sig_clr,
|
|
|
|
RTLIL::SigSpec sig_d, RTLIL::SigSpec sig_q, bool en_polarity, bool set_polarity, bool clr_polarity)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = new RTLIL::Cell;
|
|
|
|
cell->name = name;
|
|
|
|
cell->type = "$dlatchsr";
|
|
|
|
cell->parameters["\\EN_POLARITY"] = en_polarity;
|
|
|
|
cell->parameters["\\SET_POLARITY"] = set_polarity;
|
|
|
|
cell->parameters["\\CLR_POLARITY"] = clr_polarity;
|
2014-07-22 13:15:14 -05:00
|
|
|
cell->parameters["\\WIDTH"] = sig_q.size();
|
2014-07-26 07:32:50 -05:00
|
|
|
cell->set("\\EN", sig_en);
|
|
|
|
cell->set("\\SET", sig_set);
|
|
|
|
cell->set("\\CLR", sig_clr);
|
|
|
|
cell->set("\\D", sig_d);
|
|
|
|
cell->set("\\Q", sig_q);
|
2014-03-31 07:14:40 -05:00
|
|
|
add(cell);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2014-03-15 08:35:29 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::addDffGate(RTLIL::IdString name, RTLIL::SigSpec sig_clk, RTLIL::SigSpec sig_d, RTLIL::SigSpec sig_q, bool clk_polarity)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = new RTLIL::Cell;
|
|
|
|
cell->name = name;
|
|
|
|
cell->type = stringf("$_DFF_%c_", clk_polarity ? 'P' : 'N');
|
2014-07-26 07:32:50 -05:00
|
|
|
cell->set("\\C", sig_clk);
|
|
|
|
cell->set("\\D", sig_d);
|
|
|
|
cell->set("\\Q", sig_q);
|
2014-03-15 08:35:29 -05:00
|
|
|
add(cell);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::Cell* RTLIL::Module::addDffsrGate(RTLIL::IdString name, RTLIL::SigSpec sig_clk, RTLIL::SigSpec sig_set, RTLIL::SigSpec sig_clr,
|
|
|
|
RTLIL::SigSpec sig_d, RTLIL::SigSpec sig_q, bool clk_polarity, bool set_polarity, bool clr_polarity)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = new RTLIL::Cell;
|
|
|
|
cell->name = name;
|
|
|
|
cell->type = stringf("$_DFFSR_%c%c%c_", clk_polarity ? 'P' : 'N', set_polarity ? 'P' : 'N', clr_polarity ? 'P' : 'N');
|
2014-07-26 07:32:50 -05:00
|
|
|
cell->set("\\C", sig_clk);
|
|
|
|
cell->set("\\S", sig_set);
|
|
|
|
cell->set("\\R", sig_clr);
|
|
|
|
cell->set("\\D", sig_d);
|
|
|
|
cell->set("\\Q", sig_q);
|
2014-03-15 08:35:29 -05:00
|
|
|
add(cell);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::Cell* RTLIL::Module::addAdffGate(RTLIL::IdString name, RTLIL::SigSpec sig_clk, RTLIL::SigSpec sig_arst, RTLIL::SigSpec sig_d, RTLIL::SigSpec sig_q,
|
|
|
|
bool arst_value, bool clk_polarity, bool arst_polarity)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = new RTLIL::Cell;
|
|
|
|
cell->name = name;
|
|
|
|
cell->type = stringf("$_DFF_%c%c%c_", clk_polarity ? 'P' : 'N', arst_polarity ? 'P' : 'N', arst_value ? '1' : '0');
|
2014-07-26 07:32:50 -05:00
|
|
|
cell->set("\\C", sig_clk);
|
|
|
|
cell->set("\\R", sig_arst);
|
|
|
|
cell->set("\\D", sig_d);
|
|
|
|
cell->set("\\Q", sig_q);
|
2014-03-15 08:35:29 -05:00
|
|
|
add(cell);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::Cell* RTLIL::Module::addDlatchGate(RTLIL::IdString name, RTLIL::SigSpec sig_en, RTLIL::SigSpec sig_d, RTLIL::SigSpec sig_q, bool en_polarity)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = new RTLIL::Cell;
|
|
|
|
cell->name = name;
|
|
|
|
cell->type = stringf("$_DLATCH_%c_", en_polarity ? 'P' : 'N');
|
2014-07-26 07:32:50 -05:00
|
|
|
cell->set("\\E", sig_en);
|
|
|
|
cell->set("\\D", sig_d);
|
|
|
|
cell->set("\\Q", sig_q);
|
2014-03-15 08:35:29 -05:00
|
|
|
add(cell);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2014-03-31 07:14:40 -05:00
|
|
|
RTLIL::Cell* RTLIL::Module::addDlatchsrGate(RTLIL::IdString name, RTLIL::SigSpec sig_en, RTLIL::SigSpec sig_set, RTLIL::SigSpec sig_clr,
|
|
|
|
RTLIL::SigSpec sig_d, RTLIL::SigSpec sig_q, bool en_polarity, bool set_polarity, bool clr_polarity)
|
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = new RTLIL::Cell;
|
|
|
|
cell->name = name;
|
|
|
|
cell->type = stringf("$_DLATCHSR_%c%c%c_", en_polarity ? 'P' : 'N', set_polarity ? 'P' : 'N', clr_polarity ? 'P' : 'N');
|
2014-07-26 07:32:50 -05:00
|
|
|
cell->set("\\E", sig_en);
|
|
|
|
cell->set("\\S", sig_set);
|
|
|
|
cell->set("\\R", sig_clr);
|
|
|
|
cell->set("\\D", sig_d);
|
|
|
|
cell->set("\\Q", sig_q);
|
2014-03-31 07:14:40 -05:00
|
|
|
add(cell);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
RTLIL::Wire::Wire()
|
|
|
|
{
|
|
|
|
width = 1;
|
|
|
|
start_offset = 0;
|
|
|
|
port_id = 0;
|
|
|
|
port_input = false;
|
|
|
|
port_output = false;
|
2014-07-28 05:12:13 -05:00
|
|
|
upto = false;
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::Memory::Memory()
|
|
|
|
{
|
|
|
|
width = 1;
|
|
|
|
size = 0;
|
|
|
|
}
|
|
|
|
|
2014-07-26 09:11:28 -05:00
|
|
|
bool RTLIL::Cell::has(RTLIL::IdString portname)
|
|
|
|
{
|
|
|
|
return connections_.count(portname) != 0;
|
|
|
|
}
|
|
|
|
|
2014-07-26 05:22:58 -05:00
|
|
|
void RTLIL::Cell::unset(RTLIL::IdString portname)
|
|
|
|
{
|
|
|
|
connections_.erase(portname);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RTLIL::Cell::set(RTLIL::IdString portname, RTLIL::SigSpec signal)
|
|
|
|
{
|
|
|
|
connections_[portname] = signal;
|
|
|
|
}
|
|
|
|
|
2014-07-26 08:57:27 -05:00
|
|
|
const RTLIL::SigSpec &RTLIL::Cell::get(RTLIL::IdString portname) const
|
2014-07-26 05:22:58 -05:00
|
|
|
{
|
|
|
|
return connections_.at(portname);
|
|
|
|
}
|
|
|
|
|
2014-07-26 08:57:27 -05:00
|
|
|
const std::map<RTLIL::IdString, RTLIL::SigSpec> &RTLIL::Cell::connections() const
|
2014-07-26 05:22:58 -05:00
|
|
|
{
|
|
|
|
return connections_;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (type[0] != '$' || type.substr(0, 2) == "$_" || type.substr(0, 8) == "$paramod" ||
|
2014-07-27 14:12:09 -05:00
|
|
|
type.substr(0, 9) == "$verific$" || type.substr(0, 7) == "$array:" || type.substr(0, 8) == "$extern:")
|
2014-07-26 05:22:58 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (type == "$mux" || type == "$pmux" || type == "$safe_pmux")
|
|
|
|
{
|
|
|
|
parameters["\\WIDTH"] = SIZE(connections_["\\Y"]);
|
|
|
|
if (type == "$pmux" || type == "$safe_pmux")
|
|
|
|
parameters["\\S_WIDTH"] = SIZE(connections_["\\S"]);
|
|
|
|
check();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool signedness_ab = type != "$slice" && type != "$concat";
|
|
|
|
|
|
|
|
if (connections_.count("\\A")) {
|
|
|
|
if (signedness_ab) {
|
|
|
|
if (set_a_signed)
|
|
|
|
parameters["\\A_SIGNED"] = true;
|
|
|
|
else if (parameters.count("\\A_SIGNED") == 0)
|
|
|
|
parameters["\\A_SIGNED"] = false;
|
|
|
|
}
|
|
|
|
parameters["\\A_WIDTH"] = SIZE(connections_["\\A"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (connections_.count("\\B")) {
|
|
|
|
if (signedness_ab) {
|
|
|
|
if (set_b_signed)
|
|
|
|
parameters["\\B_SIGNED"] = true;
|
|
|
|
else if (parameters.count("\\B_SIGNED") == 0)
|
|
|
|
parameters["\\B_SIGNED"] = false;
|
|
|
|
}
|
|
|
|
parameters["\\B_WIDTH"] = SIZE(connections_["\\B"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (connections_.count("\\Y"))
|
|
|
|
parameters["\\Y_WIDTH"] = SIZE(connections_["\\Y"]);
|
|
|
|
|
|
|
|
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-07-23 01:59:54 -05:00
|
|
|
data = value;
|
2013-01-05 04:13:26 -06:00
|
|
|
width = data.bits.size();
|
|
|
|
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;
|
|
|
|
data = RTLIL::Const(str);
|
|
|
|
width = data.bits.size();
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::SigChunk::SigChunk(int val, int width)
|
|
|
|
{
|
|
|
|
wire = NULL;
|
|
|
|
data = RTLIL::Const(val, width);
|
|
|
|
this->width = data.bits.size();
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::SigChunk::SigChunk(RTLIL::State bit, int width)
|
|
|
|
{
|
|
|
|
wire = NULL;
|
|
|
|
data = RTLIL::Const(bit, width);
|
|
|
|
this->width = data.bits.size();
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
|
2013-11-21 21:07:13 -06:00
|
|
|
RTLIL::SigChunk::SigChunk(RTLIL::SigBit bit)
|
|
|
|
{
|
|
|
|
wire = bit.wire;
|
|
|
|
if (wire == NULL)
|
|
|
|
data = RTLIL::Const(bit.data);
|
|
|
|
offset = bit.offset;
|
|
|
|
width = 1;
|
|
|
|
}
|
|
|
|
|
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++)
|
|
|
|
ret.data.bits.push_back(data.bits[offset+i]);
|
|
|
|
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-07-22 14:40:52 -05:00
|
|
|
return data.bits < other.data.bits;
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RTLIL::SigChunk::operator ==(const RTLIL::SigChunk &other) const
|
|
|
|
{
|
|
|
|
if (wire != other.wire || width != other.width || offset != other.offset)
|
|
|
|
return false;
|
|
|
|
if (data.bits != other.data.bits)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
std::vector<RTLIL::SigSpec> parts_vec(parts.begin(), parts.end());
|
|
|
|
for (auto it = parts_vec.rbegin(); it != parts_vec.rend(); it++)
|
|
|
|
append(*it);
|
|
|
|
}
|
|
|
|
|
2014-07-26 06:59:30 -05:00
|
|
|
const RTLIL::SigSpec &RTLIL::SigSpec::operator=(const RTLIL::SigSpec &other)
|
|
|
|
{
|
|
|
|
cover("kernel.rtlil.sigspec.assign");
|
|
|
|
|
|
|
|
width_ = other.width_;
|
|
|
|
hash_ = other.hash_;
|
|
|
|
chunks_ = other.chunks_;
|
|
|
|
bits_.clear();
|
|
|
|
|
|
|
|
if (!other.bits_.empty())
|
|
|
|
{
|
|
|
|
RTLIL::SigChunk *last = NULL;
|
|
|
|
int last_end_offset = 0;
|
|
|
|
|
|
|
|
for (auto &bit : other.bits_) {
|
|
|
|
if (last && bit.wire == last->wire) {
|
|
|
|
if (bit.wire == NULL) {
|
|
|
|
last->data.bits.push_back(bit.data);
|
|
|
|
last->width++;
|
|
|
|
continue;
|
|
|
|
} else if (last_end_offset == bit.offset) {
|
|
|
|
last_end_offset++;
|
|
|
|
last->width++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
chunks_.push_back(bit);
|
|
|
|
last = &chunks_.back();
|
|
|
|
last_end_offset = bit.offset + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
check();
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
2014-07-23 01:59:54 -05:00
|
|
|
chunks_.push_back(RTLIL::SigChunk(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");
|
|
|
|
|
2014-07-22 13:12:15 -05:00
|
|
|
chunks_.push_back(chunk);
|
|
|
|
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");
|
|
|
|
|
2014-07-23 02:00:16 -05:00
|
|
|
chunks_.push_back(RTLIL::SigChunk(wire));
|
|
|
|
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");
|
|
|
|
|
2014-07-23 02:48:26 -05:00
|
|
|
chunks_.push_back(RTLIL::SigChunk(wire, offset, width));
|
|
|
|
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");
|
|
|
|
|
2014-07-22 13:12:15 -05:00
|
|
|
chunks_.push_back(RTLIL::SigChunk(str));
|
|
|
|
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");
|
|
|
|
|
2014-07-22 13:12:15 -05:00
|
|
|
chunks_.push_back(RTLIL::SigChunk(val, width));
|
|
|
|
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");
|
|
|
|
|
2014-07-22 13:12:15 -05:00
|
|
|
chunks_.push_back(RTLIL::SigChunk(bit, width));
|
|
|
|
width_ = width;
|
2014-07-23 16:58:03 -05:00
|
|
|
hash_ = 0;
|
2013-11-21 21:07:13 -06:00
|
|
|
check();
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::SigSpec::SigSpec(RTLIL::SigBit bit, int width)
|
|
|
|
{
|
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)
|
2014-07-22 13:12:15 -05:00
|
|
|
chunks_.push_back(RTLIL::SigChunk(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();
|
|
|
|
}
|
|
|
|
|
2014-07-22 16:50:21 -05:00
|
|
|
RTLIL::SigSpec::SigSpec(std::vector<RTLIL::SigChunk> chunks)
|
|
|
|
{
|
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;
|
2014-07-22 16:50:21 -05:00
|
|
|
for (auto &c : chunks)
|
|
|
|
append(c);
|
|
|
|
check();
|
|
|
|
}
|
|
|
|
|
2013-11-21 21:07:13 -06:00
|
|
|
RTLIL::SigSpec::SigSpec(std::vector<RTLIL::SigBit> bits)
|
|
|
|
{
|
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;
|
2013-11-21 21:07:13 -06:00
|
|
|
for (auto &bit : bits)
|
2014-07-20 04:00:09 -05:00
|
|
|
append_bit(bit);
|
|
|
|
check();
|
|
|
|
}
|
|
|
|
|
|
|
|
RTLIL::SigSpec::SigSpec(std::set<RTLIL::SigBit> bits)
|
|
|
|
{
|
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;
|
2014-07-20 04:00:09 -05:00
|
|
|
for (auto &bit : bits)
|
|
|
|
append_bit(bit);
|
2013-01-05 04:13:26 -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) {
|
|
|
|
last->data.bits.push_back(bit.data);
|
|
|
|
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++)
|
|
|
|
that->bits_.push_back(RTLIL::SigBit(c, i));
|
|
|
|
|
|
|
|
that->chunks_.clear();
|
2014-07-23 16:58:03 -05:00
|
|
|
that->hash_ = 0;
|
2014-07-22 14:33:52 -05:00
|
|
|
}
|
|
|
|
|
2014-07-23 16:58:03 -05:00
|
|
|
#define DJB2(_hash, _value) do { (_hash) = (((_hash) << 5) + (_hash)) + (_value); } while (0)
|
|
|
|
|
|
|
|
void RTLIL::SigSpec::hash() 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-07-23 20:50:28 -05:00
|
|
|
that->hash_ = 5381;
|
2014-07-23 16:58:03 -05:00
|
|
|
for (auto &c : that->chunks_)
|
|
|
|
if (c.wire == NULL) {
|
|
|
|
for (auto &v : c.data.bits)
|
|
|
|
DJB2(that->hash_, v);
|
|
|
|
} else {
|
|
|
|
for (auto &v : c.wire->name)
|
|
|
|
DJB2(that->hash_, v);
|
|
|
|
DJB2(that->hash_, c.offset);
|
|
|
|
DJB2(that->hash_, c.width);
|
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.sort_and_unify");
|
2014-07-22 15:26:30 -05:00
|
|
|
*this = this->to_sigbit_set();
|
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
|
|
|
|
{
|
2014-07-23 21:46:36 -05:00
|
|
|
cover("kernel.rtlil.sigspec.replace");
|
2014-07-23 20:50:28 -05:00
|
|
|
|
2014-07-22 15:26:30 -05:00
|
|
|
unpack();
|
|
|
|
pattern.unpack();
|
|
|
|
with.unpack();
|
2014-07-22 14:33:52 -05:00
|
|
|
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(other != NULL);
|
|
|
|
log_assert(width_ == other->width_);
|
2014-07-22 15:26:30 -05:00
|
|
|
other->unpack();
|
2014-07-22 14:33:52 -05:00
|
|
|
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(pattern.width_ == with.width_);
|
2014-07-22 15:26:30 -05:00
|
|
|
|
|
|
|
std::map<RTLIL::SigBit, RTLIL::SigBit> pattern_map;
|
|
|
|
for (int i = 0; i < SIZE(pattern.bits_); i++)
|
|
|
|
if (pattern.bits_[i].wire != NULL)
|
|
|
|
pattern_map[pattern.bits_[i]] = with.bits_[i];
|
|
|
|
|
|
|
|
for (int i = 0; i < SIZE(bits_); i++)
|
|
|
|
if (pattern_map.count(bits_[i]))
|
|
|
|
other->bits_[i] = pattern_map.at(bits_[i]);
|
|
|
|
|
|
|
|
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-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
|
|
|
|
2014-07-22 15:26:30 -05:00
|
|
|
std::set<RTLIL::SigBit> pattern_bits = pattern.to_sigbit_set();
|
|
|
|
std::vector<RTLIL::SigBit> new_bits, new_other_bits;
|
|
|
|
|
|
|
|
for (int i = 0; i < SIZE(bits_); i++) {
|
|
|
|
if (bits_[i].wire != NULL && pattern_bits.count(bits_[i]))
|
|
|
|
continue;
|
|
|
|
if (other != NULL)
|
|
|
|
new_other_bits.push_back(other->bits_[i]);
|
|
|
|
new_bits.push_back(bits_[i]);
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
2014-07-22 15:26:30 -05:00
|
|
|
|
|
|
|
bits_.swap(new_bits);
|
|
|
|
width_ = SIZE(bits_);
|
|
|
|
|
|
|
|
if (other != NULL) {
|
|
|
|
other->bits_.swap(new_other_bits);
|
|
|
|
other->width_ = SIZE(other->bits_);
|
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
check();
|
|
|
|
}
|
|
|
|
|
2014-07-26 08:57:27 -05:00
|
|
|
RTLIL::SigSpec RTLIL::SigSpec::extract(RTLIL::SigSpec 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-22 14:33:52 -05:00
|
|
|
pack();
|
|
|
|
pattern.pack();
|
|
|
|
|
|
|
|
if (other != NULL)
|
|
|
|
other->pack();
|
|
|
|
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(other == NULL || width_ == other->width_);
|
2013-11-21 21:07:13 -06:00
|
|
|
|
|
|
|
std::set<RTLIL::SigBit> pat = pattern.to_sigbit_set();
|
|
|
|
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++)
|
2013-11-21 21:07:13 -06:00
|
|
|
if (bits_match[i].wire && pat.count(bits_match[i]))
|
|
|
|
ret.append_bit(bits_other[i]);
|
|
|
|
} else {
|
2014-07-22 13:12:15 -05:00
|
|
|
for (int i = 0; i < width_; i++)
|
2013-11-21 21:07:13 -06:00
|
|
|
if (bits_match[i].wire && pat.count(bits_match[i]))
|
|
|
|
ret.append_bit(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;
|
|
|
|
new_chunks.reserve(SIZE(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) {
|
|
|
|
auto &this_data = my_last_c.data.bits;
|
|
|
|
auto &other_data = other_c.data.bits;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void RTLIL::SigSpec::append_bit(const RTLIL::SigBit &bit)
|
|
|
|
{
|
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) {
|
|
|
|
chunks_.back().data.bits.push_back(bit.data);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void RTLIL::SigSpec::extend(int width, bool is_signed)
|
|
|
|
{
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.extend");
|
|
|
|
|
2014-07-22 14:33:52 -05:00
|
|
|
pack();
|
|
|
|
|
2014-07-22 13:12:15 -05:00
|
|
|
if (width_ > width)
|
|
|
|
remove(width, width_ - width);
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2014-07-22 13:12:15 -05:00
|
|
|
if (width_ < width) {
|
|
|
|
RTLIL::SigSpec padding = width_ > 0 ? extract(width_ - 1, 1) : RTLIL::SigSpec(RTLIL::State::S0);
|
2013-01-05 04:13:26 -06:00
|
|
|
if (!is_signed && padding != RTLIL::SigSpec(RTLIL::State::Sx) && padding != RTLIL::SigSpec(RTLIL::State::Sz) &&
|
|
|
|
padding != RTLIL::SigSpec(RTLIL::State::Sa) && padding != RTLIL::SigSpec(RTLIL::State::Sm))
|
|
|
|
padding = RTLIL::SigSpec(RTLIL::State::S0);
|
2014-07-22 13:12:15 -05:00
|
|
|
while (width_ < width)
|
2013-01-05 04:13:26 -06:00
|
|
|
append(padding);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
2013-11-07 09:53:28 -06:00
|
|
|
|
2014-07-22 13:12:15 -05:00
|
|
|
if (width_ < width) {
|
|
|
|
RTLIL::SigSpec padding = width_ > 0 ? extract(width_ - 1, 1) : RTLIL::SigSpec(RTLIL::State::S0);
|
2013-11-07 09:53:28 -06:00
|
|
|
if (!is_signed)
|
|
|
|
padding = RTLIL::SigSpec(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++) {
|
|
|
|
const RTLIL::SigChunk chunk = chunks_[i];
|
|
|
|
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);
|
|
|
|
log_assert(chunk.data.bits.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);
|
|
|
|
log_assert(chunk.data.bits.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-07-28 04:08:55 -05:00
|
|
|
log_assert(width_ == SIZE(bits_));
|
|
|
|
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();
|
|
|
|
|
|
|
|
hash();
|
|
|
|
other.hash();
|
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;
|
|
|
|
|
2014-07-22 14:33:52 -05:00
|
|
|
pack();
|
|
|
|
other.pack();
|
|
|
|
|
2014-07-23 16:58:03 -05:00
|
|
|
if (chunks_.size() != chunks_.size())
|
2013-01-05 04:13:26 -06:00
|
|
|
return false;
|
|
|
|
|
2014-07-23 16:58:03 -05:00
|
|
|
hash();
|
|
|
|
other.hash();
|
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();
|
|
|
|
return SIZE(chunks_) == 1 && chunks_[0].wire && chunks_[0].wire->width == width_;
|
|
|
|
}
|
|
|
|
|
2014-07-25 07:23:10 -05:00
|
|
|
bool RTLIL::SigSpec::is_chunk() const
|
|
|
|
{
|
|
|
|
cover("kernel.rtlil.sigspec.is_chunk");
|
|
|
|
|
|
|
|
pack();
|
|
|
|
return SIZE(chunks_) == 1;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
for (size_t i = 0; i < it->data.bits.size(); i++)
|
|
|
|
if (it->data.bits[i] != RTLIL::State::S0 && it->data.bits[i] != RTLIL::State::S1)
|
|
|
|
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;
|
|
|
|
for (size_t i = 0; i < it->data.bits.size(); i++)
|
|
|
|
if (it->data.bits[i] != RTLIL::State::Sx && it->data.bits[i] != RTLIL::State::Sz)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
for (size_t i = 0; i < it->data.bits.size(); i++)
|
|
|
|
if (it->data.bits[i] == RTLIL::State::Sm)
|
|
|
|
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-07-28 04:08:55 -05:00
|
|
|
log_assert(is_fully_const() && SIZE(chunks_) <= 1);
|
2014-07-23 13:32:28 -05:00
|
|
|
if (width_)
|
|
|
|
return chunks_[0].data.as_bool();
|
2013-01-05 04:13:26 -06:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int RTLIL::SigSpec::as_int() const
|
|
|
|
{
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.as_int");
|
|
|
|
|
2014-07-22 14:33:52 -05:00
|
|
|
pack();
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(is_fully_const() && SIZE(chunks_) <= 1);
|
2014-07-23 13:32:28 -05:00
|
|
|
if (width_)
|
|
|
|
return chunks_[0].data.as_int();
|
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;
|
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)
|
|
|
|
for (int j = 0; j < chunk.width; j++)
|
|
|
|
str += "?";
|
|
|
|
else
|
|
|
|
str += chunk.data.as_string();
|
|
|
|
}
|
|
|
|
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-07-28 04:08:55 -05:00
|
|
|
log_assert(is_fully_const() && SIZE(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];
|
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
bool RTLIL::SigSpec::match(std::string pattern) const
|
|
|
|
{
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.match");
|
|
|
|
|
2014-07-22 14:33:52 -05:00
|
|
|
pack();
|
2013-01-05 04:13:26 -06:00
|
|
|
std::string str = as_string();
|
2014-07-28 04:08:55 -05:00
|
|
|
log_assert(pattern.size() == str.size());
|
2013-01-05 04:13:26 -06:00
|
|
|
|
|
|
|
for (size_t i = 0; i < pattern.size(); i++) {
|
|
|
|
if (pattern[i] == ' ')
|
|
|
|
continue;
|
|
|
|
if (pattern[i] == '*') {
|
|
|
|
if (str[i] != 'z' && str[i] != 'x')
|
|
|
|
return false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (pattern[i] != str[i])
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-02-02 14:35:26 -06:00
|
|
|
RTLIL::SigBit RTLIL::SigSpec::to_single_sigbit() const
|
|
|
|
{
|
2014-07-23 20:50:28 -05:00
|
|
|
cover("kernel.rtlil.sigspec.to_single_sigbit");
|
|
|
|
|
2014-07-22 14:33:52 -05:00
|
|
|
pack();
|
2014-07-22 13:12:15 -05:00
|
|
|
log_assert(width_ == 1);
|
|
|
|
for (auto &c : chunks_)
|
2014-02-02 14:35:26 -06:00
|
|
|
if (c.width)
|
|
|
|
return RTLIL::SigBit(c);
|
|
|
|
log_abort();
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if ('0' <= netname[0] && netname[0] <= '9') {
|
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");
|
2014-07-23 02:48:26 -05:00
|
|
|
sig.append(RTLIL::SigSpec(wire, atoi(index_tokens.at(0).c_str())));
|
2014-07-23 20:50:28 -05:00
|
|
|
} else {
|
|
|
|
cover("kernel.rtlil.sigspec.parse.part_sel");
|
2013-06-19 02:30:37 -05:00
|
|
|
int a = atoi(index_tokens.at(0).c_str());
|
|
|
|
int b = atoi(index_tokens.at(1).c_str());
|
|
|
|
if (a > b) {
|
|
|
|
int tmp = a;
|
|
|
|
a = b, b = tmp;
|
|
|
|
}
|
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;
|
|
|
|
long long int val = strtoll(p, &endptr, 10);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
return new_proc;
|
|
|
|
}
|
|
|
|
|
2014-07-31 06:19:47 -05:00
|
|
|
YOSYS_NAMESPACE_END
|
|
|
|
|