113 std::string top_module_name;
114 std::map<RTLIL::IdString, std::set<RTLIL::IdString>> lib_cell_ports;
116 EdifNames edif_names;
119 for (argidx = 1; argidx <
args.size(); argidx++)
121 if (
args[argidx] ==
"-top" && argidx+1 <
args.size()) {
122 top_module_name =
args[++argidx];
129 if (top_module_name.empty())
130 for (
auto & mod_it:design->
modules_)
131 if (mod_it.second->get_bool_attribute(
"\\top"))
132 top_module_name = mod_it.first.str();
134 for (
auto module_it : design->
modules_)
137 if (module->get_bool_attribute(
"\\blackbox"))
140 if (top_module_name.empty())
141 top_module_name = module->
name.
str();
144 log_error(
"Found unmapped processes in module %s: unmapped processes are not supported in EDIF backend!\n",
RTLIL::id2cstr(module->
name));
146 log_error(
"Found munmapped emories in module %s: unmapped memories are not supported in EDIF backend!\n",
RTLIL::id2cstr(module->
name));
148 for (
auto cell_it : module->
cells_)
152 lib_cell_ports[cell->
type];
154 if (p.second.size() > 1)
155 log_error(
"Found multi-bit port %s on library cell %s.%s (%s): not supported in EDIF backend!\n",
157 lib_cell_ports[cell->
type].insert(p.first);
163 if (top_module_name.empty())
164 log_error(
"No module found in design!\n");
167 *f <<
stringf(
" (edifVersion 2 0 0)\n");
168 *f <<
stringf(
" (edifLevel 0)\n");
169 *f <<
stringf(
" (keywordMap (keywordLevel 0))\n");
172 *f <<
stringf(
" (external LIB\n");
173 *f <<
stringf(
" (edifLevel 0)\n");
174 *f <<
stringf(
" (technology (numberDefinition))\n");
177 *f <<
stringf(
" (cellType GENERIC)\n");
178 *f <<
stringf(
" (view VIEW_NETLIST\n");
179 *f <<
stringf(
" (viewType NETLIST)\n");
180 *f <<
stringf(
" (interface (port G (direction OUTPUT)))\n");
185 *f <<
stringf(
" (cellType GENERIC)\n");
186 *f <<
stringf(
" (view VIEW_NETLIST\n");
187 *f <<
stringf(
" (viewType NETLIST)\n");
188 *f <<
stringf(
" (interface (port P (direction OUTPUT)))\n");
192 for (
auto &cell_it : lib_cell_ports) {
194 *f <<
stringf(
" (cellType GENERIC)\n");
195 *f <<
stringf(
" (view VIEW_NETLIST\n");
196 *f <<
stringf(
" (viewType NETLIST)\n");
197 *f <<
stringf(
" (interface\n");
198 for (
auto &port_it : cell_it.second) {
199 const char *dir =
"INOUT";
214 std::vector<RTLIL::Module*> sorted_modules;
217 std::map<RTLIL::Module*, std::set<RTLIL::Module*>> module_deps;
218 for (
auto &mod_it : design->
modules_) {
219 module_deps[mod_it.second] = std::set<RTLIL::Module*>();
220 for (
auto &cell_it : mod_it.second->cells_)
221 if (design->
modules_.count(cell_it.second->type) > 0)
222 module_deps[mod_it.second].insert(design->
modules_.at(cell_it.second->type));
227 while (module_deps.size() > 0) {
228 size_t sorted_modules_idx = sorted_modules.size();
229 for (
auto &it : module_deps) {
230 for (
auto &dep : it.second)
231 if (module_deps.count(dep) > 0)
234 sorted_modules.push_back(it.first);
237 if (sorted_modules_idx == sorted_modules.size())
238 log_error(
"Cyclic dependency between modules found! Cycle includes module %s.\n",
RTLIL::id2cstr(module_deps.begin()->first->name));
239 while (sorted_modules_idx < sorted_modules.size())
240 module_deps.erase(sorted_modules.at(sorted_modules_idx++));
244 *f <<
stringf(
" (library DESIGN\n");
245 *f <<
stringf(
" (edifLevel 0)\n");
246 *f <<
stringf(
" (technology (numberDefinition))\n");
247 for (
auto module : sorted_modules)
249 if (module->get_bool_attribute(
"\\blackbox"))
253 std::map<RTLIL::SigSpec, std::set<std::string>> net_join_db;
256 *f <<
stringf(
" (cellType GENERIC)\n");
257 *f <<
stringf(
" (view VIEW_NETLIST\n");
258 *f <<
stringf(
" (viewType NETLIST)\n");
259 *f <<
stringf(
" (interface\n");
260 for (
auto &wire_it : module->
wires_) {
264 const char *dir =
"INOUT";
269 if (wire->
width == 1) {
275 for (
int i = 0; i < wire->
width; i++) {
283 *f <<
stringf(
" (instance GND (viewRef VIEW_NETLIST (cellRef GND (libraryRef LIB))))\n");
284 *f <<
stringf(
" (instance VCC (viewRef VIEW_NETLIST (cellRef VCC (libraryRef LIB))))\n");
285 for (
auto &cell_it : module->
cells_) {
289 lib_cell_ports.count(cell->
type) > 0 ?
" (libraryRef LIB)" :
"");
292 *f <<
stringf(
"\n (property %s (string \"%s\"))",
EDIF_DEF(p.first), p.second.decode_string().c_str());
294 *f <<
stringf(
"\n (property %s (integer %u))",
EDIF_DEF(p.first), p.second.as_int());
296 std::string hex_string =
"";
297 for (
size_t i = 0; i < p.second.bits.size(); i += 4) {
299 if (i+0 < p.second.bits.size() && p.second.bits.at(i+0) ==
RTLIL::State::S1) digit_value |= 1;
300 if (i+1 < p.second.bits.size() && p.second.bits.at(i+1) ==
RTLIL::State::S1) digit_value |= 2;
301 if (i+2 < p.second.bits.size() && p.second.bits.at(i+2) ==
RTLIL::State::S1) digit_value |= 4;
302 if (i+3 < p.second.bits.size() && p.second.bits.at(i+3) ==
RTLIL::State::S1) digit_value |= 8;
303 char digit_str[2] = {
"0123456789abcdef"[digit_value], 0 };
304 hex_string = std::string(digit_str) + hex_string;
306 *f <<
stringf(
"\n (property %s (string \"%s\"))",
EDIF_DEF(p.first), hex_string.c_str());
311 for (
int i = 0; i <
GetSize(sig); i++)
318 for (
auto &it : net_join_db) {
323 for (
size_t i = 0; i < netname.size(); i++)
324 if (netname[i] ==
' ' || netname[i] ==
'\\')
325 netname.erase(netname.begin() + i--);
327 for (
auto &ref : it.second)
328 *f <<
stringf(
" %s\n", ref.c_str());
331 *f <<
stringf(
" (portRef G (instanceRef GND))\n");
333 *f <<
stringf(
" (portRef P (instanceRef VCC))\n");
344 *f <<
stringf(
" (cellRef %s (libraryRef DESIGN))\n",
EDIF_REF(top_module_name));
const char * yosys_version_str
bool is_fully_def() const
std::string stringf(const char *fmt,...)
void log_header(const char *format,...)
std::map< RTLIL::IdString, RTLIL::Wire * > wires_
const char * log_signal(const RTLIL::SigSpec &sig, bool autoint)
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)
bool cell_output(RTLIL::IdString type, RTLIL::IdString port)
int GetSize(RTLIL::Wire *wire)
static const char * id2cstr(const RTLIL::IdString &str)
std::map< RTLIL::IdString, RTLIL::Process * > processes
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)
bool cell_input(RTLIL::IdString type, RTLIL::IdString port)
const std::map< RTLIL::IdString, RTLIL::SigSpec > & connections() const