From 5a5e25c4ea7878f7c2bf70bbaaea650018622e18 Mon Sep 17 00:00:00 2001 From: Muthu Annamalai Date: Thu, 25 May 2023 16:05:16 +0000 Subject: [PATCH] [Backend] enable list of files planned in execution which will be deleted if exception thrown --- kernel/register.cc | 40 +++++++++++++++++++++++++++++++--------- kernel/register.h | 1 + 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/kernel/register.cc b/kernel/register.cc index 9ffb17c1a..3263d6559 100644 --- a/kernel/register.cc +++ b/kernel/register.cc @@ -649,16 +649,36 @@ void Backend::execute(std::vector args, RTLIL::Design *design) { std::ostream *f = NULL; auto state = pre_execute(); - execute(f, std::string(), args, design); - post_execute(state); - if (f != &std::cout) - delete f; + bool restore_log_cmd_error_throw = log_cmd_error_throw; + log_cmd_error_throw = true; + try { + execute(f, std::string(), args, design); + post_execute(state); + } catch(log_cmd_error_exception& _) { + if (f && (f != &std::cout)) { + delete f; + f = NULL; + + for(auto& itr : filenames) { + if ( itr == "" ) continue; + int code = std::remove(itr.c_str()); + if ( code ) + log("\t Failed to deleted file %s - with exitcode %d\n",itr.c_str(),code); + } + } + log_cmd_error_throw = restore_log_cmd_error_throw; + if ( log_cmd_error_throw ) + throw log_cmd_error_exception(); + } + + log_cmd_error_throw = restore_log_cmd_error_throw; + if (f && (f != &std::cout)) { + delete f; + } } void Backend::extra_args(std::ostream *&f, std::string &filename, std::vector args, size_t argidx, bool bin_output) { - bool called_with_fp = f != NULL; - for (; argidx < args.size(); argidx++) { std::string arg = args[argidx]; @@ -668,8 +688,9 @@ void Backend::extra_args(std::ostream *&f, std::string &filename, std::vector filenames; Backend(std::string name, std::string short_help = "** document me **"); void run_register() override; ~Backend() override;