#include "kernel/log.h"
#include "kernel/register.h"
#include "kernel/sigtools.h"
#include "kernel/consteval.h"
#include "kernel/celltypes.h"
#include "fsmdata.h"
#include <math.h>
#include <string.h>
#include <errno.h>
Go to the source code of this file.
Definition at line 33 of file fsm_recode.cc.
35 std::string name = cell->
parameters[
"\\NAME"].decode_string();
37 fprintf(f,
"set_fsm_state_vector {");
38 for (
int i = fsm_data.
state_bits-1; i >= 0; i--)
39 fprintf(f,
" %s_reg[%d]", name[0] ==
'\\' ? name.substr(1).c_str() : name.c_str(), i);
40 fprintf(f,
" } -name {%s_%s} {%s:/WORK/%s}\n", prefix,
RTLIL::unescape_id(name).c_str(),
43 fprintf(f,
"set_fsm_encoding {");
45 fprintf(f,
" s%d=2#", i);
49 fprintf(f,
" } -name {%s_%s} {%s:/WORK/%s}\n",
static std::string unescape_id(std::string str)
std::map< RTLIL::IdString, RTLIL::Const > parameters
int GetSize(RTLIL::Wire *wire)
std::vector< RTLIL::Const > state_table
static void fsm_recode |
( |
RTLIL::Cell * |
cell, |
|
|
RTLIL::Module * |
module, |
|
|
FILE * |
fm_set_fsm_file, |
|
|
std::string |
default_encoding |
|
) |
| |
|
static |
Definition at line 54 of file fsm_recode.cc.
56 std::string encoding = cell->attributes.count(
"\\fsm_encoding") ? cell->attributes.at(
"\\fsm_encoding").decode_string() :
"auto";
58 log(
"Recoding FSM `%s' from module `%s' using `%s' encoding:\n", cell->
name.
c_str(), module->
name.
c_str(), encoding.c_str());
60 if (encoding !=
"none" && encoding !=
"one-hot" && encoding !=
"binary" && encoding !=
"auto") {
61 log(
" unknown encoding `%s': using auto instead.\n", encoding.c_str());
65 if (encoding ==
"none") {
66 log(
" nothing to do for encoding `none'.\n");
73 if (fm_set_fsm_file !=
NULL)
76 if (encoding ==
"auto") {
77 if (!default_encoding.empty())
78 encoding = default_encoding;
81 log(
" mapping auto encoding to `%s` for this FSM.\n", encoding.c_str());
84 if (encoding ==
"one-hot") {
87 if (encoding ==
"binary") {
88 int new_num_state_bits = ceil(log2(fsm_data.
state_table.size()));
89 if (fsm_data.
state_bits == new_num_state_bits) {
90 log(
" existing encoding is already a packed binary encoding.\n");
95 log_error(
"FSM encoding `%s' is not supported!\n", encoding.c_str());
97 int state_idx_counter = fsm_data.
reset_state >= 0 ? 1 : 0;
98 for (
int i = 0; i < int(fsm_data.
state_table.size()); i++)
100 int state_idx = fsm_data.
reset_state == i ? 0 : state_idx_counter++;
103 if (encoding ==
"one-hot") {
107 if (encoding ==
"binary") {
116 if (fm_set_fsm_file !=
NULL)
const char * c_str() const
void copy_to_cell(RTLIL::Cell *cell)
void log_error(const char *format,...)
std::string as_string() const
int GetSize(RTLIL::Wire *wire)
std::vector< RTLIL::Const > state_table
void log(const char *format,...)
void copy_from_cell(RTLIL::Cell *cell)
std::vector< RTLIL::State > bits
USING_YOSYS_NAMESPACE static PRIVATE_NAMESPACE_BEGIN void fm_set_fsm_print(RTLIL::Cell *cell, RTLIL::Module *module, FsmData &fsm_data, const char *prefix, FILE *f)