aboutsummaryrefslogtreecommitdiffstats
path: root/passes/sat/mutate.cc
diff options
context:
space:
mode:
Diffstat (limited to 'passes/sat/mutate.cc')
-rw-r--r--passes/sat/mutate.cc57
1 files changed, 54 insertions, 3 deletions
diff --git a/passes/sat/mutate.cc b/passes/sat/mutate.cc
index 9621d2855..c50678c51 100644
--- a/passes/sat/mutate.cc
+++ b/passes/sat/mutate.cc
@@ -46,6 +46,8 @@ struct mutate_opts_t {
IdString ctrl_name;
int ctrl_width = -1, ctrl_value = -1;
+ bool none = false;
+
int pick_cover_prcnt = 80;
int weight_cover = 500;
@@ -422,8 +424,9 @@ void database_reduce(std::vector<mutate_t> &database, const mutate_opts_t &opts,
log("Covered %d/%d wire bits (%.2f%%).\n", covered_wirebit_cnt, GetSize(coverdb.wirebit_db), 100.0 * covered_wirebit_cnt / GetSize(coverdb.wirebit_db));
}
-void mutate_list(Design *design, const mutate_opts_t &opts, const string &filename, int N)
+void mutate_list(Design *design, const mutate_opts_t &opts, const string &filename, const string &srcsfile, int N)
{
+ pool<string> sources;
std::vector<mutate_t> database;
xs128_t rng(opts.seed);
@@ -497,6 +500,9 @@ void mutate_list(Design *design, const mutate_opts_t &opts, const string &filena
entry.wirebit = bit.offset;
}
+ if (!srcsfile.empty())
+ sources.insert(entry.src.begin(), entry.src.end());
+
entry.mode = "inv";
database_add(database, opts, entry);
@@ -522,10 +528,20 @@ void mutate_list(Design *design, const mutate_opts_t &opts, const string &filena
log("Raw database size: %d\n", GetSize(database));
if (N != 0) {
- database_reduce(database, opts, N, rng);
+ database_reduce(database, opts, opts.none ? N-1 : N, rng);
log("Reduced database size: %d\n", GetSize(database));
}
+ if (!srcsfile.empty()) {
+ std::ofstream sout;
+ sout.open(srcsfile, std::ios::out | std::ios::trunc);
+ if (!sout.is_open())
+ log_error("Could not open file \"%s\" with write access.\n", srcsfile.c_str());
+ sources.sort();
+ for (auto &s : sources)
+ sout << s << std::endl;
+ }
+
std::ofstream fout;
if (!filename.empty()) {
@@ -536,6 +552,17 @@ void mutate_list(Design *design, const mutate_opts_t &opts, const string &filena
int ctrl_value = opts.ctrl_value;
+ if (opts.none) {
+ string str = "mutate";
+ if (!opts.ctrl_name.empty())
+ str += stringf(" -ctrl %s %d %d", log_id(opts.ctrl_name), opts.ctrl_width, ctrl_value++);
+ str += " -mode none";
+ if (filename.empty())
+ log("%s\n", str.c_str());
+ else
+ fout << str << std::endl;
+ }
+
for (auto &entry : database) {
string str = "mutate";
if (!opts.ctrl_name.empty())
@@ -710,9 +737,15 @@ struct MutatePass : public Pass {
log(" -o filename\n");
log(" Write list to this file instead of console output\n");
log("\n");
+ log(" -s filename\n");
+ log(" Write a list of all src tags found in the design to the specified file\n");
+ log("\n");
log(" -seed N\n");
log(" RNG seed for selecting mutations\n");
log("\n");
+ log(" -none\n");
+ log(" Include a \"none\" mutation in the output\n");
+ log("\n");
log(" -ctrl name width value\n");
log(" Add -ctrl options to the output. Use 'value' for first mutation, then\n");
log(" simply count up from there.\n");
@@ -761,6 +794,7 @@ struct MutatePass : public Pass {
{
mutate_opts_t opts;
string filename;
+ string srcsfile;
int N = -1;
log_header(design, "Executing MUTATE pass.\n");
@@ -776,10 +810,18 @@ struct MutatePass : public Pass {
filename = args[++argidx];
continue;
}
+ if (args[argidx] == "-s" && argidx+1 < args.size()) {
+ srcsfile = args[++argidx];
+ continue;
+ }
if (args[argidx] == "-seed" && argidx+1 < args.size()) {
opts.seed = atoi(args[++argidx].c_str());
continue;
}
+ if (args[argidx] == "-none") {
+ opts.none = true;
+ continue;
+ }
if (args[argidx] == "-mode" && argidx+1 < args.size()) {
opts.mode = args[++argidx];
continue;
@@ -879,7 +921,16 @@ struct MutatePass : public Pass {
extra_args(args, argidx, design);
if (N >= 0) {
- mutate_list(design, opts, filename, N);
+ mutate_list(design, opts, filename, srcsfile, N);
+ return;
+ }
+
+ if (opts.mode == "none") {
+ if (!opts.ctrl_name.empty()) {
+ Module *topmod = opts.module.empty() ? design->top_module() : design->module(opts.module);
+ if (topmod)
+ mutate_ctrl_sig(topmod, opts.ctrl_name, opts.ctrl_width);
+ }
return;
}