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

Go to the source code of this file.

Data Structures

struct  SpiceBackend
 

Functions

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)
 
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)
 

Variables

SpiceBackend SpiceBackend
 

Function Documentation

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 
)
static

Definition at line 47 of file spice.cc.

48 {
49  SigMap sigmap(module);
50  int cell_counter = 0, conn_counter = 0, nc_counter = 0;
51 
52  for (auto &cell_it : module->cells_)
53  {
54  RTLIL::Cell *cell = cell_it.second;
55  f << stringf("X%d", cell_counter++);
56 
57  std::vector<RTLIL::SigSpec> port_sigs;
58 
59  if (design->modules_.count(cell->type) == 0)
60  {
61  log_warning("no (blackbox) module for cell type `%s' (%s.%s) found! Guessing order of ports.\n",
62  RTLIL::id2cstr(cell->type), RTLIL::id2cstr(module->name), RTLIL::id2cstr(cell->name));
63  for (auto &conn : cell->connections()) {
64  RTLIL::SigSpec sig = sigmap(conn.second);
65  port_sigs.push_back(sig);
66  }
67  }
68  else
69  {
70  RTLIL::Module *mod = design->modules_.at(cell->type);
71 
72  std::vector<RTLIL::Wire*> ports;
73  for (auto wire_it : mod->wires_) {
74  RTLIL::Wire *wire = wire_it.second;
75  if (wire->port_id == 0)
76  continue;
77  while (int(ports.size()) < wire->port_id)
78  ports.push_back(NULL);
79  ports.at(wire->port_id-1) = wire;
80  }
81 
82  for (RTLIL::Wire *wire : ports) {
83  log_assert(wire != NULL);
85  if (cell->hasPort(wire->name)) {
86  sig = sigmap(cell->getPort(wire->name));
87  sig.extend(wire->width, false);
88  }
89  port_sigs.push_back(sig);
90  }
91  }
92 
93  for (auto &sig : port_sigs) {
94  for (int i = 0; i < sig.size(); i++) {
95  RTLIL::SigSpec s = sig.extract(big_endian ? sig.size() - 1 - i : i, 1);
96  print_spice_net(f, s, neg, pos, ncpf, nc_counter);
97  }
98  }
99 
100  f << stringf(" %s\n", RTLIL::id2cstr(cell->type));
101  }
102 
103  for (auto &conn : module->connections())
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);
108  f << stringf(" DC 0\n");
109  }
110 }
std::string stringf(const char *fmt,...)
Definition: yosys.cc:58
void log_warning(const char *format,...)
Definition: log.cc:196
const std::vector< RTLIL::SigSig > & connections() const
Definition: rtlil.cc:1307
std::map< RTLIL::IdString, RTLIL::Wire * > wires_
Definition: rtlil.h:595
RTLIL::IdString name
Definition: rtlil.h:853
int width
Definition: rtlil.h:826
int port_id
Definition: rtlil.h:826
RTLIL::IdString type
Definition: rtlil.h:854
RTLIL_ATTRIBUTE_MEMBERS bool hasPort(RTLIL::IdString portname) const
Definition: rtlil.cc:1766
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
Definition: rtlil.cc:1809
#define log_assert(_assert_expr_)
Definition: log.h:85
RTLIL::IdString name
Definition: rtlil.h:599
RTLIL::IdString name
Definition: rtlil.h:825
static const char * id2cstr(const RTLIL::IdString &str)
Definition: rtlil.h:267
std::map< RTLIL::IdString, RTLIL::Module * > modules_
Definition: rtlil.h:507
#define NULL
std::map< RTLIL::IdString, RTLIL::Cell * > cells_
Definition: rtlil.h:596
RTLIL::SigSpec extract(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec *other=NULL) const
Definition: rtlil.cc:2414
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)
Definition: spice.cc:30
const std::map< RTLIL::IdString, RTLIL::SigSpec > & connections() const
Definition: rtlil.cc:1814

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 
)
static

Definition at line 30 of file spice.cc.

31 {
32  if (s.wire) {
33  if (s.wire->width > 1)
34  f << stringf(" %s[%d]", RTLIL::id2cstr(s.wire->name), s.offset);
35  else
36  f << stringf(" %s", RTLIL::id2cstr(s.wire->name));
37  } else {
38  if (s == RTLIL::State::S0)
39  f << stringf(" %s", neg.c_str());
40  else if (s == RTLIL::State::S1)
41  f << stringf(" %s", pos.c_str());
42  else
43  f << stringf(" %s%d", ncpf.c_str(), nc_counter++);
44  }
45 }
RTLIL::Wire * wire
Definition: rtlil.h:907
std::string stringf(const char *fmt,...)
Definition: yosys.cc:58
int width
Definition: rtlil.h:826
int offset
Definition: rtlil.h:910
RTLIL::IdString name
Definition: rtlil.h:825
static const char * id2cstr(const RTLIL::IdString &str)
Definition: rtlil.h:267

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation