621 log_header(
"Generating Graphviz representation of design.\n");
624 std::vector<std::pair<std::string, RTLIL::Selection>> color_selections;
625 std::vector<std::pair<std::string, RTLIL::Selection>> label_selections;
628 std::string viewer_exe;
629 std::string prefix =
stringf(
"%s/.yosys_show", getenv(
"HOME") ? getenv(
"HOME") :
".");
630 std::vector<std::string> libfiles;
631 std::vector<RTLIL::Design*> libs;
632 uint32_t colorSeed = 0;
633 bool flag_width =
false;
634 bool flag_signed =
false;
635 bool flag_stretch =
false;
636 bool flag_pause =
false;
637 bool flag_enum =
false;
638 bool flag_abbeviate =
true;
639 bool flag_notitle =
false;
642 for (argidx = 1; argidx <
args.size(); argidx++)
644 std::string arg =
args[argidx];
645 if (arg ==
"-viewer" && argidx+1 <
args.size()) {
646 viewer_exe =
args[++argidx];
649 if (arg ==
"-lib" && argidx+1 <
args.size()) {
650 libfiles.push_back(
args[++argidx]);
653 if (arg ==
"-prefix" && argidx+1 <
args.size()) {
654 prefix =
args[++argidx];
657 if (arg ==
"-color" && argidx+2 <
args.size()) {
658 std::pair<std::string, RTLIL::Selection> data;
659 data.first =
args[++argidx], argidx++;
663 color_selections.push_back(data);
666 if (arg ==
"-label" && argidx+2 <
args.size()) {
667 std::pair<std::string, RTLIL::Selection> data;
668 data.first =
args[++argidx], argidx++;
672 label_selections.push_back(data);
675 if (arg ==
"-colors" && argidx+1 <
args.size()) {
676 colorSeed = atoi(
args[++argidx].c_str());
677 for (
int i = 0; i < 100; i++)
681 if (arg ==
"-format" && argidx+1 <
args.size()) {
682 format =
args[++argidx];
685 if (arg ==
"-width") {
689 if (arg ==
"-signed") {
693 if (arg ==
"-stretch") {
697 if (arg ==
"-pause") {
701 if (arg ==
"-enum") {
703 flag_abbeviate =
false;
706 if (arg ==
"-long") {
708 flag_abbeviate =
false;
711 if (arg ==
"-notitle") {
719 if (format !=
"ps") {
721 for (
auto &mod_it : design->
modules_) {
722 if (mod_it.second->get_bool_attribute(
"\\blackbox"))
724 if (mod_it.second->cells_.empty() && mod_it.second->connections().empty())
730 log_cmd_error(
"For formats different than 'ps' only one module must be selected.\n");
733 for (
auto filename : libfiles) {
735 f.open(filename.c_str());
737 log_error(
"Can't open lib file `%s'.\n", filename.c_str());
739 Frontend::frontend_call(lib, &f, filename, (filename.size() > 3 && filename.substr(filename.size()-3) ==
".il") ?
"ilang" :
"verilog");
746 std::string dot_file =
stringf(
"%s.dot", prefix.c_str());
747 std::string out_file =
stringf(
"%s.%s", prefix.c_str(), format.empty() ?
"svg" : format.c_str());
749 log(
"Writing dot description to `%s'.\n", dot_file.c_str());
750 FILE *f = fopen(dot_file.c_str(),
"w");
752 for (
auto lib : libs)
754 log_cmd_error(
"Can't open dot file `%s' for writing.\n", dot_file.c_str());
756 ShowWorker worker(f, design, libs, colorSeed, flag_width, flag_signed, flag_stretch, flag_enum, flag_abbeviate, flag_notitle, color_selections, label_selections);
759 for (
auto lib : libs)
762 if (worker.page_counter == 0)
765 if (format !=
"dot" && !format.empty()) {
766 std::string cmd =
stringf(
"dot -T%s -o '%s' '%s'", format.c_str(), out_file.c_str(), dot_file.c_str());
767 log(
"Exec: %s\n", cmd.c_str());
772 if (!viewer_exe.empty()) {
773 std::string cmd =
stringf(
"%s '%s' &", viewer_exe.c_str(), out_file.c_str());
774 log(
"Exec: %s\n", cmd.c_str());
778 if (format.empty()) {
779 std::string cmd =
stringf(
"fuser -s '%s' || xdot '%s' < '%s' &", dot_file.c_str(), dot_file.c_str(), dot_file.c_str());
780 log(
"Exec: %s\n", cmd.c_str());
786 #ifdef YOSYS_ENABLE_READLINE
788 while ((input = readline(
"Press ENTER to continue (or type 'shell' to open a shell)> ")) !=
NULL) {
789 if (input[strspn(input,
" \t\r\n")] == 0)
791 char *p = input + strspn(input,
" \t\r\n");
792 if (!strcmp(p,
"shell")) {
798 log_cmd_error(
"This version of yosys is built without readline support => 'show -pause' is not available.\n");
std::vector< RTLIL::Selection > selection_stack
std::string stringf(const char *fmt,...)
void handle_extra_select_args(Pass *pass, std::vector< std::string > args, size_t argidx, size_t args_size, RTLIL::Design *design)
bool selected_module(RTLIL::IdString mod_name) const
void log_header(const char *format,...)
static void frontend_call(RTLIL::Design *design, std::istream *f, std::string filename, std::string command)
void log_error(const char *format,...)
int run_command(const std::string &command, std::function< void(const std::string &)> process_line)
void log_cmd_error(const char *format,...)
static uint32_t xorshift32(uint32_t x)
std::map< RTLIL::IdString, RTLIL::Module * > modules_
void log(const char *format,...)
void extra_args(std::vector< std::string > args, size_t argidx, RTLIL::Design *design, bool select=true)
static void call(RTLIL::Design *design, std::string command)