TV llvm lit: save reports to disk instead of printing to stderr to allow further processing
MODIFY
scripts/opt-alive.sh
scripts/opt-alive.sh
#!/bin/bash
-timeout 1000 $HOME/llvm/build/bin/opt -load=$HOME/alive2/build/tv/tv.so -tv-exit-on-error -tv $@ -tv -tv-smt-to=10000
+timeout 1000 $HOME/llvm/build/bin/opt -load=$HOME/alive2/build/tv/tv.so -tv-exit-on-error -tv $@ -tv -tv-smt-to=10000 -tv-report-dir=$HOME/alive2/build/logs -tv-smt-stats

MODIFY
tv/tv.cpp
tv/tv.cpp
#include "llvm/Support/raw_ostream.h"
#include <fstream>
#include <iostream>
+#include <random>
#include <unordered_map>
#include <utility>
@@ -139,18 +140,27 @@ struct TVPass : public llvm::FunctionPass {
done = true;
if (!opt_report_dir.empty()) {
- // TODO: make dir if it doesn't exist
+ static default_random_engine re;
+ static uniform_int_distribution<unsigned> rand;
+ static bool seeded = false;
+
+ if (!seeded) {
+ random_device rd;
+ re.seed(rd());
+ seeded = true;
+ }
+
+ fs::create_directories(opt_report_dir.getValue());
auto &source_file = module.getSourceFileName();
fs::path fname = source_file.empty() ? "alive.txt" : source_file;
fname.replace_extension(".txt");
fs::path path = fs::path(opt_report_dir.getValue()) / fname.filename();
- unsigned n = 0;
- while (fs::exists(path)) {
+ do {
auto newname = fname.stem();
- newname += "_" + to_string(++n) + ".txt";
+ newname += "_" + to_string(rand(re)) + ".txt";
path.replace_filename(newname);
- }
+ } while (fs::exists(path));
out_file = ofstream(path);
out = &out_file;

TV llvm lit: save reports to disk instead of printing to stderr to allow further processing