yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
fsm_export.cc File Reference
#include "kernel/log.h"
#include "kernel/register.h"
#include "kernel/sigtools.h"
#include "kernel/consteval.h"
#include "kernel/celltypes.h"
#include "fsmdata.h"
#include <string>
#include <iostream>
#include <fstream>
+ Include dependency graph for fsm_export.cc:

Go to the source code of this file.

Data Structures

struct  FsmExportPass
 

Functions

USING_YOSYS_NAMESPACE
PRIVATE_NAMESPACE_BEGIN
std::string 
kiss_convert_signal (const RTLIL::SigSpec &sig)
 
void write_kiss2 (struct RTLIL::Module *module, struct RTLIL::Cell *cell, std::string filename, bool origenc)
 

Variables

FsmExportPass FsmExportPass
 

Function Documentation

USING_YOSYS_NAMESPACE PRIVATE_NAMESPACE_BEGIN std::string kiss_convert_signal ( const RTLIL::SigSpec sig)

Convert a signal into a KISS-compatible textual representation.

Definition at line 37 of file fsm_export.cc.

37  {
39  return sig.as_const().as_string();
40 }
RTLIL::Const as_const() const
Definition: rtlil.cc:2857
std::string as_string() const
Definition: rtlil.cc:116
#define log_assert(_assert_expr_)
Definition: log.h:85
bool is_fully_const() const
Definition: rtlil.cc:2763

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void write_kiss2 ( struct RTLIL::Module module,
struct RTLIL::Cell cell,
std::string  filename,
bool  origenc 
)

Create a KISS2 file from a cell.

The destination file name is taken from the fsm_export attribute if present, e.g. (* fsm_export="filename.kiss2" *). If this attribute is not present, the file name will be assembled from the module and cell names.

Parameters
modulepointer to module which contains the FSM cell.
cellpointer to the FSM cell which should be exported.

Definition at line 52 of file fsm_export.cc.

52  {
53  std::map<RTLIL::IdString, RTLIL::Const>::iterator attr_it;
54  FsmData fsm_data;
56  std::ofstream kiss_file;
57  std::string kiss_name;
58  size_t i;
59 
60  attr_it = cell->attributes.find("\\fsm_export");
61  if (!filename.empty()) {
62  kiss_name.assign(filename);
63  } else if (attr_it != cell->attributes.end() && attr_it->second.decode_string() != "") {
64  kiss_name.assign(attr_it->second.decode_string());
65  }
66  else {
67  kiss_name.assign(log_id(module) + std::string("-") + log_id(cell) + ".kiss2");
68  }
69 
70  log("\n");
71  log("Exporting FSM `%s' from module `%s' to file `%s'.\n",
72  cell->name.c_str(),
73  module->name.c_str(),
74  kiss_name.c_str());
75 
76  kiss_file.open(kiss_name, std::ios::out | std::ios::trunc);
77 
78  if (!kiss_file.is_open()) {
79  log_error("Could not open file \"%s\" with write access.\n", kiss_name.c_str());
80  }
81 
82  fsm_data.copy_from_cell(cell);
83 
84  kiss_file << ".i " << std::dec << fsm_data.num_inputs << std::endl;
85  kiss_file << ".o " << std::dec << fsm_data.num_outputs << std::endl;
86  kiss_file << ".p " << std::dec << fsm_data.transition_table.size() << std::endl;
87  kiss_file << ".s " << std::dec << fsm_data.state_table.size() << std::endl;
88  if (origenc) {
89  kiss_file << ".r " << kiss_convert_signal(fsm_data.state_table[fsm_data.reset_state]) << std::endl;
90  } else {
91  kiss_file << ".r s" << std::dec << fsm_data.reset_state << std::endl;
92  }
93 
94  for (i = 0; i < fsm_data.transition_table.size(); i++) {
95  tr = fsm_data.transition_table[i];
96 
97  try {
98  kiss_file << kiss_convert_signal(tr.ctrl_in) << ' ';
99  if (origenc) {
100  kiss_file << kiss_convert_signal(fsm_data.state_table[tr.state_in]) << ' ';
101  kiss_file << kiss_convert_signal(fsm_data.state_table[tr.state_out]) << ' ';
102  } else {
103  kiss_file << 's' << tr.state_in << ' ';
104  kiss_file << 's' << tr.state_out << ' ';
105  }
106  kiss_file << kiss_convert_signal(tr.ctrl_out) << std::endl;
107  }
108  catch (int) {
109  kiss_file.close();
110  log_error("exporting an FSM input or output signal failed.\n");
111  }
112  }
113 
114  kiss_file.close();
115 }
const char * c_str() const
Definition: rtlil.h:178
std::vector< transition_t > transition_table
Definition: fsmdata.h:31
RTLIL::IdString name
Definition: rtlil.h:853
void log_error(const char *format,...)
Definition: log.cc:204
RTLIL::Const ctrl_out
Definition: fsmdata.h:30
USING_YOSYS_NAMESPACE PRIVATE_NAMESPACE_BEGIN std::string kiss_convert_signal(const RTLIL::SigSpec &sig)
Definition: fsm_export.cc:37
RTLIL::Const ctrl_in
Definition: fsmdata.h:30
int num_inputs
Definition: fsmdata.h:29
RTLIL::IdString name
Definition: rtlil.h:599
std::vector< RTLIL::Const > state_table
Definition: fsmdata.h:32
void log(const char *format,...)
Definition: log.cc:180
void copy_from_cell(RTLIL::Cell *cell)
Definition: fsmdata.h:79
int num_outputs
Definition: fsmdata.h:29
int reset_state
Definition: fsmdata.h:29
const char * log_id(RTLIL::IdString str)
Definition: log.cc:283

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation