77#include < sys/stat.h>
88#include < sys/wait.h>
99#include < filesystem>
10+ #include < fstream>
1011#include < iostream>
1112#include " OneTimeRewritersFwd.hpp"
1213#include " SetRemovers.hpp"
@@ -222,6 +223,31 @@ bool lineRemover(std::shared_ptr<SyntaxTree>& tree,
222223 return committed;
223224}
224225
226+ bool fileTruncator (std::shared_ptr<SyntaxTree>& tree,
227+ const std::string& stageName,
228+ const std::string& passIdx,
229+ SvBugpoint* svBugpoint) {
230+ if (std::filesystem::is_empty (svBugpoint->getMinimizedFile ())) {
231+ return false ;
232+ }
233+
234+ std::ofstream tmpFile (svBugpoint->getTmpFile (), std::ios::trunc);
235+ if (!tmpFile.is_open ()) {
236+ PRINTF_ERR (" failed to truncate '%s'\n " , svBugpoint->getTmpFile ().c_str ());
237+ exit (1 );
238+ }
239+ tmpFile.close ();
240+
241+ auto stats = AttemptStats (passIdx, stageName, svBugpoint);
242+ stats.typeInfo = " -" ;
243+ if (svBugpoint->test (stats)) {
244+ tree = svBugpoint->treeLoader .load (svBugpoint->getMinimizedFile ());
245+ return true ;
246+ }
247+
248+ return false ;
249+ }
250+
225251bool SvBugpoint::pass (const std::string& passIdx) {
226252 bool commited = false ;
227253
@@ -230,6 +256,7 @@ bool SvBugpoint::pass(const std::string& passIdx) {
230256
231257 auto tree = treeLoader.load (getMinimizedFile ());
232258
259+ commited |= fileTruncator (tree, " fileTruncator" , passIdx, this );
233260 commited |= rewriteLoop<BodyRemover>(tree, " bodyRemover" , passIdx, this );
234261 commited |= rewriteLoop<InstantationRemover>(tree, " instantiationRemover" , passIdx, this );
235262 commited |= rewriteLoop<BindRemover>(tree, " bindRemover" , passIdx, this );
0 commit comments