diff --git a/passes/techmap/abc.cc b/passes/techmap/abc.cc index a6f346ec5..184ce51d0 100644 --- a/passes/techmap/abc.cc +++ b/passes/techmap/abc.cc @@ -2037,9 +2037,7 @@ struct AbcPass : public Pass { enabled_gates.insert("MUX"); // enabled_gates.insert("NMUX"); } - std::string lib_tempdir_name = AbcPrep::tmp_base(cleanup) + "yosys-abc-lib-XXXXXX"; - lib_tempdir_name = make_temp_dir(lib_tempdir_name); - AbcPrep::lib_to_tmp(lib_tempdir_name, liberty_files); + auto lib_tempdir_name = AbcPrep::make_tmp_extract_lib(liberty_files, cleanup); for (auto mod : design->selected_modules()) { diff --git a/passes/techmap/abc9.cc b/passes/techmap/abc9.cc index 44a033611..7879bba9f 100644 --- a/passes/techmap/abc9.cc +++ b/passes/techmap/abc9.cc @@ -191,6 +191,7 @@ struct Abc9Pass : public ScriptPass bool lut_mode; int maxlut; std::string box_file; + std::vector liberty_files; void clear_flags() override { @@ -223,13 +224,17 @@ struct Abc9Pass : public ScriptPass if ((arg == "-exe" || arg == "-script" || arg == "-D" || /*arg == "-S" ||*/ arg == "-lut" || arg == "-luts" || /*arg == "-box" ||*/ arg == "-W" || arg == "-genlib" || - arg == "-constr" || arg == "-dont_use" || arg == "-liberty") && + arg == "-constr" || arg == "-dont_use") && argidx+1 < args.size()) { if (arg == "-lut" || arg == "-luts") lut_mode = true; exe_cmd << " " << arg << " " << args[++argidx]; continue; } + if (arg == "-liberty") { + liberty_files.push_back(args[++argidx]); + continue; + } if (arg == "-fast" || /* arg == "-dff" || */ /* arg == "-nocleanup" || */ arg == "-showtmp") { exe_cmd << " " << arg; @@ -276,7 +281,10 @@ struct Abc9Pass : public ScriptPass log_header(design, "Executing ABC9 pass.\n"); log_push(); + auto lib_tmpdir = AbcPrep::make_tmp_extract_lib(liberty_files, cleanup); run_script(design, run_from, run_to); + if (cleanup) + remove_directory(lib_tmpdir); log_pop(); } diff --git a/passes/techmap/abc_new.cc b/passes/techmap/abc_new.cc index 15890acf3..7d7ba9a18 100644 --- a/passes/techmap/abc_new.cc +++ b/passes/techmap/abc_new.cc @@ -115,9 +115,7 @@ struct AbcNewPass : public ScriptPass { log_header(d, "Executing ABC_NEW pass.\n"); log_push(); - std::string lib_tmpdir = AbcPrep::tmp_base(cleanup) + "yosys-abc-lib-XXXXXX"; - lib_tmpdir = make_temp_dir(lib_tmpdir); - AbcPrep::lib_to_tmp(lib_tmpdir, liberty_files); + auto lib_tmpdir = AbcPrep::make_tmp_extract_lib(liberty_files, cleanup); run_script(d, run_from, run_to); if (cleanup) remove_directory(lib_tmpdir); diff --git a/passes/techmap/abc_prep.h b/passes/techmap/abc_prep.h index 70be20c9f..af88371e9 100644 --- a/passes/techmap/abc_prep.h +++ b/passes/techmap/abc_prep.h @@ -49,6 +49,18 @@ namespace AbcPrep { } } } + + inline std::string make_tmp_extract_lib(std::vector& liberty_files, bool cleanup) + { + // Compose the path + std::string lib_tmpdir = AbcPrep::tmp_base(cleanup) + "yosys-abc-lib-XXXXXX"; + // Create the directory + lib_tmpdir = make_temp_dir(lib_tmpdir); + // Extract compressed liberty files to directory, rewrite liberty_files + AbcPrep::lib_to_tmp(lib_tmpdir, liberty_files); + // Caller responsible for cleanup + return lib_tmpdir; + } }; #endif /* ABC_PREP_H */