30 static std::string
netname(std::set<std::string> &conntypes_code, std::set<std::string> &celltypes_code, std::set<std::string> &constcells_code,
RTLIL::SigSpec sig)
35 conntypes_code.insert(
stringf(
"conntype b%d %d 2 %d\n", sig.
size(), sig.
size(), sig.
size()));
38 celltypes_code.insert(
stringf(
"celltype CONST_%d b%d *CONST cfg:%d VALUE\n", sig.
size(), sig.
size(), sig.
size()));
39 constcells_code.insert(
stringf(
"node CONST_%d_0x%x CONST_%d CONST CONST_%d_0x%x VALUE 0x%x\n",
53 log(
" write_intersynth [options] [filename]\n");
55 log(
"Write the current design to an 'intersynth' netlist file. InterSynth is\n");
56 log(
"a tool for Coarse-Grain Example-Driven Interconnect Synthesis.\n");
59 log(
" do not generate celltypes and conntypes commands. i.e. just output\n");
60 log(
" the netlists. this is used for postsilicon synthesis.\n");
62 log(
" -lib <verilog_or_ilang_file>\n");
63 log(
" Use the specified library file for determining whether cell ports are\n");
64 log(
" inputs or outputs. This option can be used multiple times to specify\n");
65 log(
" more than one library.\n");
68 log(
" only write selected modules. modules must be selected entirely or\n");
69 log(
" not at all.\n");
71 log(
"http://www.clifford.at/intersynth/\n");
79 std::vector<std::string> libfiles;
80 std::vector<RTLIL::Design*> libs;
81 bool flag_notypes =
false;
82 bool selected =
false;
85 for (argidx = 1; argidx < args.size(); argidx++)
87 if (args[argidx] ==
"-notypes") {
91 if (args[argidx] ==
"-lib" && argidx+1 < args.size()) {
92 libfiles.push_back(args[++argidx]);
95 if (args[argidx] ==
"-selected") {
103 log(
"Output filename: %s\n", filename.c_str());
105 for (
auto filename : libfiles) {
107 f.open(filename.c_str());
109 log_error(
"Can't open lib file `%s'.\n", filename.c_str());
111 Frontend::frontend_call(lib, &f, filename, (filename.size() > 3 && filename.substr(filename.size()-3) ==
".il") ?
"ilang" :
"verilog");
116 log_header(
"Continuing INTERSYNTH backend.\n");
118 std::set<std::string> conntypes_code, celltypes_code;
119 std::string netlists_code;
122 for (
auto lib : libs)
125 for (
auto module_it : design->
modules_)
130 if (module->get_bool_attribute(
"\\blackbox"))
144 log_error(
"Can't generate a netlist for a module with unprocessed memories or processes!\n");
146 std::set<std::string> constcells_code;
151 for (
auto wire_it : module->
wires_) {
154 celltypes_code.insert(
stringf(
"celltype !%s b%d %sPORT\n" "%s %s %d %s PORT\n",
158 netname(conntypes_code, celltypes_code, constcells_code, sigmap(wire)).c_str());
163 for (
auto cell_it : module->
cells_)
166 std::string celltype_code, node_code;
175 if (sig.
size() != 0) {
176 conntypes_code.insert(
stringf(
"conntype b%d %d 2 %d\n", sig.
size(), sig.
size(), sig.
size()));
183 if (param.second.bits.size() != 32) {
185 for (
int i = param.second.bits.size()-1; i >= 0; i--)
186 node_code += param.second.bits[i] ==
RTLIL::S1 ?
"1" :
"0";
191 celltypes_code.insert(celltype_code +
"\n");
192 netlists_code += node_code +
"\n";
195 if (constcells_code.size() > 0)
196 netlists_code +=
"# constant cells\n";
197 for (
auto code : constcells_code)
198 netlists_code += code;
199 netlists_code +=
"\n";
203 *f <<
stringf(
"### Connection Types\n");
204 for (
auto code : conntypes_code)
205 *f <<
stringf(
"%s", code.c_str());
206 *f <<
stringf(
"\n### Cell Types\n");
207 for (
auto code : celltypes_code)
208 *f <<
stringf(
"%s", code.c_str());
210 *f <<
stringf(
"\n### Netlists\n");
211 *f <<
stringf(
"%s", netlists_code.c_str());
213 for (
auto lib : libs)
IntersynthBackend IntersynthBackend
std::string stringf(const char *fmt,...)
bool selected_module(RTLIL::IdString mod_name) const
void log_header(const char *format,...)
std::map< RTLIL::IdString, RTLIL::Wire * > wires_
static std::string unescape_id(std::string str)
const char * log_signal(const RTLIL::SigSpec &sig, bool autoint)
static void frontend_call(RTLIL::Design *design, std::istream *f, std::string filename, std::string command)
std::map< RTLIL::IdString, RTLIL::Memory * > memories
void log_error(const char *format,...)
std::map< RTLIL::IdString, RTLIL::Const > parameters
void extra_args(std::ostream *&f, std::string &filename, std::vector< std::string > args, size_t argidx)
bool cell_known(RTLIL::IdString type)
#define PRIVATE_NAMESPACE_BEGIN
bool cell_output(RTLIL::IdString type, RTLIL::IdString port)
bool is_fully_const() const
bool selected_whole_module(RTLIL::IdString mod_name) const
#define PRIVATE_NAMESPACE_END
static const char * id2cstr(const RTLIL::IdString &str)
void log_cmd_error(const char *format,...)
std::map< RTLIL::IdString, RTLIL::Process * > processes
#define USING_YOSYS_NAMESPACE
std::map< RTLIL::IdString, RTLIL::Module * > modules_
std::map< RTLIL::IdString, RTLIL::Cell * > cells_
USING_YOSYS_NAMESPACE static PRIVATE_NAMESPACE_BEGIN std::string netname(std::set< std::string > &conntypes_code, std::set< std::string > &celltypes_code, std::set< std::string > &constcells_code, RTLIL::SigSpec sig)
int as_int(bool is_signed=false) const
void log(const char *format,...)
void setup_design(RTLIL::Design *design)
virtual void execute(std::ostream *&f, std::string filename, std::vector< std::string > args, RTLIL::Design *design)
RTLIL::Wire * as_wire() const
const std::map< RTLIL::IdString, RTLIL::SigSpec > & connections() const