int parseFormat(string ffname, ivector & tvec, svector & dnames, svector & delims, int *grpsize) { ifstream ifstr(ffname.c_str(), ios::in); if (ifstr.fail() || ifstr.eof()) { cerr << "couldnt open format file" << endl; throw; } char *next, *third, *newstr, *linebuf = new char[80]; while (!ifstr.bad() && !ifstr.eof()) { ifstr.getline(linebuf, 80); if (strlen(linebuf) > 1) { next = strchr(linebuf, ' '); *next++ = 0; third = strchr(next, ' '); if (third) *third++ = 0; dnames.push_back(next); if (strncmp(linebuf, "int", 3) == 0) { tvec.push_back(ftype_int); delims.push_back(""); } else if (strncmp(linebuf, "dint", 4) == 0) { tvec.push_back(ftype_dint); delims.push_back(""); } else if (strncmp(linebuf, "qhex", 4) == 0) { tvec.push_back(ftype_qhex); delims.push_back(""); } else if (strncmp(linebuf, "float", 5) == 0) { tvec.push_back(ftype_float); delims.push_back(""); } else if (strncmp(linebuf, "double", 6) == 0) { tvec.push_back(ftype_double); delims.push_back(""); } else if (strncmp(linebuf, "word", 4) == 0) { tvec.push_back(ftype_word); delims.push_back(""); } else if (strncmp(linebuf, "string", 6) == 0) { tvec.push_back(ftype_string); ifstr.getline(linebuf, 80); newstr = new char[strlen(linebuf)+1]; strcpy(newstr, linebuf); delims.push_back(newstr); } else if (strncmp(linebuf, "date", 4) == 0) { tvec.push_back(ftype_date); delims.push_back(""); } else if (strncmp(linebuf, "mdate", 5) == 0) { tvec.push_back(ftype_mdate); delims.push_back(""); } else if (strncmp(linebuf, "cmdate", 6) == 0) { tvec.push_back(ftype_cmdate); delims.push_back(""); } else if (strncmp(linebuf, "dt", 2) == 0) { tvec.push_back(ftype_dt); delims.push_back(""); } else if (strncmp(linebuf, "mdt", 3) == 0) { tvec.push_back(ftype_mdt); delims.push_back(""); } else if (strncmp(linebuf, "group", 5) == 0) { sscanf(third, "%d", grpsize); tvec.push_back(ftype_group); delims.push_back(""); } else if (strncmp(linebuf, "igroup", 6) == 0) { sscanf(third, "%d", grpsize); tvec.push_back(ftype_igroup); ifstr.getline(linebuf, 80); delims.push_back(linebuf); } else if (strncmp(linebuf, "digroup", 7) == 0) { sscanf(third, "%d", grpsize); tvec.push_back(ftype_digroup); ifstr.getline(linebuf, 80); delims.push_back(linebuf); } else { cerr << "couldnt parse format file line " << tvec.size()+1 << endl; throw; } } } return tvec.size(); delete [] linebuf; }
void prepare(svector<iovec>& v, void* ptr, const int sender=-1) { struct iovec iov={ptr,size*sizeof(char)}; v.push_back(iov); setCallbackArg(NULL); }
virtual void operator()(model_ref & mdl, unsigned goal_idx) { SASSERT(goal_idx == 0); for (unsigned i = 0; i < m_const.size(); ++i) { mdl->register_decl(m_const[i].first->get_decl(), m_const[i].second); } }
void fpa_decl_plugin::get_op_names(svector<builtin_name> & op_names, symbol const & logic) { // These are the operators from the final draft of the SMT FloatingPoint standard op_names.push_back(builtin_name("+oo", OP_FPA_PLUS_INF)); op_names.push_back(builtin_name("-oo", OP_FPA_MINUS_INF)); op_names.push_back(builtin_name("+zero", OP_FPA_PLUS_ZERO)); op_names.push_back(builtin_name("-zero", OP_FPA_MINUS_ZERO)); op_names.push_back(builtin_name("NaN", OP_FPA_NAN)); op_names.push_back(builtin_name("roundNearestTiesToEven", OP_FPA_RM_NEAREST_TIES_TO_EVEN)); op_names.push_back(builtin_name("roundNearestTiesToAway", OP_FPA_RM_NEAREST_TIES_TO_AWAY)); op_names.push_back(builtin_name("roundTowardPositive", OP_FPA_RM_TOWARD_POSITIVE)); op_names.push_back(builtin_name("roundTowardNegative", OP_FPA_RM_TOWARD_NEGATIVE)); op_names.push_back(builtin_name("roundTowardZero", OP_FPA_RM_TOWARD_ZERO)); op_names.push_back(builtin_name("RNE", OP_FPA_RM_NEAREST_TIES_TO_EVEN)); op_names.push_back(builtin_name("RNA", OP_FPA_RM_NEAREST_TIES_TO_AWAY)); op_names.push_back(builtin_name("RTP", OP_FPA_RM_TOWARD_POSITIVE)); op_names.push_back(builtin_name("RTN", OP_FPA_RM_TOWARD_NEGATIVE)); op_names.push_back(builtin_name("RTZ", OP_FPA_RM_TOWARD_ZERO)); op_names.push_back(builtin_name("fp.abs", OP_FPA_ABS)); op_names.push_back(builtin_name("fp.neg", OP_FPA_NEG)); op_names.push_back(builtin_name("fp.add", OP_FPA_ADD)); op_names.push_back(builtin_name("fp.sub", OP_FPA_SUB)); op_names.push_back(builtin_name("fp.mul", OP_FPA_MUL)); op_names.push_back(builtin_name("fp.div", OP_FPA_DIV)); op_names.push_back(builtin_name("fp.fma", OP_FPA_FMA)); op_names.push_back(builtin_name("fp.sqrt", OP_FPA_SQRT)); op_names.push_back(builtin_name("fp.rem", OP_FPA_REM)); op_names.push_back(builtin_name("fp.roundToIntegral", OP_FPA_ROUND_TO_INTEGRAL)); op_names.push_back(builtin_name("fp.min", OP_FPA_MIN)); op_names.push_back(builtin_name("fp.max", OP_FPA_MAX)); op_names.push_back(builtin_name("fp.leq", OP_FPA_LE)); op_names.push_back(builtin_name("fp.lt", OP_FPA_LT)); op_names.push_back(builtin_name("fp.geq", OP_FPA_GE)); op_names.push_back(builtin_name("fp.gt", OP_FPA_GT)); op_names.push_back(builtin_name("fp.eq", OP_FPA_EQ)); op_names.push_back(builtin_name("fp.isNormal", OP_FPA_IS_NORMAL)); op_names.push_back(builtin_name("fp.isSubnormal", OP_FPA_IS_SUBNORMAL)); op_names.push_back(builtin_name("fp.isZero", OP_FPA_IS_ZERO)); op_names.push_back(builtin_name("fp.isInfinite", OP_FPA_IS_INF)); op_names.push_back(builtin_name("fp.isNaN", OP_FPA_IS_NAN)); op_names.push_back(builtin_name("fp.isNegative", OP_FPA_IS_NEGATIVE)); op_names.push_back(builtin_name("fp.isPositive", OP_FPA_IS_POSITIVE)); op_names.push_back(builtin_name("fp", OP_FPA_FP)); op_names.push_back(builtin_name("fp.to_ubv", OP_FPA_TO_UBV)); op_names.push_back(builtin_name("fp.to_sbv", OP_FPA_TO_SBV)); op_names.push_back(builtin_name("fp.to_real", OP_FPA_TO_REAL)); op_names.push_back(builtin_name("to_fp", OP_FPA_TO_FP)); op_names.push_back(builtin_name("to_fp_unsigned", OP_FPA_TO_FP_UNSIGNED)); /* Extensions */ op_names.push_back(builtin_name("to_ieee_bv", OP_FPA_TO_IEEE_BV)); op_names.push_back(builtin_name("fp.to_ieee_bv", OP_FPA_TO_IEEE_BV)); }
unsigned size() const { return m_names.size(); }
void prepare(cmd_context & ctx) override { m_cmds.reset(); }
virtual void get_labels(svector<symbol> & r) { buffer<symbol> tmp; ctx().get_relevant_labels(0, tmp); r.append(tmp.size(), tmp.c_ptr()); }
BOOL ValidNode(vertex& N) { // *** Query and cache polygons for ray-casting Fvector PointUp; PointUp.set(N.Pos); PointUp.y += RCAST_Depth/2; Fvector PointDown; PointDown.set(N.Pos); PointDown.y -= RCAST_Depth/2; Fbox BB; BB.set (PointUp,PointUp); BB.grow(g_params.fPatchSize/2); // box 1 Fbox B2; B2.set (PointDown,PointDown); B2.grow(g_params.fPatchSize/2); // box 2 BB.merge(B2 ); BoxQuery(BB,false ); u32 dwCount = XRC.r_count(); if (dwCount==0) { Log("chasm1"); return FALSE; // chasm? } // *** Transfer triangles and compute sector R_ASSERT(dwCount<RCAST_MaxTris); static svector<tri,RCAST_MaxTris> tris; tris.clear(); for (u32 i=0; i<dwCount; i++) { tri& D = tris.last(); CDB::RESULT&rp = XRC.r_begin()[i]; *(Level.get_tris()+XRC.r_begin()[i].id); D.v[0].set (rp.verts[0]); D.v[1].set (rp.verts[1]); D.v[2].set (rp.verts[2]); Fvector N; N.mknormal (D.v[0],D.v[1],D.v[2]); if (N.y<=0) continue; tris.inc (); } if (tris.size()==0) { Log("chasm2"); return FALSE; // chasm? } // *** Perform ray-casts and calculate sector Fvector P,D,PLP; D.set(0,-1,0); float coeff = 0.5f*g_params.fPatchSize/float(RCAST_Count); int num_successed_rays = 0; for (int x=-RCAST_Count; x<=RCAST_Count; x++) { P.x = N.Pos.x + coeff*float(x); for (int z=-RCAST_Count; z<=RCAST_Count; z++) { P.z = N.Pos.z + coeff*float(z); P.y = N.Pos.y; N.Plane.intersectRayPoint(P,D,PLP); // "project" position P.y = PLP.y+RCAST_DepthValid/2; float tri_min_range = flt_max; int tri_selected = -1; float range = 0.f,u,v; for (i=0; i<u32(tris.size()); i++) { if (CDB::TestRayTri(P,D,tris[i].v,u,v,range,false)) { if (range<tri_min_range) { tri_min_range = range; tri_selected = i; } } } if (tri_selected>=0) { if (range<RCAST_DepthValid) num_successed_rays++; } } } if (float(num_successed_rays)/float(RCAST_Total) < 0.5f) { Msg ("Floating node."); return FALSE; } return TRUE; }
void div(svector<Numeral> & as, mpz const & g) { unsigned n = as.size(); for (unsigned i = 0; i < n; i++) m().div(as[i], g, as[i]); }
void resize_data(unsigned sz) { m_data_size = sz; m_data.resize(m_data_size+1); m_data[m_data_size] = s_delimiter; }
virtual void prepare(cmd_context & ctx) { m_cmds.reset(); }
BOOL CreateNode(Fvector& vAt, vertex& N) { // *** Query and cache polygons for ray-casting Fvector PointUp; PointUp.set(vAt); PointUp.y += RCAST_Depth; SnapXZ (PointUp); Fvector PointDown; PointDown.set(vAt); PointDown.y -= RCAST_Depth; SnapXZ (PointDown); Fbox BB; BB.set (PointUp,PointUp); BB.grow(g_params.fPatchSize/2); // box 1 Fbox B2; B2.set (PointDown,PointDown); B2.grow(g_params.fPatchSize/2); // box 2 BB.merge(B2 ); BoxQuery(BB,false ); u32 dwCount = XRC.r_count(); if (dwCount==0) { // Log("chasm1"); return FALSE; // chasm? } // *** Transfer triangles and compute sector R_ASSERT(dwCount<RCAST_MaxTris); static svector<tri,RCAST_MaxTris> tris; tris.clear(); for (u32 i=0; i<dwCount; i++) { tri& D = tris.last(); CDB::RESULT &rp = XRC.r_begin()[i]; CDB::TRI& T = *(Level.get_tris()+rp.id); D.v[0].set (rp.verts[0]); D.v[1].set (rp.verts[1]); D.v[2].set (rp.verts[2]); D.sector = T.sector; D.N.mknormal(D.v[0],D.v[1],D.v[2]); if (D.N.y<=0) continue; tris.inc (); } if (tris.size()==0) { // Log("chasm2"); return FALSE; // chasm? } // *** Perform ray-casts and calculate sector WORD Sector = 0xfffe; // mark as first time static svector<Fvector,RCAST_Total> points; points.clear(); static svector<Fvector,RCAST_Total> normals; normals.clear(); Fvector P,D; D.set(0,-1,0); float coeff = 0.5f*g_params.fPatchSize/float(RCAST_Count); for (int x=-RCAST_Count; x<=RCAST_Count; x++) { P.x = vAt.x + coeff*float(x); for (int z=-RCAST_Count; z<=RCAST_Count; z++) { P.z = vAt.z + coeff*float(z); P.y = vAt.y + 10.f; float tri_min_range = flt_max; int tri_selected = -1; float range,u,v; for (i=0; i<u32(tris.size()); i++) { if (CDB::TestRayTri(P,D,tris[i].v,u,v,range,false)) { if (range<tri_min_range) { tri_min_range = range; tri_selected = i; } } } if (tri_selected>=0) { P.y -= tri_min_range; points.push_back(P); normals.push_back(tris[tri_selected].N); WORD TS = WORD(tris[tri_selected].sector); if (Sector==0xfffe) Sector = TS; else if (Sector!=TS) Sector=InvalidSector; } } } if (points.size()<3) { // Msg ("Failed to create node at [%f,%f,%f].",vAt.x,vAt.y,vAt.z); return FALSE; } if (float(points.size())/float(RCAST_Total) < 0.7f) { // Msg ("Partial chasm at [%f,%f,%f].",vAt.x,vAt.y,vAt.z); return FALSE; } // *** Calc normal Fvector vNorm; vNorm.set(0,0,0); for (u32 n=0; n<normals.size(); n++) vNorm.add(normals[n]); vNorm.div(float(normals.size())); vNorm.normalize(); /* { // second algorithm (Magic) Fvector N,O; N.set(vNorm); O.set(points[0]); Mgc::OrthogonalPlaneFit( points.size(),(Mgc::Vector3*)points.begin(), *((Mgc::Vector3*)&O), *((Mgc::Vector3*)&N) ); if (N.y<0) N.invert(); N.normalize(); vNorm.lerp(vNorm,N,.3f); vNorm.normalize(); } */ // *** Align plane Fvector vOffs; vOffs.set(0,-1000,0); Fplane PL; PL.build(vOffs,vNorm); for (u32 p=0; p<points.size(); p++) { float dist = PL.classify(points[p]); if (dist>0) { vOffs = points[p]; PL.build(vOffs,vNorm); } } // *** Create node and register it N.Sector =Sector; // sector N.Plane.build (vOffs,vNorm); // build plane D.set (0,1,0); N.Plane.intersectRayPoint(PointDown,D,N.Pos); // "project" position // *** Validate results vNorm.set(0,1,0); if (vNorm.dotproduct(N.Plane.n)<_cos(deg2rad(60.f))) return FALSE; float y_old = vAt.y; float y_new = N.Pos.y; if (y_old>y_new) { // down if (y_old-y_new > g_params.fCanDOWN ) return FALSE; } else { // up if (y_new-y_old > g_params.fCanUP ) return FALSE; } // *** Validate plane { Fvector PLP; D.set(0,-1,0); int num_successed_rays = 0; for (int x=-RCAST_Count; x<=RCAST_Count; x++) { P.x = N.Pos.x + coeff*float(x); for (int z=-RCAST_Count; z<=RCAST_Count; z++) { P.z = N.Pos.z + coeff*float(z); P.y = N.Pos.y; N.Plane.intersectRayPoint(P,D,PLP); // "project" position P.y = PLP.y+RCAST_VALID*0.01f; float tri_min_range = flt_max; int tri_selected = -1; float range,u,v; for (i=0; i<float(tris.size()); i++) { if (CDB::TestRayTri(P,D,tris[i].v,u,v,range,false)) { if (range<tri_min_range) { tri_min_range = range; tri_selected = i; } } } if (tri_selected>=0) { if (tri_min_range<RCAST_VALID) num_successed_rays++; } } } float perc = float(num_successed_rays)/float(RCAST_Total); if (perc < 0.5f) { // Msg ("Floating node."); return FALSE; } } // *** Mask check // ??? return TRUE; }
bool empty() const { return m_entries.empty(); }
void prepare(svector<iovec>& v, void* ptr, const int sender=-1) { // just send the data not the message struct iovec iov={((COMM::TransportImpl::msg_t*)ptr)->getData(),size}; v.push_back(iov); setCallbackArg(ptr); // set the pointer for the callback }
void float_decl_plugin::get_op_names(svector<builtin_name> & op_names, symbol const & logic) { op_names.push_back(builtin_name("plusInfinity", OP_FLOAT_PLUS_INF)); op_names.push_back(builtin_name("minusInfinity", OP_FLOAT_MINUS_INF)); op_names.push_back(builtin_name("NaN", OP_FLOAT_NAN)); op_names.push_back(builtin_name("roundNearestTiesToEven", OP_RM_NEAREST_TIES_TO_EVEN)); op_names.push_back(builtin_name("roundNearestTiesToAway", OP_RM_NEAREST_TIES_TO_AWAY)); op_names.push_back(builtin_name("roundTowardPositive", OP_RM_TOWARD_POSITIVE)); op_names.push_back(builtin_name("roundTowardNegative", OP_RM_TOWARD_NEGATIVE)); op_names.push_back(builtin_name("roundTowardZero", OP_RM_TOWARD_ZERO)); op_names.push_back(builtin_name("+", OP_FLOAT_ADD)); op_names.push_back(builtin_name("-", OP_FLOAT_SUB)); op_names.push_back(builtin_name("/", OP_FLOAT_DIV)); op_names.push_back(builtin_name("*", OP_FLOAT_MUL)); op_names.push_back(builtin_name("abs", OP_FLOAT_ABS)); op_names.push_back(builtin_name("remainder", OP_FLOAT_REM)); op_names.push_back(builtin_name("fusedMA", OP_FLOAT_FUSED_MA)); op_names.push_back(builtin_name("squareRoot", OP_FLOAT_SQRT)); op_names.push_back(builtin_name("roundToIntegral", OP_FLOAT_ROUND_TO_INTEGRAL)); op_names.push_back(builtin_name("==", OP_FLOAT_EQ)); op_names.push_back(builtin_name("<", OP_FLOAT_LT)); op_names.push_back(builtin_name(">", OP_FLOAT_GT)); op_names.push_back(builtin_name("<=", OP_FLOAT_LE)); op_names.push_back(builtin_name(">=", OP_FLOAT_GE)); op_names.push_back(builtin_name("isZero", OP_FLOAT_IS_ZERO)); op_names.push_back(builtin_name("isNZero", OP_FLOAT_IS_NZERO)); op_names.push_back(builtin_name("isPZero", OP_FLOAT_IS_PZERO)); op_names.push_back(builtin_name("isSignMinus", OP_FLOAT_IS_SIGN_MINUS)); op_names.push_back(builtin_name("min", OP_FLOAT_MIN)); op_names.push_back(builtin_name("max", OP_FLOAT_MAX)); op_names.push_back(builtin_name("asFloat", OP_TO_FLOAT)); }
static void is_sorted(svector<unsigned> const& v) { for (unsigned i = 0; i + 1 < v.size(); ++i) { SASSERT(v[i] <= v[i+1]); } }
void float_decl_plugin::get_sort_names(svector<builtin_name> & sort_names, symbol const & logic) { sort_names.push_back(builtin_name("FP", FLOAT_SORT)); sort_names.push_back(builtin_name("RoundingMode", ROUNDING_MODE_SORT)); }
static Z3_ast and_vec(Z3_context ctx,svector<Z3_ast> &c) { return (c.size() > 1) ? Z3_mk_and(ctx,c.size(),&c[0]) : c[0]; }
virtual void get_labels(svector<symbol> & r) { SASSERT(m_context); buffer<symbol> tmp; m_context->get_relevant_labels(0, tmp); r.append(tmp.size(), tmp.c_ptr()); }