예제 #1
0
//=================================================================================
/*virtual*/ Node::ValueStringError BoundedPointListNode::SetValueFromString( const std::string& valueString )
{
	VarMap varMap;
	if( !ConvertValueStringToVarMap( valueString, varMap ) )
		return VSE_SYNTAX;

	Bounds trialBounds = bounds;
	if( varMap.end() != varMap.find( "xMin" ) )
		trialBounds.min.set_e1( varMap[ "xMin" ] );
	if( varMap.end() != varMap.find( "xMax" ) )
		trialBounds.max.set_e1( varMap[ "xMax" ] );
	if( varMap.end() != varMap.find( "yMin" ) )
		trialBounds.min.set_e2( varMap[ "yMin" ] );
	if( varMap.end() != varMap.find( "yMax" ) )
		trialBounds.max.set_e2( varMap[ "yMax" ] );

	if( trialBounds == bounds )
		return VSE_NO_CHANGE;
	if( !trialBounds.IsValid() )
		return VSE_INVALID;
	if( !SetBounds( trialBounds ) )
		return VSE_INVALID;

	return VSE_NONE;
}
예제 #2
0
//=================================================================================
/*virtual*/ Node::ValueStringError BoundedIntegerNode::SetValueFromString( const std::string& valueString )
{
    VarMap varMap;
    if( !ConvertValueStringToVarMap( valueString, varMap ) )
        return VSE_SYNTAX;

    Data trialData = data;
    if( varMap.end() != varMap.find( "min" ) )
        trialData.min = int( varMap[ "min" ] );
    if( varMap.end() != varMap.find( "max" ) )
        trialData.max = int( varMap[ "max" ] );
    if( varMap.end() != varMap.find( "value" ) )
        trialData.value = int( varMap[ "value" ] );
    if( varMap.end() != varMap.find( "multiple" ) )
        trialData.multiple = int( varMap[ "multiple" ] );

    if( !trialData.IsValid() )
        return VSE_INVALID;

    if( trialData == data )
        return VSE_NO_CHANGE;

    data = trialData;
    return VSE_NONE;
}
예제 #3
0
파일: output.cpp 프로젝트: msayagh/srcSlice
void TestSlice2(const VarMap& mp){
	for(VarMap::const_iterator vmIt = mp.begin(); vmIt != mp.end(); ++vmIt){
		std::cerr<<"-------------------------"<<std::endl;
		std::cerr<<"Variable: "<<vmIt->first<<std::endl;
		std::cerr<<"Slines: {";
		for(unsigned int sl : vmIt->second.slines){
			std::cerr<<sl<<",";
		}
		std::cerr<<"}"<<std::endl;
		std::cerr<<"dvars: {";
		for(std::string dv : vmIt->second.dvars){
			std::cerr<<dv<<",";
		}
		std::cerr<<"}"<<std::endl;
		std::cerr<<"is aliase for: {";
		for(std::string al : vmIt->second.aliases){
			std::cerr<<al<<",";
		}
		std::cerr<<"}"<<std::endl;
		std::cerr<<"cfuntions: {";
		for(auto cfunc : vmIt->second.cfunctions){
			std::cerr<<cfunc.first<<" "<<cfunc.second<<",";
		}
		std::cerr<<"}"<<std::endl;
		std::cerr<<"-------------------------"<<std::endl;
	}
}
예제 #4
0
bool generateOutTuple(std::vector<std::string> &s, lindaTuple &newTuple, 
		      VarMap &localVars, 
		      FunctSet &userDefinedFuncs, LoopMap &loopSymbols, int threadNum) {
  for (std::vector<std::string>::iterator it = s.begin(); it != s.end(); it++) {
    if (isExp(*it)) {
      int result = evaluateExp(*it, loopSymbols, userDefinedFuncs, localVars, threadNum);
      if (result != -1) {
	newTuple.push_back(new intObj(result));
      } else {
	// wait and block
      }
    } else if (isVarPattern(*it)) {
      if (localVars.find(*it) != localVars.end()) {
	newTuple.push_back(localVars[*it]);
      } else {
	std::cout<< "Can not find local var " << *it << std::endl;
	return false;
      }
    }
    else if (isString(*it))
      newTuple.push_back(new stringObj(*it));
    else if (isInt(*it))
      newTuple.push_back(new intObj(atoi(it->c_str())));
    else if (isDouble(*it))
      newTuple.push_back(new doubleObj(atof(it->c_str())));
    else {
      std::cout << "Parse input error: " << *it << std::endl;
      exit(EXIT_FAILURE);
    }
  }
  return true;
}
예제 #5
0
파일: V3Delayed.cpp 프로젝트: torc-isi/torc
    AstVarScope* createVarSc(AstVarScope* oldvarscp, string name, int width/*0==fromoldvar*/) {
	// Because we've already scoped it, we may need to add both the AstVar and the AstVarScope
	if (!oldvarscp->scopep()) oldvarscp->v3fatalSrc("Var unscoped");
	AstVar* varp;
	AstNodeModule* addmodp = oldvarscp->scopep()->modp();
	// We need a new AstVar, but only one for all scopes, to match the new AstVarScope
	VarMap::iterator iter = m_modVarMap.find(make_pair(addmodp,name));
	if (iter != m_modVarMap.end()) {
	    // Created module's AstVar earlier under some other scope
	    varp = iter->second;
	} else {
	    if (width==0) {
		varp = new AstVar (oldvarscp->fileline(), AstVarType::BLOCKTEMP, name, oldvarscp->varp());
		varp->widthSignedFrom(oldvarscp);
	    } else { // Used for vset and dimensions, so can zero init
		varp = new AstVar (oldvarscp->fileline(), AstVarType::BLOCKTEMP, name, AstBitPacked(), width);
	    }
	    addmodp->addStmtp(varp);
	    m_modVarMap.insert(make_pair(make_pair(addmodp, name), varp));
	}

	AstVarScope* varscp = new AstVarScope (oldvarscp->fileline(), oldvarscp->scopep(), varp);
	oldvarscp->scopep()->addVarp(varscp);
	return varscp;
    }
