547 std::string techmap_cmd =
"techmap -assert";
548 std::string ilang_file;
550 std::ofstream vlog_file;
551 bool verbose =
false;
552 bool constmode =
false;
559 num_iter = atoi(
args[++argidx].c_str());
567 techmap_cmd +=
" -map " +
args[++argidx];
571 ilang_file =
args[++argidx];
576 techmap_cmd =
"script " +
args[++argidx];
579 if (
args[argidx] ==
"-simlib") {
580 techmap_cmd =
"techmap -map +/simlib.v -max_iter 2 -autoproc";
583 if (
args[argidx] ==
"-const") {
587 if (
args[argidx] ==
"-nosat") {
591 if (
args[argidx] ==
"-v") {
596 vlog_file.open(
args[++argidx], std::ios_base::trunc);
597 if (!vlog_file.is_open())
609 std::map<std::string, std::string> cell_types;
610 std::vector<std::string> selected_cell_types;
612 cell_types[
"$not"] =
"ASY";
613 cell_types[
"$pos"] =
"ASY";
614 cell_types[
"$neg"] =
"ASY";
616 cell_types[
"$and"] =
"ABSY";
617 cell_types[
"$or"] =
"ABSY";
618 cell_types[
"$xor"] =
"ABSY";
619 cell_types[
"$xnor"] =
"ABSY";
621 cell_types[
"$reduce_and"] =
"ASY";
622 cell_types[
"$reduce_or"] =
"ASY";
623 cell_types[
"$reduce_xor"] =
"ASY";
624 cell_types[
"$reduce_xnor"] =
"ASY";
625 cell_types[
"$reduce_bool"] =
"ASY";
627 cell_types[
"$shl"] =
"ABshY";
628 cell_types[
"$shr"] =
"ABshY";
629 cell_types[
"$sshl"] =
"ABshY";
630 cell_types[
"$sshr"] =
"ABshY";
631 cell_types[
"$shift"] =
"ABshY";
632 cell_types[
"$shiftx"] =
"ABshY";
634 cell_types[
"$lt"] =
"ABSY";
635 cell_types[
"$le"] =
"ABSY";
636 cell_types[
"$eq"] =
"ABSY";
637 cell_types[
"$ne"] =
"ABSY";
640 cell_types[
"$ge"] =
"ABSY";
641 cell_types[
"$gt"] =
"ABSY";
643 cell_types[
"$add"] =
"ABSY";
644 cell_types[
"$sub"] =
"ABSY";
645 cell_types[
"$mul"] =
"ABSY";
646 cell_types[
"$div"] =
"ABSY";
647 cell_types[
"$mod"] =
"ABSY";
650 cell_types[
"$logic_not"] =
"ASY";
651 cell_types[
"$logic_and"] =
"ABSY";
652 cell_types[
"$logic_or"] =
"ABSY";
660 cell_types[
"$lut"] =
"*";
661 cell_types[
"$alu"] =
"ABSY";
662 cell_types[
"$lcu"] =
"*";
663 cell_types[
"$macc"] =
"*";
664 cell_types[
"$fa"] =
"*";
668 if (
args[argidx].rfind(
"-", 0) == 0)
671 if (
args[argidx] ==
"all") {
672 for (
auto &it : cell_types)
673 if (std::count(selected_cell_types.begin(), selected_cell_types.end(), it.first) == 0)
674 selected_cell_types.push_back(it.first);
678 if (cell_types.count(
args[argidx]) == 0) {
679 std::string cell_type_list;
681 for (
auto &it : cell_types) {
682 if (charcount > 60) {
683 cell_type_list +=
"\n" + it.first;
686 cell_type_list +=
" " + it.first;
687 charcount +=
GetSize(it.first);
689 log_cmd_error(
"The cell type `%s' is currently not supported. Try one of these:%s\n",
690 args[argidx].c_str(), cell_type_list.c_str());
693 if (std::count(selected_cell_types.begin(), selected_cell_types.end(),
args[argidx]) == 0)
694 selected_cell_types.push_back(
args[argidx]);
697 if (!ilang_file.empty()) {
698 if (!selected_cell_types.empty())
699 log_cmd_error(
"Do not specify any cell types when using -f.\n");
700 selected_cell_types.push_back(
"ilang");
703 if (selected_cell_types.empty())
706 std::vector<std::string> uut_names;
708 for (
auto cell_type : selected_cell_types)
709 for (
int i = 0; i < num_iter; i++)
712 if (cell_type ==
"ilang")
716 Pass::call(design,
stringf(
"copy gold gate; cd gate; %s; cd ..; opt -fast gate", techmap_cmd.c_str()));
718 Pass::call(design,
"miter -equiv -flatten -make_outputs -ignore_gold_x gold gate miter");
723 Pass::call(design,
"sat -verify -enable_undef -prove trigger 0 -show-inputs -show-outputs miter");
724 std::string uut_name =
stringf(
"uut_%s_%d", cell_type.substr(1).c_str(), i);
725 if (vlog_file.is_open()) {
726 Pass::call(design,
stringf(
"copy gold %s_expr; select %s_expr", uut_name.c_str(), uut_name.c_str()));
728 Pass::call(design,
stringf(
"copy gold %s_noexpr; select %s_noexpr", uut_name.c_str(), uut_name.c_str()));
730 uut_names.push_back(uut_name);
736 if (vlog_file.is_open()) {
737 vlog_file <<
"\nmodule testbench;\n";
738 for (
auto &uut : uut_names)
739 vlog_file <<
stringf(
" %s %s ();\n", uut.c_str(), uut.c_str());
740 vlog_file <<
" initial begin\n";
741 for (
auto &uut : uut_names)
742 vlog_file <<
" " << uut <<
".run;\n";
743 vlog_file <<
" end\n";
744 vlog_file <<
"endmodule\n";
std::string stringf(const char *fmt,...)
static void frontend_call(RTLIL::Design *design, std::istream *f, std::string filename, std::string command)
USING_YOSYS_NAMESPACE static PRIVATE_NAMESPACE_BEGIN uint32_t xorshift32_state
static void run_eval_test(RTLIL::Design *design, bool verbose, bool nosat, std::string uut_name, std::ofstream &vlog_file)
static void backend_call(RTLIL::Design *design, std::ostream *f, std::string filename, std::string command)
int GetSize(RTLIL::Wire *wire)
void log_cmd_error(const char *format,...)
static void create_gold_module(RTLIL::Design *design, RTLIL::IdString cell_type, std::string cell_type_flags, bool constmode)
void log(const char *format,...)
static void call(RTLIL::Design *design, std::string command)