39 f <<
stringf(
" %s", neg.c_str());
41 f <<
stringf(
" %s", pos.c_str());
43 f <<
stringf(
" %s%d", ncpf.c_str(), nc_counter++);
50 int cell_counter = 0, conn_counter = 0, nc_counter = 0;
52 for (
auto &cell_it : module->
cells_)
55 f <<
stringf(
"X%d", cell_counter++);
57 std::vector<RTLIL::SigSpec> port_sigs;
61 log_warning(
"no (blackbox) module for cell type `%s' (%s.%s) found! Guessing order of ports.\n",
65 port_sigs.push_back(sig);
72 std::vector<RTLIL::Wire*> ports;
73 for (
auto wire_it : mod->
wires_) {
77 while (
int(ports.size()) < wire->
port_id)
78 ports.push_back(
NULL);
79 ports.at(wire->
port_id-1) = wire;
85 if (cell->
hasPort(wire->name)) {
86 sig = sigmap(cell->
getPort(wire->name));
87 sig.
extend(wire->width,
false);
89 port_sigs.push_back(sig);
93 for (
auto &sig : port_sigs) {
94 for (
int i = 0; i < sig.size(); i++) {
104 for (
int i = 0; i < conn.first.size(); i++) {
105 f <<
stringf(
"V%d", conn_counter++);
106 print_spice_net(f, conn.first.extract(i, 1), neg, pos, ncpf, nc_counter);
107 print_spice_net(f, conn.second.extract(i, 1), neg, pos, ncpf, nc_counter);
118 log(
" write_spice [options] [filename]\n");
120 log(
"Write the current design to an SPICE netlist file.\n");
122 log(
" -big_endian\n");
123 log(
" generate multi-bit ports in MSB first order \n");
124 log(
" (default is LSB first)\n");
126 log(
" -neg net_name\n");
127 log(
" set the net name for constant 0 (default: Vss)\n");
129 log(
" -pos net_name\n");
130 log(
" set the net name for constant 1 (default: Vdd)\n");
132 log(
" -nc_prefix\n");
133 log(
" prefix for not-connected nets (default: _NC)\n");
135 log(
" -top top_module\n");
136 log(
" set the specified module as design top module\n");
141 std::string top_module_name;
143 bool big_endian =
false;
144 std::string neg =
"Vss", pos =
"Vdd", ncpf =
"_NC";
149 for (argidx = 1; argidx < args.size(); argidx++)
151 if (args[argidx] ==
"-big_endian") {
155 if (args[argidx] ==
"-neg" && argidx+1 < args.size()) {
156 neg = args[++argidx];
159 if (args[argidx] ==
"-pos" && argidx+1 < args.size()) {
160 pos = args[++argidx];
163 if (args[argidx] ==
"-nc_prefix" && argidx+1 < args.size()) {
164 ncpf = args[++argidx];
167 if (args[argidx] ==
"-top" && argidx+1 < args.size()) {
168 top_module_name = args[++argidx];
175 if (top_module_name.empty())
176 for (
auto & mod_it:design->
modules_)
177 if (mod_it.second->get_bool_attribute(
"\\top"))
178 top_module_name = mod_it.first.str();
183 for (
auto module_it : design->
modules_)
186 if (module->get_bool_attribute(
"\\blackbox"))
190 log_error(
"Found unmapped processes in module %s: unmapped processes are not supported in SPICE backend!\n",
RTLIL::id2cstr(module->
name));
192 log_error(
"Found munmapped emories in module %s: unmapped memories are not supported in SPICE backend!\n",
RTLIL::id2cstr(module->
name));
199 std::vector<RTLIL::Wire*> ports;
200 for (
auto wire_it : module->
wires_) {
204 while (
int(ports.size()) < wire->
port_id)
205 ports.push_back(
NULL);
206 ports.at(wire->
port_id-1) = wire;
212 if (wire->width > 1) {
213 for (
int i = 0; i < wire->width; i++)
223 if (!top_module_name.empty()) {
224 if (top_module ==
NULL)
225 log_error(
"Can't find top module `%s'!\n", top_module_name.c_str());
230 *f <<
stringf(
"************************\n");
231 *f <<
stringf(
"* end of SPICE netlist *\n");
232 *f <<
stringf(
"************************\n");
const char * yosys_version_str
std::string stringf(const char *fmt,...)
void log_warning(const char *format,...)
void log_header(const char *format,...)
const std::vector< RTLIL::SigSig > & connections() const
std::map< RTLIL::IdString, RTLIL::Wire * > wires_
std::map< RTLIL::IdString, RTLIL::Memory * > memories
void log_error(const char *format,...)
SpiceBackend SpiceBackend
static std::string escape_id(std::string str)
void extra_args(std::ostream *&f, std::string &filename, std::vector< std::string > args, size_t argidx)
#define PRIVATE_NAMESPACE_BEGIN
RTLIL_ATTRIBUTE_MEMBERS bool hasPort(RTLIL::IdString portname) const
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
virtual void execute(std::ostream *&f, std::string filename, std::vector< std::string > args, RTLIL::Design *design)
#define log_assert(_assert_expr_)
static void print_spice_module(std::ostream &f, RTLIL::Module *module, RTLIL::Design *design, std::string &neg, std::string &pos, std::string &ncpf, bool big_endian)
#define PRIVATE_NAMESPACE_END
static const char * id2cstr(const RTLIL::IdString &str)
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_
void log(const char *format,...)
RTLIL::SigSpec extract(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec *other=NULL) const
USING_YOSYS_NAMESPACE static PRIVATE_NAMESPACE_BEGIN void print_spice_net(std::ostream &f, RTLIL::SigBit s, std::string &neg, std::string &pos, std::string &ncpf, int &nc_counter)
void extend(int width, bool is_signed=false)
const std::map< RTLIL::IdString, RTLIL::SigSpec > & connections() const