Example #1
0
Flow CFAnalysis::controlDependenceGraph(Flow& controlFlow) {
  LabelSet condLabels=conditionLabels(controlFlow);
  LabelSet targetLabels;
  Flow controlDependenceEdges;
  for(LabelSet::iterator i=condLabels.begin();i!=condLabels.end();++i) {
    SgNode* condition=getLabeler()->getNode(*i);
    cerr<<"DEBUG: cond:"<<condition->class_name()<<endl;
    SgNode* stmt=SgNodeHelper::getParent(condition);
    cerr<<"DEBUG: stmt:"<<stmt->class_name()<<endl;
    // while/dowhile/for
    if(SgNodeHelper::isLoopCond(condition)) {
      SgNode* loopBody=SgNodeHelper::getLoopBody(stmt);
      cerr<<"DEBUG: loopBody:"<<loopBody->class_name()<<endl;
      LabelSet loopBodyInitLabels=setOfInitialLabelsOfStmtsInBlock(loopBody);
      targetLabels=loopBodyInitLabels;
    }
    // if
    if(isSgIfStmt(stmt)) {
      SgNode* trueBranch=SgNodeHelper::getTrueBranch(stmt);
      LabelSet trueBranchInitLabels=setOfInitialLabelsOfStmtsInBlock(trueBranch);
      SgNode* falseBranch=SgNodeHelper::getFalseBranch(stmt);
      LabelSet falseBranchInitLabels=setOfInitialLabelsOfStmtsInBlock(falseBranch);
      targetLabels=trueBranchInitLabels+falseBranchInitLabels;
    }
    for(LabelSet::iterator j=targetLabels.begin();j!=targetLabels.end();++j) {
      controlDependenceEdges.insert(Edge(*i,EDGE_FORWARD,*j));
    }
  }
  return controlDependenceEdges;
}
Example #2
0
int CFAnalysis::reduceNode(Flow& flow, Label lab) {
  Flow inFlow=flow.inEdges(lab);
  Flow outFlow=flow.outEdges(lab);
  /* description of essential operations:
   *   inedges: (n_i,b)
   *   outedge: (b,n2) 
   *   remove(n_i,b)
   *   remove(b,n2)
   *   insert(n1,n2)
   */
  if(inFlow.size()==0 && outFlow.size()==0)
    return 0;

  if(inFlow.size()==0 || outFlow.size()==0) {
    Flow edges=inFlow+outFlow;
    flow.deleteEdges(edges);
    return 1;
  }

  for(Flow::iterator initer=inFlow.begin();initer!=inFlow.end();++initer) {
    for(Flow::iterator outiter=outFlow.begin();outiter!=outFlow.end();++outiter) {
      Edge e1=*initer;
      Edge e2=*outiter;
      Edge newEdge=Edge(e1.source,e1.types(),e2.target);
      flow.erase(e1);
      flow.erase(e2);
      flow.insert(newEdge);
    }
  }
  return 1;
}
Example #3
0
File: Flow.C Project: 8l/rose
Flow Flow::operator+(Flow& s2) {
  Flow result;
  result=*this;
  for(Flow::iterator i2=s2.begin();i2!=s2.end();++i2)
    result.insert(*i2);
  return result;
}
Example #4
0
int CFAnalyzer::reduceBlockBeginNodes(Flow& flow) {
  LabelSet labs=flow.nodeLabels();
  int cnt=0;
  for(LabelSet::iterator i=labs.begin();i!=labs.end();++i) {
	if(isSgBasicBlock(getNode(*i))) {
	  cnt++;
	  Flow inFlow=flow.inEdges(*i);
	  Flow outFlow=flow.outEdges(*i);

	  // multiple out-edges not supported yet
	  assert(outFlow.size()<=1); 

	  /* description of essential operations:
	   *   inedges: (n_i,b)
	   *   outedge: (b,n2) 
	   *   remove(n_i,b)
	   *   remove(b,n2)
	   *   insert(n1,n2)
	   */
	  for(Flow::iterator initer=inFlow.begin();initer!=inFlow.end();++initer) {
		Edge e1=*initer;
		Edge e2=*outFlow.begin();
		Edge newEdge=Edge(e1.source,e1.types(),e2.target);
		flow.erase(e1);
		flow.erase(e2);
		flow.insert(newEdge);
	  }
	}
  }
  return cnt;
}
Example #5
0
static int ntop_get_interface_flow_by_key(lua_State* vm) {
  NetworkInterface *ntop_interface;
  u_int32_t key;
  Flow *f;

  if(ntop_lua_check(vm, __FUNCTION__, 1, LUA_TNUMBER)) return(CONST_LUA_ERROR);
  key = (u_int32_t)lua_tonumber(vm, 1);

  lua_getglobal(vm, "ntop_interface");
  if((ntop_interface = (NetworkInterface*)lua_touserdata(vm, lua_gettop(vm))) == NULL) {
    handle_null_interface(vm);
    return(CONST_LUA_ERROR);
    // ntop_interface = ntop->getInterfaceId(0);
  }

  if(!ntop_interface) return(false);

  f = ntop_interface->findFlowByKey(key);

  if(f == NULL)
    return(false);
  else {
    f->lua(vm, true);
    return(true);
  }
}
Example #6
0
/*! 
  * \author Markus Schordan
  * \date 2013.
 */