예제 #6
0
	void ClientOptions::insertVarMapIntoDOM(ticpp::Element* parent, const VarMap &vars)
	{
		for (VarMap::const_iterator it = vars.begin(), end = vars.end(); it != end; ++it)
		{
			ticpp::Element* var = new ticpp::Element("var");
			var->SetAttribute("name", it->first.c_str());
			var->SetAttribute("value", it->second.c_str());
			parent->LinkEndChild( var );
		}
	}
예제 #7
0
//=================================================================================
/*virtual*/ Node::ValueStringError BivectorE3GANode::SetValueFromString( const std::string& valueString )
{
	VarMap varMap;
	if( !ConvertValueStringToVarMap( valueString, varMap ) )
		return VSE_SYNTAX;

	// Get the new bivector.
	c3ga::bivectorE3GA trialBivector = *bivector;
	if( varMap.end() != varMap.find( "yz" ) )
		trialBivector.set_e2_e3( varMap[ "yz" ] );
	if( varMap.end() != varMap.find( "zx" ) )
		trialBivector.set_e3_e1( varMap[ "zx" ] );
	if( varMap.end() != varMap.find( "xy" ) )
		trialBivector.set_e1_e2( varMap[ "xy" ] );
	
	// Validate the new bivector.
	if( c3ga::norm( trialBivector ) > maxArea )
		return VSE_INVALID;

	// Get the new max-area.
	double trialMaxArea = maxArea;
	if( varMap.end() != varMap.find( "maxArea" ) )
		trialMaxArea = varMap[ "maxArea" ];

	// Validate the new max-area.
	if( trialMaxArea <= 0.0 )
		return VSE_INVALID;
	
	// Reject if no change occurred.
	if( c3ga::equals( trialBivector, *bivector, 0.0 ) && trialMaxArea == maxArea )
		return VSE_NO_CHANGE;

	// Accept the new values.
	*bivector = trialBivector;
	maxArea = trialMaxArea;
	return VSE_NONE;
}
예제 #8
0
파일: Node.cpp 프로젝트: spencerparkin/Junk
//=================================================================================
/*static*/ bool Node::ConvertValueStringFromVarMap( std::string& valueString, const VarMap& varMap )
{
	valueString = "";
	for( VarMap::const_iterator iter = varMap.begin(); iter != varMap.end(); iter++ )
	{
		std::string key = iter->first;
		double numericalValue = iter->second;
		std::ostringstream stream;
		stream << numericalValue;
		std::string value = stream.str();
		if( !valueString.empty() )
			valueString += ", ";
		valueString += key + "=" + value;
	}

	return true;
}
예제 #9
0
    virtual void visit(AstVarRef* nodep, AstNUser*) {
	if (nodep->lvalue() && !nodep->user2()) {
	    nodep->user2(true); // mark this ref as visited
	    AstVar* key = nodep->varp();

	    VarMap::iterator it = m_lhsmapp->find(key);
	    if (it == m_lhsmapp->end()) {
		// this key does not exist yet, so create it
		RefVec* refs = new RefVec();
		refs->push_back(nodep);
		m_lhsmapp->insert(pair<AstVar*, RefVec*>(key, refs));
	    } else {
		(*it).second->push_back(nodep);
	    }
	    nodep->user3p(m_sel); // attach the sel to this varref
	}
	nodep->iterateChildren(*this);
    }
