bool LLVMVisitor::leaveAddExpression(AddExpression* expr) { if(expr->getRule() == AddExpressionEnum::Plus || expr->getRule() == AddExpressionEnum::Minus) { ASSERT_T_MSG(this->valueStack.size() >= 2u, format("%u stackSize(%u)", expr->getId(), this->valueStack.size()) ); auto rhs = this->valueStack.top(); auto rhsType = rhs->getType(); this->valueStack.pop(); auto lhs = this->valueStack.top(); auto lhsType = lhs->getType(); this->valueStack.pop(); LLVMDump(lhs); LLVMDump(rhs); ASSERT_EQ(valueStack.size(), 0u); if(rhsType->isIntegerTy() && rhsType->isIntegerTy()) { if(rhsType->getIntegerBitWidth() == lhsType->getIntegerBitWidth()) { this->valueStack.push( expr->getRule() == AddExpressionEnum::Plus ? this->builder.CreateAdd(lhs, rhs, "Add") : this->builder.CreateSub(lhs, rhs, "Sub") ); } else { throw LLVMVisitorException(format("%s operation" " between Integers of different size lhs(%u) rhs(%u)", expr->getRule() == AddExpressionEnum::Plus ? "Add" : "Minus", lhsType->getIntegerBitWidth(), rhsType->getIntegerBitWidth()), Loc()); } } if((rhsType->isFloatTy() || rhsType->isDoubleTy() || rhsType->isX86_FP80Ty()) && rhsType->getTypeID() == lhsType->getTypeID()) { this->valueStack.push( expr->getRule() == AddExpressionEnum::Plus ? this->builder.CreateFAdd(lhs, rhs, "Add") : this->builder.CreateFSub(lhs, rhs, "Sub") ); } else { throw LLVMVisitorException(format("%s operation" " between different float types of different size " "lhs(%u) rhs(%u)", expr->getRule() == AddExpressionEnum::Plus ? "Add" : "Minus", lhsType->getTypeID(), rhsType->getTypeID()), Loc()); } ASSERT_EQ(valueStack.size(), 1u); LLVMDump(this->valueStack.top()); } return true; }
/** * @brief Get the length of the ASCII string this TypedValue represents, * not counting a null terminator character, if any (same behavior * as strlen). * @warning This must only be used with string types (i.e. Char and VarChar). * * @return The length of the string represented by this TypedValue. **/ inline std::size_t getAsciiStringLength() const { DCHECK(getTypeID() == kChar || getTypeID() == kVarChar); DCHECK(!isNull()); if (getTypeID() == kChar) { return strnlen(static_cast<const char*>(value_union_.out_of_line_data), getDataSize()); } else { return getDataSize() - 1; } }
/** * @brief Get a pointer to the underlying data represented by this TypedValue. * @warning This must not be used with null values. * * @return A raw pointer to this TypedValue's data. **/ inline const void* getDataPtr() const { DCHECK(!isNull()); if (value_info_ & kSizeBitsMask) { // Data is out-of-line. DCHECK(!RepresentedInline(getTypeID())); return value_union_.out_of_line_data; } else { // According to the C standard, a pointer to a union points to each of // its members and vice versa (i.e. every non-bitfield member of a union // is always aligned at the front of the union itself). DCHECK(RepresentedInline(getTypeID())); return &value_union_; } }
Entity::~Entity() { for( int i = 0; i<Animations_Max ; i++) { if(allAnimations[i] != nullptr) { delete allAnimations[i]; allAnimations[i] = nullptr; } } if(getTypeID() == NPC_Boy2 || getTypeID() == NPC_Girl1 || getTypeID() == NPC_Girl2) { delete currentAnimation; } }
/** * @brief Make a reference pointing to the data represented by this * TypedValue. * @note If this is a literal which is represented in-line, then a literal * TypedValue will actually be returned, which is just as efficient as * a reference and requires less indirection. * * @return A reference to this TypedValue's data. **/ inline TypedValue makeReferenceToThis() const { if (ownsOutOfLineData()) { return TypedValue(getTypeID(), value_union_.out_of_line_data, getDataSize()); } else { return *this; } }
bool createIDMap(PAKFile &out, const ExtractInformation *eI, const int *needList) { int dataEntries = 0; // Count entries in the need list for (const int *n = needList; *n != -1; ++n) ++dataEntries; const int mapSize = 2 + dataEntries * (2 + 1 + 4); uint8 *map = new uint8[mapSize]; uint8 *dst = map; WRITE_BE_UINT16(dst, dataEntries); dst += 2; for (const int *id = needList; *id != -1; ++id) { WRITE_BE_UINT16(dst, *id); dst += 2; const ExtractFilename *fDesc = getFilenameDesc(*id); if (!fDesc) return false; *dst++ = getTypeID(fDesc->type); WRITE_BE_UINT32(dst, getFilename(eI, *id)); dst += 4; } char filename[12]; if (!getFilename(filename, eI, 0)) { fprintf(stderr, "ERROR: Could not create ID map for game\n"); return false; } out.removeFile(filename); if (!out.addFile(filename, map, mapSize)) { fprintf(stderr, "ERROR: Could not add ID map \"%s\" to kyra.dat\n", filename); return false; } return true; }
/** * Print a bitcast instruction. * * @param ty the destination type * @param srcTy the source type */ void JVMWriter::printBitCastInstruction(const Type *ty, const Type *srcTy) { char typeID = getTypeID(ty); char srcTypeID = getTypeID(srcTy); if(srcTypeID == 'J' && typeID == 'D') printSimpleInstruction("invokestatic", "java/lang/Double/longBitsToDouble(J)D"); else if(srcTypeID == 'I' && typeID == 'F') printSimpleInstruction("invokestatic", "java/lang/Float/intBitsToFloat(I)F"); if(srcTypeID == 'D' && typeID == 'J') printSimpleInstruction("invokestatic", "java/lang/Double/doubleToRawLongBits(D)J"); else if(srcTypeID == 'F' && typeID == 'I') printSimpleInstruction("invokestatic", "java/lang/Float/floatToRawIntBits(F)I"); }
llvm::Value * Generator::visit(Return & node) { llvm::Value * returnValue = nullptr; if (node.expression) { returnValue = node.expression->accept(this); auto type = returnValue->getType(); if (type->isVoidTy()) { returnValue = nullptr; } else if (type->getTypeID() == 14 || type->getTypeID() == 13) { returnValue = builder.CreateLoad(returnValue); } } return builder.CreateRet(returnValue); }
void Airspace::debug() { qDebug() << "AsName=" << getName() << "ASId=" << getId() << "AsType=" << getTypeName(getTypeID()) << "Country=" << getCountry() << "ULimit=" << m_uLimit.getMeters() << "LLimit=" << m_lLimit.getMeters(); }
/** * @brief Get the out-of-line data which this TypedValue points to. * @warning This must only be used with a TypedValue which has out-of-line * data (i.e. not NULL, and not a numeric nor a date type * which is represented in-line). * * @return The out-of-line data this TypedValue points to. **/ inline const void* getOutOfLineData() const { DCHECK(!(getTypeID() == kInt || getTypeID() == kLong || getTypeID() == kFloat || getTypeID() == kDouble || getTypeID() == kDatetime || getTypeID() == kDatetimeInterval || getTypeID() == kYearMonthInterval)); DCHECK(!isNull()); return value_union_.out_of_line_data; }
void SphereVtkOutput::configure() { bodies_.clear(); for( auto blockIt = blockStorage_.begin(); blockIt != blockStorage_.end(); ++blockIt ) { const Storage& bs = *(blockIt->getData<const Storage>( storageID_ )); for( auto it = bs[0].begin(); it != bs[0].end(); ++it ) { if (it->getTypeID() == Sphere::getStaticTypeID()) bodies_.push_back( static_cast<ConstSphereID> (*it) ); } } }
/** * @brief Get the size of this value's data. * @warning Only usable with non-NULL values. * * @return The size, in bytes, of this value's data. **/ inline std::size_t getDataSize() const { DCHECK(!isNull()); switch (getTypeID()) { case kInt: case kFloat: return sizeof(int); case kLong: case kDouble: case kDatetime: case kDatetimeInterval: case kYearMonthInterval: return sizeof(value_union_); default: return value_info_ >> kSizeShift; } }
//----[ compareTo ]---------------------------------------------------------- int Image::compareTo(const dc::dcGenericResource* other) const { if (!other || getTypeID() != other->getTypeID()) { return dc::dcGenericResource::compareTo(other); } else { bool this_is_wall = wall_texture_.getValue(); bool this_is_terrain = terrain_texture_.getValue() || this_is_wall; const Image* other_image = ((const Image*)other); bool other_is_wall = other_image->wall_texture_.getValue(); bool other_is_terrain = other_is_wall || other_image->terrain_texture_.getValue(); if (this_is_terrain && !other_is_terrain) return +1; if (!this_is_terrain && other_is_terrain) return -1; if (this_is_wall && !other_is_wall) return +1; if (!this_is_wall && other_is_wall) return -1; return 0; } }
Image ImageType::convert (const Image& source) const { if (source.isNull() || getTypeID() == (ScopedPointer<ImageType> (source.getPixelData()->createType())->getTypeID())) return source; const Image::BitmapData src (source, Image::BitmapData::readOnly); Image newImage (create (src.pixelFormat, src.width, src.height, false)); Image::BitmapData dest (newImage, Image::BitmapData::writeOnly); jassert (src.pixelStride == dest.pixelStride && src.pixelFormat == dest.pixelFormat); for (int y = 0; y < dest.height; ++y) memcpy (dest.getLinePointer (y), src.getLinePointer (y), (size_t) dest.lineStride); return newImage; }
void NPC::update(float _dt) { Entity::update(_dt); setSpeed(50.0f); //Set the endPosition in relation to their current Position if(!hasNewPosition) { endPosition.X = getAnchorPoint().X + rand() % 100 * (rand() % 2 ? 1.0f : -1.0f); endPosition.Y = getAnchorPoint().Y + rand() % 100 * (rand() % 2 ? 1.0f : -1.0f); hasNewPosition = true; } //Reduce the current Time timer += _dt; //Create a vector to the position Vector2 vel = endPosition - getPosition(); //If they are close dont move any more and pick a new spot if(vel.length() < 1.0f) { hasNewPosition = false; return; } //normalize the vector vel.normalize(); //Scale the vector vel *= getSpeed(); //Set the enemies Velocity setVelocity(vel); //Multiply the velocity by time and add to the position setPosition(getPosition() + vel * _dt); if(getTypeID() == NPC_Boy1) { vel.normalize(); setDirection(getEnumDirection(vel)); } }
Airspace* Airspace::createAirspaceObject() { // We need that method because the default constructor cannot setup a // complete airspace. The default constructor is only used as a collection // container during parsing of airspace source file. Airspace* as = new Airspace( getName(), getTypeID(), getProjectedPolygon(), m_uLimit.getFeet(), m_uLimitType, m_lLimit.getFeet(), m_lLimitType, m_id, getCountry() ); as->setFlarmAlertZone( m_flarmAlertZone ); return as; }
bool GCType::operator==(const GCType& other) const { if(getTypeID() == other.getTypeID()) switch(other.getTypeID()) { case FuncPtrTypeID: return *FuncPtrGCType::narrow(this) == (FuncPtrGCType&)other; case GCPtrTypeID: return *GCPtrGCType::narrow(this) == (GCPtrGCType&)other; case ArrayTypeID: return *ArrayGCType::narrow(this) == (ArrayGCType&)other; case StructTypeID: return *StructGCType::narrow(this) == (StructGCType&)other; case PrimTypeID: return *PrimGCType::narrow(this) == (PrimGCType&)other; case NativePtrTypeID: return *NativePtrGCType::narrow(this) == (NativePtrGCType&)other; } return false; }
bool TypedValue::isPlausibleInstanceOf(const TypeSignature type) const { TypeID type_id = getTypeID(); if (type_id != type.id) { return false; } if (isNull()) { return type.nullable; } switch (type_id) { case kInt: case kLong: case kFloat: case kDouble: case kDatetime: case kDatetimeInterval: case kYearMonthInterval: return true; case kChar: { size_t data_size = getDataSize(); if (data_size == type.length) { return true; } else if (data_size < type.length) { // If the data is shorter than the max size for a CHAR type, make sure // it is null-terminated. return (memchr(value_union_.out_of_line_data, '\0', data_size) != nullptr); } else { return false; } } case kVarChar: return getDataSize() <= (type.length + 1); default: { size_t data_size = getDataSize(); return (data_size <= type.length); } } }
bool Person::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper) { switch (variable) { case TRACI_ID_LIST: return wrapper->wrapStringList(objID, variable, getIDList()); case ID_COUNT: return wrapper->wrapInt(objID, variable, getIDCount()); case VAR_POSITION: return wrapper->wrapPosition(objID, variable, getPosition(objID)); case VAR_POSITION3D: return wrapper->wrapPosition(objID, variable, getPosition(objID, true)); case VAR_ANGLE: return wrapper->wrapDouble(objID, variable, getAngle(objID)); case VAR_SLOPE: return wrapper->wrapDouble(objID, variable, getSlope(objID)); case VAR_SPEED: return wrapper->wrapDouble(objID, variable, getSpeed(objID)); case VAR_ROAD_ID: return wrapper->wrapString(objID, variable, getRoadID(objID)); case VAR_LANEPOSITION: return wrapper->wrapDouble(objID, variable, getLanePosition(objID)); case VAR_COLOR: return wrapper->wrapColor(objID, variable, getColor(objID)); case VAR_WAITING_TIME: return wrapper->wrapDouble(objID, variable, getWaitingTime(objID)); case VAR_TYPE: return wrapper->wrapString(objID, variable, getTypeID(objID)); case VAR_NEXT_EDGE: return wrapper->wrapString(objID, variable, getNextEdge(objID)); case VAR_STAGES_REMAINING: return wrapper->wrapInt(objID, variable, getRemainingStages(objID)); case VAR_VEHICLE: return wrapper->wrapString(objID, variable, getVehicle(objID)); default: return false; } }
Image ImageType::convert (const Image& source) const { if (source.isNull() || getTypeID() == (std::unique_ptr<ImageType> (source.getPixelData()->createType())->getTypeID())) return source; const Image::BitmapData src (source, Image::BitmapData::readOnly); Image newImage (create (src.pixelFormat, src.width, src.height, false)); Image::BitmapData dest (newImage, Image::BitmapData::writeOnly); if (src.pixelStride == dest.pixelStride && src.pixelFormat == dest.pixelFormat) { for (int y = 0; y < dest.height; ++y) memcpy (dest.getLinePointer (y), src.getLinePointer (y), (size_t) dest.lineStride); } else { for (int y = 0; y < dest.height; ++y) for (int x = 0; x < dest.width; ++x) dest.setPixelColour (x, y, src.getPixelColour (x, y)); } return newImage; }
void Entity::update(float _dt) { if(getTypeID() == NPC_Boy2 || getTypeID() == NPC_Girl1 || getTypeID() == NPC_Girl2 || getTypeID() == NPC_MerchantFour|| getTypeID() == NPC_MerchantTwo || getTypeID() == NPC_MerchantThree) { collisionRect = Rect2(getPosition().X,getPosition().Y,32,32); return; } if(returnDirection()<8) { currentAnimation = allAnimations[returnDirection()]; } if(currentAnimation->frames.size()!=0) { currentAnimation->Update(_dt); collisionRect = currentAnimation->frames[currentAnimation->getCurrFrame()]->collisionRect; collisionRect.x = position.X - currentAnimation->frames[currentAnimation->getCurrFrame()]->anchorPoint.X; collisionRect.y = position.Y - currentAnimation->frames[currentAnimation->getCurrFrame()]->anchorPoint.Y; } }
serialization::TypedValue TypedValue::getProto() const { serialization::TypedValue proto; // NOTE(chasseur): To represent a NULL value, only the 'type_id' field of the // proto is filled in, and all the optional value fields are omitted. switch (getTypeID()) { case kInt: proto.set_type_id(serialization::Type::INT); if (!isNull()) { proto.set_int_value(getLiteral<int>()); } break; case kLong: proto.set_type_id(serialization::Type::LONG); if (!isNull()) { proto.set_long_value(getLiteral<std::int64_t>()); } break; case kFloat: proto.set_type_id(serialization::Type::FLOAT); if (!isNull()) { proto.set_float_value(getLiteral<float>()); } break; case kDouble: proto.set_type_id(serialization::Type::DOUBLE); if (!isNull()) { proto.set_double_value(getLiteral<double>()); } break; case kDatetime: proto.set_type_id(serialization::Type::DATETIME); if (!isNull()) { proto.set_datetime_value(value_union_.datetime_value.ticks); } break; case kDatetimeInterval: proto.set_type_id(serialization::Type::DATETIME_INTERVAL); if (!isNull()) { proto.set_datetime_interval_value(value_union_.datetime_interval_value.interval_ticks); } break; case kYearMonthInterval: proto.set_type_id(serialization::Type::YEAR_MONTH_INTERVAL); if (!isNull()) { proto.set_year_month_interval_value(value_union_.year_month_interval_value.months); } break; case kChar: proto.set_type_id(serialization::Type::CHAR); if (!isNull()) { proto.set_out_of_line_data(static_cast<const char*>(getOutOfLineData()), getDataSize()); } break; case kVarChar: proto.set_type_id(serialization::Type::VAR_CHAR); if (!isNull()) { proto.set_out_of_line_data(static_cast<const char*>(getOutOfLineData()), getDataSize()); } break; case kNullType: proto.set_type_id(serialization::Type::NULL_TYPE); DCHECK(isNull()); break; default: FATAL_ERROR("Unrecognized TypeID in TypedValue::getProto"); } return proto; }
void SocketServer::handle_conn(int sockfd) { //MPI_CONNECTION_INIT // TODO: check this! int argc = 0; #ifndef NDEBUG std::cout << "INFO" << ": trying MPI_Init " << std::endl; #endif MPI_Init( &argc, NULL ); #ifndef NDEBUG std::cout << "INFO" << ": ... done " << std::endl; #endif // Create MPI Structure int sizeOfData; MPI_Type_size( MPI_INT,&sizeOfData ); int array_of_block_lengths[2] = {1, 1}; MPI_Aint array_of_displacements[2] = {0, sizeOfData}; MPI_Datatype array_of_types[2] = { MPI_INT, MPI_INT }; MPI_Type_create_struct(2, array_of_block_lengths, array_of_displacements, array_of_types, &ArgListType); MPI_Type_commit(&ArgListType); // End of MPI struct client = MPI_COMM_WORLD; #ifndef NDEBUG std::cout << "DEBUG: Waiting for IR\n" << std::endl; #endif MPI_Status status; int mpi_server_tag = MPI_SERVER_TAG; int myrank; MPI_Comm_rank(client, &myrank); int mpi_server_rank =0; // TODO: check this! if(myrank==0) mpi_server_rank = 1; int incomingMessageSize=0; MPI_Probe(MPI_ANY_SOURCE, mpi_server_tag, client, &status); MPI_Get_count(&status,MPI_CHAR,&incomingMessageSize); char *module_ir_buffer = (char *) calloc(incomingMessageSize + 1 , sizeof(char)); MPI_Recv(module_ir_buffer, incomingMessageSize + 1, MPI_CHAR, MPI_ANY_SOURCE, mpi_server_tag, client, &status); #ifndef NDEBUG std::cout << "DEBUG: Recieved IR\n" << std::endl; #endif auto backend = parseIRtoBackend(module_ir_buffer); // notify client that calls can be accepted now by sending time taken for optimizing module and initialising backend const std::string readyStr(std::to_string(TimeDiffOpt.count()) + ":" + std::to_string(TimeDiffInit.count())); MPI_Send((void *)readyStr.c_str(), readyStr.size() , MPI_CHAR, mpi_server_rank, mpi_server_tag, client); free(module_ir_buffer); // initialise msg_buffer std::shared_ptr<char> msg_buffer((char*)calloc(MSG_BUFFER_SIZE, sizeof(char)), &free); while (1) { bzero(msg_buffer.get(), MSG_BUFFER_SIZE); // first acquire message length unsigned msg_length; auto UINT_MAX_str_len = std::to_string(UINT_MAX).length(); int num_chars = recv(sockfd, msg_buffer.get(), UINT_MAX_str_len + 1, 0); if (num_chars == 0) { std::cout << "Client assigned to process " << getpid() << " has closed its socket 3 \n"; exit(0); } if (num_chars < 0) error("ERROR, could not read from socket"); #ifndef NDEBUG //std::cout << getpid() << ": got message \"" << msg_buffer << "\"\n"; // TODO command line argument to print messages std::cout << getpid() << ": got message \n"; #endif llvm::Function* calledFunction = nullptr; std::vector<llvm::GenericValue> args; std::list<std::vector<llvm::GenericValue>::size_type> indexesOfPointersInArgs; llvm::GenericValue result = handleCall(backend.get(), msg_buffer.get(), calledFunction, args, indexesOfPointersInArgs); // reset buffer and write time taken to buffer bzero(msg_buffer.get(), MSG_BUFFER_SIZE); sprintf(msg_buffer.get(), ";%ld", (long)TimeDiffLastExecution.count()); //MPI_DATA_MOVEMENT //Send data back to the client //Create the MPI data structure //allocate memory for struct #ifndef TIMING auto StartTime = std::chrono::high_resolution_clock::now(); #endif struct ArgumentList argList[MAX_NUMBER_OF_ARGUMENTS]; MPI_Status status; //Create the structure int structSize=0; for (const auto& indexOfPtr : indexesOfPointersInArgs) { auto paramType = calledFunction->getFunctionType()->getParamType(indexOfPtr); while (paramType->getTypeID() == llvm::Type::ArrayTyID || paramType->getTypeID() == llvm::Type::PointerTyID) paramType = llvm::cast<llvm::SequentialType>(paramType)->getElementType(); if (paramType->getTypeID() == llvm::Type::IntegerTyID) { argList[structSize].typeofArg = ENUM_MPI_INT; } else { argList[structSize].typeofArg = ENUM_MPI_DOUBLE; } argList[structSize].sizeOfArg =argumentList[indexOfPtr].sizeOfArg; structSize++; } #ifndef NDEBUG std::cout << "\nMPI SERVER: Sending message back from server to client"; std::cout.flush(); #endif #ifndef NDEBUG std::cout << "\nMPI SERVER: Sending MPI Header"; std::cout.flush(); for (int i=0; i<structSize; i++) { std::cout << "\n MPI Sent DS : Size : " << argList[i].sizeOfArg << " Type" << argList[i].typeofArg ; std::cout.flush(); } #endif MPI_Send(argList, structSize, ArgListType, mpi_server_rank, mpi_server_tag, client); #ifndef NDEBUG std::cout << "\nMPI SERVER: Sent MPI Header"; std::cout.flush(); std::cout << "\nMPI SERVER: Sending data"; std::cout.flush(); #endif //Start sending individual arrrays for (const auto& indexOfPtr : indexesOfPointersInArgs) { auto paramType = calledFunction->getFunctionType()->getParamType(indexOfPtr); while (paramType->getTypeID() == llvm::Type::ArrayTyID || paramType->getTypeID() == llvm::Type::PointerTyID) paramType = llvm::cast<llvm::SequentialType>(paramType)->getElementType(); if (paramType->getTypeID() == llvm::Type::IntegerTyID) { MPI_Send(args[indexOfPtr].PointerVal,argList[indexOfPtr].sizeOfArg, MPI_INT, mpi_server_rank, mpi_server_tag, client); } else { MPI_Send(args[indexOfPtr].PointerVal, argList[indexOfPtr].sizeOfArg, MPI_DOUBLE, mpi_server_rank, mpi_server_tag, client); } free(args[indexOfPtr].PointerVal); } #ifndef TIMING auto EndTime = std::chrono::high_resolution_clock::now(); std::cout << "\n SERVR: MPI_DATA_TRANSFER S->C = " << std::chrono::duration_cast<std::chrono::microseconds>(EndTime - StartTime).count() << "\n"; #endif #ifndef NDEBUG std::cout << "\nMPI SERVER: Data sent"; std::cout.flush(); std::cout << "\nMPI SERVER: Return Messages sent"; std::cout.flush(); #endif char returnValStr[MAX_VAL_SIZE]; switch (calledFunction->getReturnType()->getTypeID()) { case llvm::Type::VoidTyID: sprintf(returnValStr, ":"); break; case llvm::Type::FloatTyID: sprintf(returnValStr, ":%a", result.FloatVal); break; case llvm::Type::DoubleTyID: sprintf(returnValStr, ":%la", result.DoubleVal); break; case llvm::Type::X86_FP80TyID: returnValStr[0]=':'; llvm::APFloat(llvm::APFloat::x87DoubleExtended, result.IntVal).convertToHexString(returnValStr+1, 0U, false, llvm::APFloat::roundingMode::rmNearestTiesToEven); break; case llvm::Type::FP128TyID: returnValStr[0]=':'; llvm::APFloat(llvm::APFloat::IEEEquad, result.IntVal).convertToHexString(returnValStr+1, 0U, false, llvm::APFloat::roundingMode::rmNearestTiesToEven); break; case llvm::Type::IntegerTyID: // Note: LLVM does not differentiate between signed/unsiged int types sprintf(returnValStr, ":%s", result.IntVal.toString(16,false).c_str()); break; default: error(std::string("ERROR, LLVM TypeID " + std::to_string(calledFunction->getReturnType()->getTypeID()) + " of result of function \"" + calledFunction->getName().str() + "\" is not supported").c_str()); } strcat(msg_buffer.get(), returnValStr); //Send the message MPI_Send(msg_buffer.get(), strlen(msg_buffer.get()), MPI_CHAR, mpi_server_rank, mpi_server_tag, client); MPI_Type_free(&ArgListType); // TODO: check this! MPI_Finalize(); } }
void ShmemServer::handle_conn() { #ifndef NDEBUG std::cout << "DEBUG" << ": got IR" << std::endl; #endif // initialize backend with received IR auto backend = parseIRtoBackend((char *) shmemptr); *(long *)shmemptr = TimeDiffOpt.count(); *(((long *)shmemptr) + 1) = TimeDiffInit.count(); // signal to client: got IR, ready to get calls, time measures in shmem sem_post(shmem_sem); while (1) { sem_wait(shmem_force_order_sem); // wait for call sem_wait(shmem_sem); sem_post(shmem_force_order_sem); #ifndef NDEBUG std::cout << "DEBUG" << ": got call \n"; #endif // check for exit symbol if (((char *)shmemptr)[0] == ';') { #ifndef NDEBUG std::cout << "DEBUG" << ": found exit symbol \n"; #endif break; } llvm::Function* calledFunction = nullptr; std::vector<llvm::GenericValue> args; std::list<std::vector<llvm::GenericValue>::size_type> indexesOfPointersInArgs; llvm::GenericValue result = handleCall(backend.get(), (char *) shmemptr, calledFunction, args, indexesOfPointersInArgs); auto shmempos = shmemptr; // write measured time to memory *(long *)shmempos = TimeDiffLastExecution.count(); shmempos = (long *)shmempos + 1; // write changes to args and result back to shared memory for (const auto& indexOfPtr : indexesOfPointersInArgs) { auto paramType = calledFunction->getFunctionType()->getParamType(indexOfPtr); while (paramType->getTypeID() == llvm::Type::ArrayTyID || paramType->getTypeID() == llvm::Type::PointerTyID) paramType = llvm::cast<llvm::SequentialType>(paramType)->getElementType(); if (paramType->getTypeID() == llvm::Type::IntegerTyID) { ShmemHelperFunctions::marshallArrayOfSizeAndTypeIntoMemory(args[indexOfPtr].PointerVal, args[indexOfPtr+1].IntVal.getSExtValue(), std::pair<llvm::Type::TypeID, unsigned>(paramType->getTypeID(), ((llvm::IntegerType*)paramType)->getBitWidth()), shmempos); } else ShmemHelperFunctions::marshallArrayOfSizeAndTypeIntoMemory(args[indexOfPtr].PointerVal, args[indexOfPtr+1].IntVal.getSExtValue(), std::pair<llvm::Type::TypeID, unsigned>(paramType->getTypeID(), 0U), shmempos); free(args[indexOfPtr].PointerVal); } switch (calledFunction->getReturnType()->getTypeID()) { case llvm::Type::VoidTyID: // void return break; case llvm::Type::FloatTyID: *(float *)shmempos = result.FloatVal; break; case llvm::Type::DoubleTyID: *(double *)shmempos = result.DoubleVal; break; case llvm::Type::X86_FP80TyID: { char tmpHexString[64]; llvm::APFloat(llvm::APFloat::x87DoubleExtended, result.IntVal).convertToHexString(tmpHexString, 0U, false, llvm::APFloat::roundingMode::rmNearestTiesToEven); *(long double *)shmempos = strtold(tmpHexString, nullptr); break; } case llvm::Type::FP128TyID: { char tmpHexString[64]; llvm::APFloat(llvm::APFloat::IEEEquad, result.IntVal).convertToHexString(tmpHexString, 0U, false, llvm::APFloat::roundingMode::rmNearestTiesToEven); *(long double *)shmempos = strtold(tmpHexString, nullptr); break; } case llvm::Type::IntegerTyID: // Note: LLVM does not differentiate between signed/unsiged int types switch (result.IntVal.getBitWidth()) { case 8: *(uint8_t *)shmempos = (uint8_t) result.IntVal.getZExtValue(); break; case 16: *(uint16_t *)shmempos = (uint16_t) result.IntVal.getZExtValue(); break; case 32: *(uint32_t *)shmempos = (uint32_t) result.IntVal.getZExtValue(); break; case 64: *(uint64_t *)shmempos = (uint64_t) result.IntVal.getZExtValue(); break; default: error(std::string("ERROR, integer bitwidth of " + std::to_string(result.IntVal.getBitWidth()) + " not supported").c_str()); } break; default: error(std::string("ERROR, LLVM TypeID " + std::to_string(calledFunction->getReturnType()->getTypeID()) + " of result of function \"" + calledFunction->getName().str() + "\" is not supported").c_str()); } #ifndef NDEBUG std::cout << "DEBUG" << ": signaling 'result is ready' to client \n"; #endif sem_post(shmem_sem); } }
HelperMesh JObjectLoader::getMesh(std::ifstream & stream){ std::string garbage, info; if(stream.eof()){ exit(0); } std::vector<glm::vec3> positions; std::vector<glm::vec3> normals; std::vector<glm::vec3> tangents; std::vector<glm::vec2> textureCoords; std::vector<GLuint> indices; HelperMesh mesh; stream >> mesh.meshName; stream.ignore(150,'\n'); bool nextMesh =false; do{ stream>> info; if(stream.eof()) break; switch(getTypeID(info)){ case VERTEX:{ glm::vec3 v; stream >> v.x >> v.y >> v.z; positions.push_back(v); stream.ignore(150,'\n'); break; }case NORMAL:{ glm::vec3 v; stream >> v.x >> v.y >> v.z; normals.push_back(v); stream.ignore(150,'\n'); break; }case TEX_COORD:{ glm::vec2 v; stream >> v.x >> v.y; textureCoords.push_back(v); stream.ignore(150,'\n'); break; }case INDEX: { std::string s1,s2,s3; stream >> s1 >> s2 >> s3; addToIndices(s1,s2,s3,indices); stream.ignore(150,'\n'); break; }case TANGENT:{ glm::vec3 v; stream >> v.x >> v.y >> v.z; tangents.push_back(v); stream.ignore(150,'\n'); break; }case MATERIAL:{ stream >> info; mesh.materialName = info; stream.ignore(150,'\n'); stream.ignore(150,'\n'); break; }case OBJECT:{ nextMesh = true; break; }case -1:{ // EOF nextMesh =true; break; } } }while(!stream.eof() && !nextMesh); std::vector<glm::vec3> newPos, newNormals, newTangents; std::vector<glm::vec2> newTexCoords; newPos.reserve(indices.size()); newNormals.reserve(indices.size()); newTangents.reserve(indices.size()); // newTexCoords.reserve(indices.size()/3); for(int i =0; i < indices.size(); i+=9){ newPos.push_back(positions[indices[i]]); newPos.push_back(positions[indices[i+3]]); newPos.push_back(positions[indices[i+6]]); newTexCoords.push_back(textureCoords[indices[i+1]]); newTexCoords.push_back(textureCoords[indices[i+4]]); newTexCoords.push_back(textureCoords[indices[i+7]]); newNormals.push_back(normals[indices[i+2]]); newNormals.push_back(normals[indices[i+5]]); newNormals.push_back(normals[indices[i+8]]); } std::vector<GLuint> temp; for(int i = 0; i < indices.size()/3; i ++){ temp.push_back(i); } mesh.indices = std::move(temp); mesh.positions = newPos; mesh.textureCoords = newTexCoords; mesh.normals = newNormals; // ERROR NOT EVEN SETTING VERTEs return mesh; }
/** * @brief Get the name of this Type. * @note Default version just returns the name from kTypeNames. Subclasses * may override this to provided additional information, like lengths. * * @return The human-readable name of this Type (if the Type is nullable, * this will include the NULL specifier). **/ virtual std::string getName() const { return std::string(kTypeNames[getTypeID()]).append(nullable_ ? " NULL" : ""); }