From 8231c0b85fe4212c7e6a86179f9d1bfef987c0fd Mon Sep 17 00:00:00 2001 From: phsauter Date: Thu, 19 Sep 2024 18:06:42 +0200 Subject: [PATCH] abc: add helper script files option --- passes/techmap/abc.cc | 47 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/passes/techmap/abc.cc b/passes/techmap/abc.cc index 5a1e23c81..29932c962 100644 --- a/passes/techmap/abc.cc +++ b/passes/techmap/abc.cc @@ -56,6 +56,7 @@ #include #include #include +#include #ifndef _WIN32 # include @@ -711,7 +712,7 @@ void substitute(std::string &str, const std::string &placeholder, const std::str } void abc_module(RTLIL::Design *design, RTLIL::Module *current_module, std::string script_file, std::string exe_file, std::string exe_flags, - std::string input_file, std::string output_file, std::vector &liberty_files, std::vector &genlib_files, + std::string input_file, std::string output_file, std::vector &helper_files, std::vector &liberty_files, std::vector &genlib_files, std::string constr_file, bool cleanup, vector lut_costs, bool dff_mode, std::string clk_str, bool keepff, std::string delay_target, std::string sop_inputs, std::string sop_products, std::string lutin_shared, bool fast_mode, const std::vector &cells, bool show_tempdir, bool sop_mode, bool abc_dress, std::vector &dont_use_cells, @@ -842,6 +843,41 @@ void abc_module(RTLIL::Design *design, RTLIL::Module *current_module, std::strin fprintf(f, "%s\n", abc_script.c_str()); fclose(f); + for (const std::string &hfile : helper_files) { + std::ifstream fstream(hfile); + if (!fstream) { + std::cerr << "Error: Unable to open file " << hfile << std::endl; + continue; + } + + std::string hscript((std::istreambuf_iterator(fstream)), + std::istreambuf_iterator()); + fstream.close(); + + // Substitute placeholders + substitute(hscript, "{D}", delay_target); + substitute(hscript, "{I}", sop_inputs); + substitute(hscript, "{P}", sop_products); + substitute(hscript, "{S}", lutin_shared); + substitute(hscript, "{tmpdir}", tempdir_name.c_str()); + substitute(hscript, "{input}", input_file.c_str()); + substitute(hscript, "{output}", output_file.c_str()); + + // Get filename only (strip the directory path) + std::string filename = std::filesystem::path(hfile).filename().string(); + + // Write to tempdir + std::string hpath = tempdir_name + "/" + filename; + std::ofstream tmp_hstream(hpath); + if (!tmp_hstream) { + std::cerr << "Error: Unable to write tmpfile" << hpath << std::endl; + continue; + } + + tmp_hstream << hscript; + tmp_hstream.close(); + } + // parse clock domain if (clk_str != "$") { @@ -1713,6 +1749,7 @@ struct AbcPass : public Pass { std::string input_file = "input.blif"; std::string output_file = "output.blif"; std::string exe_flags = "-s -f"; + std::vector helper_files; std::string delay_target, sop_inputs, sop_products, lutin_shared = "-S 1"; bool fast_mode = false, dff_mode = false, keepff = false, cleanup = true; bool show_tempdir = false, sop_mode = false; @@ -1798,6 +1835,10 @@ struct AbcPass : public Pass { liberty_files.push_back(args[++argidx]); continue; } + if (arg == "-helper" && argidx+1 < args.size()) { + helper_files.push_back(args[++argidx]); + continue; + } if (arg == "-dont_use" && argidx+1 < args.size()) { dont_use_cells.push_back(args[++argidx]); continue; @@ -2116,7 +2157,7 @@ struct AbcPass : public Pass { initvals.set(&assign_map, mod); if (!dff_mode || !clk_str.empty()) { - abc_module(design, mod, script_file, exe_file, exe_flags, input_file, output_file, liberty_files, genlib_files, constr_file, cleanup, lut_costs, dff_mode, clk_str, keepff, + abc_module(design, mod, script_file, exe_file, exe_flags, input_file, output_file, helper_files, liberty_files, genlib_files, constr_file, cleanup, lut_costs, dff_mode, clk_str, keepff, delay_target, sop_inputs, sop_products, lutin_shared, fast_mode, mod->selected_cells(), show_tempdir, sop_mode, abc_dress, dont_use_cells, custom_flow); continue; } @@ -2278,7 +2319,7 @@ struct AbcPass : public Pass { arst_sig = assign_map(std::get<5>(it.first)); srst_polarity = std::get<6>(it.first); srst_sig = assign_map(std::get<7>(it.first)); - abc_module(design, mod, script_file, exe_file, exe_flags, input_file, output_file, liberty_files, genlib_files, constr_file, cleanup, lut_costs, !clk_sig.empty(), "$", keepff, + abc_module(design, mod, script_file, exe_file, exe_flags, input_file, output_file, helper_files, liberty_files, genlib_files, constr_file, cleanup, lut_costs, !clk_sig.empty(), "$", keepff, delay_target, sop_inputs, sop_products, lutin_shared, fast_mode, it.second, show_tempdir, sop_mode, abc_dress, dont_use_cells, custom_flow); assign_map.set(mod); }