예제 #10
0
int evaluateExp(std::string expr, LoopMap &loopSymbols, FunctSet &userDefinedFuncs, VarMap &localVars, int threadNum) {
  int result = -1;
  std::string expName = (expr).substr(0, (expr).find("("));
  std::string expNameT = expName + std::to_string(static_cast<long long int>(threadNum));
  size_t start = (expr).find("(") + 1;
  size_t end = (expr).find_last_of(")");
  std::string params = (expr).substr(start, end - start);

  if (userDefinedFuncs.find(expNameT) != userDefinedFuncs.end()) {
    // Case 1: The expression is a user defined function
    if (!isInt(params)) {
      if (loopSymbols.find(params) != loopSymbols.end()) {
	params = std::to_string(static_cast<long long int>(loopSymbols[params]));
      } else if (localVars.find(params) != localVars.end()) {
	intObj *intO = dynamic_cast<intObj *>(localVars[params]);
	params = std::to_string(static_cast<long long int>(intO->get()));
      }
    }
    int status = system(("./" + expNameT + " " + params).c_str());
    result = WEXITSTATUS(status);
  } else {
    // Case 2: The expression is inp or rdp
    //std::cout << "condition is " << expr << std::endl;
    LINDA_TYPE type = findFunctionType(expr);
    //std::cout << "expr type is " << type << std::endl;
    std::vector<std::string> elems;
    if (type == INP) {
      getInOutElems(expr, elems);
      return inp(elems, localVars, userDefinedFuncs, loopSymbols, threadNum);
    } else if (type == RDP) {
      getInOutElems(expr, elems);
      return rdp(elems, localVars, userDefinedFuncs, loopSymbols, threadNum);
    } else {
      std::cout << "Couldn't evaluate expression " << expr << std::endl;
      std::cout << "No boolean return type or couldn't find expr name" << std::endl;
      exit(EXIT_FAILURE);
    } 
  }
  return result;
}
예제 #11
0
//=================================================================================
/*virtual*/ Node::ValueStringError ConeNode::SetValueFromString( const std::string& valueString )
{
	ValueStringError vse = VectorE3GANode::SetValueFromString( valueString );
	if( !( vse == VSE_NONE || vse == VSE_NO_CHANGE ) )
		return vse;

	VarMap varMap;
	if( !ConvertValueStringToVarMap( valueString, varMap ) )
		return VSE_SYNTAX;

	double trialConeAngle = coneAngle;
	if( varMap.end() != varMap.find( "coneAngle" ) )
		trialConeAngle = varMap[ "coneAngle" ];

	if( trialConeAngle < 0.0 || trialConeAngle > M_PI )
		return VSE_INVALID;

	if( trialConeAngle == coneAngle && vse == VSE_NO_CHANGE )
		return VSE_NO_CHANGE;

	coneAngle = trialConeAngle;
	return VSE_NONE;
}
예제 #12
0
    virtual void visit(AstNodeModule* nodep, AstNUser*) {
	UINFO(9," MOD   "<<nodep<<endl);
	m_unique = 0;
	VarMap* lhsmapp = new VarMap();

	// expand tristate nodes and detect multiple LHS drivers for this module
	TristateExpander(nodep, lhsmapp);

	// iterate the children to grab any  __en signals from subcells
	m_modp = nodep;
	nodep->iterateChildren(*this);
	m_modp = NULL;

	// go through each multiple lhs driver & collapse it to a single driver
	for (VarMap::iterator nextit, it=lhsmapp->begin(); it != lhsmapp->end(); it=nextit) {
	    nextit = it; ++nextit;
	    m_unique = 0;
	    AstVar* lhsp = (*it).first;
	    RefVec* refs = (*it).second;
	    bool isOutput = (lhsp->varType() == AstVarType::OUTPUT) && (nodep->level() > 1); // force termination at top level

	    if (refs->size() < 2 && isOutput) {
		// if only one driver and this is an output, then exit and
		// let the driver propagate on its own.  If the signals
		// terminates at this level, then we need to let the
		// undriven state get generated.
		lhsmapp->erase(lhsp);
		delete refs;
		continue;
	    }


	    UINFO(9, "       Checking " << refs->size() << " drivers for tristates signals on net " << lhsp << endl);
	    int pull = 0;  // initially assume no pull direction

	    // Now remove and multple lhs signals that do not have __en for
	    // all possible drivers.
	    bool complete = true;
	    int found_one = 0;

	    for (RefVec::iterator ii=refs->begin(); ii != refs->end(); ++ii) {
		AstVarRef* refp = (*ii);
		if (!refp->user1p()) { // if no __en signal, then delete the entry
		    complete = false;
		} else {
		    found_one++;
		}
	    }
	    if (!complete) {
		if (found_one) {
		    UINFO(9, "       Problem mixing tristate and low-Z on " << lhsp << endl);
		    UINFO(9, "       Found " << found_one << " __en signals from of " << refs->size() << " possible drivers" << endl);
		    // not sure what I should do here other than error that they are mixing low-Z and tristate drivers.
		    // The other scenerio, and probably more likely, is that they are using a high-Z construct that
		    // is not supported.  Improving the high-Z detection logic will reduce the occurance of this failure.
		    nodep->v3error("Mixing tristate and low-Z drivers.  Perhaps you are using a high-Z construct not supported");
		} else  {
		    UINFO(9, "       No tristates found on " << lhsp <<endl);
		}
		lhsmapp->erase(lhsp);
		delete refs;
		continue;
	    }

	    UINFO(9, "       TRISTATE LHS DRIVER FOUND:" << lhsp << endl);

	    AstNode* orp = NULL,* andp = NULL,* undrivenp = NULL,* newenlogicp = NULL;

	    // loop through the lhs drivers to build the driver resolution logic
	    for (RefVec::iterator ii=refs->begin(); ii != refs->end(); ++ii) {
		AstVarRef* refp = (*ii);
		int w = lhsp->width();
		int wfill = 0; // width filler when necessary due to sels
		AstSel* selp = NULL;
		if (refp->user3p()) { // this varref has a sel
		    selp = (AstSel*) refp->user3p();
		    w = selp->widthConst();
		    wfill = lhsp->width() - w;
		}

		// create a new var for this assignment.
		AstVar* enp = (AstVar*)refp->user1p();
		AstVar* newlhsp = new AstVar(lhsp->fileline(),
					     AstVarType::MODULETEMP,
					     lhsp->name()+"__lhs"+cvtToStr(m_unique++),
					     AstLogicPacked(), w);
		nodep->addStmtp(newlhsp);

		// now append this driver to the driver logic.
		AstNode* ref1 = new AstVarRef(nodep->fileline(), newlhsp,false);
		AstNode* ref2 = new AstVarRef(nodep->fileline(), enp, false);
		andp = new AstAnd(nodep->fileline(), ref1, ref2);


		AstVar* bitselp = NULL;
		if (selp) { // this varref has a sel
		    int ws = V3Number::log2b(lhsp->width())+1;
		    bitselp = new AstVar(lhsp->fileline(),
					 AstVarType::MODULETEMP,
					 lhsp->name()+"__sel"+cvtToStr(m_unique-1),
					 AstLogicPacked(), ws);
		    //
		    nodep->addStmtp(bitselp);
		    nodep->addStmtp(new AstAssignW(lhsp->fileline(),
						   new AstVarRef(lhsp->fileline(), bitselp, true),
						   selp->lsbp()->cloneTree(false)));
		    andp = new AstShiftL(lhsp->fileline(),
					 new AstConcat(lhsp->fileline(), new AstConst(lhsp->fileline(), V3Number(lhsp->fileline(), wfill, 0)), andp),
					 new AstVarRef(lhsp->fileline(), bitselp, false),
					 lhsp->width()
			);

		    selp->replaceWith(new AstVarRef(refp->fileline(), newlhsp, true));
		    pushDeletep(selp);  // Setting selp here or deleting immediately
		    // breaks the t_tri_select test, this probably indicates a problem
		} else {
		    refp->varp(newlhsp); // assign the new var to the varref
		    refp->name(newlhsp->name());
		}

		// or this to the others
		orp = (!orp) ? andp : new AstOr(nodep->fileline(), orp, andp);

		if (isOutput) {
		    AstNode *en1p = new AstVarRef(nodep->fileline(), enp, false);
		    if (selp) {
			en1p = new AstShiftL(enp->fileline(),
					     new AstConcat(lhsp->fileline(), new AstConst(lhsp->fileline(), V3Number(lhsp->fileline(), wfill, 0)), en1p),
					     new AstVarRef(lhsp->fileline(), bitselp, false),
					     lhsp->width()
			    );
		    }
		    if (!newenlogicp) {
			newenlogicp = en1p;
		    } else {
			newenlogicp = new AstOr(nodep->fileline(), newenlogicp, en1p);
		    }
		} else {
		    if (!undrivenp) {
			undrivenp = new AstNot(nodep->fileline(), new AstVarRef(nodep->fileline(), enp, false));
			if (selp)
			    undrivenp = new AstShiftL(enp->fileline(),
						      new AstConcat(lhsp->fileline(), new AstConst(lhsp->fileline(), V3Number(lhsp->fileline(), wfill, 0)), undrivenp),
						      new AstVarRef(lhsp->fileline(), bitselp, false),
						      lhsp->width());
		    } else {
			AstNode *tmp = new AstNot(nodep->fileline(), new AstVarRef(nodep->fileline(), enp, false));
			if (selp) {
			    tmp = new AstShiftL(enp->fileline(),
						new AstConcat(lhsp->fileline(), new AstConst(lhsp->fileline(), V3Number(lhsp->fileline(), wfill, 0)), tmp),
						new AstVarRef(lhsp->fileline(), bitselp, false),
						lhsp->width());
			}
			undrivenp = new AstAnd(nodep->fileline(), tmp, undrivenp);
		    }
		}

		refp->user1p(NULL); // clear the user1p() as we done with it in the VarRef at this point

		if (enp->user2()) { // if this net is pulled up/down
		    int newpull = enp->user2();
		    if (pull == 0) {
			pull = newpull;
		    } else if (newpull != pull) {
			pull = -1; // conflict over the pull direction
		    }
		}
	    }
	    if (isOutput) {
		AstVar* newenp = new AstVar(lhsp->fileline(),
					    AstVarType::OUTPUT,
					    lhsp->name()+"__enout"+cvtToStr(m_unique++),
					    lhsp);
		nodep->addStmtp(newenp);
		nodep->addStmtp(new AstAssignW(lhsp->fileline(),
					       new AstVarRef(lhsp->fileline(), newenp, true),
					       newenlogicp));
		newenp->user2(pull); // put the pull direction in the next __en signal to pass it up
		lhsp->user1p(newenp); // put the new __en signal in the var so it can be pushed up the hierarchy.

	    } else { // this is the level where the signal terminates, we do final conflict resolution here
		UINFO(9, "       Terminating tristate logic for " << lhsp->name() << endl);
		UINFO(9, "       Pull direction is " << pull << " where -1=X, 0=Z, 1=low, 2=high." << endl);
		// figure out what to drive when no one is driving the bus
		V3Number num(nodep->fileline(), lhsp->width());
		if (pull==0) {
		    num.setAllBitsZ();
		} else if (pull==1) {
		    num.setAllBits0();
		} else if (pull==2) {
		    num.setAllBits1();
		} else {
		    num.setAllBitsX();
		}
		undrivenp = new AstAnd(nodep->fileline(), undrivenp,
				       new AstConst(nodep->fileline(), num));
		orp = new AstOr(nodep->fileline(), orp, undrivenp);
	    }
	    nodep->addStmtp(new AstAssignW(lhsp->fileline(),
					   new AstVarRef(lhsp->fileline(), lhsp, true), orp));

	    // delete the map and vector list now that we have collapsed it.
	    lhsmapp->erase(lhsp);
	    delete refs;
	}
	delete lhsmapp; // delete the map now that we are done
	nodep->user1p(NULL);
    }