int CFAnalysis::inlineTrivialFunctions(Flow& flow) {
  //cerr<<"Error: inlineTrivialFunctions is deactivated."<<endl;
  //exit(1);
  // 1) compute all functions that are called exactly once (i.e. number of pred in ICFG is 1)
  //    AND have the number of formal parameters is 0 AND have void return type.
  // 2) inline function
  // more advanced version will also clone function-CFGs, but this makes the mapping label<->code loose the 1-1 mapping property.
  int numInlined=0;
  LabelSet lnLabs=functionEntryLabels(flow);
  for(LabelSet::iterator i=lnLabs.begin();i!=lnLabs.end();++i) {
    LabelSet pred=flow.pred(*i);
    if(pred.size()==1) {
      Label lc=*pred.begin();
      ROSE_ASSERT(getLabeler()->isFunctionCallLabel(lc));
      // check the number of formal parameters of ln
      if(numberOfFunctionParameters(*i)==0 && isVoidFunction(*i)) {

        // reduce all four nodes: lc,ln,lx,lr (this also reduces a possibly existing local edge)
        Label ln=*i;
        Label lx=correspondingFunctionExitLabel(ln);
        LabelSet succ=flow.succ(lx);
        // since we have exactly one call there must be exactly one return edge
        ROSE_ASSERT(succ.size()==1);
        Label lr=*succ.begin();
        // reduce all four nodes now
        reduceNode(flow,lc);
        reduceNode(flow,ln);
        reduceNode(flow,lx);
        reduceNode(flow,lr);
        numInlined++;
      }
    }
  }
  return numInlined;
}
Example #7
0
int Colour_Generator::
PickColourPair(const size_t & beam,const size_t & index) {
  msg_Tracking()<<METHOD<<"(beam = "<<beam<<", index = "<<index<<"): "
		<<m_col[beam][index].size()<<" "<<m_col[1-beam][1-index].size();
  int col(-1);
  for (set<int>::iterator cit1=m_col[beam][index].begin();
       cit1!=m_col[beam][index].end();cit1++) {
    for (set<int>::iterator cit2=m_col[1-beam][1-index].begin();
	 cit2!=m_col[1-beam][1-index].end();cit2++) {
      if ((*cit1)==(*cit2)) {
	col = (*cit1);
	m_col[beam][index].erase(col);
	m_col[1-beam][1-index].erase(col);
	break;
      }
    }
    if (col!=-1) break;
  }
  if (col==-1) {
    Flow Flow;
    col = Flow.Counter();
    m_col[beam][1-index].insert(col);
    m_col[1-beam][index].insert(col);
  }
  msg_Tracking()<<" ---> "<<col<<".\n";
  return col;
}
Example #8
0
Flow* FlowHash::find(IpAddress *src_ip, IpAddress *dst_ip,
		     u_int16_t src_port, u_int16_t dst_port, 
		     u_int16_t vlanId, u_int8_t protocol,
		     bool *src2dst_direction) {

  u_int32_t hash = ((src_ip->key()+dst_ip->key()+src_port+dst_port+vlanId+protocol) % num_hashes);
  Flow *head = (Flow*)table[hash];
  u_int16_t num_loops = 0;
  
  while(head) {
    if((!head->idle())
       && head->equal(src_ip, dst_ip, src_port, dst_port, vlanId, protocol, src2dst_direction)) {
      if(num_loops > max_num_loops) {
	ntop->getTrace()->traceEvent(TRACE_INFO, "DEBUG: [Num loops: %u][hashId: %u]", num_loops, hash);
	max_num_loops = num_loops;
      }
      return(head);
    } else
      head = (Flow*)head->next(), num_loops++;
  }

  if(num_loops > max_num_loops) {
    ntop->getTrace()->traceEvent(TRACE_INFO, "DEBUG: [Num loops: %u][hashId: %u]", num_loops, hash);
    max_num_loops = num_loops;
  }

  return(NULL);
}
Example #9
0
void Colour_Generator::PickTwoColours(const size_t & beam,int * cols) {
  Flow flow;
  size_t index;
  cols[0] = cols[1] = -1;
  for (index=0;index<2;index++) {
    if (m_col[beam][index].size()==0) cols[index] = flow.Counter();
    else {
      cols[index] = (*m_col[beam][index].begin());
    }
  }
  if (cols[0]==cols[1]) {
    if (m_col[beam][0].size()==1 && m_col[beam][1].size()==1) {
      cols[ran->Get()>0.5?0:1] = flow.Counter();
    }
    else {
      index = m_col[beam][0].size()>m_col[beam][1].size()?0:1;
      set<int>::iterator cit=m_col[beam][index].begin();
      cit++;
      cols[index] = (*cit);
      m_col[beam][index].erase(cols[index]);
    }
  }
  for (index=0;index<2;index++) {
    if (cols[index]==(*m_col[beam][1-index].begin())) {
      m_col[beam][1-index].erase(cols[index]);
    }
  }
  msg_Tracking()<<METHOD<<" yields "<<cols[0]<<" "<<cols[1]<<".\n";
}
Example #10
0
/// Find the flow corresponding to the specified transport and remote IP
/// address and port.
Flow* FlowTable::find_flow(pjsip_transport* transport, const pj_sockaddr* raddr)
{
  Flow* flow = NULL;
  FlowKey key(transport->key.type, raddr);

  char buf[100];
  LOG_DEBUG("Find flow for transport %s (%d), remote address %s",
            transport->obj_name, transport->key.type,
            pj_sockaddr_print(raddr, buf, sizeof(buf), 3));

  pthread_mutex_lock(&_flow_map_lock);

  std::map<FlowKey, Flow*>::iterator i = _tp2flow_map.find(key);

  if (i != _tp2flow_map.end())
  {
    // Found a matching flow, so return this one.
    flow = i->second;

    // Increment the reference count on the flow.
    flow->inc_ref();

    LOG_DEBUG("Found flow record %p", flow);
  }

  pthread_mutex_unlock(&_flow_map_lock);

  return flow;
}
Example #11
0
File: Flow.C Project: 8l/rose
SPRAY::Flow Flow::reverseFlow() {
  Flow reverseFlow;
  for(Flow::iterator i=begin();i!=end();++i) {
    reverseFlow.insert(Edge((*i).target,(*i).getTypes(),(*i).source));
  }
  return reverseFlow;
}
Example #12
0
Flow CFAnalysis::WhileAndDoWhileLoopFlow(SgNode* node, 
                                         Flow edgeSet,
                                         EdgeType edgeTypeParam1,
                                         EdgeType edgeTypeParam2) {
  if(!(isSgWhileStmt(node) || isSgDoWhileStmt(node))) {
    throw SPRAY::Exception("Error: WhileAndDoWhileLoopFlow: unsupported loop construct.");
  }
  SgNode* condNode=SgNodeHelper::getCond(node);
  Label condLabel=getLabel(condNode);
  SgNode* bodyNode=SgNodeHelper::getLoopBody(node);
  assert(bodyNode);
  Edge edge=Edge(condLabel,EDGE_TRUE,initialLabel(bodyNode));
  edge.addType(edgeTypeParam1);
  Flow flowB=flow(bodyNode);
  LabelSet finalSetB=finalLabels(bodyNode);
  edgeSet+=flowB;
  edgeSet.insert(edge);
  // back edges in while (forward edges in do-while)
  for(LabelSet::iterator i=finalSetB.begin();i!=finalSetB.end();++i) {
    Edge e;
    if(SgNodeHelper::isCond(labeler->getNode(*i))) {
      e=Edge(*i,EDGE_FALSE,condLabel);
      e.addType(edgeTypeParam2);
    } else {
      e=Edge(*i,edgeTypeParam2,condLabel);
    }
    edgeSet.insert(e);
  }
  return edgeSet;
}
Example #13
0
File: Flow.C Project: 8l/rose
Flow Flow::inEdges(Label label) {
  Flow flow;
  for(Flow::iterator i=begin();i!=end();++i) {
    if((*i).target==label)
      flow.insert(*i);
  }
  flow.setDotOptionDisplayLabel(_dotOptionDisplayLabel);
  flow.setDotOptionDisplayStmt(_dotOptionDisplayStmt);
  return flow;
}
Example #14
0
File: Flow.C Project: 8l/rose
Flow Flow::edgesOfType(EdgeType edgeType) {
  Flow flow;
  for(Flow::iterator i=begin();i!=end();++i) {
    if((*i).isType(edgeType))
      flow.insert(*i);
  }
  flow.setDotOptionDisplayLabel(_dotOptionDisplayLabel);
  flow.setDotOptionDisplayStmt(_dotOptionDisplayStmt);
  return flow;
}
Example #15
0
File: Flow.hpp Project: fev2g/SGL
	/*!  Computes the minimum cut of a network */
	void operator()(int source) 
	{ 
		bfs_select(source); 
		for(unsigned int i = 0; i < vertices.size(); i++)
			if(vertices[i])
			{
				typename Graph::iterator it(G, i);
				for(Flow *e = it.beg(); !it.end(); e = it.nxt())
					if(!vertices[e->other(i)] /*&& e->capRto(e->other(i)) == 0*/ && e->from(i))
						cut.push_back(e);
			}
	}
