|
| 1 | +#include "kernel/rtlil.h" |
| 2 | +#include "kernel/log.h" |
| 3 | + |
| 4 | +USING_YOSYS_NAMESPACE |
| 5 | +PRIVATE_NAMESPACE_BEGIN |
| 6 | + |
| 7 | +struct SdcexpandPass : public ScriptPass |
| 8 | +{ |
| 9 | + const char* default_sta_cmd = "sta"; |
| 10 | + SdcexpandPass() : ScriptPass("sdc_expand", "run OpenSTA") { } |
| 11 | + |
| 12 | + void help() override |
| 13 | + { |
| 14 | + // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---| |
| 15 | + log("\n"); |
| 16 | + log(" sdc_expand [options]\n"); |
| 17 | + log("\n"); |
| 18 | + // TODO |
| 19 | + log("\n"); |
| 20 | + log(" -exe <command>\n"); |
| 21 | + log(" use <command> to run OpenSTA instead of \"%s\"\n", default_sta_cmd); |
| 22 | + log("\n"); |
| 23 | + log(" -sdc-in <filename>\n"); |
| 24 | + log(" expand SDC file <filename>\n"); |
| 25 | + log("\n"); |
| 26 | + log(" -nocleanup\n"); |
| 27 | + log("\n"); |
| 28 | + log("\n"); |
| 29 | + log("The following commands are executed by this synthesis command:\n"); |
| 30 | + help_script(); |
| 31 | + log("\n"); |
| 32 | + } |
| 33 | + |
| 34 | + string opensta_exe, sdc_filename, sdc_expanded_filename; |
| 35 | + bool cleanup; |
| 36 | + void execute(std::vector<std::string> args, RTLIL::Design *design) override |
| 37 | + { |
| 38 | + string run_from, run_to; |
| 39 | + cleanup = true; |
| 40 | + |
| 41 | + size_t argidx; |
| 42 | + for (argidx = 1; argidx < args.size(); argidx++) |
| 43 | + { |
| 44 | + if (args[argidx] == "-exe" && argidx+1 < args.size()) { |
| 45 | + opensta_exe = args[++argidx]; |
| 46 | + continue; |
| 47 | + } |
| 48 | + if (args[argidx] == "-sdc-in" && argidx+1 < args.size()) { |
| 49 | + sdc_filename = args[++argidx]; |
| 50 | + continue; |
| 51 | + } |
| 52 | + if (args[argidx] == "-sdc-out" && argidx+1 < args.size()) { |
| 53 | + sdc_expanded_filename = args[++argidx]; |
| 54 | + continue; |
| 55 | + } |
| 56 | + if (args[argidx] == "-nocleanup") { |
| 57 | + cleanup = false; |
| 58 | + continue; |
| 59 | + } |
| 60 | + // repetitive boring bit |
| 61 | + if (args[argidx] == "-run" && argidx+1 < args.size()) { |
| 62 | + size_t pos = args[argidx+1].find(':'); |
| 63 | + if (pos == std::string::npos) { |
| 64 | + run_from = args[++argidx]; |
| 65 | + run_to = args[argidx]; |
| 66 | + } else { |
| 67 | + run_from = args[++argidx].substr(0, pos); |
| 68 | + run_to = args[argidx].substr(pos+1); |
| 69 | + } |
| 70 | + continue; |
| 71 | + } |
| 72 | + break; |
| 73 | + } |
| 74 | + extra_args(args, argidx, design); |
| 75 | + |
| 76 | + if (!design->full_selection()) |
| 77 | + log_cmd_error("This command only operates on fully selected designs!\n"); |
| 78 | + |
| 79 | + log_header(design, "Executing OPENSTA pass.\n"); |
| 80 | + log_push(); |
| 81 | + |
| 82 | + run_script(design, run_from, run_to); |
| 83 | + |
| 84 | + log_pop(); |
| 85 | + } |
| 86 | + |
| 87 | + void script() override |
| 88 | + { |
| 89 | + std::string tempdir_name; |
| 90 | + std::string liberty_path; |
| 91 | + std::string verilog_path; |
| 92 | + |
| 93 | + run("design -save pre_expand"); |
| 94 | + run("proc"); |
| 95 | + run("memory"); |
| 96 | + // run("dfflegalize -cell $dff"); |
| 97 | + |
| 98 | + std::string write_verilog_cmd = "write_verilog -norename -noexpr -attr2comment -defparam "; |
| 99 | + if (help_mode) { |
| 100 | + run(write_verilog_cmd + "<tmp_dir>/elaborated.v"); |
| 101 | + } else { |
| 102 | + if (cleanup) |
| 103 | + tempdir_name = get_base_tmpdir() + "/"; |
| 104 | + else |
| 105 | + tempdir_name = "_tmp_"; |
| 106 | + tempdir_name += proc_program_prefix() + "yosys-sdc_expand-XXXXXX"; |
| 107 | + tempdir_name = make_temp_dir(tempdir_name); |
| 108 | + verilog_path = tempdir_name + "/elaborated.v"; |
| 109 | + run(write_verilog_cmd + verilog_path); |
| 110 | + } |
| 111 | + |
| 112 | + run("read_verilog -setattr whitebox -defer -DSIMLIB_NOCHECKS +/simlib.v"); |
| 113 | + run("proc"); |
| 114 | + run("hierarchy -auto-top"); |
| 115 | + run("publish"); |
| 116 | + |
| 117 | + if (help_mode) { |
| 118 | + run("icell_liberty <tmp_dir>/yosys.lib"); |
| 119 | + } else { |
| 120 | + liberty_path = tempdir_name + "/yosys.lib"; |
| 121 | + run(stringf("icell_liberty %s", liberty_path.c_str())); |
| 122 | + } |
| 123 | + |
| 124 | + std::string opensta_pass_call = "opensta -exe "; |
| 125 | + opensta_pass_call += help_mode ? "<exe>" : opensta_exe; |
| 126 | + opensta_pass_call += " -sdc-in "; |
| 127 | + opensta_pass_call += help_mode ? "<sdc-in>" : sdc_filename; |
| 128 | + opensta_pass_call += " -sdc-out "; |
| 129 | + opensta_pass_call += help_mode ? "<sdc-out>" : sdc_expanded_filename; |
| 130 | + opensta_pass_call += " -verilog "; |
| 131 | + opensta_pass_call += help_mode ? "<verilog>" : verilog_path; |
| 132 | + opensta_pass_call += " -liberty "; |
| 133 | + opensta_pass_call += help_mode ? "<tmp_dir>/yosys.lib" : liberty_path; |
| 134 | + if (!cleanup) |
| 135 | + opensta_pass_call += " -nocleanup"; |
| 136 | + run(opensta_pass_call.c_str()); |
| 137 | + |
| 138 | + if (!help_mode) { |
| 139 | + if (cleanup) { |
| 140 | + log("Removing temp directory.\n"); |
| 141 | + remove_directory(tempdir_name); |
| 142 | + } else { |
| 143 | + log("Keeping temp directory %s\n", tempdir_name.c_str()); |
| 144 | + } |
| 145 | + } |
| 146 | + run("design -load pre_expand"); |
| 147 | + } |
| 148 | +} SdcexpandPass; |
| 149 | + |
| 150 | +PRIVATE_NAMESPACE_END |
0 commit comments