2013-11-21 06:49:00 -06:00
|
|
|
/*
|
|
|
|
* yosys -- Yosys Open SYnthesis Suite
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2013-11-21 06:49:00 -06:00
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2013-11-21 06:49:00 -06:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "kernel/register.h"
|
|
|
|
#include "kernel/sigtools.h"
|
|
|
|
#include "kernel/log.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
USING_YOSYS_NAMESPACE
|
|
|
|
PRIVATE_NAMESPACE_BEGIN
|
|
|
|
|
2019-07-09 03:14:52 -05:00
|
|
|
void proc_init(RTLIL::Module *mod, SigMap &sigmap, RTLIL::Process *proc)
|
2013-11-21 06:49:00 -06:00
|
|
|
{
|
|
|
|
bool found_init = false;
|
|
|
|
|
|
|
|
for (auto &sync : proc->syncs)
|
|
|
|
if (sync->type == RTLIL::SyncType::STi)
|
|
|
|
{
|
|
|
|
found_init = true;
|
|
|
|
log("Found init rule in `%s.%s'.\n", mod->name.c_str(), proc->name.c_str());
|
|
|
|
|
|
|
|
for (auto &action : sync->actions)
|
|
|
|
{
|
|
|
|
RTLIL::SigSpec lhs = action.first;
|
2019-07-09 03:14:52 -05:00
|
|
|
RTLIL::SigSpec rhs = sigmap(action.second);
|
2013-11-21 06:49:00 -06:00
|
|
|
|
|
|
|
if (!rhs.is_fully_const())
|
|
|
|
log_cmd_error("Failed to get a constant init value for %s: %s\n", log_signal(lhs), log_signal(rhs));
|
|
|
|
|
|
|
|
int offset = 0;
|
2016-04-22 05:13:06 -05:00
|
|
|
for (auto &lhs_c : lhs.chunks())
|
|
|
|
{
|
|
|
|
if (lhs_c.wire != nullptr)
|
|
|
|
{
|
|
|
|
SigSpec valuesig = rhs.extract(offset, lhs_c.width);
|
|
|
|
if (!valuesig.is_fully_const())
|
|
|
|
log_cmd_error("Non-const initialization value: %s = %s\n", log_signal(lhs_c), log_signal(valuesig));
|
|
|
|
|
|
|
|
Const value = valuesig.as_const();
|
2020-04-02 11:51:32 -05:00
|
|
|
Const &wireinit = lhs_c.wire->attributes[ID::init];
|
2016-04-22 05:13:06 -05:00
|
|
|
|
|
|
|
while (GetSize(wireinit.bits) < lhs_c.wire->width)
|
|
|
|
wireinit.bits.push_back(State::Sx);
|
|
|
|
|
|
|
|
for (int i = 0; i < lhs_c.width; i++) {
|
|
|
|
auto &initbit = wireinit.bits[i + lhs_c.offset];
|
|
|
|
if (initbit != State::Sx && initbit != value[i])
|
|
|
|
log_cmd_error("Conflicting initialization values for %s.\n", log_signal(lhs_c));
|
|
|
|
initbit = value[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
log(" Set init value: %s = %s\n", log_signal(lhs_c.wire), log_signal(wireinit));
|
2014-07-24 15:47:57 -05:00
|
|
|
}
|
|
|
|
offset += lhs_c.width;
|
2013-11-21 06:49:00 -06:00
|
|
|
}
|
|
|
|
}
|
2021-02-22 17:21:46 -06:00
|
|
|
sync->actions.clear();
|
2013-11-21 06:49:00 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ProcInitPass : public Pass {
|
|
|
|
ProcInitPass() : Pass("proc_init", "convert initial block to init attributes") { }
|
2020-06-18 18:34:52 -05:00
|
|
|
void help() override
|
2013-11-21 06:49:00 -06:00
|
|
|
{
|
|
|
|
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
|
|
|
log("\n");
|
|
|
|
log(" proc_init [selection]\n");
|
|
|
|
log("\n");
|
2015-08-14 04:27:19 -05:00
|
|
|
log("This pass extracts the 'init' actions from processes (generated from Verilog\n");
|
2013-11-21 06:49:00 -06:00
|
|
|
log("'initial' blocks) and sets the initial value to the 'init' attribute on the\n");
|
|
|
|
log("respective wire.\n");
|
|
|
|
log("\n");
|
|
|
|
}
|
2020-06-18 18:34:52 -05:00
|
|
|
void execute(std::vector<std::string> args, RTLIL::Design *design) override
|
2013-11-21 06:49:00 -06:00
|
|
|
{
|
2016-04-21 16:28:37 -05:00
|
|
|
log_header(design, "Executing PROC_INIT pass (extract init attributes).\n");
|
2013-11-21 06:49:00 -06:00
|
|
|
|
|
|
|
extra_args(args, 1, design);
|
|
|
|
|
2014-07-27 03:41:42 -05:00
|
|
|
for (auto mod : design->modules())
|
2019-07-09 03:14:52 -05:00
|
|
|
if (design->selected(mod)) {
|
|
|
|
SigMap sigmap(mod);
|
2014-07-27 03:41:42 -05:00
|
|
|
for (auto &proc_it : mod->processes)
|
|
|
|
if (design->selected(mod, proc_it.second))
|
2019-07-09 03:14:52 -05:00
|
|
|
proc_init(mod, sigmap, proc_it.second);
|
|
|
|
}
|
2013-11-21 06:49:00 -06:00
|
|
|
}
|
|
|
|
} ProcInitPass;
|
2015-07-02 04:14:30 -05:00
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
PRIVATE_NAMESPACE_END
|