llvm::Function* FunctionAST::codegen() { debug_info_helper->emitLocation(getLoc()); llvm::Function* function = prototype_->codegen(); CHECK(function != nullptr); CurFunctionGuard guard(function); debug_info_helper->createFunction(function, getLoc(), false); std::string body_label = stringPrintf("%s.entry", function->getName().data()); llvm::BasicBlock* basic_block = llvm::BasicBlock::Create(*context, body_label, function); llvm::IRBuilder<>::InsertPointGuard InsertPointGuard(*cur_builder); cur_builder->SetInsertPoint(basic_block); // Don't allow to break on argument initialization. // global_debug_info.emitLocation(nullptr); auto arg_it = function->arg_begin(); for (size_t i = 0; i < function->arg_size(); ++i, ++arg_it) { llvm::Value* variable = createVariable(arg_it->getName(), getLoc(), i + 1); cur_builder->CreateStore(&*arg_it, variable); } // global_debug_info.emitLocation(nullptr); llvm::Value* ret_val = body_->codegen(); CHECK(ret_val != nullptr); cur_builder->CreateRet(ret_val); debug_info_helper->endFunction(); return function; }
void wheel::calc(glm::mat4* parent, glm::mat4* parent2) { oldHeight = getLoc().z; if(parent == NULL) { ModelMatrix = LocalMatrix * TurnMatrix * MoveMatrix; } else { ModelMatrix = (*parent) * (*parent2) * LocalMatrix * TurnMatrix * MoveMatrix; } newHeight = getLoc().z; }
llvm::Value* VariableExprAST::codegen() { debug_info_helper->emitLocation(getLoc()); llvm::Value* variable = getVariable(name_); if (variable == nullptr) { LOG(FATAL) << "Using unassigned variable: " << name_ << ", loc " << getLoc().toString(); } llvm::LoadInst* load_inst = cur_builder->CreateLoad(variable, getTmpName()); return load_inst; }
llvm::Value* AssignmentExprAST::codegen() { debug_info_helper->emitLocation(getLoc()); llvm::Value* variable = getVariable(var_name_); if (variable == nullptr) { variable = createVariable(var_name_, getLoc(), 0); } CHECK(variable != nullptr); llvm::Value* value = right_->codegen(); cur_builder->CreateStore(value, variable); return value; }
void Dsymbol::error(const char *format, ...) { va_list ap; va_start(ap, format); ::verror(getLoc(), format, ap, kind(), toPrettyChars()); va_end(ap); }
bool wheel::checkCollide(terrain* world) { tritest::Sphere s; glm::vec4 loc = getLoc(); s.c = glm::vec3(loc.x, loc.y, loc.z); s.r = radius; int gridX, gridY; world->getGridPos(loc.x, loc.y, gridX, gridY); for(int x = gridX-1; x<=gridX+1; x++) { if(x<0)continue; if(x>=world->width-1)break; for(int y = gridY-1; y<=gridY+1; y++) { if(y<0)continue; if(y>=world->height-1)break; Vertex* a = &world->model->vertices[x+y*world->width]; Vertex* b = &world->model->vertices[x+(y+1)*world->width]; Vertex* c = &world->model->vertices[x+1+y*world->width]; Vertex* d = &world->model->vertices[x+1+(y+1)*world->width]; /* glm::vec3 a = glm::vec3(x*world->gridSize, y*world->gridSize, world->getHeight(x,y)); glm::vec3 b = glm::vec3(x*world->gridSize, (y+1)*world->gridSize, world->getHeight(x,y+1)); glm::vec3 c = glm::vec3((x+1)*world->gridSize, y*world->gridSize, world->getHeight(x+1,y)); glm::vec3 d = glm::vec3((x+1)*world->gridSize, (y+1)*world->gridSize, world->getHeight(x+1,y+1));*/ if(checkCollide(world, s, a, b, d)) { return true; } if(checkCollide(world, s, a, c, d)) { return true; } } } return false; }
void Dsymbol::deprecation(const char *format, ...) { va_list ap; va_start(ap, format); ::vdeprecation(getLoc(), format, ap, kind(), toPrettyChars()); va_end(ap); }
llvm::Value* BlockExprAST::codegen() { debug_info_helper->emitLocation(getLoc()); llvm::Value* last_value = llvm::ConstantFP::get(*context, llvm::APFloat(0.0)); for (auto& expr : exprs_) { last_value = expr->codegen(); } return last_value; }
unsigned Map::didWin(char player) const { std::vector<bool> visited; std::vector<unsigned> route; Loc startLoc = {0,0}; unsigned int* incr = nullptr; if (player == US) { startLoc.y = 0; incr = &startLoc.x; } else { startLoc.x = 0; incr = &startLoc.y; } for (unsigned i = 0; i < BOARD_DIM; i++) { unsigned numSqs = 0; route.clear(); route.reserve(BOARD_SIZE * 2); visited.clear(); visited.assign(BOARD_SIZE, false); *incr = i; if (get(startLoc).owner != player) continue; unsigned start = get(startLoc).num; visited[start] = true; route.push_back(start); while (!route.empty()) { unsigned temp(route.back()); if (getLoc(temp).y == BOARD_DIM-1 && player == US) return numSqs; else if (getLoc(temp).x == BOARD_DIM-1 && player == ENEMY) return numSqs; route.pop_back(); std::vector<unsigned> adjs = getAdj(temp, player); for (unsigned j = 0; j < adjs.size(); j++) { if (visited[adjs[j]]) continue; visited[adjs[j]] = true; route.push_back(adjs[j]); if (orig->get(adjs[j]).owner == player) { numSqs++; } } } } return 0; }
void tokenize(const LangOptions &LangOpts, const SourceManager &SM, unsigned BufferID, unsigned Offset, unsigned EndOffset, CommentRetentionMode RetainComments, TriviaRetentionMode TriviaRetention, bool TokenizeInterpolatedString, ArrayRef<Token> SplitTokens, DF &&DestFunc) { assert((TriviaRetention != TriviaRetentionMode::WithTrivia || !TokenizeInterpolatedString) && "string interpolation with trivia is not implemented yet"); if (Offset == 0 && EndOffset == 0) EndOffset = SM.getRangeForBuffer(BufferID).getByteLength(); Lexer L(LangOpts, SM, BufferID, /*Diags=*/nullptr, /*InSILMode=*/false, RetainComments, TriviaRetention, Offset, EndOffset); auto TokComp = [&](const Token &A, const Token &B) { return SM.isBeforeInBuffer(A.getLoc(), B.getLoc()); }; std::set<Token, decltype(TokComp)> ResetTokens(TokComp); for (auto C = SplitTokens.begin(), E = SplitTokens.end(); C != E; ++C) { ResetTokens.insert(*C); } Token Tok; syntax::Trivia LeadingTrivia, TrailingTrivia; do { L.lex(Tok, LeadingTrivia, TrailingTrivia); // If the token has the same location as a reset location, // reset the token stream auto F = ResetTokens.find(Tok); if (F != ResetTokens.end()) { assert(F->isNot(tok::string_literal)); DestFunc(*F, syntax::Trivia(), syntax::Trivia()); auto NewState = L.getStateForBeginningOfTokenLoc( F->getLoc().getAdvancedLoc(F->getLength())); L.restoreState(NewState); continue; } if (Tok.is(tok::string_literal) && TokenizeInterpolatedString) { std::vector<Token> StrTokens; getStringPartTokens(Tok, LangOpts, SM, BufferID, StrTokens); for (auto &StrTok : StrTokens) { DestFunc(StrTok, syntax::Trivia(), syntax::Trivia()); } } else { DestFunc(Tok, LeadingTrivia, TrailingTrivia); } } while (Tok.getKind() != tok::eof); }
llvm::Value* CallExprAST::codegen() { debug_info_helper->emitLocation(getLoc()); llvm::Function* function = cur_module->getFunction(callee_); CHECK(function != nullptr); CHECK_EQ(function->arg_size(), args_.size()); std::vector<llvm::Value*> values; for (auto& arg : args_) { llvm::Value* value = arg->codegen(); values.push_back(value); } return cur_builder->CreateCall(function, values, getTmpName()); }
llvm::Function* PrototypeAST::codegen() { debug_info_helper->emitLocation(getLoc()); std::vector<llvm::Type*> doubles(args_.size(), llvm::Type::getDoubleTy(*context)); llvm::FunctionType* function_type = llvm::FunctionType::get(llvm::Type::getDoubleTy(*context), doubles, false); llvm::Function* function = llvm::Function::Create(function_type, llvm::GlobalValue::ExternalLinkage, name_, cur_module); auto arg_it = function->arg_begin(); for (size_t i = 0; i < function->arg_size(); ++i, ++arg_it) { arg_it->setName(args_[i]); } return function; }
/* Install an identifier in the global symbol table */ void Ginstall(char *NAME,int TYPE,int SIZE,ArgStruct *ARGLIST) { int i; struct Gsymbol *Gnode = malloc(sizeof(struct Gsymbol)); Gnode->NAME = malloc(sizeof(char) * (strlen(NAME)+1)); strcpy(Gnode->NAME,NAME); Gnode->ARGLIST = ARGLIST; Gnode->TYPE = TYPE; Gnode->SIZE = SIZE; Gnode->LOCATION = getLoc(); if(SIZE > 0) { for(i=0;i<SIZE-1;i++) getLoc(); } Gnode->NEXT = Ghead; Ghead = Gnode; }
/* Get_sep: Calculates the separation between two satellites along the satellite beam, in the normal- and parallel- to look direction. Inputs are: a state vector from scene 1, in GEI coordinates; the name of the ceos for image 2; the slant range and doppler of the center of the beam; and pointers to the output normal and parallel baselines. */ void get_sep(stateVector stVec1, meta_parameters *meta2, double range, double dop,double *Bn,double *Bp) { double lat,phi,earthRadius; vector target,up,relPos; vector upBeam,alongBeam,beamNormal; double t,timeDelta; stateVector stVec2; GEOLOCATE_REC *g; /*Target is the patch of ground at beam center.*/ /*Initialize the transformation.*/ g=init_geolocate_meta(&stVec1,meta2); getLoc(g,range,dop, &lat,&phi,&earthRadius); free_geolocate(g); sph2cart(earthRadius,lat,phi,&target); /*Create beam plane unit vectors.*/ vecSub(stVec1.pos,target,&alongBeam); vecNormalize(&alongBeam); up=stVec1.pos; vecNormalize(&up); vecCross(up,alongBeam,&beamNormal); vecNormalize(&beamNormal); vecCross(alongBeam,beamNormal,&upBeam); vecNormalize(&upBeam); /*Find the time when the second satellite crosses the first's beam.*/ t=0.0; stVec2=meta_get_stVec(meta2,t); timeDelta=1.0; while (fabs(timeDelta)>0.00001) { vecSub(stVec1.pos,stVec2.pos,&relPos); timeDelta=vecDot(beamNormal,relPos)/vecDot(beamNormal,stVec2.vel); t+=timeDelta; if (!quietflag) { printf(" Time=%f sec, delta=%f sec\n",t,timeDelta); printf(" Distance from beam plane=%f m\n",vecDot(beamNormal,relPos)); } stVec2=meta_get_stVec(meta2,t); } /*Now we have the second satellite sitting in the plane of the first's beam, so we just separate that position into components along-beam and across-beam, and return.*/ vecSub(stVec2.pos,stVec1.pos,&relPos); *Bp=vecDot(alongBeam,relPos); *Bn=vecDot(upBeam,relPos); }
llvm::Value* UnaryExprAST::codegen() { debug_info_helper->emitLocation(getLoc()); llvm::Value* right_value = right_->codegen(); CHECK(right_value != nullptr); std::string op_str = op_.desc; if (op_str == "-") { return cur_builder->CreateFNeg(right_value, getTmpName()); } llvm::Function* function = cur_module->getFunction("unary" + op_str); if (function != nullptr) { CHECK_EQ(1u, function->arg_size()); std::vector<llvm::Value*> values(1, right_value); return cur_builder->CreateCall(function, values, getTmpName()); } LOG(FATAL) << "Unexpected unary operator " << op_str; return nullptr; }
llvm::Value* BinaryExprAST::codegen() { debug_info_helper->emitLocation(getLoc()); llvm::Value* left_value = left_->codegen(); CHECK(left_value != nullptr); llvm::Value* right_value = right_->codegen(); CHECK(right_value != nullptr); llvm::Value* result = nullptr; std::string op_str = op_.desc; llvm::Function* function = cur_module->getFunction("binary" + op_str); if (function != nullptr) { CHECK_EQ(2u, function->arg_size()); std::vector<llvm::Value*> values; values.push_back(left_value); values.push_back(right_value); return cur_builder->CreateCall(function, values, getTmpName()); } if (op_str == "<") { result = cur_builder->CreateFCmpOLT(left_value, right_value, getTmpName()); } else if (op_str == "<=") { result = cur_builder->CreateFCmpOLE(left_value, right_value, getTmpName()); } else if (op_str == "==") { result = cur_builder->CreateFCmpOEQ(left_value, right_value, getTmpName()); } else if (op_str == "!=") { result = cur_builder->CreateFCmpONE(left_value, right_value, getTmpName()); } else if (op_str == ">") { result = cur_builder->CreateFCmpOGT(left_value, right_value, getTmpName()); } else if (op_str == ">=") { result = cur_builder->CreateFCmpOGT(left_value, right_value, getTmpName()); } else if (op_str == "+") { result = cur_builder->CreateFAdd(left_value, right_value, getTmpName()); } else if (op_str == "-") { result = cur_builder->CreateFSub(left_value, right_value, getTmpName()); } else if (op_str == "*") { result = cur_builder->CreateFMul(left_value, right_value, getTmpName()); } else if (op_str == "/") { result = cur_builder->CreateFDiv(left_value, right_value, getTmpName()); } else { LOG(FATAL) << "Unexpected binary operator " << op_str; } result = cur_builder->CreateUIToFP(result, llvm::Type::getDoubleTy(*context)); return result; }
llvm::Value* ForExprAST::codegen() { debug_info_helper->emitLocation(getLoc()); // Init block. ScopeGuard scoped_guard_init; init_expr_->codegen(); llvm::BasicBlock* init_end_block = cur_builder->GetInsertBlock(); // Cmp block. llvm::BasicBlock* cmp_begin_block = llvm::BasicBlock::Create(*context, "for_cmp", cur_function); cur_builder->SetInsertPoint(cmp_begin_block); llvm::Value* cond_value = cond_expr_->codegen(); llvm::BasicBlock* cmp_end_block = cur_builder->GetInsertBlock(); // Loop block. llvm::BasicBlock* loop_begin_block = llvm::BasicBlock::Create(*context, "for_loop", cur_function); cur_builder->SetInsertPoint(loop_begin_block); block_expr_->codegen(); next_expr_->codegen(); llvm::BasicBlock* loop_end_block = cur_builder->GetInsertBlock(); // After loop block. llvm::BasicBlock* after_loop_block = llvm::BasicBlock::Create(*context, "for_after_loop", cur_function); // Fix branches. cur_builder->SetInsertPoint(init_end_block); cur_builder->CreateBr(cmp_begin_block); cur_builder->SetInsertPoint(cmp_end_block); llvm::Value* cmp_value = cond_value; if (cmp_value->getType() == llvm::Type::getDoubleTy(*context)) { cmp_value = cur_builder->CreateFCmpONE(cond_value, llvm::ConstantFP::get(*context, llvm::APFloat(0.0))); } cur_builder->CreateCondBr(cmp_value, loop_begin_block, after_loop_block); cur_builder->SetInsertPoint(loop_end_block); cur_builder->CreateBr(cmp_begin_block); cur_builder->SetInsertPoint(after_loop_block); return llvm::ConstantFP::get(*context, llvm::APFloat(0.0)); }
llvm::Value* StringLiteralExprAST::codegen() { debug_info_helper->emitLocation(getLoc()); std::vector<llvm::Constant*> v; const char* p = val_.c_str(); llvm::IntegerType* char_type = llvm::IntegerType::get(*context, 8); do { v.push_back(llvm::ConstantInt::get(char_type, *p)); } while (*p++ != '\0'); llvm::ArrayType* array_type = llvm::ArrayType::get(char_type, val_.size() + 1); llvm::Constant* array = llvm::ConstantArray::get(array_type, v); llvm::GlobalVariable* variable = new llvm::GlobalVariable( *cur_module, array_type, true, llvm::GlobalValue::InternalLinkage, array); llvm::Type* int_type = llvm::Type::getInt32Ty(*context); llvm::Constant* zero = llvm::ConstantInt::get(int_type, 0); std::vector<llvm::Value*> v2(1, zero); llvm::Value* array_ptr = cur_builder->CreateInBoundsGEP(variable, v2); llvm::Type* char_ptype = llvm::Type::getInt8PtrTy(*context); return cur_builder->CreatePointerCast(array_ptr, char_ptype); }
void ModelRenderProcessor::doStep(const StepData& stepData) { auto sGConnector = graphics.lock(); if(!sGConnector) throw WeakPtrException(EXCEPTION_INFO); for(auto& i : idToObject) { View& object = i.second; object.doAnimationStep(stepData.stepMSec); mat4 mvpMatrix = stepData.perspectiveView * object.getTransform(); auto model = loader->getModelBy(object.getPath()); vector<Mesh3d>& meshes = model->getMeshes(); for(auto& s : meshes) { auto material = model->getMaterialBy(s); auto programName = material.getProgramName(); auto programContext = nameToProgramContext.at(programName); std::vector<IGraphicsConnector::ProgramParam> params; IGraphicsConnector::ProgramParam mvp; mvp.id = programContext->getLoc(programContext->getMvpBinding()); mvp.mat4 = std::make_shared<glm::mat4>(mvpMatrix); params.push_back(mvp); auto bonesData = prepareAnimationStep(object, s); string meshName = model->getUniqueMeshName(s); auto& buffer = meshToBuffer.at(meshName); sGConnector->draw(buffer, programContext, params, bonesData); } } StepData step = stepData; step.extraData = &idToObject; __super::doStep(step); }
llvm::Value* IfExprAST::codegen() { debug_info_helper->emitLocation(getLoc()); std::vector<llvm::BasicBlock*> cond_begin_blocks; std::vector<llvm::BasicBlock*> cond_end_blocks; std::vector<llvm::BasicBlock*> then_begin_blocks; std::vector<llvm::BasicBlock*> then_end_blocks; std::vector<llvm::Value*> cond_values; std::vector<llvm::Value*> then_values; for (size_t i = 0; i < cond_then_exprs_.size(); ++i) { // Cond block. if (i != 0) { llvm::BasicBlock* cond_block = llvm::BasicBlock::Create(*context, "if_cond", cur_function); cur_builder->SetInsertPoint(cond_block); } cond_begin_blocks.push_back(cur_builder->GetInsertBlock()); llvm::Value* cond_value = cond_then_exprs_[i].first->codegen(); cond_values.push_back(cond_value); cond_end_blocks.push_back(cur_builder->GetInsertBlock()); // Then block. llvm::BasicBlock* then_block = llvm::BasicBlock::Create(*context, "if_then", cur_function); cur_builder->SetInsertPoint(then_block); then_begin_blocks.push_back(cur_builder->GetInsertBlock()); llvm::Value* then_value = cond_then_exprs_[i].second->codegen(); then_values.push_back(then_value); then_end_blocks.push_back(cur_builder->GetInsertBlock()); } // Else block. llvm::BasicBlock* else_begin_block = llvm::BasicBlock::Create(*context, "if_else", cur_function); cur_builder->SetInsertPoint(else_begin_block); llvm::Value* else_value = llvm::ConstantFP::get(*context, llvm::APFloat(0.0)); if (else_expr_ != nullptr) { else_value = else_expr_->codegen(); } llvm::BasicBlock* else_end_block = cur_builder->GetInsertBlock(); llvm::BasicBlock* merge_block = llvm::BasicBlock::Create(*context, "if_endif", cur_function); // Fix up branches. for (size_t i = 0; i < cond_then_exprs_.size(); ++i) { cur_builder->SetInsertPoint(cond_end_blocks[i]); llvm::Value* cmp_value = cond_values[i]; if (cmp_value->getType() == llvm::Type::getDoubleTy(*context)) { cmp_value = cur_builder->CreateFCmpONE(cond_values[i], llvm::ConstantFP::get(*context, llvm::APFloat(0.0))); } cur_builder->CreateCondBr( cmp_value, then_begin_blocks[i], (i + 1 < cond_then_exprs_.size() ? cond_begin_blocks[i + 1] : else_begin_block)); cur_builder->SetInsertPoint(then_end_blocks[i]); cur_builder->CreateBr(merge_block); } cur_builder->SetInsertPoint(else_end_block); cur_builder->CreateBr(merge_block); cur_builder->SetInsertPoint(merge_block); llvm::PHINode* phi_node = cur_builder->CreatePHI(llvm::Type::getDoubleTy(*context), cond_then_exprs_.size() + 1, "iftmp"); for (size_t i = 0; i < cond_then_exprs_.size(); ++i) { phi_node->addIncoming(then_values[i], then_end_blocks[i]); } phi_node->addIncoming(else_value, else_end_block); return phi_node; }
void Shader::SetUniform2fv(const std::string& name, const float value[2])const { glUniform2fv(getLoc(program, name), 1, value); }
// // Do folding between a pair of nodes // TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNode) { TConstUnion *unionArray = getUnionArrayPointer(); int objectSize = getType().getObjectSize(); TConstUnion* newConstArray = 0; // For most cases, the return type matches the argument type, so set that // up and just code to exceptions below. TType returnType; returnType.shallowCopy(getType()); // // A pair of nodes is to be folded together // TIntermConstantUnion *node = constantNode->getAsConstantUnion(); TConstUnion *rightUnionArray = node->getUnionArrayPointer(); if (constantNode->getType().getObjectSize() == 1 && objectSize > 1) { // for a case like float f = vec4(2,3,4,5) + 1.2; rightUnionArray = new TConstUnion[objectSize]; for (int i = 0; i < objectSize; ++i) rightUnionArray[i] = *node->getUnionArrayPointer(); } else if (constantNode->getType().getObjectSize() > 1 && objectSize == 1) { // for a case like float f = 1.2 + vec4(2,3,4,5); rightUnionArray = node->getUnionArrayPointer(); unionArray = new TConstUnion[constantNode->getType().getObjectSize()]; for (int i = 0; i < constantNode->getType().getObjectSize(); ++i) unionArray[i] = *getUnionArrayPointer(); returnType.shallowCopy(node->getType()); objectSize = constantNode->getType().getObjectSize(); } int index = 0; bool boolNodeFlag = false; switch(op) { case EOpAdd: newConstArray = new TConstUnion[objectSize]; for (int i = 0; i < objectSize; i++) newConstArray[i] = unionArray[i] + rightUnionArray[i]; break; case EOpSub: newConstArray = new TConstUnion[objectSize]; for (int i = 0; i < objectSize; i++) newConstArray[i] = unionArray[i] - rightUnionArray[i]; break; case EOpMul: case EOpVectorTimesScalar: case EOpMatrixTimesScalar: newConstArray = new TConstUnion[objectSize]; for (int i = 0; i < objectSize; i++) newConstArray[i] = unionArray[i] * rightUnionArray[i]; break; case EOpMatrixTimesMatrix: newConstArray = new TConstUnion[getMatrixRows() * node->getMatrixCols()]; for (int row = 0; row < getMatrixRows(); row++) { for (int column = 0; column < node->getMatrixCols(); column++) { double sum = 0.0f; for (int i = 0; i < node->getMatrixRows(); i++) sum += unionArray[i * getMatrixRows() + row].getDConst() * rightUnionArray[column * node->getMatrixRows() + i].getDConst(); newConstArray[column * getMatrixRows() + row].setDConst(sum); } } returnType.shallowCopy(TType(getType().getBasicType(), EvqConst, 0, getMatrixRows(), node->getMatrixCols())); break; case EOpDiv: newConstArray = new TConstUnion[objectSize]; for (int i = 0; i < objectSize; i++) { switch (getType().getBasicType()) { case EbtDouble: case EbtFloat: newConstArray[i].setDConst(unionArray[i].getDConst() / rightUnionArray[i].getDConst()); break; case EbtInt: if (rightUnionArray[i] == 0) { newConstArray[i].setIConst(0xEFFFFFFF); } else newConstArray[i].setIConst(unionArray[i].getIConst() / rightUnionArray[i].getIConst()); break; case EbtUint: if (rightUnionArray[i] == 0) { newConstArray[i].setUConst(0xFFFFFFFF); } else newConstArray[i].setUConst(unionArray[i].getUConst() / rightUnionArray[i].getUConst()); break; default: return 0; } } break; case EOpMatrixTimesVector: newConstArray = new TConstUnion[getMatrixRows()]; for (int i = 0; i < getMatrixRows(); i++) { double sum = 0.0f; for (int j = 0; j < node->getVectorSize(); j++) { sum += unionArray[j*getMatrixRows() + i].getDConst() * rightUnionArray[j].getDConst(); } newConstArray[i].setDConst(sum); } returnType.shallowCopy(TType(getBasicType(), EvqConst, getMatrixRows())); break; case EOpVectorTimesMatrix: newConstArray = new TConstUnion[node->getMatrixCols()]; for (int i = 0; i < node->getMatrixCols(); i++) { double sum = 0.0f; for (int j = 0; j < getVectorSize(); j++) sum += unionArray[j].getDConst() * rightUnionArray[i*node->getMatrixRows() + j].getDConst(); newConstArray[i].setDConst(sum); } returnType.shallowCopy(TType(getBasicType(), EvqConst, node->getMatrixCols())); break; case EOpMod: newConstArray = new TConstUnion[objectSize]; for (int i = 0; i < objectSize; i++) newConstArray[i] = unionArray[i] % rightUnionArray[i]; break; case EOpRightShift: newConstArray = new TConstUnion[objectSize]; for (int i = 0; i < objectSize; i++) newConstArray[i] = unionArray[i] >> rightUnionArray[i]; break; case EOpLeftShift: newConstArray = new TConstUnion[objectSize]; for (int i = 0; i < objectSize; i++) newConstArray[i] = unionArray[i] << rightUnionArray[i]; break; case EOpAnd: newConstArray = new TConstUnion[objectSize]; for (int i = 0; i < objectSize; i++) newConstArray[i] = unionArray[i] & rightUnionArray[i]; break; case EOpInclusiveOr: newConstArray = new TConstUnion[objectSize]; for (int i = 0; i < objectSize; i++) newConstArray[i] = unionArray[i] | rightUnionArray[i]; break; case EOpExclusiveOr: newConstArray = new TConstUnion[objectSize]; for (int i = 0; i < objectSize; i++) newConstArray[i] = unionArray[i] ^ rightUnionArray[i]; break; case EOpLogicalAnd: // this code is written for possible future use, will not get executed currently newConstArray = new TConstUnion[objectSize]; for (int i = 0; i < objectSize; i++) newConstArray[i] = unionArray[i] && rightUnionArray[i]; break; case EOpLogicalOr: // this code is written for possible future use, will not get executed currently newConstArray = new TConstUnion[objectSize]; for (int i = 0; i < objectSize; i++) newConstArray[i] = unionArray[i] || rightUnionArray[i]; break; case EOpLogicalXor: newConstArray = new TConstUnion[objectSize]; for (int i = 0; i < objectSize; i++) { switch (getType().getBasicType()) { case EbtBool: newConstArray[i].setBConst((unionArray[i] == rightUnionArray[i]) ? false : true); break; default: assert(false && "Default missing"); } } break; case EOpLessThan: assert(objectSize == 1); newConstArray = new TConstUnion[1]; newConstArray->setBConst(*unionArray < *rightUnionArray); returnType.shallowCopy(TType(EbtBool, EvqConst)); break; case EOpGreaterThan: assert(objectSize == 1); newConstArray = new TConstUnion[1]; newConstArray->setBConst(*unionArray > *rightUnionArray); returnType.shallowCopy(TType(EbtBool, EvqConst)); break; case EOpLessThanEqual: { assert(objectSize == 1); TConstUnion constant; constant.setBConst(*unionArray > *rightUnionArray); newConstArray = new TConstUnion[1]; newConstArray->setBConst(!constant.getBConst()); returnType.shallowCopy(TType(EbtBool, EvqConst)); break; } case EOpGreaterThanEqual: { assert(objectSize == 1); TConstUnion constant; constant.setBConst(*unionArray < *rightUnionArray); newConstArray = new TConstUnion[1]; newConstArray->setBConst(!constant.getBConst()); returnType.shallowCopy(TType(EbtBool, EvqConst)); break; } case EOpEqual: if (getType().getBasicType() == EbtStruct) { if (! CompareStructure(node->getType(), node->getUnionArrayPointer(), unionArray)) boolNodeFlag = true; } else { for (int i = 0; i < objectSize; i++) { if (unionArray[i] != rightUnionArray[i]) { boolNodeFlag = true; break; // break out of for loop } } } newConstArray = new TConstUnion[1]; newConstArray->setBConst(! boolNodeFlag); returnType.shallowCopy(TType(EbtBool, EvqConst)); break; case EOpNotEqual: if (getType().getBasicType() == EbtStruct) { if (CompareStructure(node->getType(), node->getUnionArrayPointer(), unionArray)) boolNodeFlag = true; } else { for (int i = 0; i < objectSize; i++) { if (unionArray[i] == rightUnionArray[i]) { boolNodeFlag = true; break; // break out of for loop } } } newConstArray = new TConstUnion[1]; newConstArray->setBConst(! boolNodeFlag); returnType.shallowCopy(TType(EbtBool, EvqConst)); break; default: return 0; } TIntermConstantUnion *newNode = new TIntermConstantUnion(newConstArray, returnType); newNode->setLoc(getLoc()); return newNode; }
// // Do single unary node folding // TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TType& returnType) { TConstUnion *unionArray = getUnionArrayPointer(); int objectSize = getType().getObjectSize(); // First, size the result, which is mostly the same as the argument's size, // but not always. TConstUnion* newConstArray; switch (op) { // TODO: functionality: constant folding: finish listing exceptions to size here case EOpDeterminant: case EOpAny: case EOpAll: case EOpLength: newConstArray = new TConstUnion[1]; break; case EOpEmitStreamVertex: case EOpEndStreamPrimitive: // These don't actually fold return 0; default: newConstArray = new TConstUnion[objectSize]; } // Process non-component-wise operations switch (op) { case EOpLength: case EOpNormalize: { double sum = 0; for (int i = 0; i < objectSize; i++) sum += double(unionArray[i].getDConst()) * unionArray[i].getDConst(); double length = sqrt(sum); if (op == EOpLength) newConstArray[0].setDConst(length); else { for (int i = 0; i < objectSize; i++) newConstArray[i].setDConst(unionArray[i].getDConst() / length); } break; } default: break; } for (int i = 0; i < objectSize; i++) { switch (op) { case EOpNegative: switch (getType().getBasicType()) { case EbtDouble: case EbtFloat: newConstArray[i].setDConst(-unionArray[i].getDConst()); break; case EbtInt: newConstArray[i].setIConst(-unionArray[i].getIConst()); break; case EbtUint: newConstArray[i].setUConst(static_cast<unsigned int>(-static_cast<int>(unionArray[i].getUConst()))); break; default: return 0; } break; case EOpLogicalNot: case EOpVectorLogicalNot: switch (getType().getBasicType()) { case EbtBool: newConstArray[i].setBConst(!unionArray[i].getBConst()); break; default: return 0; } break; case EOpBitwiseNot: newConstArray[i] = ~unionArray[i]; break; case EOpRadians: newConstArray[i].setDConst(unionArray[i].getDConst() * pi / 180.0); break; case EOpDegrees: newConstArray[i].setDConst(unionArray[i].getDConst() * 180.0 / pi); break; case EOpSin: newConstArray[i].setDConst(sin(unionArray[i].getDConst())); break; case EOpCos: newConstArray[i].setDConst(cos(unionArray[i].getDConst())); break; case EOpTan: newConstArray[i].setDConst(tan(unionArray[i].getDConst())); break; case EOpAsin: newConstArray[i].setDConst(asin(unionArray[i].getDConst())); break; case EOpAcos: newConstArray[i].setDConst(acos(unionArray[i].getDConst())); break; case EOpAtan: newConstArray[i].setDConst(atan(unionArray[i].getDConst())); break; case EOpLength: case EOpNormalize: // handled above as special case break; case EOpDPdx: case EOpDPdy: case EOpFwidth: // The derivatives are all mandated to create a constant 0. newConstArray[i].setDConst(0.0); break; case EOpExp: newConstArray[i].setDConst(exp(unionArray[i].getDConst())); break; case EOpLog: newConstArray[i].setDConst(log(unionArray[i].getDConst())); break; case EOpExp2: { const double inv_log2_e = 0.69314718055994530941723212145818; newConstArray[i].setDConst(exp(unionArray[i].getDConst() * inv_log2_e)); break; } case EOpLog2: { const double log2_e = 1.4426950408889634073599246810019; newConstArray[i].setDConst(log2_e * log(unionArray[i].getDConst())); break; } case EOpSqrt: newConstArray[i].setDConst(sqrt(unionArray[i].getDConst())); break; case EOpInverseSqrt: newConstArray[i].setDConst(1.0 / sqrt(unionArray[i].getDConst())); break; case EOpAbs: if (unionArray[i].getType() == EbtDouble) newConstArray[i].setDConst(fabs(unionArray[i].getDConst())); else if (unionArray[i].getType() == EbtInt) newConstArray[i].setIConst(abs(unionArray[i].getIConst())); else newConstArray[i] = unionArray[i]; break; case EOpSign: #define SIGN(X) (X == 0 ? 0 : (X < 0 ? -1 : 1)) if (unionArray[i].getType() == EbtDouble) newConstArray[i].setDConst(SIGN(unionArray[i].getDConst())); else newConstArray[i].setIConst(SIGN(unionArray[i].getIConst())); break; case EOpFloor: newConstArray[i].setDConst(floor(unionArray[i].getDConst())); break; case EOpTrunc: if (unionArray[i].getDConst() > 0) newConstArray[i].setDConst(floor(unionArray[i].getDConst())); else newConstArray[i].setDConst(ceil(unionArray[i].getDConst())); break; case EOpRound: newConstArray[i].setDConst(floor(0.5 + unionArray[i].getDConst())); break; case EOpRoundEven: { double flr = floor(unionArray[i].getDConst()); bool even = flr / 2.0 == floor(flr / 2.0); double rounded = even ? ceil(unionArray[i].getDConst() - 0.5) : floor(unionArray[i].getDConst() + 0.5); newConstArray[i].setDConst(rounded); break; } case EOpCeil: newConstArray[i].setDConst(ceil(unionArray[i].getDConst())); break; case EOpFract: { double x = unionArray[i].getDConst(); newConstArray[i].setDConst(x - floor(x)); break; } case EOpIsNan: { newConstArray[i].setBConst(isNan(unionArray[i].getDConst())); break; } case EOpIsInf: { newConstArray[i].setBConst(isInf(unionArray[i].getDConst())); break; } // TODO: Functionality: constant folding: the rest of the ops have to be fleshed out case EOpSinh: case EOpCosh: case EOpTanh: case EOpAsinh: case EOpAcosh: case EOpAtanh: case EOpFloatBitsToInt: case EOpFloatBitsToUint: case EOpIntBitsToFloat: case EOpUintBitsToFloat: case EOpPackSnorm2x16: case EOpUnpackSnorm2x16: case EOpPackUnorm2x16: case EOpUnpackUnorm2x16: case EOpPackHalf2x16: case EOpUnpackHalf2x16: case EOpDeterminant: case EOpMatrixInverse: case EOpTranspose: case EOpAny: case EOpAll: default: return 0; } } TIntermConstantUnion *newNode = new TIntermConstantUnion(newConstArray, returnType); newNode->getWritableType().getQualifier().storage = EvqConst; newNode->setLoc(getLoc()); return newNode; }
void GLUniform<glm::mat4>::apply(glm::mat4& val){ glUniformMatrix4fv(getLoc(),1,GL_FALSE,glm::value_ptr(val)); }
Process::Process(QObject *parent) : QObject(parent) { isBarcodeLocated = false; connect(&Locator,SIGNAL(sendBarcodeLocation(cv::Rect)) , this , SLOT(getLoc(cv::Rect)) ); connect(&Locator,SIGNAL(sendIsBarcodeLocated(bool)) , this , SLOT(getIsBarcode(bool)) ); }
llvm::Value* NumberExprAST::codegen() { debug_info_helper->emitLocation(getLoc()); return llvm::ConstantFP::get(*context, llvm::APFloat(val_)); }
void GLUniform<GLfloat>::apply(GLfloat& val){ glUniform1f(getLoc(),val); }
char *Dsymbol::locToChars() { return getLoc().toChars(); }
void GLUniform<GLint>::apply(GLint& val){ glUniform1i(getLoc(),val); }
void GLUniform<glm::vec4>::apply(glm::vec4& val){ glUniform4fv(getLoc(),1,glm::value_ptr(val)); }