33 #define EDIF_DEF(_id) edif_names(RTLIL::unescape_id(_id), true).c_str() 
   34 #define EDIF_REF(_id) edif_names(RTLIL::unescape_id(_id), false).c_str() 
   41         std::set<std::string> generated_names, used_names;
 
   42         std::map<std::string, std::string> name_map;
 
   44         EdifNames() : counter(1) { }
 
   46         std::string operator()(std::string 
id, 
bool define)
 
   49                 std::string 
new_id = operator()(
id, 
false);
 
   50                 return new_id != 
id ? 
stringf(
"(rename %s \"%s\")", new_id.c_str(), 
id.c_str()) : 
id;
 
   53             if (name_map.count(
id) > 0)
 
   54                 return name_map.at(
id);
 
   55             if (generated_names.count(
id) > 0)
 
   57             if (
id == 
"GND" || 
id == 
"VCC")
 
   60             for (
size_t i = 0; i < 
id.size(); i++) {
 
   61                 if (
'A' <= 
id[i] && 
id[i] <= 
'Z')
 
   63                 if (
'a' <= 
id[i] && 
id[i] <= 
'z')
 
   65                 if (
'0' <= 
id[i] && 
id[i] <= 
'9' && i > 0)
 
   67                 if (
id[i] == 
'_' && i > 0 && i != 
id.size()-1)
 
   72             used_names.insert(
id);
 
   78                 gen_name = 
stringf(
"id%05d", counter++);
 
   79                 if (generated_names.count(gen_name) == 0 &&
 
   80                         used_names.count(gen_name) == 0)
 
   83             generated_names.insert(gen_name);
 
   84             name_map[
id] = gen_name;
 
   96         log(
"    write_edif [options] [filename]\n");
 
   98         log(
"Write the current design to an EDIF netlist file.\n");
 
  100         log(
"    -top top_module\n");
 
  101         log(
"        set the specified module as design top module\n");
 
  103         log(
"Unfortunately there are different \"flavors\" of the EDIF file format. This\n");
 
  104         log(
"command generates EDIF files for the Xilinx place&route tools. It might be\n");
 
  105         log(
"necessary to make small modifications to this command when a different tool\n");
 
  106         log(
"is targeted.\n");
 
  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";
 
  203                     else if (!ct.
cell_input(cell_it.first, port_it))
 
  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");
 
  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");
 
  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
 
virtual void execute(std::ostream *&f, std::string filename, std::vector< std::string > args, RTLIL::Design *design)
 
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,...)
 
RTLIL::IdString new_id(std::string file, int line, std::string func)
 
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)
 
int GetSize(RTLIL::Wire *wire)
 
#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_
 
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)
 
void log(const char *format,...)
 
bool cell_input(RTLIL::IdString type, RTLIL::IdString port)
 
std::string id(RTLIL::IdString internal_id, bool may_rename=true)
 
const std::map< RTLIL::IdString, RTLIL::SigSpec > & connections() const