std::pair<exprt,exprt> ranking_synthesis_qbf_bitwiset::duplicate( const std::pair<exprt,exprt> pp, unsigned bits) { if(bits<=1) return pp; std::pair<exprt,exprt> res; res.first.id(ID_concatenation); res.first.type() = unsignedbv_typet(bits); res.second.id(ID_concatenation); res.second.type() = unsignedbv_typet(bits); std::vector<replace_mapt> replace_maps(bits); for(coefficient_mapt::const_iterator it=coefficient_map.begin(); it!=coefficient_map.end(); it++) { const exprt *sym=&it->second; while(sym->id()==ID_typecast) sym=&sym->op0(); assert(sym->id()==ID_symbol); exprt nsym(*sym); std::string original_id=sym->get_string(ID_identifier); for(unsigned i=1; i<bits; i++) { nsym.set(ID_identifier, original_id + "@" + i2string(i)); replace_maps[i][*sym] = nsym; } } for(int i=bits-1; i>0; i--) { exprt pre=pp.first; exprt post=pp.second; replace_expr(replace_maps[i], pre); replace_expr(replace_maps[i], post); res.first.move_to_operands(pre); res.second.move_to_operands(post); } res.first.copy_to_operands(pp.first); // 0-bit is not renamed! res.second.copy_to_operands(pp.second); return res; }
bool ranking_synthesis_qbf_bitwiset::extract_ranking_relation(boolbvt &converter) { replace_mapt replace_map; for(coefficient_mapt::const_iterator it=coefficient_map.begin(); it!=coefficient_map.end(); it++) { const exprt *sym=&it->second; while(sym->id()==ID_typecast) sym=&sym->op0(); if(bitwise_width<=1) { exprt value; value=converter.get(*sym); // this returns a constant. replace_map[*sym] = value; std::cout << from_expr(ns, "", it->second) << " = " << from_expr(ns, "", value) << std::endl; } else { assert(sym->id()==ID_symbol); exprt nsym(*sym); std::string original_id=sym->get_string(ID_identifier); for(unsigned i=0; i<bitwise_width; i++) { if(i!=0) nsym.set(ID_identifier, original_id + "@" + i2string(i)); exprt value = converter.get(nsym); replace_map[nsym] = value; // bit i std::cout << from_expr(ns, "", nsym) << " = " << from_expr(ns, "", value) << std::endl; } } } if(const_coefficient.id()!=ID_nil) { exprt value=converter.get(const_coefficient); std::cout << from_expr(ns, "", const_coefficient) << " = " << from_expr(ns, "", value) << std::endl; replace_map[const_coefficient]=value; } replace_expr(replace_map, rank_relation); simplify(rank_relation, ns); return false; }
int ri_inter (void) { /* This is the shortest version of the interpreter, containing only those RASL operators which * are produced by the REFAL compiler. */ /* July, 27, 1985. D.T. */ /* Some macros have been expanded because the PC compiler can't handle too many macros. (its stack overflows.) * DT July 1 1986. */ /* Some other macros have been replaced by functions to reduce the size of object module. March 7 1987. DT. */ register short n; int error; char c, ins = 0; long mdig, bifnum; char *arg; /* short m;*/ error = 0; restart: while (error == 0) { ins = *p; # if MDEBUG if (dump_toggle) printf ("%lx: %d\n", p, ins); # endif switch (ins) { case ACT1: ASGN_CHARP (++p, arg); p += sizeof (char *); act1 (arg); curk ++; break; case BL: p++; bl; break; case BLR: p++; ri_blr (); break; case BR: p++; br; break; case CL: p++; cl; break; case SYM: c = (unsigned char) * ++p; p++; sym (c); break; case SYMR: c = (unsigned char) * ++p; p++; symr (c); break; case EMP: p++; emp; break; case EST: curk --; est; p = break0; break; case MULE: /* n = * ++p; ++p; mule ((int) n); */ ASGN_LONG (++p, mdig); p += sizeof (long); mule (mdig); break; case MULS: /*n = * ++p; muls (n); p++; break;*/ ASGN_LONG (++p, mdig); p += sizeof (long); muls (mdig); break; case PLEN: p++; plen; p++; break; case PLENS: p++; plens; break; case PLENP: p++; plenp; break; case PS: ++p; ps; break; case PSR: ++p; psr; break; case OEXP: n = (unsigned char) * ++p; ++p; oexp (n); break; case OEXPR: n = (unsigned char) * ++p; ++p; oexpr (n); break; case OVSYM: n = (unsigned char) * ++p; ovsym (n); ++p; break; case OVSYMR: n = (unsigned char) * ++p; ovsymr (n); p++; break; case TERM: p++; term; break; case TERMR: p++; termr; break; case RDY: n = (unsigned char) * ++p; ++p; rdy (n); break; case SETB: /* n = (unsigned char) * ++p; m = (unsigned char) * ++p; ++p; setb (n,m); break; */ { long l_n, l_m; ASGN_LONG (++p, l_n); p += sizeof (long); ASGN_LONG (p, l_m); p += sizeof (long); setb (l_n, l_m); } break; case LEN: p++; len; break; case LENS: c = (unsigned char) *++p; p++; lens (c); break; case LENP: ++p; lenp; break; case SYMS: n = (unsigned char) * ++p; p++; syms (n); break; case SYMSR: n = (unsigned char) * ++p; p++; symsr (n) break; case TEXT: n = (unsigned char) * ++p; p++; text (n); break; case NS: c = (unsigned char) * ++p; ++p; ns (c); break; case TPLE: /* n = * ++p; p++; tple (n); break; */ ASGN_LONG (++p, mdig); p += sizeof (long); tple (mdig); break; case TPLS: /* n = * ++p; p++; tpls (n); break; */ ASGN_LONG (++p, mdig); p += sizeof (long); tpls (mdig); break; case TRAN: ASGN_CHARP (++p, arg); p += sizeof (char *); tran (arg); break; case VSYM: p++; vsym; break; case VSYMR: ++p; vsymr; break; case OUTEST: curk --; out (2); est; p = break0; break; case ECOND: if (tel - te + nel + 100 >= size_table_element) { if (fp_debugInfo != NULL) ri_print_error_code(fp_debugInfo,13); ri_error (13); } ASGN_CHARP (++p, arg); b = st[sp].b1; b = st[sp].b1; act1 (arg); tel += (teoff = nel); est; p = break0; break; case POPVF: ++p; tel -= teoff; nel = teoff + 3; sp = stoff-1; teoff = st[sp].nel; stoff = (long) st[sp].b2; break; case PUSHVF: if (sp + 20 >= size_local_stack) { if (fp_debugInfo != NULL) ri_print_error_code(fp_debugInfo,14); ri_error (14); } ++p; b = tbel (2) -> prec; blr; pushst (b->prec,b,NULL,NULL); sp++; pushst (b,stoff,teoff, IMP_); b = b -> prec; stoff = sp + 1; break; case STLEN: ++p; sp = stoff; break; case CSYM: ASGN_CHARP (++p, arg); p += sizeof (char *); csym (arg); break; case CSYMR: ASGN_CHARP (++p, arg); p += sizeof (char *); csymr (arg); break; case NSYM: ASGN_LONG (++p, mdig); p += sizeof (long); nsym (mdig); break; case NSYMR: ASGN_LONG (++p, mdig); p += sizeof (long); nsymr (mdig); break; case NCS: ASGN_CHARP (++p, arg); p += sizeof (char *); ncs (arg); break; case NNS: ASGN_LONG (++p, mdig); p += sizeof (long); nns (mdig); break; /* builtin functions: R.N. - 20 Jul 85 */ case BUILT_IN: /* a call to a built in function no arguments. */ curk --; ASGN_LONG (p+1, bifnum); error = ri_bif (bifnum,NULL); p = break0; break; /* builtin functions with one argument: D.T. - July 27, 1985. */ case BUILT_IN1: /* a call to a function with one argument. */ /* Arguments are stored before function address. */ curk --; ASGN_CHARP(++p, arg); ASGN_LONG (p + (sizeof (char *)), bifnum); error = ri_bif (bifnum, arg); p = break0; break; default: ri_default (ins, &error); break; } } if (error != 0) { fprintf (stderr,"RASL instruction: %4d at address: %lx\n", *p, (unsigned long) p); if (fp_debugInfo != NULL) fprintf (fp_debugInfo,"RASL instruction: %4d at address: %lx\n", *p, (unsigned long) p); ri_error(4); } return 0; }
void ranking_synthesis_qbf_bitwiset::quantify_variables( boolbvt &converter, qdimacs_coret &solver) { // first quantify all coefficients; those have to be constants for(coefficient_mapt::const_iterator it=coefficient_map.begin(); it!=coefficient_map.end(); it++) { const exprt &c = it->second; const exprt *sym=&c; while(sym->id()==ID_typecast) sym=&sym->op0(); exprt nsym(*sym); std::string original_id=sym->get_string(ID_identifier); //base_type(nsym, ns); for(unsigned i=0; i<bitwise_width; i++) { if(i!=0) nsym.set(ID_identifier, original_id + "@" + i2string(i)); quantify_variable(converter, solver, nsym, false); } } for(bodyt::variable_mapt::const_iterator it=body.variable_map.begin(); it!=body.variable_map.end(); it++) { if(used_variables.find(it->first)==used_variables.end()) continue; exprt presym=symbol_exprt(it->second, ns.lookup(it->second).type); //base_type(presym, ns); #if 0 std::cout << "Quantifying " << from_expr(pre) << " (" << from_expr(post) << ")" << std::endl; #endif quantify_variable(converter, solver, presym, true); // x } for(intermediate_statet::const_iterator it=intermediate_state.begin(); it!=intermediate_state.end(); it++) { if(used_variables.find(*it)==used_variables.end()) continue; irep_idt ident=(id2string(*it).substr(0, id2string(*it).rfind('@'))); ident=(id2string(ident).substr(0, id2string(ident).rfind('#'))); exprt symbol=symbol_exprt(ident, ns.lookup(ident).type); //base_type(symbol, ns); quantify_variable(converter, solver, symbol, true); } for(bodyt::variable_mapt::const_iterator it=body.variable_map.begin(); it!=body.variable_map.end(); it++) { if(used_variables.find(it->first)==used_variables.end()) continue; exprt postsym=symbol_exprt(it->first, ns.lookup(it->first).type); //base_type(postsym, ns); // we assume that x' is determined by R(x,x') quantify_variable(converter, solver, postsym, true); // x' } }