int main (int argc, char **argv) { const char *file_name, *error; aiger *aiger; int i, res; file_name = 0; res = 0; for (i = 1; i < argc; i++) { if (!strcmp (argv[i], "-h")) { fprintf (stderr, "usage: aignm [-h][input]\n"); return 0; } else if (file_name) { fprintf (stderr, "*** [aignm] multiple files\n"); return 1; } else file_name = argv[i]; } aiger = aiger_init (); if (file_name) error = aiger_open_and_read_from_file (aiger, file_name); else error = aiger_read_from_file (aiger, stdin); if (error) { fprintf (stderr, "*** [aignm] %s\n", error); res = 1; } else res = (aiger_write_symbols_to_file (aiger, stdout) == EOF); aiger_reset (aiger); return res; }
bool Synth::run() { init_cudd(cudd); aiger_spec = aiger_init(); const char *err = aiger_open_and_read_from_file(aiger_spec, aiger_file_name.c_str()); MASSERT(err == NULL, err); Cleaner cleaner(aiger_spec); // main part L_INF("synthesize.. number of vars = " << aiger_spec->num_inputs + aiger_spec->num_latches); // grapher = new Grapher(); timer.sec_restart(); // grapher->compute_deps(aiger_spec); L_INF("calculating deps graph took (sec): " << timer.sec_restart()); //grapher.dump_dot(); //print_set(grapher.deps[STRIP_LIT(aiger_spec->outputs[0].lit)], aiger_spec); // Create all variables. _tmp ensures that BDD have positive refs. vector<BDD> _tmp; for (uint i = 0; i < aiger_spec->num_inputs + aiger_spec->num_latches; ++i) _tmp.push_back(cudd.bddVar(i)); for (uint i = 0; i < aiger_spec->num_inputs; ++i) { auto aiger_strip_lit = aiger_spec->inputs[i].lit; cudd_by_aiger[aiger_strip_lit] = i; aiger_by_cudd[i] = aiger_strip_lit; } for (uint i = 0; i < aiger_spec->num_latches; ++i) { auto aiger_strip_lit = aiger_spec->latches[i].lit; auto cudd_idx = i + aiger_spec->num_inputs; cudd_by_aiger[aiger_strip_lit] = cudd_idx; aiger_by_cudd[cudd_idx] = aiger_strip_lit; } // vector<int> permutation = compute_permutation(grapher, cudd, aiger_spec); // MASSERT(permutation.size() == (uint) cudd.ReadSize(), ""); /* L_INF("frequencies of latches"); for (uint i = 0; i < aiger_spec->num_latches; ++i) { auto lit = aiger_spec->latches[i].lit; cout << "latch lit " << lit << " : " << grapher.freq_map[lit] << endl; } L_INF("frequencies of inputs"); for (uint i = 0; i < aiger_spec->num_inputs; ++i) { auto lit = aiger_spec->inputs[i].lit; cout << "input lit " << lit << " : " << grapher.freq_map[lit] << endl; } */ /* vector<BDD> nodes; nodes.push_back(error); vector<string> names; vector<const char*> names_; names.push_back(string("weird0")); names_.push_back(names[0].data()); for (uint i = 1; i < aiger_spec->num_latches + aiger_spec->num_inputs+1; ++i) { names.push_back(to_string(i)); if (aiger_is_input(aiger_spec, i*2)) { auto s = aiger_is_input(aiger_spec, i*2); if (s->name) names.push_back(string(s->name)); else names.push_back(to_string(i*2)); } if (aiger_is_latch(aiger_spec, i*2)) { auto s = aiger_is_latch(aiger_spec, i*2); if (s->name) names.push_back(string(s->name)); else names.push_back(to_string(i*2)); } names_.push_back(names[i].data()); } cudd.DumpDot(nodes, names_.data(), NULL); cout << cudd.OrderString() << endl; exit(0); */ compose_init_state_bdd(); timer.sec_restart(); compose_transition_vector(); L_INF("calc_trans_rel took (sec): " << timer.sec_restart()); introduce_error_bdd(); L_INF("introduce_error_bdd took (sec): " << timer.sec_restart()); // cout << "before comput: nof_vars = " << cudd.ReadSize() << endl; // reachable = compute_reachable(aiger_spec, init, transition_func, error, cudd); // cout << "after comput: nof_vars = " << cudd.ReadSize() << endl; // no need for cache bdd_by_aiger_unlit.clear(); // reorder_opt(cudd); // print_aiger_like_order(cudd); timer.sec_restart(); win_region = calc_win_region(); L_INF("calc_win_region took (sec): " << timer.sec_restart()); // print_aiger_like_order(cudd); // Cudd_MakeTreeNode(cudd.getManager(), 5, 8, MTR_FIXED); // reorder_opt(cudd); // cout << "optimal order after calc_win_region" << endl; // print_aiger_like_order(cudd); // cout << cudd.ReadNodeCount() << endl; if (win_region.IsZero()) { cout << "UNREALIZABLE" << endl; return 0; } cout << "REALIZABLE" << endl; non_det_strategy = get_nondet_strategy(); //cleaning non-used bdds win_region = cudd.bddZero(); transition_func.clear(); init = cudd.bddZero(); error = cudd.bddZero(); // // TODO: set time limit on reordering? or even disable it if no time? hmap<uint, BDD> model_by_cuddidx = extract_output_funcs(); L_INF("extract_output_funcs took (sec): " << timer.sec_restart()); //cleaning non-used bdds non_det_strategy = cudd.bddZero(); // auto elapsed_sec = time_limit_sec - timer.sec_from_origin(); if (elapsed_sec > 100) { // leave 100sec just in case auto spare_time_sec = elapsed_sec - 100; cudd.ResetStartTime(); cudd.IncreaseTimeLimit((unsigned long) (spare_time_sec * 1000)); cudd.ReduceHeap(CUDD_REORDER_SIFT_CONVERGE); cudd.UnsetTimeLimit(); cudd.AutodynDisable(); // just in case -- cudd hangs on timeout } for (auto const it : model_by_cuddidx) model_to_aiger(cudd.ReadVars((int)it.first), it.second); L_INF("model_to_aiger took (sec): " << timer.sec_restart()); L_INF("circuit size: " << (aiger_spec->num_ands + aiger_spec->num_latches)); int res = 1; if (output_file_name == "stdout") res = aiger_write_to_file(aiger_spec, aiger_ascii_mode, stdout); else if (!output_file_name.empty()) { L_INF("writing a model to " << output_file_name); res = aiger_open_and_write_to_file(aiger_spec, output_file_name.c_str()); } MASSERT(res, "Could not write result file"); return 1; }
Aiger () : aig (aiger_init()) {}
int main (int argc, char ** argv) { const char * input, * output, * err; aiger_and * a; unsigned j; int i, ok; input = output = 0; for (i = 1; i < argc; i++) { if (!strcmp (argv[i], "-h")) { printf ("%s", USAGE); exit (0); } else if (!strcmp (argv[i], "-v")) verbose = 1; else if (!strcmp (argv[i], "-i")) ignore = 1; else if (!strcmp (argv[i], "-r")) reverse = 1; else if (argv[i][0] == '-') die ("invalid command line option '%s'", argv[i]); else if (output) die ("too many arguments"); else if (input) output = argv[i]; else input = argv[i]; } src = aiger_init (); if (input) { msg ("reading '%s'", input); err = aiger_open_and_read_from_file (src, input); } else { msg ("reading '<stdin>'"); err = aiger_read_from_file (src, stdin); } if (err) die ("read error: %s", err); msg ("read MILOA %u %u %u %u %u BCJF %u %u %u %u", src->maxvar, src->num_inputs, src->num_latches, src->num_outputs, src->num_ands, src->num_bad, src->num_constraints, src->num_justice, src->num_fairness); if (!ignore && src->num_justice) die ("will not ignore justice properties (use '-i')"); if (!ignore && src->num_fairness) die ("will not ignore fairness properties (use '-i')"); if (!reverse && src->num_outputs && !src->num_bad && !src->num_constraints && !src->num_justice && !src->num_fairness) die ("only outputs founds (use '-r' for reverse move)"); dst = aiger_init (); for (j = 0; j < src->num_inputs; j++) aiger_add_input (dst, src->inputs[j].lit, src->inputs[j].name); for (j = 0; j < src->num_latches; j++) { aiger_add_latch (dst, src->latches[j].lit, src->latches[j].next, src->latches[j].name); aiger_add_reset (dst, src->latches[j].lit, src->latches[j].reset); } for (j = 0; j < src->num_ands; j++) { a = src->ands + j; aiger_add_and (dst, a->lhs, a->rhs0, a->rhs1); } if (reverse) { for (j = 0; j < src->num_outputs; j++) aiger_add_bad (dst, src->outputs[j].lit, src->outputs[j].name); } else { for (j = 0; j < src->num_outputs; j++) aiger_add_output (dst, src->outputs[j].lit, src->outputs[j].name); if (src->num_bad && src->num_constraints) { if (src->num_latches) { latch = next (); valid = latch + 2*src->num_constraints; aiger_add_latch (dst, latch, aiger_not (valid), "AIGMOVE_INVALID_LATCH"); prev = aiger_not (latch); for (j = 0; j < src->num_constraints; j++) { unsigned tmp = latch + 2*(j+1); aiger_add_and (dst, tmp, prev, src->constraints[j].lit); prev = tmp; } assert (prev == valid); } else { valid = src->constraints[0].lit; for (j = 1; j < src->num_constraints; j++) { unsigned tmp = next (); aiger_add_and (dst, tmp, valid, src->constraints[j].lit); valid = tmp; } } for (j = 0; j < src->num_bad; j++) { bad = next (); aiger_add_and (dst, bad, valid, src->bad[j].lit); aiger_add_output (dst, bad, src->bad[j].name); } } else for (j = 0; j < src->num_bad; j++) aiger_add_output (dst, src->bad[j].lit, src->bad[j].name); } aiger_reset (src); msg ("write MILOA %u %u %u %u %u", dst->maxvar, dst->num_inputs, dst->num_latches, dst->num_outputs, dst->num_ands); if (output) { msg ("writing '%s'", output); ok = aiger_open_and_write_to_file (dst, output); } else { msg ("writing '<stdout>'", output); ok = aiger_write_to_file (dst, (isatty (1) ? aiger_ascii_mode : aiger_binary_mode), stdout); } if (!ok) die ("write error"); aiger_reset (dst); return 0; }
int main (int argc, char **argv) { const char *name, *error; char *renamed; aiger *aiger; int i, res; name = 0; for (i = 1; i < argc; i++) { if (!strcmp (argv[i], "-h")) { fprintf (stderr, "usage: aigstrip [-h][<file>]\n"); return 0; } else if (argv[i][0] == '-') { fprintf (stderr, "*** [aigstrip] invalid option '%s'\n", argv[i]); return 1; } else if (name) { fprintf (stderr, "*** [aigstrip] multiple files\n"); return 1; } else name = argv[i]; } res = 0; aiger = aiger_init (); if (!name) { if((error = aiger_read_from_file (aiger, stdin))) goto PARSE_ERROR; (void) aiger_strip_symbols_and_comments (aiger); if (!aiger_write_to_file (aiger, (isatty (1) ? aiger_ascii_mode : aiger_binary_mode), stdout)) { fprintf (stderr, "*** [aigstrip] write error\n"); res = 1; } } else if ((error = aiger_open_and_read_from_file (aiger, name))) { PARSE_ERROR: fprintf (stderr, "*** [aigstrip] read error: %s\n", error); res = 1; } else { (void) aiger_strip_symbols_and_comments (aiger); renamed = malloc (strlen (name) + 2); sprintf (renamed, "%s~", name); if (rename (name, renamed)) { fprintf (stderr, "*** [aigstrip] failed to rename '%s'\n", name); res = 1; } else if (aiger_open_and_write_to_file (aiger, name)) { if (unlink (renamed)) { fprintf (stderr, "*** [aigstrip] failed to remove '%s'\n", renamed); res = 0; /* !!! */ } } else { fprintf (stderr, "*** [aigstrip] failed to write '%s'\n", name); res = 1; if (rename (renamed, name)) fprintf (stderr, "*** [aigstrip] backup in '%s'\n", renamed); else fprintf (stderr, "*** [aigstrip] original file restored\n"); } free (renamed); } aiger_reset (aiger); return res; }
int main (int argc, char **argv) { const char *src, *dst, *p, *err; aiger_mode mode; simpaig *res; int i, ascii; src = dst = 0; ascii = 0; for (i = 1; i < argc; i++) { for (p = argv[i]; isdigit (*p); p++) ; if (!*p) k = atoi (argv[i]); else if (!strcmp (argv[i], "-h")) { fprintf (stderr, USAGE); exit (0); } else if (!strcmp (argv[i], "-a")) ascii = 1; else if (!strcmp (argv[i], "-s")) strip = 1; else if (!strcmp (argv[i], "-v")) verbose++; else if (argv[i][0] == '-') die ("invalid command line option '%s'", argv[i]); else if (!src) src = argv[i]; else if (!dst) dst = argv[i]; else die ("too many files"); } if (ascii && dst) die ("'dst' file and '-a' specified"); if (!ascii && !dst && isatty (1)) ascii = 1; if (src && dst && !strcmp (src, dst)) die ("identical 'src' and 'dst' file"); model = aiger_init (); if (src) err = aiger_open_and_read_from_file (model, src); else err = aiger_read_from_file (model, stdin); if (!src) src = "<stdin>"; if (err) die ("%s: %s", src, err); if (!model->num_outputs) die ("%s: no output"); if (model->num_outputs > 1) die ("%s: more than one output"); aiger_reencode (model); mgr = simpaig_init (); res = build (); expansion = aiger_init (); expand (res); simpaig_dec (mgr, res); for (i = 0; i <= model->maxvar; i++) simpaig_dec (mgr, lois[i].aig); assert (!simpaig_current_nodes (mgr)); simpaig_reset (mgr); aiger_reset (model); free (lois); if (dst) { if (!aiger_open_and_write_to_file (expansion, dst)) { unlink (dst); WRITE_ERROR: die ("%s: write error", dst); } } else { mode = ascii ? aiger_ascii_mode : aiger_binary_mode; if (!aiger_write_to_file (expansion, mode, stdout)) goto WRITE_ERROR; } aiger_reset (expansion); return 0; }