void test_capture_var() { template_capture_var<int>(); // OK template_capture_var<int&>(); // expected-note{{in instantiation of function template specialization 'template_capture_var<int &>' requested here}} Val<float> Obj; Obj.set(0.0f); // OK }
bool ValHeap:: upheap(int pos) { if(print) cerr << "in Upheap " << pos << " " << array.size() << endl; if(pos == 0) return false; Val* atp = array[pos]; assert(atp); double merit = atp->fom(); int parPos = parent(pos); Val* par = array[parPos]; double pmerit = par->fom(); if(print) cerr << "merits " << merit << " " << pmerit<< endl; if(merit > pmerit) { array[parPos] = atp; array[pos] = par; if(print) cerr << "Put " << pos << " in " << parPos << endl; upheap(parPos); return true; } else if(print) { cerr << "upheap of " << merit << "stopped by " << parPos << " " << pmerit << endl; } return false; }
Val* ClassRule:: apply(FullHist* treeh) { Val* trdTree = NULL; Bchart* cb = treeh->cb; assert(cb); Val* curVal = cb->curVal; Val* gcurVal = cb->gcurVal; int curDir = cb->curDir; //int wI = Feature::whichInt; //wcerr << "AP " << *this << endl; //if(curVal) wcerr << "APCV " << *curVal << endl; if(rel_ == 0) { trdTree = gcurVal; } else if(rel_ == 1) trdTree = sibling_tree(curVal, curDir); else if(rel_ == 2) trdTree = rel2_tree(curVal, curDir); else if(rel_ == 4) trdTree = curVal; else error(L"bad relation"); if(!trdTree) { return NULL; } int ct = trdTree->trm(); //wcerr << "foudn " << t_ << " " << ct << " " << *trdTree << endl; if(t_ != ct) { return NULL; } return trdTree; }
int Assignement::execute(Env* e, Store* s) { Val v = eval(s,e); if(v.getType() == EMPTY) { return 1; } return 0; }
static bool GetGlobalExport(JSContext* cx, const GlobalDescVector& globals, uint32_t globalIndex, const ValVector& globalImports, MutableHandleValue jsval) { const GlobalDesc& global = globals[globalIndex]; // Imports are located upfront in the globals array. Val val; switch (global.kind()) { case GlobalKind::Import: val = globalImports[globalIndex]; break; case GlobalKind::Variable: MOZ_CRASH("mutable variables can't be exported"); case GlobalKind::Constant: val = global.constantValue(); break; } switch (global.type()) { case ValType::I32: { jsval.set(Int32Value(val.i32())); return true; } case ValType::I64: { MOZ_ASSERT(JitOptions.wasmTestMode, "no int64 in asm.js/wasm"); RootedObject obj(cx, CreateI64Object(cx, val.i64())); if (!obj) return false; jsval.set(ObjectValue(*obj)); return true; } case ValType::F32: { float f = val.f32(); if (JitOptions.wasmTestMode && IsNaN(f)) { RootedObject obj(cx, CreateCustomNaNObject(cx, &f)); if (!obj) return false; jsval.set(ObjectValue(*obj)); return true; } jsval.set(DoubleValue(double(f))); return true; } case ValType::F64: { double d = val.f64(); if (JitOptions.wasmTestMode && IsNaN(d)) { RootedObject obj(cx, CreateCustomNaNObject(cx, &d)); if (!obj) return false; jsval.set(ObjectValue(*obj)); return true; } jsval.set(DoubleValue(d)); return true; } default: { break; } } MOZ_CRASH("unexpected type when creating global exports"); }
bool operator==(Val& v1, Val& v2) { if(v1.edge() != v2.edge()) return false; shortIter si2 = v2.vec().begin(); for(shortIter si = v1.vec().begin(); si != v1.vec().end() ; si++) { if((*si) != (*si2)) return false; si2++; } return true; }
int tree_ruleHead_third(FullHist* treeh) { Val* specTree = NULL; if(Feature::isLM) specTree = tree_ruleTree(treeh, 2); if(specTree) { FullHist* pt = treeh->back; if(!pt) return nullWordInt; int ans = pt->hd->toInt(); return ans; } Val* trdtree = tree_ruleTree(treeh,3); if(!trdtree) return nullWordInt; else return trdtree->wrd(); }
int fh_parent_head(FullHist* tree) { Val* spectree = NULL; if(Feature::isLM) spectree = tree_ruleTree(tree, 2); if(spectree) { //cerr << "found st " << endl; return spectree->wrd(); } FullHist* pt = tree->back; if(!pt) return nullWordInt; int ans = pt->hd->toInt(); assert(ans >= -1); return ans; }
template<typename T> inline static void toVal(Val& mV, T&& mX) { Arr result; result.reserve(sizeof...(TArgs)); // TODO: fwd macro? tplFor([&result](auto&& mI){ result.emplace_back(fwd<decltype(mI)>(mI)); }, fwd<T>(mX)); mV.setArr(std::move(result)); }
void AvgAggrLitPrinter::weight(const Val &v) { int num = v.number(); min_ = std::min(min_, num); max_ = std::max(max_, num); output_->addToList(symbol_, v); }
inline static bool SSVU_ATTRIBUTE(pure) areArrItemsOfType(const Val& mV) noexcept { SSVU_ASSERT(mV.is<Arr>()); for(const auto& v : mV.getArr()) if(!v.template isNoNum<T>()) return false; return true; }
template<typename T> inline static void toVal(Val& mV, T&& mX) { mV.setArr(Arr { Val{moveIfRValue<decltype(mX)>(mX.first)}, Val{moveIfRValue<decltype(mX)>(mX.second)} }); }
inline static EnableIf < TI<sizeof...(TArgs), bool> isTpl(const Val& mV) noexcept { SSVU_ASSERT(mV.is<Arr>() && mV.getArr().size() > TI); if(!mV[TI].isNoNum<TplArg<TI, Tpl<TArgs...>>>()) return false; return isTpl<TI + 1, TArgs...>(mV); }
void SumAggrLitPrinter::weight(const Val &v) { int num = v.number(); min_ += std::min(0, num); max_ += std::max(0, num); output_->addToList(symbol_, v); if(num < 0) { hasNeg_ = true; } if(pos_ && (num != 0 || head_)) { output_->addDep(symbol_); } }
Val *Parser::parseLitVal(){ Val *v; Type *ty; switch( curr() ){ case T_INTCONST: v=new Val( toint(text()) ); ty=Type::int32; break; case T_FLOATCONST: v=new Val( tofloat(text()) ); ty=Type::float32; break; default: exp( "integer or floating point literal value" ); } next(); ty=parseLitType( ty ); return v->cast( ty ); }
tribool ParityAggrLit::accumulate(Grounder *g, const Val &weight, Lit &lit) throw(const Val*) { (void)g; int32_t num = weight.number(); if(num % 2 == 0 && !head()) return true; if(set_ && !lit.testUnique(uniques_)) return true; if(!lit.fact()) factOnly_ = false; else if (num % 2 != 0) fixed_ = !fixed_; return lit.fact() ? tribool(true) : unknown; }
Val Call::eval(Store* s, Env* e) { function::Function *f = NULL; NFunction *nf = NULL; Val v = e->get(this->name); if(VERBOSE) cout << "call => " << name << endl; if(v.getType() == FUNCTION) { if(v.to_function()->getType() == NATIVE_FUNCTION) { nf = dynamic_cast<NFunction*>(v.to_function()); } else { f = dynamic_cast<function::Function*>(v.to_function()); } } else { f = ::getProgFunction(name); nf = ::getNativeFunction(name); } if(f != NULL) { Env *ne = new Env(f->getNbVar()); if(argument.size() != f->getArity()) { cout << "wrong arity during calling " << name << ", expected " << f->getArity() << ", " << argument.size() << " given " << endl; exit(1); } for(unsigned int i = 0; i < argument.size(); i++) { ne->set(i, argument[i]->eval(s,e), f->getVarName(i)); } f->execute(ne, s); Val v = ne->get(f->getNbVar()); delete ne; return v; } if(nf != NULL) { return nf->eval(s,e,argument, this->line(), this->file()); } cout << "undefined symbol " << name << endl; return Val(); }
vector<char> LodepngDecodePolicy::Encode(uImage img, bool flip) { Val data = flip ? invertImage(move(img.data), img.height, img.width * img.channels) : move(img.data); LodePNGColorType colortype = LCT_RGB; switch(img.channels) { case 1: colortype = LCT_GREY; break; case 3: colortype = LCT_RGB; break; case 4: colortype = LCT_RGBA; break; default: CASSERT(0, "Invalid channels for image saving"); } ubyte* buff = nullptr; size_t buff_s = 0; if(Val error = lodepng_encode_memory(&buff, &buff_s, data.data(), img.width, img.height, colortype, 8)) CERROR("Lodepng error: "<<lodepng_error_text(error)); vector<char> image(buff, buff + buff_s); free(buff); return image; }
Val Id::eval(Store* s, Env* e) { Val v = e->get(ref); if(v.to_s() == "(-> Empty <-)") { function::Function *f = ::getProgFunction(name); NFunction *nf = ::getNativeFunction(name); if(f == NULL) { if(nf == NULL) { cout << "variable " << name << " not define " << endl; } else { return Val(nf); } } else { //cout << "on a trouvé la fonction" << endl; return Val(f); } } return v; }
Val* Val:: newIth(int ith, Val* oval, bool& stop) { int ithc = oval->vec(ith); if(ithc > 0) stop = true; short nxtI = ithc +1;; //cerr<< "Wnt " << nxtI << "th var on pos " << ith << " of " << *oval<< endl; if(oval->wrd() >= 0) return NULL; //???; double ovalprob = oval->prob(); //if(oval->status == TERMINALVAL) return NULL; Val* nval = ithBst(ith,oval->bsts()).next(nxtI); if(!nval) return NULL; double ovalcompprob = ithBst(ith, oval->bsts()).nth(ithc)->prob(); double nprob = nval->prob(); //cerr << "Its prob is " << nprob << endl; if(nprob < 0) return NULL; Val* ans = new Val(oval); ans->vec(ith) = nxtI; double frac = nprob/ovalcompprob; ans->prob() *= frac; assert(nxtI <= ithBst(ith,ans->bsts()).num()); //cerr << "ith is " << ith << " " << ans->vec().size() << " " // << ans->vec()[ith] << " " << frac << endl; //cerr << "The var is " << *ans << endl; //assert(ans->check()); return ans; }
CGExp *Parser::parseLitExp( Type *ty ){ int sign=0; for(;;){ if( cparse('+') ){ }else if( cparse('-') ){ sign=sign ? -sign : -1; }else{ break; } } Val *v; switch( curr() ){ case T_INTCONST:{ int64 n=toint(text()); if( sign<0 ) n=-n; v=new Val( n ); next(); break; } case T_FLOATCONST:{ double n=tofloat(text()); if( sign<0 ) n=-n; v=new Val( n ); next(); break; } case T_STRINGCONST:{ if( sign ) exp( "Numeric or string literal value" ); v=new Val( parseBString() ); break; } default: exp( "Numeric or string literal value" ); } ty=parseLitType( ty ); v=v->cast( ty ); return v->cg_exp; }
void ValHeap:: downHeap(int pos) { if(print) cerr << "downHeap " << pos << endl; if(pos >= unusedPos_-1) return; Val* par = array[pos]; double merit = par->fom(); int lc = left_child(pos); int rc = right_child(pos); int largec; int lcthere = 0; Val* lct = NULL; if(lc < unusedPos_) { lct = array[lc]; if(lct) lcthere = 1; } int rcthere = 0; Val* rct = NULL; if(rc < unusedPos_) { rct = array[rc]; if(rct) rcthere = 1; } if(!lcthere && !rcthere) return; assert(lcthere); if(!rcthere || (lct->fom() > rct->fom())) largec = lc; else largec = rc; Val* largeatp = array[largec]; if(merit >= largeatp->fom()) { if(print) cerr << "downheap of " << merit << " stopped by " << " " << largeatp->fom() << endl; return; } array[pos] = largeatp; array[largec] = par; downHeap(largec); }
void test_capture_var() { // CHECK-5: define {{.*}} void @_Z20template_capture_varIiLj201EEvv // CHECK-5-NOT: } // CHECK-5: store i32* // CHECK-5: call void @__captured_stmt // CHECK-5-NEXT: ret void template_capture_var<int, 201>(); // CHECK-5: define {{.*}} void @_ZN3ValIfLi202EE3setEv // CHECK-5-NOT: } // CHECK-5: store %class.Val* // CHECK-5: call void @__captured_stmt // CHECK-5-NEXT: ret void Val<float, 202> Obj; Obj.set(); // CHECK-5: define {{.*}} void @_ZN3ValIfLi202EE3fooIdLi203EEEvT_ // CHECK-5-NOT: } // CHECK-5: store %class.Val* // CHECK-5: store double // CHECK-5: call void @__captured_stmt // CHECK-5-NEXT: ret void Obj.foo<double, 203>(1.0); }
bool DebugState::getGlobal(Instance& instance, uint32_t globalIndex, MutableHandleValue vp) { const GlobalDesc& global = metadata().globals[globalIndex]; if (global.isConstant()) { Val value = global.constantValue(); switch (value.type()) { case ValType::I32: vp.set(Int32Value(value.i32())); break; case ValType::I64: // Just display as a Number; it's ok if we lose some precision vp.set(NumberValue((double)value.i64())); break; case ValType::F32: vp.set(NumberValue(JS::CanonicalizeNaN(value.f32()))); break; case ValType::F64: vp.set(NumberValue(JS::CanonicalizeNaN(value.f64()))); break; default: MOZ_CRASH("Global constant type"); } return true; } uint8_t* globalData = instance.globalData(); void* dataPtr = globalData + global.offset(); switch (global.type()) { case ValType::I32: { vp.set(Int32Value(*static_cast<int32_t*>(dataPtr))); break; } case ValType::I64: { // Just display as a Number; it's ok if we lose some precision vp.set(NumberValue((double)*static_cast<int64_t*>(dataPtr))); break; } case ValType::F32: { vp.set(NumberValue(JS::CanonicalizeNaN(*static_cast<float*>(dataPtr)))); break; } case ValType::F64: { vp.set(NumberValue(JS::CanonicalizeNaN(*static_cast<double*>(dataPtr)))); break; } default: MOZ_CRASH("Global variable type"); break; } return true; }
tribool SumAggrLit::accumulate(Grounder *g, const Val &weight, Lit &lit) throw(const Val*) { (void)g; int32_t num = weight.number(); if(num == 0 && !head()) return true; if(set() && !lit.testUnique(uniques_)) return true; if(lit.fact()) { fixed_ += num; if(checkUpperBound_ && fixed_ > upperBound_) return false; } else { factOnly_ = false; if(num < 0) valLower_ += num; if(num > 0) valUpper_ += num; } return lit.fact() ? tribool(true) : unknown; }
template<typename T> inline static void toVal(Val& mV, T&& mX) { Arr result; result.reserve(TS); for(auto i(0u); i < TS; ++i) result.emplace_back(moveIfRValue<decltype(mX)>(mX[i])); mV.setArr(std::move(result)); }
template<typename T> inline static void toVal(Val& mVal, T&& mX) { mVal = Arr{}; for(auto& p : mX) mVal.getArr().emplace_back(moveIfRValue<decltype(mX)>(p)); }
template<typename T> inline static void toVal(Val& mV, T&& mX) { Arr result; result.reserve(mX.size()); for(const auto& v : mX) result.emplace_back(moveIfRValue<decltype(mX)>(v)); mV.setArr(std::move(result)); }
template<typename T> inline static void toVal(Val& mV, T&& mX) { Arr result; result.reserve(sizeof...(TArgs)); TplCnvHelper::fromTpl<0, TArgs...>(result, fwd<T>(mX)); mV.setArr(std::move(result)); }
inline static void toVal(Val& mV, const char* mX) { mV.setStr(mX); }