static void forstmt(int lab, Swtch swp, int lev) { int once = 0; Tree e1 = NULL, e2 = NULL, e3 = NULL; Coordinate pt2, pt3; t = gettok(); expect('('); definept(NULL); if (kind[t] == ID) e1 = texpr(expr0, ';', FUNC); else expect(';'); walk(e1, 0, 0); pt2 = src; refinc *= 10.0; if (kind[t] == ID) e2 = texpr(conditional, ';', FUNC); else expect(';'); pt3 = src; if (kind[t] == ID) e3 = texpr(expr0, ')', FUNC); else { static char stop[] = { IF, ID, '}', 0 }; test(')', stop); } if (e2) { once = foldcond(e1, e2); if (!once) branch(lab + 3); } definelab(lab); statement(lab, swp, lev); definelab(lab + 1); definept(&pt3); if (e3) walk(e3, 0, 0); if (e2) { if (!once) definelab(lab + 3); definept(&pt2); walk(e2, lab, 0); } else { definept(&pt2); branch(lab); } if (findlabel(lab + 2)->ref) definelab(lab + 2); }
void BlockObj::logBlock(ExpandedModel* emrow,ExpandedModel* emcol) { ostringstream oss; oss<<GV(logdir)<<emrow->qualifiedName()<<"_"<<emcol->qualifiedName()<<".objblk"; ofstream out(oss.str().c_str()); string objname = emrow->model->obj_comp==NULL? "null":emrow->model->obj_comp->name; out<<"Objective Block - (Assume to be Partial)"<<endl; out<<"Objective Declared/Row Model: "<<emrow->name<<"\t\t Name:"<<objname<<endl; out<<"Variables Declared/Col Model: "<<emrow->name<<"\t\t Size:"<<emrow->numLocalVars<<endl; out<<endl; out<<endl<<"Local Variables:"<<endl; vector<string> conNames, varNames; std::vector<VarComp*>::iterator varcomp=emrow->model->var_comps.begin(); for(;varcomp!=emrow->model->var_comps.end();varcomp++) { Var* var = static_cast<Var*>(emrow->ctx.getCompValue(*varcomp)); var_multi_map_by_order& var_by_order = var->varMultiMap.get<0>(); var_multi_map_by_order::iterator ivar = var_by_order.begin(); for(;ivar!=var_by_order.end();ivar++) { string name = emrow->name+"_"+var->name+"_"+(*ivar)->indicies; out<<"\t"<<name<<"\t\t"<<(*ivar)->toString()<<endl; } } out<<endl<<"Object Constraint"<<endl; string node_expr = this->objective==NULL?"NULL":texpr(this->objective); out<<"\t"<<objname<<"\t\t"<<node_expr<<endl; //printing dependent block information out<<endl; out.flush(); }
//_______________________________________________________________________________ // Generates a vector with all the indices of this category that satisfy the // given cuts std::vector<size_t> Analysis::TreeCategory::MakeSlice( std::string cuts, bool check ) { std::vector<size_t> treeEntries; Analysis::TreeBoolExpression texpr( cuts, fTree, check ); for ( auto it = fTreeEntries.begin(); it != fTreeEntries.end(); it++ ) { fTree -> GetEntry( *it ); if ( texpr.Evaluate() ) treeEntries.push_back( *it ); } return treeEntries; }
//_______________________________________________________________________________ // Makes a new histogram for a expression TH1* Analysis::TreeCategory::MakeHistogram( std::string name, std::string expr, size_t nbins, double vmin, double vmax, std::string cuts, bool check ) { std::string hname = ( name + "_" + fName ).c_str(); // The returned histogram is always double-valued TH1 *hist = new TH1D( hname.c_str(), hname.c_str(), nbins, vmin, vmax );; std::vector<size_t> ventries; if ( cuts.size() ) ventries = this -> MakeSlice( cuts, check ); else ventries = fTreeEntries; Analysis::TreeDoubleExpression texpr( expr, fTree, check ); for ( auto it = ventries.begin(); it != ventries.end(); it++ ) { fTree -> GetEntry( *it ); hist -> Fill( texpr.Calculate() ); } return hist; }
/** * Parse and execute a script command. */ void exec_script (char *cmd) { const char *t; uint32_t v, count; tlast = NULL; /* Blank lines and comments are ignored */ t = tfirst (cmd); if (!t) return; if (*t == '#') return; /*********** capture [subcommand] [args...] ***************/ if (teq (t, "capture")) { struct signal_expression *ex; t = tnext (); if (teq (t, "start")) { ex = texpr (); signal_capture_start (ex); } else if (teq (t, "stop")) { ex = texpr (); signal_capture_stop (ex); } else if (teq (t, "debug")) { } else if (teq (t, "file")) { t = tnext (); signal_capture_set_file (t); } else if (teq (t, "add")) { signal_capture_add (tsigno ()); } else if (teq (t, "del")) { signal_capture_del (tsigno ()); } } /*********** set [var] [value] ***************/ else if (teq (t, "set")) { t = tnext (); v = tconst (); conf_write (t, v); } /*********** p/print [var] ***************/ else if (teq (t, "p") || teq (t, "print")) { v = tconst (); simlog (SLC_DEBUG, "%d", v); } /*********** include [filename] ***************/ else if (teq (t, "include")) { t = tnext (); exec_script_file (t); } /*********** sw [id] ***************/ else if (teq (t, "sw")) { v = tsw (); count = tconst (); if (count == 0) count = 1; while (count > 0) { sim_switch_depress (v); count--; } } /*********** swtoggle [id] ***************/ else if (teq (t, "swtoggle")) { v = tsw (); count = tconst (); if (count == 0) count = 1; while (count > 0) { sim_switch_toggle (v); count--; } } /*********** key [keyname] [switch] ***************/ else if (teq (t, "key")) { t = tnext (); v = tsw (); simlog (SLC_DEBUG, "Key '%c' = %s", *t, names_of_switches[v]); sim_key_install (*t, v); } /*********** push [value] ***************/ else if (teq (t, "push")) { v = tconst (); conf_push (v); } /*********** pop [argcount] ***************/ else if (teq (t, "pop")) { v = tconst (); conf_pop (v); } /*********** sleep [time] ***************/ else if (teq (t, "sleep")) { v = tconst (); simlog (SLC_DEBUG, "Sleeping for %d ms", v); v /= IRQS_PER_TICK; do { task_sleep (TIME_16MS); } while (--v > 0); simlog (SLC_DEBUG, "Awake again.", v); } /*********** exit ***************/ else if (teq (t, "exit")) { sim_exit (0); } }
/** * Parse a complex expression and return a * signal_expression that describes it. */ struct signal_expression *texpr (void) { struct signal_expression *ex, *ex1, *ex2; const char *t; t = tnext (); if (!t) return NULL; ex = expr_alloc (); if (teq (t, "at")) { ex->op = SIG_TIME; ex->u.timer = tconst (); } else if (teq (t, "after")) { ex->op = SIG_TIMEDIFF; ex->u.timer = tconst (); } else { tunget (t); ex->op = SIG_SIGNO; ex->u.signo = tsigno (); simlog (SLC_DEBUG, "Signo changed = 0x%X\n", ex->u.signo); t = tnext (); if (t) { if (teq (t, "is")) { ex1 = ex; ex2 = expr_alloc (); ex2->op = SIG_CONST; ex2->u.value = tconst (); ex = expr_alloc (); ex->op = SIG_EQ; ex->u.binary.left = ex1; ex->u.binary.right = ex2; } } } t = tnext (); if (t) { ex1 = ex; ex2 = texpr (); ex = expr_alloc (); ex->u.binary.left = ex1; ex->u.binary.right = ex2; if (teq (t, "and")) ex->op = SIG_AND; else if (teq (t, "or")) ex->op = SIG_OR; } return ex; }