Example #16
0
void GCN::show_flows()
{
    map<int, Flow*>::iterator flow_map_iter;
    Flow* flow;
    cout << endl << "---Short info about flows in Network " << endl;
    for(flow_map_iter = flow_map.begin(); flow_map_iter != flow_map.end(); ++flow_map_iter)
    {
        flow = flow_map_iter->second;
        flow->get_flow_info();
    }
    cout << endl;
}
Example #17
0
 void visitExpression(Expression* curr) {
   if (curr->is<Const>()) return;
   // try to evaluate this into a const
   Flow flow;
   try {
     flow = StandaloneExpressionRunner().visit(curr);
   } catch (StandaloneExpressionRunner::NonstandaloneException& e) {
     return;
   }
   if (flow.breaking()) return; // TODO: can create a break as a replacement in some cases (not NONSTANDALONE)
   if (isConcreteWasmType(flow.value.type)) {
     replaceCurrent(Builder(*getModule()).makeConst(flow.value));
   }
 }
Example #18
0
Flow *Flow::fromModelFlow(const ModelFlow *modelFlow)
{
    Flow *flow = new Flow();
    flow->_modelFlow = modelFlow;
    flow->setName(modelFlow->name());
    if(modelFlow->type()=="in")
        flow->setType(Input);
    else
        flow->setType(Output);

    Property *flowprop = Property::fromModelFlow(modelFlow);
    flow->_assocProperty = flowprop;

    return flow;
}
Example #19
0
void CFAnalyzer::intraInterFlow(Flow& flow, InterFlow& interFlow) {
  for(InterFlow::iterator i=interFlow.begin();i!=interFlow.end();++i) {
	if((*i).entry==Labeler::NO_LABEL && (*i).exit==Labeler::NO_LABEL) {
	  Edge externalEdge=Edge((*i).call,EDGE_EXTERNAL,(*i).callReturn);	  
	  flow.insert(externalEdge);
	} else {
	  Edge callEdge=Edge((*i).call,EDGE_CALL,(*i).entry);
	  Edge callReturnEdge=Edge((*i).exit,EDGE_CALLRETURN,(*i).callReturn);
	  Edge localEdge=Edge((*i).call,EDGE_LOCAL,(*i).callReturn);
	  flow.insert(callEdge);
	  flow.insert(callReturnEdge);
	  flow.insert(localEdge);
	}
  }
}
Example #20
0
DECLARE_EXPORT void Buffer::setOnHand(double f)
{
  // The dummy operation to model the inventory may need to be created
  Operation *o = Operation::find(INVENTORY_OPERATION);
  Flow *fl;
  if (!o)
  {
    // Create a fixed time operation with zero leadtime, hidden from the xml
    // output, hidden for the solver, and without problem detection.
    o = new OperationFixedTime();
    o->setName(INVENTORY_OPERATION);
    o->setHidden(true);
    o->setDetectProblems(false);
    fl = new FlowEnd(o, this, 1);
  }
  else
    // Find the flow of this operation
    fl = const_cast<Flow*>(&*(o->getFlows().begin()));

  // Check valid pointers
  if (!fl || !o)
    throw LogicException("Failed creating inventory operation for '"
        + getName() + "'");

  // Make sure the sign of the flow is correct: +1 or -1.
  fl->setQuantity(f>=0.0 ? 1.0 : -1.0);

  // Create a dummy operationplan on the inventory operation
  OperationPlan::iterator i(o);
  if (i == OperationPlan::end())
  {
    // No operationplan exists yet
    OperationPlan *opplan = o->createOperationPlan(
        fabs(f), Date::infinitePast, Date::infinitePast);
    opplan->setLocked(true);
    opplan->activate();
  }
  else
  {
    // Update the existing operationplan
    i->setLocked(false);
    i->setQuantity(fabs(f));
    i->setLocked(true);
  }
  setChanged();
}
Example #21
0
/**
 *\brief Add new extension NTP header into Flow.
 *\param [in] packet.
 *\param [out] rec Destination Flow.
 */
