static void encodeArray(it const ita, it const ite, std::string const & fn) { libmaus2::aio::OutputStreamInstance COS(fn); std::string const indexfn = fn+".idx"; libmaus2::util::TempFileRemovalContainer::addTempFile(indexfn); libmaus2::aio::InputOutputStream::unique_ptr_type PindexCOS(libmaus2::aio::InputOutputStreamFactoryContainer::constructUnique(indexfn, std::ios::in|std::ios::out|std::ios::trunc|std::ios::binary)); // libmaus2::aio::CheckedInputOutputStream indexCOS(indexfn); encodeArray(ita,ite,COS,*PindexCOS); PindexCOS.reset(); libmaus2::aio::FileRemoval::removeFile(indexfn); }
// Set the specified attribute bool DBObject::setAttribute(CK_ATTRIBUTE_TYPE type, const OSAttribute& attribute) { MutexLocker lock(_mutex); if (_connection == NULL) { ERROR_MSG("Object is not connected to the database."); return false; } if (_objectId == 0) { ERROR_MSG("Cannot update invalid object."); return false; } // Retrieve and existing attribute if it exists or NULL if it doesn't OSAttribute *attr = getAttributeDB(type); // Update an existing attribute... if (attr) { DB::Statement statement; bool bindByteString = true; if (attr->isBooleanAttribute()) { // update boolean attribute statement = _connection->prepare( "update attribute_boolean set value=%d where type=%lu and object_id=%lld", attribute.getBooleanValue() ? 1 : 0, type, _objectId); bindByteString = false; } else if (attr->isUnsignedLongAttribute()) { // update integer attribute statement = _connection->prepare( "update attribute_integer set value=%lld where type=%lu and object_id=%lld", static_cast<long long>(attribute.getUnsignedLongValue()), type, _objectId); bindByteString = false; } else if (attr->isByteStringAttribute()) { // update binary attribute statement = _connection->prepare( "update attribute_binary set value=? where type=%lu and object_id=%lld", type, _objectId); //bindByteString = true; } else if (attr->isArrayAttribute()) { // update array attribute ByteString value; if (!encodeArray(value, attribute.getArrayValue())) { return false; } statement = _connection->prepare( "update attribute_array set value=? where type=%lu and object_id=%lld", type, _objectId); DB::Bindings(statement).bindBlob(1, value.const_byte_str(), value.size(), SQLITE_TRANSIENT); bindByteString = false; } if (bindByteString) { DB::Bindings(statement).bindBlob(1, attribute.getByteStringValue().const_byte_str(), attribute.getByteStringValue().size(), SQLITE_STATIC); } // Statement is valid when a prepared statement has been attached to it. if (statement.isValid()) { if (!_connection->execute(statement)) { ERROR_MSG("Failed to update attribute %lu for object %lld",type,_objectId); return false; } if (_transaction) { std::map<CK_ATTRIBUTE_TYPE,OSAttribute*>::iterator it = _transaction->find(type); if (it != _transaction->end()) *it->second = attribute; else (*_transaction)[type] = new OSAttribute(attribute); } else *attr = attribute; return true; } } DB::Statement statement; // Insert the attribute, because it is currently unknown if (attribute.isBooleanAttribute()) { // Could not update it, so we need to insert it. statement = _connection->prepare( "insert into attribute_boolean (value,type,object_id) values (%d,%lu,%lld)", attribute.getBooleanValue() ? 1 : 0, type, _objectId); } else if (attribute.isUnsignedLongAttribute()) { // Could not update it, so we need to insert it. statement = _connection->prepare( "insert into attribute_integer (value,type,object_id) values (%lld,%lu,%lld)", static_cast<long long>(attribute.getUnsignedLongValue()), type, _objectId); } else if (attribute.isByteStringAttribute()) { // Could not update it, so we need to insert it. statement = _connection->prepare( "insert into attribute_binary (value,type,object_id) values (?,%lu,%lld)", type, _objectId); DB::Bindings(statement).bindBlob(1, attribute.getByteStringValue().const_byte_str(), attribute.getByteStringValue().size(), SQLITE_STATIC); } else if (attribute.isArrayAttribute()) { // Could not update it, so we need to insert it. ByteString value; if (!encodeArray(value, attribute.getArrayValue())) { return false; } statement = _connection->prepare( "insert into attribute_array (value,type,object_id) values (?,%lu,%lld)", type, _objectId); DB::Bindings(statement).bindBlob(1, value.const_byte_str(), value.size(), SQLITE_TRANSIENT); } // Statement is valid when a prepared statement has been attached to it. if (statement.isValid()) { if (!_connection->execute(statement)) { ERROR_MSG("Failed to insert attribute %lu for object %lld",type,_objectId); return false; } if (_transaction) (*_transaction)[type] = new OSAttribute(attribute); else _attributes[type] = new OSAttribute(attribute); return true; } return false; }
std::string getUpdateXML( const DataBase* database, const Encoding encoding, const Revision has_revision ) { std::list<renderlist::Buffer*> buffers; std::list<renderlist::Image*> images; std::list<renderlist::Shader*> shaders; std::list<renderlist::Action*> actions; std::list<renderlist::Action*> draworder; std::list<renderlist::Item*> keep; bool new_draworder; bool needs_pruning; Revision revision = database->changes( buffers, images, shaders, actions, new_draworder, draworder, needs_pruning, keep, has_revision ); std::stringstream o; o << "<?xml version=\"1.0\"?>" << std::endl; o << "<renderList" << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" << " xmlns=\"http://cloudviz.sintef.no/renderlist/1.0\"" << " xsi:schemaLocation=\"http://cloudviz.sintef.no/renderlist/1.0 renderlist.xsd\"" << " from=\"" << has_revision << "\"" << " to=\"" << revision << "\"" << ">" << std::endl; if( revision != has_revision ) { o << " <updateItems>" << std::endl; if( !buffers.empty() ) { o << " <buffers>" << std::endl; for( std::list<renderlist::Buffer*>::iterator it=buffers.begin(); it!=buffers.end(); ++it ) { const Buffer* b = *it; switch( b->type() ) { case ELEMENT_INT: o << " <update id=\"" << b->id() << "\" type=\"int\" count=\"" << b->count() << "\">" << std::endl; encodeArray<int>( o, encoding, b->intData(), b->count() ); o << std::endl << " </update>" << std::endl; break; case ELEMENT_FLOAT: o << " <update id=\"" << b->id() << "\" type=\"float\" count=\"" << b->count() << "\">" << std::endl; encodeArray<float>( o, encoding, b->floatData(), b->count() ); o << std::endl << " </update>" << std::endl; break; } } o << " </buffers>" << std::endl; } if( !images.empty() ) { o << " <images>" << std::endl; o << " </images>" << std::endl; } if( !shaders.empty() ) { o << " <shaders>" << std::endl; for( std::list<renderlist::Shader*>::iterator it=shaders.begin(); it!=shaders.end(); ++it ) { const Shader* s = *it; const std::string& vs = s->vertexStage(); const std::string& tc = s->tessCtrlStage(); const std::string& te = s->tessEvalStage(); const std::string& gs = s->geometryStage(); const std::string& fs = s->fragmentStage(); o << " <update id=\"" << s->id() << "\">" << std::endl; if( !vs.empty() ) { o << " <vertex>" << std::endl << vs << " </vertex>" << std::endl; } if( !tc.empty() ) { o << " <tessControl>" << std::endl << tc << " </tessControl>" << std::endl; } if( !te.empty() ) { o << " <tessEvaluation>" << std::endl << te << " </tessEvaluation>" << std::endl; } if( !gs.empty() ) { o << " <geometry>" << std::endl << gs << " </geometry>" << std::endl; } if( !fs.empty() ) { o << " <fragment>" << std::endl << fs << " </fragment>" << std::endl; } o << " </update>" << std::endl; } o << " </shaders>" << std::endl; } if( !actions.empty() ) { o << " <actions>" << std::endl; for(std::list<renderlist::Action*>::iterator it=actions.begin(); it!=actions.end(); ++it ) { // --- <draw> -------------------------------------------------- if( typeid(**it) == typeid(Draw) ) { const Draw* a = static_cast<const Draw*>( *it ); o << " <draw id=\"" << a->id() << "\" mode=\""; encodePrimitiveType( o, a->primitiveType() ); o << "\""; if( a->isIndexed() ) { o << " indices=\"" << a->indexBufferId() << "\""; } o << " first=\"" << a->first() << "\" count=\"" << a->count()<< "\" />" << std::endl; } // --- <setPixelState> ----------------------------------------- else if( typeid(**it) == typeid(SetPixelState) ) { const SetPixelState* a = static_cast<const SetPixelState*>( *it ); o << " <setPixelState id=\"" << a->id() << "\">" << std::endl; if( a->isDepthTestEnabled() ) { o << " <depthTest>1</depthTest>"<< std::endl; o << " <depthFunc>"; encodeDepthFunc( o, a->depthFunc() ); o << "</depthFunc>" << std::endl; } else { o << " <depthTest>0</depthTest>" << std::endl; } if( a->isBlendingEnabled() ) { o << " <blend>1</blend>" << std::endl; o << " <blendSrcRGB>"; encodeBlendFunc( o, a->blendSrcRGB() ); o << "</blendSrcRGB>" << std::endl; o << " <blendDstRGB>"; encodeBlendFunc( o, a->blendDstRGB() ); o << "</blendDstRGB>" << std::endl; o << " <blendSrcAlpha>"; encodeBlendFunc( o, a->blendSrcAlpha() ); o << "</blendSrcAlpha>" << std::endl; o << " <blendDstAlpha>"; encodeBlendFunc( o, a->blendDstAlpha() ); o << "</blendDstAlpha>" << std::endl; } else { o << " <blend>0</blend>" << std::endl; } o << " </setPixelState>" << std::endl; } // --- <setRasterState> ---------------------------------------- else if( typeid(**it) == typeid(SetRasterState) ) { const SetRasterState* a = static_cast<const SetRasterState*>( *it ); o << " <setRasterState id=\"" << a->id() << "\" />" << std::endl; } // --- <setFramebufferState> ----------------------------------- else if( typeid(**it) == typeid(SetFramebufferState) ) { const SetFramebufferState* a = static_cast<const SetFramebufferState*>( *it ); o << " <setFramebufferState id=\"" << a->id() << "\">" << std::endl; o << " <colorWriteMask>"; encodeArray( o, encoding, a->colorWriteMask(), 4 ); o << "</colorWriteMask>" << std::endl; o << " <depthWriteMask>" << a->depthWriteMask() << "</depthWriteMask>" << std::endl; o << " </setFramebufferState>" << std::endl; } // --- <setFramebuffer> ---------------------------------------- else if( typeid(**it) == typeid(SetFramebuffer) ) { const SetFramebuffer* a = static_cast<const SetFramebuffer*>( *it ); const renderlist::Id i = a->imageId(); o << " <setFramebuffer id=\"" << a->id() << "\" "; if( i != ~0u ) { o << "image=\"" << i << "\" "; } o << "/>" << std::endl; } // --- <setInputs> --------------------------------------------- else if( typeid(**it) == typeid(SetInputs) ) { const SetInputs* a = static_cast<const SetInputs*>( *it ); o << " <setInputs id=\""<< a->id() << "\" shader=\"" << a->shaderId() << "\">" << std::endl; for( size_t i=0; i<a->count(); i++ ) { o << " <input symbol=\"" << a->symbol(i) << "\" buffer=\"" << a->bufferId(i) << "\" components=\"" << a->components(i) << "\" offset=\"" << a->offset(i) << "\" stride=\"" << a->stride(i) << "\" />" << std::endl; } o << " </setInputs>" << std::endl; } // --- <setLight> ---------------------------------------------- else if( typeid(**it) == typeid(SetLight) ) { const SetLight* a = static_cast<const SetLight*>( *it ); o << " <setLight id=\"" << a->id() << "\" "; o << "index=\"" << a->index() << "\" "; o << "type=\""; switch( a->type() ) { case LIGHT_AMBIENT: o << "AMBIENT"; break; case LIGHT_DIRECTIONAL: o << "DIRECTIONAL"; break; case LIGHT_POINT: o << "POINT"; break; case LIGHT_SPOT: o << "SPOT"; break; } o << "\">" << std::endl; o << " <color>"; encodeArray( o, encoding, a->color(), 4 ); o << "</color>" << std::endl; if( a->type() != LIGHT_AMBIENT ) { if( a->type() != LIGHT_DIRECTIONAL ) { o << " <attenuation>"; encodeArray( o, encoding, a->attenuation(), 3 ); o << "</attenuation>" << std::endl; } if( a->type() == LIGHT_SPOT ) { o << " <falloff>"; encodeArray( o, encoding, a->falloff(), 2 ); o << "</falloff>" << std::endl; } o << " <fromWorld>"; encodeArray( o, encoding, a->fromWorld(), 16 ); o << "</fromWorld>" << std::endl; o << " <toWorld>"; encodeArray( o, encoding, a->toWorld(), 16 ); o << "</toWorld>" << std::endl; } o << " </setLight>" << std::endl; } // --- <setLocalCoordSys> -------------------------------------- else if( typeid(**it) == typeid(SetLocalCoordSys) ) { const SetLocalCoordSys* a = static_cast<const SetLocalCoordSys*>( *it ); o << " <setLocalCoordSys id=\""<< a->id() << "\">" << std::endl; o << " <fromWorld>"; encodeArray( o, encoding, a->fromWorld(), 16 ); o << "</fromWorld>" << std::endl; o << " <toWorld>"; encodeArray( o, encoding, a->toWorld(), 16 ); o << "</toWorld>" << std::endl; o << " </setLocalCoordSys>" << std::endl; } // --- <setShader> --------------------------------------------- else if( typeid(**it) == typeid(SetShader) ) { const SetShader* a = static_cast<const SetShader*>( *it ); o << " <setShader id=\"" << a->id() << "\" shader=\"" << a->shaderId() << "\" />" << std::endl; } // --- <setUniforms> ------------------------------------------- else if( typeid(**it) == typeid(SetUniforms) ) { const SetUniforms* a = static_cast<const SetUniforms*>( *it ); o << " <setUniforms id=\"" << a->id() << "\""; o << " shader=\"" << a->shaderId() << "\">" << std::endl; for(size_t i=0; i<a->count(); i++ ) { o << " <uniform symbol=\"" << a->symbol( i ) << "\""; if( a->type(i) == UNIFORM_SEMANTIC ) { o << " semantic=\""; switch( a->semantic(i) ) { case SEMANTIC_MODELVIEW_PROJECTION_MATRIX: o << "MODELVIEW_PROJECTION_MATRIX"; break; case SEMANTIC_NORMAL_MATRIX: o << "NORMAL_MATRIX"; break; } o << "\"/>" << std::endl; } else { o << ">"; switch( a->type(i) ) { case UNIFORM_SEMANTIC: break; case UNIFORM_INT: o << "<int>"; encodeArray( o, encoding, a->intData(i), 1 ); o << "</int>"; break; case UNIFORM_FLOAT: o << "<float>"; encodeArray( o, encoding, a->floatData(i), 1 ); o << "</float>"; break; case UNIFORM_FLOAT2: o << "<float2>"; encodeArray( o, encoding, a->floatData(i), 2 ); o << "</float2>"; break; case UNIFORM_FLOAT3: o << "<float3>"; encodeArray( o, encoding, a->floatData(i), 3 ); o << "</float3>"; break; case UNIFORM_FLOAT4: o << "<float4>"; encodeArray( o, encoding, a->floatData(i), 4 ); o << "</float4>"; break; case UNIFORM_FLOAT3X3: o << "<float3x3>"; encodeArray( o, encoding, a->floatData(i), 9 ); o << "</float3x3>"; break; case UNIFORM_FLOAT4X4: o << "<float4x4>"; encodeArray( o, encoding, a->floatData(i), 16 ); o << "</float4x4>"; break; } o << "</uniform>" << std::endl; } } o << " </setUniforms>" << std::endl; } // --- <SetViewCoordSys> --------------------------------------- else if( typeid(**it) == typeid(SetViewCoordSys) ) { SetViewCoordSys* a = static_cast<SetViewCoordSys*>( *it ); o << " <SetViewCoordSys id=\"" << a->id() << "\">" << std::endl; o << " <projection>"; encodeArray( o, encoding, a->projection(), 16 ); o << "</projection>" << std::endl; o << " <projectionInverse>"; encodeArray( o, encoding, a->projectionInverse(), 16 ); o << "</projectionInverse>" << std::endl; o << " <fromWorld>"; encodeArray( o, encoding, a->fromWorld(), 16 ); o << "</fromWorld>" << std::endl; o << " <toWorld>"; encodeArray( o, encoding, a->toWorld(), 16 ); o << "</toWorld>" << std::endl; o << " </SetViewCoordSys>" << std::endl; } } o << " </actions>" << std::endl; } o << " </updateItems>" << std::endl; if( needs_pruning ) { o << " <pruneItems>" << std::endl; for( std::list<renderlist::Item*>::iterator it=keep.begin(); it!=keep.end(); ++it ) { o << " <keep id=\"" << (*it)->id() << "\"/>" << std::endl; } o << " </pruneItems>" << std::endl; } if( new_draworder ) { o << " <drawOrder>" << std::endl; for( std::list<renderlist::Action*>::iterator it=draworder.begin(); it!=draworder.end(); ++it ) { o << " <invoke action=\"" << (*it)->id() << "\"/>" << std::endl; } o << " </drawOrder>" << std::endl; } } o << "</renderList>" << std::endl; return o.str(); }
void QPpsObjectPrivate::encodeData(pps_encoder_t *encoder, const char *name, const QVariant &data, bool *ok) { QString errorFunction; pps_encoder_error_t error = PPS_ENCODER_OK; switch (data.type()) { case QVariant::Bool: error = pps_encoder_add_bool(encoder, name, data.toBool()); errorFunction = QStringLiteral("pps_encoder_add_bool"); break; // We want to support encoding uint even though libpps doesn't support it directly. // We can't encode uint as an int since that will lose precision (e.g. 2^31+1 can't be // encoded that way). However, we can convert uint to double without losing precision. // QVariant.toDouble() conveniently takes care of the conversion for us. case QVariant::UInt: case QVariant::Double: error = pps_encoder_add_double(encoder, name, data.toDouble()); errorFunction = QStringLiteral("pps_encoder_add_double"); break; case QVariant::Int: error = pps_encoder_add_int(encoder, name, data.toInt()); errorFunction = QStringLiteral("pps_encoder_add_int"); break; case QVariant::LongLong: error = pps_encoder_add_int64(encoder, name, data.toLongLong()); errorFunction = QStringLiteral("pps_encoder_add_int64"); break; case QVariant::String: error = pps_encoder_add_string(encoder, name, data.toString().toUtf8().constData()); errorFunction = QStringLiteral("pps_encoder_add_string"); break; case QVariant::List: error = pps_encoder_start_array(encoder, name); errorFunction = QStringLiteral("pps_encoder_start_array"); if (error == PPS_ENCODER_OK) { encodeArray(encoder, data.toList(), ok); error = pps_encoder_end_array(encoder); errorFunction = QStringLiteral("pps_encoder_end_array"); } break; case QVariant::Map: error = pps_encoder_start_object(encoder, name); errorFunction = QStringLiteral("pps_encoder_start_object"); if (error == PPS_ENCODER_OK) { encodeObject(encoder, data.toMap(), ok); error = pps_encoder_end_object(encoder); errorFunction = QStringLiteral("pps_encoder_end_object"); } break; case QVariant::Invalid: error = pps_encoder_add_null(encoder, name); errorFunction = QStringLiteral("pps_encoder_add_null"); break; default: qWarning() << "QPpsObjectPrivate::encodeData: the type of the parameter data is invalid"; *ok = false; return; } if (error != PPS_ENCODER_OK) { qWarning() << "QPpsObjectPrivate::encodeData: " << errorFunction << " failed"; *ok = false; } else { *ok = true; } }
void PrinterBase::impl_print(const PVField& pv) { static const PVField* marker = (const PVField*)▮ /* Depth first recursive iteration. * Each PV to be printed is appended to the todo queue. * The last child of a structure is followed by a NULL. * As the tree is walked structures and structarrays * are appended to the inprog queue. */ std::deque<const PVField*> todo, inprog; todo.push_back(&pv); while(!todo.empty()) { const PVField *next = todo.front(); todo.pop_front(); if(next==marker) { // finished with a structure or structarray, // now we fall back to its parent. assert(!inprog.empty()); switch(inprog.back()->getField()->getType()) { case structure: endStructure(*static_cast<const PVStructure *>(inprog.back())); break; case structureArray: endStructureArray(*static_cast<const PVStructureArray *>(inprog.back())); break; case union_: endUnion(*static_cast<const PVUnion *>(inprog.back())); break; case unionArray: endUnionArray(*static_cast<const PVUnionArray *>(inprog.back())); break; default: assert(false); // oops! return; } inprog.pop_back(); } else { // real field if(!next) { // NULL entry in a structure array encodeNull(); continue; } switch(next->getField()->getType()) { case scalar: encodeScalar(*static_cast<const PVScalar*>(next)); break; case scalarArray: encodeArray(*static_cast<const PVScalarArray*>(next)); break; case structure: { const PVStructure &fld = *static_cast<const PVStructure*>(next); const PVFieldPtrArray& vals = fld.getPVFields(); inprog.push_back(next); beginStructure(fld); for(size_t i=0, nfld=fld.getStructure()->getNumberFields(); i<nfld; i++) todo.push_back(vals[i].get()); todo.push_back(marker); break; } case structureArray: { const PVStructureArray &fld = *static_cast<const PVStructureArray*>(next); PVStructureArray::const_svector vals(fld.view()); inprog.push_back(next); beginStructureArray(fld); for(PVStructureArray::const_svector::const_iterator it=vals.begin(); it!=vals.end(); ++it) { todo.push_back(it->get()); } todo.push_back(marker); break; } case union_: { const PVUnion &fld = *static_cast<const PVUnion*>(next); inprog.push_back(next); beginUnion(fld); PVFieldPtr val = fld.get(); if (val.get()) // TODO print "(none)" ? todo.push_back(val.get()); todo.push_back(marker); break; } case unionArray: { const PVUnionArray &fld = *static_cast<const PVUnionArray*>(next); PVUnionArray::const_svector vals(fld.view()); inprog.push_back(next); beginUnionArray(fld); for(PVUnionArray::const_svector::const_iterator it=vals.begin(); it!=vals.end(); ++it) { todo.push_back(it->get()); } todo.push_back(marker); break; } } } } }
BinaryExprPtr SPGen::encodeInst(BasicBlock *p, std::vector<BasicBlock *> &pcds, const ExprPtr psi, const ExprPtr gamma, BasicBlock::iterator it){ BasicBlock *currentBB = it -> getParent(); assert(currentBB && "current basic block is null"); // std::cout << "\nInstruction" << std::endl; // it -> print(outs()); // std::string s = p ? p -> getName().str() : "null"; // std::string postDomName = !pcds.empty() ? pcds.back()->getName().str() // : "null"; // std::cout << "CURRENT BB: " // << currentBB -> getName().str() // << "PREVIOUS BB: " // << s // <<"Common: " // << postDomName // << std::endl; unsigned opcode = it->getOpcode(); if(opcode != Instruction::PHI && !pcds.empty() && pcds.back() == currentBB) return Expression::mkBinExpr(Expression::mkTrue(),Expression::mkTrue()); BinaryExprPtr enc; switch (opcode) { case Instruction::Br:{ enc = encodeBr(pcds, psi, gamma, cast<BranchInst>(it)); break; } case Instruction::Call:{ // check if this call was inserted by the VarsForArrays pass. If such then // only its name and its first parameters name are relevant. CallInst *call = dyn_cast<CallInst>(it); Function *f = call -> getCalledFunction(); if(f == array_aux_1 || f == array_aux_2){ Value *param = call -> getArgOperand(0); context -> setOldArrayName(param); if(f == array_aux_2){ context -> setNewArrayName(call); } enc = Expression::mkBinExpr(Expression::mkTrue(),Expression::mkTrue()); } else { enc = Expression::mkBinExpr(Expression::mkTrue(),encodeAnn(psi, gamma, cast<CallInst>(it))); } break; } case Instruction::Ret:{ enc = Expression::mkBinExpr(Expression::mkTrue(),Expression::mkTrue()); break; } case Instruction::Unreachable:{ enc = Expression::mkBinExpr(Expression::mkTrue(),Expression::mkTrue()); break; } case Instruction::Add: case Instruction::FAdd: case Instruction::Sub: case Instruction::FSub: case Instruction::Mul: case Instruction::FMul: case Instruction::UDiv: case Instruction::SDiv: case Instruction::FDiv: case Instruction::URem: case Instruction::SRem: case Instruction::FRem: case Instruction::And: case Instruction::Or: case Instruction::Xor: case Instruction::Shl: case Instruction::LShr: case Instruction::AShr:{ ExprPtr e = encoder.encode(cast<BinaryOperator>(it)); enc = Expression::mkBinExpr(e, Expression::mkTrue()); break; } case Instruction::ICmp:{ ExprPtr e = encoder.encode(cast<ICmpInst>(it)); enc = Expression::mkBinExpr(e, Expression::mkTrue()); break; } case Instruction::SExt:{ ExprPtr e = encoder.encode(cast<SExtInst>(it)); enc = Expression::mkBinExpr(e, Expression::mkTrue()); break; } case Instruction::ZExt:{ ExprPtr e = encoder.encode(cast<ZExtInst>(it)); enc = Expression::mkBinExpr(e, Expression::mkTrue()); break; } case Instruction::Select:{ ExprPtr e = encoder.encode(cast<SelectInst>(it)); enc = Expression::mkBinExpr(e, Expression::mkTrue()); break; } case Instruction::PHI:{ assert(p && "trying to encode a phi instruction with no previous block\n"); ExprPtr e = encoder.encode(cast<PHINode>(it),p); enc = Expression::mkBinExpr(e, Expression::mkTrue()); break; } case Instruction::Switch:{ assert(0 && "switch not implemented yet"); // ExprPtr e = encoder.encode(cast<SwitchInst>(it)); // ExprPtr impl = ExprUtils::mkImpl(pi.encode(), e); // vcs.addToE(impl); // psi2.add(impl); break; } case Instruction::Alloca:{ ExprPtr e = encodeArray(cast<AllocaInst>(it)); enc = Expression::mkBinExpr(e,Expression::mkTrue()); break; } case Instruction::Store:{ ExprPtr e = encodeArray(cast<StoreInst>(it)); enc = Expression::mkBinExpr(e,Expression::mkTrue()); break; } case Instruction::Load:{ ExprPtr e = encodeArray(cast<LoadInst>(it)); enc = Expression::mkBinExpr(e,Expression::mkTrue()); break; } case Instruction::GetElementPtr:{ ExprPtr e = encodeArray(cast<GetElementPtrInst>(it)); enc = Expression::mkBinExpr(e,Expression::mkTrue()); break; } case Instruction::PtrToInt:{ assert(0 && "PtrToInt not implemented yet"); // ExprPtr e = encoder.encode(cast<PtrToIntInst>(it)); // ExprPtr impl = ExprUtils::mkImpl(pi.encode(), e); // vcs.addToE(impl); // psi2.add(impl); break; } case Instruction::VAArg:{ assert(0 && "VAArg not implemented yet"); // ExprPtr e = encoder.encode(cast<VAArgInst>(it)); // ExprPtr impl = ExprUtils::mkImpl(pi.encode(), e); // vcs.addToE(impl); // psi2.add(impl); break; } case Instruction::Invoke:{ assert(0 && "Invoke not implemented yet"); // ExprPtr e = encoder.encode(cast<InvokeInst>(it)); // ExprPtr impl = ExprUtils::mkImpl(pi.encode(), e); // vcs.addToE(impl); // psi2.add(impl); break; } case Instruction::Trunc:{ assert(0 && "Trunc not implemented yet"); // ExprPtr e = encoder.encode(cast<TruncInst>(it)); // ExprPtr impl = ExprUtils::mkImpl(pi.encode(), e); // vcs.addToE(impl); // psi2.add(impl); break; } case Instruction::FPTrunc:{ assert(0 && "FPTrunc not implemented yet"); // ExprPtr e = encoder.encode(cast<FPTruncInst>(it)); // ExprPtr impl = ExprUtils::mkImpl(pi.encode(), e); // vcs.addToE(impl); // psi2.add(impl); break; } case Instruction::FPExt:{ assert(0 && "FPExt not implemented yet"); // ExprPtr e = encoder.encode(cast<FPExtInst>(it)); // ExprPtr impl = ExprUtils::mkImpl(pi.encode(), e); // vcs.addToE(impl); // psi2.add(impl); break; } case Instruction::UIToFP:{ assert(0 && "UIToFP not implemented yet"); // ExprPtr e = encoder.encode(cast<UIToFPInst>(it)); // ExprPtr impl = ExprUtils::mkImpl(pi.encode(), e); // vcs.addToE(impl); // psi2.add(impl); break; } case Instruction::SIToFP:{ assert(0 && "SIToFP not implemented yet"); // ExprPtr e = encoder.encode(cast<SIToFPInst>(it)); // ExprPtr impl = ExprUtils::mkImpl(pi.encode(), e); // vcs.addToE(impl); // psi2.add(impl); break; } case Instruction::FPToUI:{ assert(0 && "FPToUI not implemented yet"); // ExprPtr e = encoder.encode(cast<FPToUIInst>(it)); // ExprPtr impl = ExprUtils::mkImpl(pi.encode(), e); // vcs.addToE(impl); // psi2.add(impl); break; } case Instruction::FPToSI:{ assert(0 && "FPToSI not implemented yet"); // ExprPtr e = encoder.encode(cast<FPToSIInst>(it)); // ExprPtr impl = ExprUtils::mkImpl(pi.encode(), e); // vcs.addToE(impl); // psi2.add(impl); break; } case Instruction::IntToPtr:{ assert(0 && "IntToPtr not implemented yet"); // ExprPtr e = encoder.encode(cast<IntToPtrInst>(it)); // ExprPtr impl = ExprUtils::mkImpl(pi.encode(), e); // vcs.addToE(impl); // psi2.add(impl); break; } case Instruction::BitCast:{ assert(0 && "BitCast not implemented yet"); // ExprPtr e = encoder.encode(cast<BitCastInst>(it)); // ExprPtr impl = ExprUtils::mkImpl(pi.encode(), e); // vcs.addToE(impl); // psi2.add(impl); break; } case Instruction::FCmp:{ assert(0 && "FCmp not implemented yet"); // ExprPtr e = encoder.encode(cast<FCmpInst>(it)); // ExprPtr impl = ExprUtils::mkImpl(pi.encode(), e); // vcs.addToE(impl); // psi2.add(impl); break; } case Instruction::ExtractElement:{ assert(0 && "ExtractElement not implemented yet"); // ExprPtr e = encoder.encode(cast<ExtractElementInst>(it)); // ExprPtr impl = ExprUtils::mkImpl(pi.encode(), e); // vcs.addToE(impl); // psi2.add(impl); break; } case Instruction::InsertElement:{ assert(0 && "InsertElement not implemented yet"); // ExprPtr e = encoder.encode(cast<InsertElementInst>(it)); // ExprPtr impl = ExprUtils::mkImpl(pi.encode(), e); // vcs.addToE(impl); // psi2.add(impl); break; } case Instruction::ShuffleVector:{ assert(0 && "ShuffleVector not implemented yet"); // ExprPtr e = encoder.encode(cast<ShuffleVectorInst>(it)); // ExprPtr impl = ExprUtils::mkImpl(pi.encode(), e); // vcs.addToE(impl); // psi2.add(impl); break; } case Instruction::ExtractValue:{ assert(0 && "ExtractValue not implemented yet"); // ExprPtr e = encoder.encode(cast<ExtractValueInst>(it)); // ExprPtr impl = ExprUtils::mkImpl(pi.encode(), e); // vcs.addToE(impl); // psi2.add(impl); break; } case Instruction::InsertValue:{ assert(0 && "InsertValue not implemented yet"); // ExprPtr e = encoder.encode(cast<InsertValueInst>(it)); // ExprPtr impl = ExprUtils::mkImpl(pi.encode(), e); // vcs.addToE(impl); // psi2.add(impl); break; } default: std::cout << "UNREACHABLE OPCODE: " << it->getOpcode() << std::endl; llvm_unreachable("Illegal opcode!"); } ++it; if(it != currentBB -> end()){ ExprPtr psi2 = ExprUtils::mkAnd(psi,enc->getExpr1()); ExprPtr gamma2 = ExprUtils::mkAnd(gamma,enc->getExpr2()); BinaryExprPtr enc2 = encodeInst(p,pcds,psi2,gamma2,it); return Expression::mkBinExpr(ExprUtils::mkAnd(enc -> getExpr1(), enc2 -> getExpr1()), ExprUtils::mkAnd(enc -> getExpr2(), enc2 -> getExpr2())); } else return enc; }
void encodeValue(bson *bb, const char *name, v8::Local<v8::Value> element, bool doJson) { if (element.IsEmpty() || element->IsUndefined() || element->IsFunction()) ; else if (element->IsNull()) bson_append_null(bb, name); else if (element->IsDate()) bson_append_date(bb, name, (bson_date_t) element->NumberValue()); else if (element->IsBoolean()) bson_append_bool(bb, name, element->IsTrue()); else if (element->IsNumber() || element->IsNumberObject()) { double value = element->NumberValue(); int64_t num = (int64_t) value; if (value == (double) num) { if (num >= -2147483648ll && num <= 2147483647ll) bson_append_int(bb, name, (int) num); else bson_append_long(bb, name, num); } else bson_append_double(bb, name, value); } else if (element->IsArray()) encodeArray(bb, name, element); else if (element->IsRegExp()) { v8::Local<v8::RegExp> re = v8::Local<v8::RegExp>::Cast(element); v8::Local<v8::String> src = re->GetSource(); v8::RegExp::Flags flgs = re->GetFlags(); char flgStr[4]; char *p = flgStr; if (flgs & v8::RegExp::kIgnoreCase) *p++ = 'i'; if (flgs & v8::RegExp::kGlobal) *p++ = 'g'; if (flgs & v8::RegExp::kMultiline) *p++ = 'm'; *p = 0; bson_append_regex(bb, name, *v8::String::Utf8Value(src), flgStr); } else if (element->IsObject()) { { obj_ptr<Int64> num = (Int64 *)Int64_base::getInstance(element); if (num) { if (num->m_num >= -2147483648ll && num->m_num <= 2147483647ll) bson_append_int(bb, name, (int) num->m_num); else bson_append_long(bb, name, num->m_num); return; } } { obj_ptr<Buffer_base> buf = Buffer_base::getInstance(element); if (buf) { std::string strBuf; buf->toString(strBuf); bson_append_binary(bb, name, BSON_BIN_BINARY, strBuf.c_str(), (int) strBuf.length()); return; } } { obj_ptr<MongoID> oid = (MongoID *) MongoID_base::getInstance( element); if (oid) { bson_append_oid(bb, name, &oid->m_id); return; } } encodeObject(bb, name, element, doJson); } else { v8::String::Utf8Value v(element); bson_append_string(bb, name, ToCString(v)); } }