Skip to content

Commit 4fd8b38

Browse files
committed
Add -no-startoffset option to write_aiger
1 parent afe258e commit 4fd8b38

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

backends/aiger/aiger.cc

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ struct AigerWriter
606606
f << stringf("c\nGenerated by %s\n", yosys_version_str);
607607
}
608608

609-
void write_map(std::ostream &f, bool verbose_map)
609+
void write_map(std::ostream &f, bool verbose_map, bool no_startoffset)
610610
{
611611
dict<int, string> input_lines;
612612
dict<int, string> init_lines;
@@ -627,32 +627,33 @@ struct AigerWriter
627627
continue;
628628

629629
int a = aig_map.at(sig[i]);
630+
int index = no_startoffset ? i : (wire->start_offset+i);
630631

631632
if (verbose_map)
632-
wire_lines[a] += stringf("wire %d %d %s\n", a, wire->start_offset+i, log_id(wire));
633+
wire_lines[a] += stringf("wire %d %d %s\n", a, index, log_id(wire));
633634

634635
if (wire->port_input) {
635636
log_assert((a & 1) == 0);
636-
input_lines[a] += stringf("input %d %d %s\n", (a >> 1)-1, wire->start_offset+i, log_id(wire));
637+
input_lines[a] += stringf("input %d %d %s\n", (a >> 1)-1, index, log_id(wire));
637638
}
638639

639640
if (wire->port_output) {
640641
int o = ordered_outputs.at(sig[i]);
641-
output_lines[o] += stringf("output %d %d %s\n", o, wire->start_offset+i, log_id(wire));
642+
output_lines[o] += stringf("output %d %d %s\n", o, index, log_id(wire));
642643
}
643644

644645
if (init_inputs.count(sig[i])) {
645646
int a = init_inputs.at(sig[i]);
646647
log_assert((a & 1) == 0);
647-
init_lines[a] += stringf("init %d %d %s\n", (a >> 1)-1, wire->start_offset+i, log_id(wire));
648+
init_lines[a] += stringf("init %d %d %s\n", (a >> 1)-1, index, log_id(wire));
648649
}
649650

650651
if (ordered_latches.count(sig[i])) {
651652
int l = ordered_latches.at(sig[i]);
652653
if (zinit_mode && (aig_latchinit.at(l) == 1))
653-
latch_lines[l] += stringf("invlatch %d %d %s\n", l, wire->start_offset+i, log_id(wire));
654+
latch_lines[l] += stringf("invlatch %d %d %s\n", l, index, log_id(wire));
654655
else
655-
latch_lines[l] += stringf("latch %d %d %s\n", l, wire->start_offset+i, log_id(wire));
656+
latch_lines[l] += stringf("latch %d %d %s\n", l, index, log_id(wire));
656657
}
657658
}
658659
}
@@ -713,6 +714,9 @@ struct AigerBackend : public Backend {
713714
log(" -vmap <filename>\n");
714715
log(" like -map, but more verbose\n");
715716
log("\n");
717+
log(" -no-startoffset\n");
718+
log(" make indexes zero based, enable using map files with smt solvers.\n");
719+
log("\n");
716720
log(" -I, -O, -B, -L\n");
717721
log(" If the design contains no input/output/assert/flip-flop then create one\n");
718722
log(" dummy input/output/bad_state-pin or latch to make the tools reading the\n");
@@ -730,6 +734,7 @@ struct AigerBackend : public Backend {
730734
bool omode = false;
731735
bool bmode = false;
732736
bool lmode = false;
737+
bool no_startoffset = false;
733738
std::string map_filename;
734739

735740
log_header(design, "Executing AIGER backend.\n");
@@ -762,6 +767,10 @@ struct AigerBackend : public Backend {
762767
verbose_map = true;
763768
continue;
764769
}
770+
if (args[argidx] == "-no-startoffset") {
771+
no_startoffset = true;
772+
continue;
773+
}
765774
if (args[argidx] == "-I") {
766775
imode = true;
767776
continue;
@@ -804,7 +813,7 @@ struct AigerBackend : public Backend {
804813
mapf.open(map_filename.c_str(), std::ofstream::trunc);
805814
if (mapf.fail())
806815
log_error("Can't open file `%s' for writing: %s\n", map_filename.c_str(), strerror(errno));
807-
writer.write_map(mapf, verbose_map);
816+
writer.write_map(mapf, verbose_map, no_startoffset);
808817
}
809818
}
810819
} AigerBackend;

0 commit comments

Comments
 (0)