main() { int i, j; my_init(MEMORY_SIZE, PHYSICAL_MEM_LIMIT); /* The MEMORY SIZE is in megabytes */ /* PHYSICAL MEMORY SIZE is in number of system pages */ /* The page size on Sparc 4 and Sparc 5 is 4Kb */ dump_out(); for (i = 0; i < NUM_BUFS; i++) { sbuf[i] = (char *)my_malloc(SMALL_BUF_SIZE); lbuf[i] = (char *)my_malloc(LARGE_BUF_SIZE); printf("The buffer small pointers is %x and large pointer is %x.\n",(unsigned)sbuf[i],(unsigned)lbuf[i] ); dump_out(); } for (i = 0; i < NUM_BUFS; i++) { memset(temp_buffer, 'A'+i, LARGE_BUF_SIZE); my_write(sbuf[i], SMALL_BUF_SIZE, temp_buffer); my_write(lbuf[i], LARGE_BUF_SIZE, temp_buffer); my_read(lbuf[i], LARGE_BUF_SIZE, temp_buffer); } read_start(); my_read(lbuf[NUM_BUFS-1], LARGE_BUF_SIZE, temp_buffer); my_write(lbuf[0], LARGE_BUF_SIZE, temp_buffer); my_read(lbuf[NUM_BUFS - 1], LARGE_BUF_SIZE, temp_buffer); my_write(lbuf[1]+5, 3, temp_buffer); my_read(sbuf[NUM_BUFS-1], SMALL_BUF_SIZE, temp_buffer); my_write(sbuf[0], SMALL_BUF_SIZE, temp_buffer); my_read(sbuf[NUM_BUFS - 1], SMALL_BUF_SIZE, temp_buffer); my_write(sbuf[1]+5, 3, temp_buffer); read_start(); for (i = 0; i < NUM_BUFS; i++) { memset(temp_buffer, 'Z'-i, LARGE_BUF_SIZE); my_write(sbuf[i] + 5, SMALL_BUF_SIZE - 5, temp_buffer); my_read(sbuf[i], SMALL_BUF_SIZE, temp_buffer); my_write(lbuf[i] + 5, LARGE_BUF_SIZE - 5, temp_buffer); } read_start(); for (i = 0; i < NUM_BUFS; i++) { my_free((void *) sbuf[i]); my_free((void *) lbuf[i]); } dump_out(); my_terminate(); }
main() { int i, j; my_init(MEMORY_SIZE, PHYSICAL_MEM_LIMIT); dump_out(); for (i = 0; i < NUM_BUFS; i++) { sbuf[i] = (char *)my_malloc(SMALL_BUF_SIZE); lbuf[i] = (char *)my_malloc(LARGE_BUF_SIZE); printf("The buffer small pointers is %x, and large pointer is %x\n", (unsigned)sbuf[i], (unsigned)lbuf[i]); } dump_out(); for (i = 0; i < NUM_BUFS; i++) { my_free((void *) sbuf[i]); my_free((void *) lbuf[i]); } dump_out(); my_terminate(); }
void THandler::verifyDeductionWithExternalTool( Enode * imp ) { assert( imp->isDeduced( ) ); // First stage: print declarations const char * name = "/tmp/verifydeduction.smt2"; std::ofstream dump_out( name ); core_solver.dumpHeaderToFile( dump_out ); dump_out << "(assert" << endl; dump_out << "(and" << endl; for ( int j = 0 ; j < trail.size( ) ; j ++ ) { Var v = var( trail[ j ] ); if ( v == var_True || v == var_False ) continue; Enode * e = varToEnode( v ); assert( e ); if ( !e->isTAtom( ) ) continue; bool negated = sign( trail[ j ] ); if ( negated ) dump_out << "(not "; e->print( dump_out ); if ( negated ) dump_out << ")"; dump_out << endl; } if ( imp->getDeduced( ) == l_True ) dump_out << "(not " << imp << ")" << endl; else dump_out << imp << endl; dump_out << "))" << endl; dump_out << "(check-sat)" << endl; dump_out << "(exit)" << endl; dump_out.close( ); // Second stage, check the formula const bool tool_res = callCertifyingSolver( name ); if ( tool_res ) opensmt_error2( config.certifying_solver, " says this is not a valid deduction" ); }
void THandler::verifyCallWithExternalTool( bool res, size_t trail_size ) { // First stage: print declarations const char * name = "/tmp/verifycall.smt2"; std::ofstream dump_out( name ); core_solver.dumpHeaderToFile( dump_out ); dump_out << "(assert" << endl; dump_out << "(and" << endl; for ( size_t j = 0 ; j <= trail_size ; j ++ ) { Var v = var( trail[ j ] ); if ( v == var_True || v == var_False ) continue; // Enode * e = var_to_enode[ v ]; Enode * e = varToEnode( v ); assert( e ); if ( !e->isTAtom( ) ) continue; bool negated = sign( trail[ j ] ); if ( negated ) dump_out << "(not "; e->print( dump_out ); if ( negated ) dump_out << ")"; dump_out << endl; } dump_out << "))" << endl; dump_out << "(check-sat)" << endl; dump_out << "(exit)" << endl; dump_out.close( ); // Second stage, check the formula const bool tool_res = callCertifyingSolver( name ); if ( res == false && tool_res == true ) opensmt_error2( config.certifying_solver, " says SAT stack, but we say UNSAT" ); if ( res == true && tool_res == false ) opensmt_error2( config.certifying_solver, " says UNSAT stack, but we say SAT" ); }
void CoreSMTSolver::dumpCNF( ) { const char * name = "cnf.smt2"; std::ofstream dump_out( name ); egraph.dumpHeaderToFile( dump_out ); dump_out << "(assert" << endl; dump_out << "(and" << endl; for ( int i = 0 ; i < clauses.size( ) ; i ++ ) { Clause & c = *clauses[ i ]; if ( c.mark( ) == 1 ) continue; printSMTClause( dump_out, c ); dump_out << endl; } // // Also dump the trail which contains clauses of size 1 // for ( int i = 0 ; i < trail.size( ) ; i ++ ) { Var v = var(trail[i]); if ( v <= 1 ) continue; Enode * e = theory_handler->varToEnode( v ); dump_out << (sign(trail[i])?"(not ":" ") << e << (sign(trail[i])?") ":" ") << endl; } dump_out << "))" << endl; dump_out << "(check-sat)" << endl; dump_out << "(exit)" << endl; dump_out.close( ); cerr << "[Dumped " << name << "]" << endl; }
void THandler::verifyExplanationWithExternalTool( vector< Enode * > & expl ) { // First stage: print declarations const char * name = "/tmp/verifyexp.smt2"; std::ofstream dump_out( name ); core_solver.dumpHeaderToFile( dump_out ); dump_out << "(assert " << endl; dump_out << "(and" << endl; for ( size_t j = 0 ; j < expl.size( ) ; j ++ ) { Enode * e = expl[ j ]; assert( e->isTAtom( ) ); assert( e->getPolarity( ) != l_Undef ); bool negated = e->getPolarity( ) == l_False; if ( negated ) dump_out << "(not "; e->print( dump_out ); if ( negated ) dump_out << ")"; dump_out << endl; } dump_out << "))" << endl; dump_out << "(check-sat)" << endl; dump_out << "(exit)" << endl; dump_out.close( ); // Third stage, check the formula const bool tool_res = callCertifyingSolver( name ); if ( tool_res == true ) opensmt_error2( config.certifying_solver, " says this is not an explanation" ); }
int process(char *fname, int components, int z_lookup, unsigned char *startbuf, unsigned char *endbuf, int z_draw, int x_draw, int y_draw, struct graphics *gc, int mapbits, int metabits, int dump, int gps, struct color_range *colors, int xoff, int yoff) { int bytes = bytesfor(mapbits, metabits, components, z_lookup); int ret = 0; char fn[strlen(fname) + 1 + 5 + 1 + 5 + 1]; struct tilecontext tc; tc.z = z_draw; tc.x = x_draw; tc.y = y_draw; tc.xoff = xoff; tc.yoff = yoff; if (components == 1) { sprintf(fn, "%s/1,0", fname); } else { sprintf(fn, "%s/%d,%d", fname, components, z_lookup); } int fd = open(fn, O_RDONLY); if (fd < 0) { // perror(fn); return ret; } struct stat st; if (fstat(fd, &st) < 0) { perror("stat"); exit(EXIT_FAILURE); } unsigned char *map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0); if (map == MAP_FAILED) { perror("mmap"); exit(EXIT_FAILURE); } gSortBytes = bytes; unsigned char *start = search(startbuf, map, st.st_size / bytes, bytes, bufcmp); unsigned char *end = search(endbuf, map, st.st_size / bytes, bytes, bufcmp); end += bytes; // points to the last value in range; need the one after that if (memcmp(start, startbuf, bytes) < 0) { start += bytes; // if not exact match, points to element before match } int step = 1; double brush = 1; double thick = line_thick; double bright1; if (components == 1) { bright1 = dot_bright; if (z_draw > dot_base) { step = 1; brush = exp(log(2.0) * (z_draw - dot_base)); bright1 *= exp(log(dot_ramp) * (z_draw - dot_base)); } else { step = floor(exp(log(exponent) * (dot_base - z_draw)) + .5); bright1 *= exp(log(dot_ramp) * (z_draw - dot_base)); bright1 = bright1 * step / (1 << (dot_base - z_draw)); } bright1 /= point_size; brush *= point_size; } else { bright1 = dot_bright * line_per_dot / line_thick; if (line_ramp >= 1) { thick *= exp(log(line_ramp) * (z_draw - dot_base)); bright1 *= exp(log(dot_ramp / line_ramp) * (z_draw - dot_base)); } else { bright1 *= exp(log(dot_ramp) * (z_draw - dot_base)); } } if (mercator >= 0) { double lat, lon; tile2latlon((x_draw + .5) * (1LL << (32 - z_draw)), (y_draw + .5) * (1LL << (32 - z_draw)), 32, &lat, &lon); double rat = cos(lat * M_PI / 180); double base = cos(mercator * M_PI / 180); brush /= rat * rat / (base * base); } if (dump) { step = 1; } else { // Align to step size so each zoom is a superset of the previous start = (start - map + (step * bytes - 1)) / (step * bytes) * (step * bytes) + map; } double size = cloudsize(z_draw, x_draw, y_draw); int innerstep = 1; long long todo = 0; size *= tilesize; // convert to pixels if (circle > 0) { // An additional 4 zoom levels without skipping // XXX Why 4? if (step > 1 && size > .0625) { innerstep = step; step = 1; } } const double b = brush * (tilesize / 256.0) * (tilesize / 256.0); for (; start < end; start += step * bytes) { unsigned int x[components], y[components]; double xd[components], yd[components]; int k; unsigned long long meta = 0; buf2xys(start, mapbits, metabits, z_lookup, components, x, y, &meta); if (meta > maxmeta) { continue; } if (!dump && z_draw >= mapbits / 2 - 8) { // Add noise below the bottom of the file resolution // so that it looks less gridded when overzoomed int j; for (j = 0; j < components; j++) { int noisebits = 32 - mapbits / 2; int i; for (i = 0; i < noisebits; i++) { x[j] |= ((y[j] >> (2 * noisebits - 1 - i)) & 1) << i; y[j] |= ((x[j] >> (2 * noisebits - 1 - i)) & 1) << i; } } } double hue = -1; if (metabits > 0 && colors->active) { hue = (((double) meta - colors->meta1) / (colors->meta2 - colors->meta1) * (colors->hue2 - colors->hue1) + colors->hue1) / 360; if (hue < -2) { hue = -1; } else { while (hue < 0) { hue++; } while (hue > 1) { hue--; } } } double bright = bright1; double bb = b; if (metabright) { bright *= meta; } if (metabrush) { bb = bb * meta; } for (k = 0; k < components; k++) { wxy2fxy(x[k], y[k], &xd[k], &yd[k], z_draw, x_draw, y_draw); } if (dump) { int should = 0; if (components == 1) { should = 1; } else { for (k = 1; k < components; k++) { double x1 = xd[k - 1]; double y1 = yd[k - 1]; double x2 = xd[k]; double y2 = yd[k]; if (clip(&x1, &y1, &x2, &y2, 0, 0, 1, 1)) { should = 1; break; } } } if (should) { dump_out(dump, x, y, components, metabits, meta); } } else if (components == 1) { if (!antialias) { xd[0] = ((int) (xd[0] * tilesize) + .5) / tilesize; yd[0] = ((int) (yd[0] * tilesize) + .5) / tilesize; } if (circle > 0) { if (size < .5) { if (bb <= 1) { drawPixel((xd[0] * tilesize - .5) + xoff, (yd[0] * tilesize - .5) + yoff, gc, bright * bb * meta / innerstep, hue, meta, &tc); } else { drawBrush((xd[0] * tilesize) + xoff, (yd[0] * tilesize) + yoff, gc, bright * meta / innerstep, bb, hue, meta, gaussian, &tc); ret = 1; } } else { double xc = (xd[0] * tilesize) + xoff; double yc = (yd[0] * tilesize) + yoff; if (xc + size >= 0 && yc + size >= 0 && xc - size <= tilesize && yc - size <= tilesize) { srand(x[0] * 37 + y[0]); for (todo += meta; todo > 0; todo -= innerstep) { double r = sqrt(((double) (rand() & (INT_MAX - 1))) / (INT_MAX)); double ang = ((double) (rand() & (INT_MAX - 1))) / (INT_MAX) * 2 * M_PI; double xp = xc + size * r * cos(ang); double yp = yc + size * r * sin(ang); if (bb <= 1) { drawPixel(xp - .5, yp - .5, gc, bright * bb, hue, meta, &tc); } else { drawBrush(xp, yp, gc, bright, bb, hue, meta, gaussian, &tc); ret = 1; } } } } } else { if (bb <= 1) { drawPixel((xd[0] * tilesize - .5) + xoff, (yd[0] * tilesize - .5) + yoff, gc, bright * bb, hue, meta, &tc); } else { drawBrush((xd[0] * tilesize) + xoff, (yd[0] * tilesize) + yoff, gc, bright, bb, hue, meta, gaussian, &tc); ret = 1; } } } else { for (k = 1; k < components; k++) { double bright1 = bright; long long xk1 = x[k - 1]; long long xk = x[k]; if (gps) { double xdist = (long long) x[k] - (long long) x[k - 1]; double ydist = (long long) y[k] - (long long) y[k - 1]; double dist = sqrt(xdist * xdist + ydist * ydist); double min = gps_dist; min = min * exp(log(gps_ramp) * (gps_base - z_draw)); if (dist > min) { bright1 /= (dist / min); } if (bright1 < .0025) { continue; } } double thick1 = thick * tilesize / 256.0; if (xk - xk1 >= (1LL << 31)) { wxy2fxy(xk - (1LL << 32), y[k], &xd[k], &yd[k], z_draw, x_draw, y_draw); drawClip(xd[k - 1] * tilesize + xoff, yd[k - 1] * tilesize + yoff, xd[k] * tilesize + xoff, yd[k] * tilesize + yoff, gc, bright1, hue, meta, antialias, thick1, &tc); wxy2fxy(x[k], y[k], &xd[k], &yd[k], z_draw, x_draw, y_draw); wxy2fxy(xk1 + (1LL << 32), y[k - 1], &xd[k - 1], &yd[k - 1], z_draw, x_draw, y_draw); drawClip(xd[k - 1] * tilesize + xoff, yd[k - 1] * tilesize + yoff, xd[k] * tilesize + xoff, yd[k] * tilesize + yoff, gc, bright1, hue, meta, antialias, thick1, &tc); wxy2fxy(x[k - 1], y[k - 1], &xd[k - 1], &yd[k - 1], z_draw, x_draw, y_draw); } else if (xk1 - xk >= (1LL << 31)) { wxy2fxy(xk1 - (1LL << 32), y[k - 1], &xd[k - 1], &yd[k - 1], z_draw, x_draw, y_draw); drawClip(xd[k - 1] * tilesize + xoff, yd[k - 1] * tilesize + yoff, xd[k] * tilesize + xoff, yd[k] * tilesize + yoff, gc, bright1, hue, meta, antialias, thick1, &tc); wxy2fxy(x[k - 1], y[k - 1], &xd[k - 1], &yd[k - 1], z_draw, x_draw, y_draw); wxy2fxy(xk + (1LL << 32), y[k], &xd[k], &yd[k], z_draw, x_draw, y_draw); drawClip(xd[k - 1] * tilesize + xoff, yd[k - 1] * tilesize + yoff, xd[k] * tilesize + xoff, yd[k] * tilesize + yoff, gc, bright1, hue, meta, antialias, thick1, &tc); wxy2fxy(x[k], y[k], &xd[k], &yd[k], z_draw, x_draw, y_draw); } else { drawClip(xd[k - 1] * tilesize + xoff, yd[k - 1] * tilesize + yoff, xd[k] * tilesize + xoff, yd[k] * tilesize + yoff, gc, bright1, hue, meta, antialias, thick1, &tc); } } } }
void THandler::verifyInterpolantWithExternalTool( vector< Enode * > & expl , Enode * interp_list ) { uint64_t mask = 0xFFFFFFFFFFFFFFFEULL; for ( unsigned in = 1 ; in < core_solver.getNofPartitions( ) ; in ++ ) { Enode * args = interp_list; // Advance in the interpolants list for ( unsigned i = 0 ; i < in - 1 ; i ++ ) args = args->getCdr( ); Enode * interp = args->getCar( ); mask &= ~SETBIT( in ); // Check A -> I, i.e., A & !I // First stage: print declarations const char * name = "/tmp/verifyinterp.smt2"; std::ofstream dump_out( name ); core_solver.dumpHeaderToFile( dump_out ); // Print only A atoms dump_out << "(assert " << endl; dump_out << "(and" << endl; for ( size_t j = 0 ; j < expl.size( ) ; j ++ ) { Enode * e = expl[ j ]; assert( e->isTAtom( ) ); assert( e->getPolarity( ) != l_Undef ); assert( (core_solver.getIPartitions( e ) & mask) != 0 || (core_solver.getIPartitions( e ) & ~mask) != 0 ); if ( (core_solver.getIPartitions( e ) & ~mask) != 0 ) { bool negated = e->getPolarity( ) == l_False; if ( negated ) dump_out << "(not "; e->print( dump_out ); if ( negated ) dump_out << ")"; dump_out << endl; } } dump_out << "(not " << interp << ")" << endl; dump_out << "))" << endl; dump_out << "(check-sat)" << endl; dump_out << "(exit)" << endl; dump_out.close( ); // Check ! bool tool_res; if ( int pid = fork() ) { int status; waitpid(pid, &status, 0); switch ( WEXITSTATUS( status ) ) { case 0: tool_res = false; break; case 1: tool_res = true; break; default: perror( "Tool" ); exit( EXIT_FAILURE ); } } else { execlp( "tool_wrapper.sh", "tool_wrapper.sh", name, 0 ); perror( "Tool" ); exit( 1 ); } if ( tool_res == true ) opensmt_error2( config.certifying_solver, " says A -> I does not hold" ); // Now check B & I dump_out.open( name ); core_solver.dumpHeaderToFile( dump_out ); // Print only B atoms dump_out << "(assert " << endl; dump_out << "(and" << endl; for ( size_t j = 0 ; j < expl.size( ) ; j ++ ) { Enode * e = expl[ j ]; assert( e->isTAtom( ) ); assert( e->getPolarity( ) != l_Undef ); assert( (core_solver.getIPartitions( e ) & mask) != 0 || (core_solver.getIPartitions( e ) & ~mask) != 0 ); if ( (core_solver.getIPartitions( e ) & mask) != 0 ) { bool negated = e->getPolarity( ) == l_False; if ( negated ) dump_out << "(not "; e->print( dump_out ); if ( negated ) dump_out << ")"; dump_out << endl; } } dump_out << interp << endl; dump_out << "))" << endl; dump_out << "(check-sat)" << endl; dump_out << "(exit)" << endl; dump_out.close( ); // Check ! tool_res; if ( int pid = fork() ) { int status; waitpid(pid, &status, 0); switch ( WEXITSTATUS( status ) ) { case 0: tool_res = false; break; case 1: tool_res = true; break; default: perror( "Tool" ); exit( EXIT_FAILURE ); } } else { execlp( "tool_wrapper.sh", "tool_wrapper.sh", name, 0 ); perror( "Tool" ); exit( 1 ); } if ( tool_res == true ) opensmt_error2( config.certifying_solver, " says B & I does not hold" ); } }