Skip to content

Commit 93dcc78

Browse files
committed
[#92342] Add fileTruncator pass
Signed-off-by: Artur Bieniek <abieniek@internships.antmicro.com>
1 parent 06d24cd commit 93dcc78

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

source/SvBugpoint.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
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+
225251
bool 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);

tests/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@ test_dont_abort_after_err:
88
test: test_short test_caliptra test_comment_dir test_tricky_missing_newline test_irremovable_verilator_config test_comment_dir2
99

1010
.PHONY: test_short
11-
test_short: test_short_exit0 test_short_exit1 test_short_grep test_short_verilator_errmsg test_short_multi_file_verilator_errmsg test_short_multi_file_flag_y_verilator_errmsg test_short_multi_file_flag_f_verilator_errmsg
11+
test_short: test_short_exit0 test_truncator test_short_exit1 test_short_grep test_short_verilator_errmsg test_short_multi_file_verilator_errmsg test_short_multi_file_flag_y_verilator_errmsg test_short_multi_file_flag_f_verilator_errmsg
1212

1313
.PHONY: test_short_exit0
1414
test_short_exit0:
1515
@./run_test short_exit0 checkexit0.sh ${INPUT_DIR}/short_in.sv
1616

17+
.PHONY: test_truncator
18+
test_truncator:
19+
@./run_test truncator checkexit0.sh ${INPUT_DIR}/short_in.sv
20+
@awk -F'\t' '$$2=="fileTruncator" && $$4=="1"{found=1} END{if(!found){print "FAILED: fileTruncator pass not committed" > "/dev/stderr"; exit(1)}}' out/truncator/debug/trace
21+
1722
.PHONY: test_short_verilator_errmsg
1823
test_short_verilator_errmsg:
1924
@verilator --version >/dev/null || (printf "FAILED: verilator not found\n"; exit 1)

tests/golden/truncator/sv-bugpoint-combined.sv

Whitespace-only changes.

0 commit comments

Comments
 (0)