void NTPPlugin::add_ext_ntp(Flow &rec, const Packet &pkt)
{
   RecordExtNTP *ntp_data_ext = new RecordExtNTP();
   if (!parse_ntp(pkt, ntp_data_ext)) {
      delete ntp_data_ext; /*Don't add new extension packet.*/
   } else {
      rec.addExtension(ntp_data_ext); /*Add extension to  packet.*/
   }
}
Example #22
0
int CFAnalysis::reduceEmptyConditionNodes(Flow& flow) {
  LabelSet labs=conditionLabels(flow);
  int cnt=0;
  for(LabelSet::iterator i=labs.begin();i!=labs.end();++i) {
    if(flow.succ(*i).size()==1) {
      cnt+=reduceNode(flow,*i);
    }
  }
  return cnt;
}
Example #23
0
LabelSet CFAnalysis::functionEntryLabels(Flow& flow) {
  LabelSet resultSet;
  LabelSet nodeLabels;
  nodeLabels=flow.nodeLabels();
  for(LabelSet::iterator i=nodeLabels.begin();i!=nodeLabels.end();++i) {
    if(labeler->isFunctionEntryLabel(*i))
      resultSet.insert(*i);
  }
  return resultSet;
}
Example #24
0
int CFAnalysis::reduceBlockEndNodes(Flow& flow) {
  LabelSet labs=flow.nodeLabels();
  int cnt=0;
  for(LabelSet::iterator i=labs.begin();i!=labs.end();++i) {
    if(labeler->isBlockEndLabel(*i)) {
      cnt+=reduceNode(flow,*i);
    }
  }
  return cnt;
}
Example #25
0
/// Find or create a flow corresponding to the specified transport and remote
/// IP address and port. This is a single method to ensure it is atomic.
Flow* FlowTable::find_create_flow(pjsip_transport* transport, const pj_sockaddr* raddr)
{
  Flow* flow = NULL;
  FlowKey key(transport->key.type, raddr);

  char buf[100];
  LOG_DEBUG("Find or create flow for transport %s (%d), remote address %s",
            transport->obj_name, transport->key.type,
            pj_sockaddr_print(raddr, buf, sizeof(buf), 3));

  pthread_mutex_lock(&_flow_map_lock);

  std::map<FlowKey, Flow*>::iterator i = _tp2flow_map.find(key);

  if (i == _tp2flow_map.end())
  {
    // No matching flow, so create a new one.
    flow = new Flow(this, transport, raddr);

    // Add the new flow to the maps.
    _tp2flow_map.insert(std::make_pair(key, flow));
    _tk2flow_map.insert(std::make_pair(flow->token(), flow));

    LOG_DEBUG("Added flow record %p", flow);

    report_flow_count();
  }
  else
  {
    // Found a matching flow, so return this one.
    flow = i->second;

    LOG_DEBUG("Found flow record %p", flow);
  }

  // Add a reference to the flow.
  flow->inc_ref();

  pthread_mutex_unlock(&_flow_map_lock);

  return flow;
}
Example #26
0
static void CheckClock( StorageObject &s, Flow &inOrOut ) {

	if( Clock::getTime() ) {
		cout << "Attempt to connect " << s.name() << " and "
		     << inOrOut.name()
		     << " after start of simulation!!!" << endl;
		cout << "All connections must be established"
		     << " before the first clock tick." << endl;
		throw ArchLibError( "StorageObject connection attempted after start of simulation" );
	}
}
Flow* ParProTransitionGraph::toFlowEnumerateStates(NumberGenerator& numGen) {
  Flow* result = new Flow();
  unordered_map<const ParProEState*, Label> eState2Label;
  for (EStateTransitionMap::iterator i=_outEdges.begin(); i!=_outEdges.end(); i++) {
    for (ParProTransitions::iterator k=i->second.begin(); k!=i->second.end(); k++) {
      const ParProEState* source = (*k).source;
      if (eState2Label.find(source) == eState2Label.end()) {
	eState2Label[source] = Label(numGen.next());
      }
      const ParProEState* target = (*k).target;
      if (eState2Label.find(target) == eState2Label.end()) {
	eState2Label[target] = Label(numGen.next());
      }
      Edge e(eState2Label[source], eState2Label[target]);
      e.setAnnotation(k->edge.getAnnotation());
      result->insert(e);
    }
  }
  return result;
}
Example #28
0
int main(int argc, char **argv)
#endif
{

    try
    {
        Flow mainGame;
        mainGame.startFlow();
    }
    catch (std::exception& e)
    {
#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
        MessageBoxA(NULL, e.what(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
        fprintf(stderr, "An exception has occurred: %s\n", e.what());
#endif
    }

    return 0;
}
Example #29
0
/* This method returns the centerline spacing between an extrusion using this
   flow and another one using another flow.
   this->spacing(other) shall return the same value as other.spacing(*this) */
float
Flow::spacing(const Flow &other) const {
    assert(this->height == other.height);
    assert(this->bridge == other.bridge);
    
    if (this->bridge) {
        return this->width/2 + other.width/2 + BRIDGE_EXTRA_SPACING;
    }
    
    return this->spacing()/2 + other.spacing()/2;
}
Example #30
0
File: Flow.C Project: 8l/rose
/*! 
  * \author Markus Schordan
  * \date 2013.
 */
size_t Flow::deleteEdges(Flow& edges) {
  // MS: this function is supposed to allow a subset of edges of the very same graph as parameter
  // hence, we must be careful about iterator semantics
  size_t numDeleted=0;
  Flow::iterator i=edges.begin();
  while(i!=end()) {
    erase(i++); // MS: it is paramount to pass a copy of the iterator, and perform a post-increment.
    numDeleted++;
  }
  return numDeleted;
}