Exemplo n.º 1
0
void Circuit::dumpCircuit()
{
    cout<<endl;
    cout<<"  Gate Name\tGate Level"<<endl;
    cout<<"========================================="<<endl;
    for( unsigned i = 0; i< numGate(); ++i )
    {
        Gate g = gate( i );
        cout<< "  " << g.name() << '\t' ;
        cout<< g.level() << '\t' ;
        //cout<< bitset<32>( value[i] ) <<'\t';
        cout<< endl;
    }

    cout<<endl;
    cout<<"  WireID\tWire Name\tType    \tValue"<<endl;
    cout<<"======================================================================================="<<endl;
    for( unsigned j = 0; j< numWire(); ++j )
    {
        Wire w = wire( j );
        cout<< "  "<< j << "\t\t";
        cout<< w.name() << "\t\t";
        cout<< setiosflags(ios::left) << setw(8) << w.type() <<'\t';
        if( w.type() != "UNUSED" )
            cout<< bitset<32>( w.valueSet() )<<'\t';
        else
            cout<<"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"<<'\t';
        cout<<endl;
    }
}
Exemplo n.º 2
0
bool CirMgr::print_io(){
    cout << "========= PRINT_IO =========" << endl; 
    cout << "GATE:" << endl;
    for(size_t i=0 ; i<GateList[0].size() ; ++i){
        cout << "(" << i << ")";
        cout << " ID = " << GateList[0][i]->getId();
        cout << ", Type = " << GateList[0][i]->getType();
        cout << ", Fanin0 = " << GateList[0][i]->getFin0()->getId();
        if(GateList[0][i]->getFin1()!=0)
            cout << ", Fanin1 = " << GateList[0][i]->getFin1()->getId();
        cout << ", Fanout = " << GateList[0][i]->getFout()->getId();
        cout << endl;
    }

    cout << "WIRE: " << endl;
    for(size_t i=0 ; i<WireList[0].size() ; ++i){
        cout << "(" << i << ")";
        cout << " ID = " << WireList[0][i]->getId();
        if(WireList[0][i]->getFin()!=0){
            cout << ", Fanin = " << WireList[0][i]->getFin()->getId() << " (";
            Gate* gate = WireList[0][i]->getFin();
            cout << " " << gate->getFin0()->getId();
            if(gate->getFin1()!=0)
                cout << " " << gate->getFin1()->getId();
            cout << " )";
        }
        cout << endl;
    }
    cout << endl;
    return true;
}
Exemplo n.º 3
0
ACE_THR_FUNC_RETURN Gate::
tracker_thunk (void* arg)
{
  Gate* a = reinterpret_cast<Gate*> (arg);
  a->tracker ();
  return 0;
}
Exemplo n.º 4
0
static void CreateGate( int flag, const AcDbObjectId& host, const AcGePoint3d& pt, double angle )
{
    Gate* pGate;
    switch( flag )
    {
    case 1:
        pGate = new PermanentGate( pt, angle );  // 永久风门
        break;
    case 2:
        pGate = new TemporaryGate( pt, angle );  // 临时风门
        break;
    case 3:
        pGate = new DoubleGate( pt, angle );    // 双向风门
        break;

    case 4:
        pGate = new BalanceGate( pt, angle ); // 平衡风门
        break;

    default:
        pGate = 0;
    }

    if( pGate == 0 ) return;

    pGate->setRelatedGE( host );

    if( !ArxUtilHelper::PostToModelSpace( pGate ) ) delete pGate;
}
Exemplo n.º 5
0
bool Atpg::FaultActivate() { // TODO: TDF support 
    Gate *fg = &cir_->gates_[current_fault_->gate_]; 
    int fline = current_fault_->line_; 

    if (fline) { // input stuck fault on GUT. 
        Value v = impl_->GetVal(fg->fis_[fline-1]); 
        if (v==X) { // faulted input at X? 
            Value objv = (current_fault_->type_==Fault::SA0 
                || current_fault_->type_==Fault::STR)?H:L;
            current_obj_.first = fg->fis_[fline-1]; 
            current_obj_.second = objv; 
        }
        else { 
            Value objv = fg->getOutputCtrlValue(); 
            if (objv==X) assert(0); //NOT, PO, PPO, TODO: XOR, XNOR
            current_obj_.first = fg->id_; 
            current_obj_.second = objv; 
            return true; 
        }
    }
    else { 
        Value objv = (current_fault_->type_==Fault::SA0 
            || current_fault_->type_==Fault::STR)?H:L;
        current_obj_.first = fg->id_; 
        current_obj_.second = objv; 
        return true; 
    }
}
void FileStreamerThread::processQuit(volatile Request *request)
{
	NOT_NULL(request);

	ExitChain::quit();
	Gate *gate = request->gate;
	delete request;
	gate->open();
}
	void RadarScreen::Refresh()	{

		int x, y;
		EifIterator  GateIt;
		EifIterator FlightPathIt;
		EifIterator AtLandmarkIt;
		Gate *CrntGate;
		AtLandmark *CrntAtLndmrk;
		FlightPath *CrntFlightPath;


		//Draw Boundary
		window
			(
			winleft_c   - POSITION_WIDTH,
			wintop_c    - POSITION_HEIGHT,
			winright_c  + POSITION_WIDTH,
			winbottom_c + POSITION_HEIGHT
			);

		textcolor (BOUNDARY_TEXT_COLOUR);
		textbackground (BOUNDARY_BACK_COLOUR);

		clrscr();

		// DrawGates
		GateIt = Gates_c.Iterator();
		while (!GateIt.Finished())	{
			CrntGate = Gates_c.Item (GateIt);

			x = CrntGate->GrndPos().X() * POSITION_WIDTH + 1;
			if (CrntGate->GrndPos().X() == MAX_X)	{
				x++;
			}
			y = (MAX_Y - CrntGate->GrndPos().Y() + 1) * POSITION_HEIGHT;

			gotoxy (x, y);
			cprintf (PRINT_GATE);
			cprintf ("%d", CrntGate->ID());


			GateIt.Forth();
		}

		// Draw radar screen
		Select();
		clrscr();

		for (x = MIN_FIELD_X; x <= MAX_FIELD_X; x++)	{
			for (y = MIN_FIELD_Y; y <= MAX_FIELD_Y; y++)	{
				 PrintBackPosition (Position (x,y));

			}
			assert (True);
		}
	}
Exemplo n.º 8
0
void lua_pushGate( lua_State* L, const Gate& g )
{
    lua_newtable   ( L );
    lua_pushnumber ( L, g.getMean() );
    lua_setfield   ( L, -2, "mean" );
    lua_pushnumber ( L, g.getStdDev() );
    lua_setfield   ( L, -2, "stdDev" );
    lua_pushinteger( L, g.getSource() );
    lua_setfield   ( L, -2, "source" );
    lua_pushinteger( L, g.getID() );
    lua_setfield   ( L, -2, "id" );
}
Exemplo n.º 9
0
Arquivo: gate.cpp Projeto: ebos/Epiar
Gate::Gate(Coordinate pos) {
	top = true;
	SetImage( Image::Get("Resources/Graphics/gate1_top.png") );
	
	// Create the PartnerID Gate
	Gate* partner = new Gate(this->GetID());
	partnerID = partner->GetID();
	exitID = 0;
	SpriteManager::Instance()->Add((Sprite*)partner);

	// Set both Position and Angle at the same time
	SetWorldPosition(pos);
	SetAngle( float( rand() %360 ) );
}
Exemplo n.º 10
0
 bool eval(){
     bool ret;
     if(type>='A' && type<='Z') ret = v[type-'A']==1?true:false;
     else{
         bool lv = l->eval();
         bool rv = r->eval();
         if(linv) lv = !lv;
         if(rinv) rv = !rv;
         if(type==')') ret = lv&&rv;
         else ret = lv||rv;
     }
     if(inv) ret = !ret;
     return ret;
 }
Exemplo n.º 11
0
	ATCInput::ATCInput (Traffic *Traff_i, Landmarks *Lmarks_i) :

		//Screen initialisations
		ATCScreen
			(
			1,
			46,
			60,
			50,
			ATC_TEXT_MODE,
			BLACK,
			WHITE
			),
		CrntColumn_c (1),

		Traff_c (Traff_i),
		Gates_c (True),
		Airports_c (True),
		Beacons_c (True),
		NextProcess_c (&GetPlane),
		IsCmndToCollect_c (False),
		LastCmnd_c (NULL)
			{
		int GateIx, AirportIx, BeaconIx;
		Gate *CrntGate;
		Airport *CrntAirport;
		Beacon *CrntBeacon;


		for (GateIx = 0; GateIx < Lmarks_i->NoOfGates(); GateIx++)	{
			CrntGate = Lmarks_i->AllGates() [GateIx];

			Gates_c.Add (CrntGate, CrntGate->ID());
		}

		for (AirportIx = 0; AirportIx < Lmarks_i->NoOfAirports(); AirportIx++)	{
			CrntAirport = Lmarks_i->AllAirports() [AirportIx];

			Airports_c.Add (CrntAirport, CrntAirport->ID());
		}

		for (BeaconIx = 0; BeaconIx < Lmarks_i->NoOfBeacons(); BeaconIx++)	{
			CrntBeacon = Lmarks_i->AllBeacons() [BeaconIx];

			Beacons_c.Add (CrntBeacon, CrntBeacon->ID());
		}
	}
Exemplo n.º 12
0
void PWSCircuit::
evalGates(const vector<int>& start, const vector<int>& end)
{
  // We don't deal with input gates.
  for (size_t lNum= 1; lNum < end.size(); lNum++)
  {
    CircuitLayer& prevLayer = getGatePosLayer(lNum - 1);
    CircuitLayer& layer = getGatePosLayer(lNum);

    int gNumStart = start.size() > lNum ? start[lNum] : 0;
    for (int gNum = gNumStart; gNum < end[lNum]; gNum++)
    {
      Gate rop = layer.gate(gNum);
      rop.computeGateValue(prevLayer.gate(rop.wiring.in1), prevLayer.gate(rop.wiring.in2));
    }
  }
}
Exemplo n.º 13
0
/**\brief Creates a Top Gate as well as a Bottom Gate automatically
 * \todo Remove the SpriteManager Instance access.
 */
Gate::Gate(Coordinate pos, string _name) {
	top = true;
	SetImage( Image::Get("Resources/Graphics/gate1_top.png") );
	
	// Create the PartnerID Gate
	Gate* partner = new Gate(GetID());
	partnerID = partner->GetID();
	exitID = 0;
	SpriteManager::Instance()->Add((Sprite*)partner);

	// Set both Position and Angle at the same time
	SetWorldPosition(pos);
	SetAngle( float( rand() %360 ) );

	if( _name == "" ) {
		stringstream val_ss;
		val_ss << GetID();
		val_ss >> _name;
	}
		int calcOutput()
		{
			Gate* ptr = pHead;
			while( ptr != null )
			{
				for( int i = 0; i < ptr->numInputs; i++ )
				{
					if( ptr->pInputs[i]->isDefined == DEFINED_BY_CALC )
					{
						ptr->pInputs[i]->isDefined = NOT_DEFINED;
					}
				}
				ptr = ptr->nextGate;
			}

			int dummy; // TODO : Overload GetID func
			Gate* outputGate = getGateIDFromSerial(outputSerial, &dummy);
			return outputGate->GetOutput();
		}
Exemplo n.º 15
0
int Net::computeDelay()
{
  if(drivers->size() == 0) {
    return 0; // Input gate
  }
  int cumulativeMaxVal = 0;
  for(vector<Gate*>::iterator it=drivers->begin(); it!=drivers->end(); it++) {
    Gate *g = *it;
    
    // Find max values of the gate's nets
    int maxVal = 0;
    for(vector<Net*>::iterator jt=g->getInputs()->begin(); jt!=g->getInputs()->end(); jt++) {
      maxVal = max(maxVal, (*jt)->computeDelay());
    }
    
    cumulativeMaxVal = max(cumulativeMaxVal, maxVal + g->getDelay());
  }
	return cumulativeMaxVal;
}
Exemplo n.º 16
0
/* Detects the destination component of the connection */
bool AddConnection::DetectDestinationComponent() {
	Component* comp = mAppManager->GetOutput()->GetComponentAtPin(mGfxInfo.x2, mGfxInfo.y2);

	if (comp == NULL || comp == mSrcPin->GetGate()) {
		return false;
	}
	else if (dynamic_cast<Gate*>(comp) != NULL) {
		Gate* gate = (Gate*)comp;
		mDstPinIndex = gate->GetInputPinIndex(mGfxInfo.x2, mGfxInfo.y2);
		gate->GetInputPinCoordinates(mGfxInfo.x2, mGfxInfo.y2, mDstPinIndex);
		mDstPin = gate->GetInputPin(mDstPinIndex);

		if (mDstPin == NULL || mDstPin->IsFull()) {
			return false;
		}

		return true;
	}

	return false;
}
	CmndInput::CmndInput
		(
		Landmarks *Lmarks_i,
		Traffic *Traff_i
		) :

		Traff_c (Traff_i),
		IsCmndToCollect_c (False),
		LastCmnd_c (NULL)

			{
		int GateIx, AirportIx, BeaconIx;
		Gate *CrntGate;
		Airport *CrntAirport;
		Beacon *CrntBeacon;


		Out_c.Refresh();

		for (GateIx = 0; GateIx < Lmarks_i->NoOfGates(); GateIx++)	{
			CrntGate = Lmarks_i->AllGates() [GateIx];

			Landmarks_c.Gates.Add (CrntGate, CrntGate->ID());
		}

		for (AirportIx = 0; AirportIx < Lmarks_i->NoOfAirports(); AirportIx++)	{
			CrntAirport = Lmarks_i->AllAirports() [AirportIx];

			Landmarks_c.Airports.Add (CrntAirport, CrntAirport->ID());
		}

		for (BeaconIx = 0; BeaconIx < Lmarks_i->NoOfBeacons(); BeaconIx++)	{
			CrntBeacon = Lmarks_i->AllBeacons() [BeaconIx];

			Landmarks_c.Beacons.Add (CrntBeacon, CrntBeacon->ID());
		}
		SetForNewCmnd();

	}
Exemplo n.º 18
0
int main()
{
    bool begin = true;
    while(gets(s)){
        memset(pic,' ',sizeof pic);
        memset(vis,0,sizeof vis);
        int len = strlen(s);
        int ri,rj;
        for(int j=0;j<len;j++){
            pic[1][1+j] = s[j];
            if(s[j]=='?') ri = 1, rj=1+j;
        }
        //pic[0][len] = 0;
        int n=1;
        while(gets(s),s[0]!='*'){
            ++n;
            len = strlen(s);
            for(int j=0;j<len;j++){
                pic[n][1+j] = s[j];
                if(s[j]=='?') ri = n, rj = 1+j;
            }
            //pic[n][len] = 0;
        }
        //bfs until a A, ) o >
        if(begin)begin=false;
        else
            printf("\n");
        vis[ri][rj] = 1;
        Gate *root = build(ri,rj);
        while(gets(s),s[0]!='*'){
            for(int i=0;i<26;i++)
                v[i] = s[i]-'0';
            if(root->eval())printf("1\n");
            else printf("0\n");
        }
    }
    return 0;
}
Exemplo n.º 19
0
bool Atpg::DDrive() { 
    GateVec dfront; 
    impl_->GetDFrontier(dfront); 

    if (dfront.size()==0) return false; 

    Gate *fg = &cir_->gates_[current_fault_->gate_]; 
    assert(impl_->GetVal(fg->id_)==D || impl_->GetVal(fg->id_)==B); 
    
    Gate *gtoprop = NULL; 
    int observ = INT_MAX; 
    for (size_t i=0; i<dfront.size(); i++) 
        if(dfront[i]->co_o_<observ) { 
            gtoprop = dfront[i]; 
            observ = dfront[i]->co_o_; 
        }

    assert(gtoprop->isUnary()==L); 
    current_obj_.first = gtoprop->id_; 
    current_obj_.second = gtoprop->getOutputCtrlValue(); 

    return true; 
}
Exemplo n.º 20
0
void MyContactListener::BeginContact(b2Contact* contact) {
    b2Body * bodyA = contact->GetFixtureA()->GetBody();
    b2Body * bodyB = contact->GetFixtureB()->GetBody();
    
    b2Sprite * spriteA = (b2Sprite *) bodyA->GetUserData();
    b2Sprite * spriteB = (b2Sprite *) bodyB->GetUserData();
    
    if (spriteA && spriteB) 
	{
		Gate *gate = NULL;
        Ball *b = NULL;
        
		if (kSpriteFootballer == spriteA->getSpriteType() ||
			kSpriteFootballer == spriteB->getSpriteType())
		{
			SimpleAudioEngine::sharedEngine()->playEffect(BALL_SOUND);

			return;
		}

		if (kSpriteGate == spriteA->getSpriteType()) 
		{
			gate = (Gate*)spriteA;
			b = (Ball*)spriteB;
		} 
		else if (kSpriteGate == spriteB->getSpriteType()) 
		{
            gate = (Gate*)spriteB;
            b = (Ball*)spriteA;
		}
        
		if(NULL != gate){
			
            if (NULL != b)
            {
				if (gate->getType() == kRight && b->getPosition().x > (gate->getPositionX() - gate->boundingBox().size.width / 2))
				{
	                gate->setHoldsBall(true);
				}
				else if (gate->getType() == kLeft && b->getPosition().x < (gate->getPositionX() + gate->boundingBox().size.width / 2))
				{
					gate->setHoldsBall(true);
				}
            }
        }
	}
}
Exemplo n.º 21
0
/* Detects the source component of the connection */
bool AddConnection::DetectSourceComponent() {
	Component* comp = mAppManager->GetOutput()->GetComponentAtPin(mGfxInfo.x1, mGfxInfo.y1);

	if (comp == NULL) {
		return false;
	}
	else {
		Gate* gate;

		if (dynamic_cast<Gate*>(comp) != NULL)
			gate = (Gate*)comp;
		else
			gate = ((Connection*)comp)->GetSourcePin()->GetGate();

		gate->GetOutputPinCoordinates(mGfxInfo.x1, mGfxInfo.y1);
		mSrcPin = gate->GetOutputPin();

		if (mSrcPin == NULL || mSrcPin->IsFull()) {
			return false;
		}
	}

	return true;
}
Exemplo n.º 22
0
bool Atpg::Backtrace() {
    Gate *g = &cir_->gates_[current_obj_.first]; 
    Value objv = current_obj_.second; 
    while (!(g->type_==Gate::PI 
        || g->type_==Gate::PPI)) { // while objective net not fed by P/PI 
        
        if (g->getOutputCtrlValue()==X) { //NOT, BUF, TODO: XOR, XNOR 
            if (g->type_==Gate::INV) 
                objv = EvalNot(objv); 
            g = &cir_->gates_[g->fis_[0]]; 
            assert(impl_->GetVal(g->id_)==X); 
            continue; 
        } 

        Gate *gnext = NULL; 
        if (objv==EvalNot(g->getOutputCtrlValue())) { // if objv is easy to set 
            // choose input of "g" which 
            //  1) is at X 
            //  2) is easiest to control 
            gnext = FindEasiestToSetFanIn(g, objv); 
        }
        else if (objv==g->getOutputCtrlValue()) { // is objv is hard to set
            // choose input of "g" which 
            //  1) is at X 
            //  2) is hardest to control 
            gnext = FindHardestToSetFanIn(g, objv); 
        } 
        
        if (g->isInverse()) 
            objv = EvalNot(objv); 

        g = gnext; 
    }

    return impl_->MakeDecision(g, objv); 
}
Exemplo n.º 23
0
		gluLookAt(400, 400, 1, 0, 1, 0, 400, 400, 0);
	}
}

void TimerFunction(int value)
{
	if(!orthomode)camera.Update();

	gate.Update();
	squaretree.Update();
	roundtree.Update();
	elevator.Update();
	cone.Update();

	
Exemplo n.º 24
0
int main( int argc, char* argv[] )
{
	Gate gate;
 	bool debug = false;

	char c;
  	while ((c = getopt (argc, argv, "tup:a:d")) != -1)
	    switch (c)
	    {
	      case 'd':
	      	debug = true;
	      	break;
	      case 'p':
	        int port;
	        sscanf( optarg, "%d", &port );
	        gate.setPort(port);
	        break;
	      case 'a':
	        gate.setAddr(optarg);
	        break;
	      case 't':
	        gate.setTCP();
	        break;
	      case 'u':
	        gate.setUDP();
	        break;
	      case '?':
	        if ( optopt == 'p' || optopt == 'a')
	          fprintf (stderr, "Option -%c requires an argument.\n", optopt);
	        else if (isprint (optopt))
	          fprintf (stderr, "Unknown option `-%c'.\n", optopt);
	        else
	          fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt);
	        return 1;
	      default:
	        abort ();
	    }

    gate.bind( handle );

    return 0;
}
Exemplo n.º 25
0
void CircuitBuilder::levelize() {
    bool processed[cir_->nGates()];
    bool levelized[cir_->nGates()];
    memset(processed, false, sizeof(bool) * cir_->nGates());
    memset(levelized, false, sizeof(bool) * cir_->nGates());
    for (size_t i = 0; i < cir_->nGates(); ++i)
        cir_->getGate(i)->setId(i);

    queue<Gate *> que;
    for (size_t i = 0; i < cir_->nPis() + cir_->nSeqs(); ++i)
        que.push(cir_->getGate(i));

    while (!que.empty()) {
        Gate *g = que.front();
        que.pop();

        int maxlvl = -1;
        bool ready = true;

        // determine level only if all fanins are levelized
        // 1. PPI is set to level zero 
        // 2. PPI has input PPO
        // 3. Skip PPI directly
        if(g->getType() != Gate::PPI){
            for (size_t i = 0; i < g->nFis(); ++i) {
                Gate *fi = g->getFi(i);
                if (!levelized[fi->getId()]) {
                    ready = false;
                    break;
                }
                if (fi->getLvl() > maxlvl)
                    maxlvl = fi->getLvl();
            }
        }
        // put back to queue if not ready
        if (!ready) {
            que.push(g);
            continue;
        }

        // set level
        g->setLvl(maxlvl + 1);
        levelized[g->getId()] = true;

        // determine circuit level
        if ((g->getType() == Gate::PO || g->getType() == Gate::PPO)
            && g->getLvl() > cir_->getLvl())
            cir_->setLvl(g->getLvl());

        // put fanouts into queue
        for (size_t i = 0; i < g->nFos(); ++i) {
            Gate *fo = g->getFo(i);
            if (processed[fo->getId()])
                continue;
            processed[fo->getId()] = true;
            que.push(fo);
        }
    }

    // set all POs to highest level
    for (size_t i = 0; i < cir_->nPos(); ++i)
        cir_->getPo(i)->setLvl(cir_->getLvl());
    for (size_t i = 0; i < cir_->nSeqs(); ++i)
        cir_->getPpo(i)->setLvl(cir_->getLvl());
    cir_->setLvl(cir_->getLvl() + 1);

    // sort gates by their level
    stable_sort(cir_->getGates()->begin()
        , cir_->getGates()->end()
        , cmpGateLvl);

    // set gate id
    for (size_t i = 0; i < cir_->nGates(); ++i)
        cir_->getGate(i)->setId(i);
}
Exemplo n.º 26
0
void CircuitBuilder::build(Design * const design, const size_t &f) {
    delete cir_;
    cir_ = new Circuit;
    cir_->setFrame(f);
    cir_->setOccRoot(design->getOcc());
    cir_->setModRoot(design->getTop());
    map<string,Gate*> FFMap;    // flip-flop map, used to connecte PPI & PPO
    // create PI
    // ignore CK, test_si, and test_so
    for (size_t i = 0; i < design->getTop()->nModTerms(); ++i) {
        ModTerm *term = design->getTop()->getModTerm(i);
        if (term->getType() != ModTerm::INPUT 
            || strcmp(term->getName(),"test_si") == 0 
            || strcmp(term->getName(),"test_se") == 0
            || strcmp(term->getName(),"CK") == 0 )
            continue;
        Gate *g = new PiGate;
        g->setOcc(design->getOcc());
        cir_->addPi(g);
    }

    // create PPI
    for (size_t i = 0; i < design->getOcc()->nChildren(); ++i) {
        Occ *occ = design->getOcc()->getChild(i);
        string modName(occ->getModInst()->getModName());
        if (modName.size() < 4 || modName.substr(0,4) != "SDFF")
            continue;
        Gate *g = new PpiGate;
        g->setOcc(occ);
        cir_->addPpi(g);
        cir_->setOccToGate(occ, g);
        FFMap[occ->getModInst()->getName()] = g;
    }

    // create combinational gates
    for (size_t i = 0; i < design->getOcc()->nChildren(); ++i) {
        Occ *occ = design->getOcc()->getChild(i);
        string modName(occ->getModInst()->getModName());
        if (modName.size() > 3 && modName.substr(0,4) == "SDFF")
            continue;
        Gate *g = createGate(occ);
        g->setOcc(occ);
        cir_->addComb(g);
        cir_->setOccToGate(occ, g);
    }

    // create PO
    for (size_t i = 0; i < design->getTop()->nModTerms(); ++i) {
        ModTerm *term = design->getTop()->getModTerm(i);
        if (term->getType() != ModTerm::OUTPUT)
            continue;
        Gate *g = new PoGate;
        g->setOcc(design->getOcc());
        cir_->addPo(g);
    }

    // create PPO
    for (size_t i = 0; i < design->getOcc()->nChildren(); ++i) {
        Occ *occ = design->getOcc()->getChild(i);
        string modName(occ->getModInst()->getModName());
        if (modName.size() < 4 || modName.substr(0,4) != "SDFF")
            continue;
        Gate *g = new PpoGate;
        g->setOcc(occ);
        cir_->addPpo(g);
        FFMap[occ->getModInst()->getName()]->addFi(g);
    }

    // connect gates
    for (size_t i = cir_->nPis() + cir_->nSeqs(); i < cir_->nGates(); ++i) {
        Gate *g = cir_->getGate(i);
        Occ *occ = g->getOcc();
        size_t nTerm = 0;
        if (g->getType() == Gate::PO || g->getType() == Gate::PPO)
            nTerm = 1;
        else
            nTerm = occ->getModInst()->nModInstTerms() - 1;
        for (size_t j = 0; j < nTerm; ++j) {
            ModTerm *term = NULL;
            ModInstTerm *instTerm = NULL;
            ModNet *net = NULL;
            if (g->getType() == Gate::PO) {
                // because we ignore 3 inputs(CK,test_si,test_so)
                // we have to add 3 in idx to match id in ModTerm
                size_t id = i - cir_->nCombs() - cir_->nSeqs() + 3;
                term = design->getTop()->getModTerm(id);
                net = term->getModNet();
            }
            else if (g->getType() == Gate::PPO) {
                instTerm = occ->getModInst()->getModInstTerm("D");
                net = instTerm->getModNet();
            }
            else {
                instTerm = occ->getModInst()->getModInstTerm(j);
                net = instTerm->getModNet();
            }

            // find fanin
            Gate *fi = NULL;
            for (size_t k = 0; k < net->nModTerms(); ++k) {
                if (net->getModTerm(k) == term
                    || net->getModTerm(k)->getType() == ModTerm::OUTPUT)
                    continue;
                // because we ignore 3 inputs(CK,test_si,test_so)
                // we have to minus 3 in idx to match id in ModTerm
                size_t id = net->getModTerm(k)->getPos()-3;
                fi = cir_->getGate(id);
                break;
            }
            if (!fi) {
                for (size_t k = 0; k < net->nModInstTerms(); ++k) {
                    ModInst *inst = net->getModInstTerm(k)->getModInst();
                    if (net->getModInstTerm(k) == instTerm
                        || inst->getModule()->getModTerm(net->getModInstTerm(k)->getName())->getType() == ModTerm::INPUT)
                        continue;
                    const char *name = net->getModInstTerm(k)->getModInst()->getName();
                    fi = cir_->getGate(design->getOcc()->getChild(name));
                    break;
                }
            }
            // connect gates
            g->addFi(fi);
            fi->addFo(g);
        }
    }


    levelize();
    setTimeFrame(f);

}
Exemplo n.º 27
0
void AddGate::Execute()
{
	//Get a Pointer to the Input / Output Interfaces
	Output* pOut = pManager->GetOutput();
	Input* pIn = pManager->GetInput();

	//A generic gate pointer to hold any type of gate to be added
	Gate *pG = NULL;

	//Create new object of a gate according to the type of the action
	switch (ActType)
	{
	case ADD_AND_GATE_2:
	{
		pG = new AND2(GInfo, AND2_FANOUT);
		break;
	}
	case ADD_OR_GATE_2:
	{
		pG = new OR2(GInfo, AND2_FANOUT);
		break;
	}
	case ADD_Buff:
	{
		pG = new BUFFER(GInfo, AND2_FANOUT);
		break;
	}
	case ADD_INV:
	{
		pG = new NOT(GInfo, AND2_FANOUT);
		break;
	}
	case ADD_NAND_GATE_2:
	{
		pG = new NAND2(GInfo, AND2_FANOUT);
		break;
	}
	case ADD_NOR_GATE_2:
	{
		pG = new NOR2(GInfo, AND2_FANOUT);
		break;
	}
	case ADD_XOR_GATE_2:
	{
		pG = new XOR2(GInfo, AND2_FANOUT);
		break;
	}
	case ADD_XNOR_GATE_2:
	{
		pG = new XNOR2(GInfo, AND2_FANOUT);
		break;
	}
	case ADD_AND_GATE_3:
	{
		pG = new AND3(GInfo, AND2_FANOUT);
		break;
	}
	case ADD_OR_GATE_3:
	{
		pG = new OR3(GInfo, AND2_FANOUT);
		break;
	}
	case ADD_NAND_GATE_3:
	{
		pG = new NAND3(GInfo, AND2_FANOUT);
		break;
	}
	case ADD_NOR_GATE_3:
	{
		pG = new NOR3(GInfo, AND2_FANOUT);
		break;
	}
	case ADD_XOR_GATE_3:
	{
		pG = new XOR3(GInfo, AND2_FANOUT);
		break;
	}
	case ADD_XNOR_GATE_3:
	{
		pG = new XNOR3(GInfo, AND2_FANOUT);
		break;
	}
	}

	//if redo draw the gate in it's initial position
	if (REDO)
	{
		string GateImage = "Images\\PNG Gates\\", GateNumber;
		stringstream ss;
		ss << (int)ActType ;
		ss >> GateNumber;
		GateImage += GateNumber + ".png";
		pManager->GetOutput()->DrawPNGImage(GateImage, GInfo);
		pManager->AddComponent(pG);
		return;
	}

	//if the gate wase successfully added this will return true and false if escape key was pressed to cancel the addition
	if (pOut->FollowMouseAndDraw(pManager, pG))
		pManager->AddComponent(pG), GInfo = pG->get_GraphicInfo();

	else delete pG;
}
void FileStreamerThread::processRead(volatile Request *request)
{
	NOT_NULL(request);

	// shortcut to the file
	OsFile *osFile = request->osFile;

	// seek to the requested offset
	osFile->seek(request->offset);

	// read the data
	if (request->bytesToBeRead > cms_maxReadSize)
	{
		// only read up to FileStreamerThread::cms_maxReadSize, then resubmit smaller request
		const int amountRead = osFile->read(request->buffer, cms_maxReadSize);

		request->offset += amountRead;
		request->bytesRead += amountRead;
		request->bytesToBeRead -= amountRead;
		request->buffer = reinterpret_cast<byte *>(request->buffer) + amountRead;

		// if we read less than we could have, we're done
		if (amountRead < cms_maxReadSize)
		{
			// store final number of bytes read in storage accessible to main thread
			*request->returnValue = static_cast<int>(request->bytesRead);

			Gate *gate = request->gate;
			delete request;

			//set event so other main thread continues
			gate->open();
		}
		else
		{
			// resubmit request (put it on the head so we get it back first)
			if (request->priority == AbstractFile::PriorityAudioVideo)
			{
				ms_queueCriticalSection.enter();
					if (ms_firstAudioVideoRequest)
					{
						request->next = ms_firstAudioVideoRequest;
						ms_firstAudioVideoRequest = request;
					}
					else
					{
						ms_firstAudioVideoRequest = request;
						ms_lastAudioVideoRequest = request;
					}
				ms_queueCriticalSection.leave();
			}
			else
				if (request->priority == AbstractFile::PriorityData)
				{
					ms_queueCriticalSection.enter();
						if (ms_firstDataRequest)
						{
							request->next = ms_firstDataRequest;
							ms_firstDataRequest = request;
						}
						else
						{
							ms_firstDataRequest = request;
							ms_lastDataRequest = request;
						}
					ms_queueCriticalSection.leave();
				}
				else
					if (request->priority == AbstractFile::PriorityLow)
					{
						ms_queueCriticalSection.enter();
							if (ms_firstLowRequest)
							{
								request->next = ms_firstLowRequest;
								ms_firstLowRequest = request;
							}
							else
							{
								ms_firstLowRequest = request;
								ms_lastLowRequest = request;
							}
						ms_queueCriticalSection.leave();
					}
					else
						DEBUG_FATAL(true, ("FileStreamerThread::processRead request has unknown priority type"));

			// signal the file thread that a new request is waiting
			ms_eventsPending.signal();
		}
	}
	else
	{
		// fulfill entire read request
		const int amountRead = osFile->read(request->buffer, request->bytesToBeRead);

		request->bytesRead += amountRead;
		request->bytesToBeRead -= amountRead;

		// store final number of bytes read in storage accessible to main thread
		*request->returnValue = static_cast<int>(request->bytesRead);

		Gate *gate = request->gate;
		delete request;
		gate->open();
	}
}
Exemplo n.º 29
0
bool Evaluate( Circuit& circuit)
{
    int level=1;
    multimap<int,Element*>:: iterator levelIter;
    map<string,Wire*> ::iterator iter =  (circuit.PriInputs).begin();

    CIRCUIT_DFILE << "Circuit evaluation called for" << endl;

    /// First propagate the values on primary inputs to the immediate branches. Not doing so leads to big bugs. Whenever  a value is assigned
    ///to a wire, check for its branches and assign values to those too.
    for ( iter = (circuit.PriInputs).begin(); iter != (circuit.PriInputs).end(); iter++)
    {
        Wire *outputWire = (iter->second);
        Value curValue = outputWire->value;
                if  ((outputWire->outputs).size() > 1) 
                {
                    list<Element*>::iterator iterator = (outputWire->outputs).begin();
                    CIRCUIT_DFILE << "Evaluating stemouts of wire " << outputWire->id << endl;
                    /** Reasons for using dynamic cast: 
                     * If the output wire has > 1 output, they are all bound to 
                     * be wires.
                     * */
                    for (;iterator != (outputWire->outputs).end(); iterator++)
                    {
                        Wire* check = (dynamic_cast<Wire*>(*iterator));
                        assert(check);
                        CIRCUIT_DFILE << "Setting value of branch " <<  check->id <<   " of wire " << outputWire->id << " to "  << (int) curValue << endl;
                        /// if the value of the wire is already set, don't set it again. (might be becuase it is faulty)
                        if (check->value == U)
                            check->value = curValue;

                    }

                }
    }

    do
    {
        /* first and second are the end-point iterators that has been
         * returned on qeurying the multimap on a value
         */
        for (levelIter = ((circuit.Levels).equal_range(level)).first; 
                levelIter !=((circuit.Levels).equal_range(level)).second; levelIter++)
        {
            if ( (levelIter->second)->type == GATE)
            {
                Gate* curGate = dynamic_cast<Gate*>(levelIter->second);
                Value curValue = curGate->Evaluate();
                Wire* outputWire = curGate->output;
                CIRCUIT_DFILE << "Setting value of wire " << outputWire->id << " to " << (int)curValue << endl; 
                // if the value of the wire is already set, don't set it again. (might be becuase it is faulty)
                if (outputWire->value == U)
                    outputWire->value = curValue;

                if  ((outputWire->outputs).size() > 1) 
                {
                    list<Element*>::iterator iter = (outputWire->outputs).begin();
                    CIRCUIT_DFILE << "Evaluating stemouts of wire " << outputWire->id << endl;
                    /* Reasons for the dynamic cast: 
                     * If the output wire has > 1 output, they are all bound to
                     * be wires.
                     * */
                    for (;iter != (outputWire->outputs).end(); iter++)
                    {
                        //cout << "output: " << (*iter)->id << endl;
                        Wire* check = (dynamic_cast<Wire*>(*iter));
                        assert(check);
                        CIRCUIT_DFILE << "Setting value of branch " <<  check->id <<   " of wire " << outputWire->id << " to "  << (int) curValue << endl;
                        // if the value of the wire is already set, don't set it again. (might be becuase it is faulty)
                        if (check->value == U)
                            check->value = curValue;

                    }

                }

            }
            else cout << "something wrong" << endl;


        }
    }while (   (circuit.Levels).find(++level) != (circuit.Levels).end() ); 

    iter = (circuit.PriOutputs).begin();
    
    return true;
}
int main ()	{

	textmode (ATC_TEXT_MODE);
	clrscr();

	Position::MaxX = 30;
	Position::MaxY = 30;



	char pid;

	Position::MaxX = 30;
	Position::MaxY = 30;

	RadarScreen *r;
	Landmarks l;

	Traffic t;
	Plane *p1;
	Gate g (Position  (0,  10), 1, D90);
	Gate g1 (Position (0,  0),  2, D45);
	Gate g2 (Position (10, 0),  3, D0);
	Gate g3 (Position (MAX_X, MAX_Y), 4, D225);
//	Gate g4 (Position (10, 0), 4, D0);
	Airport a1 (Position (5, 5), 1, Heading (D90));
	Airport a2 (Position (10, 12), 2, Heading (D45));
	Beacon b1 (Position (7,13), 1);
	Beacon b2 (Position (1,1), 2);
	FlightPath fp (Position (MIN_FIELD_X, MIN_FIELD_Y),
		Position (MAX_FIELD_X, MAX_FIELD_Y));

	FlightPath fp1 (Position (MIN_FIELD_X, MAX_FIELD_Y),
		Position (MAX_FIELD_X, MIN_FIELD_Y));

	FlightPath fp2 (Position (10, 1), Position (10, MAX_FIELD_Y));

	int i;

	l.AddAirport (&a1);

	l.AddAirport (&a2);
	l.AddBeacon (&b1);
	l.AddBeacon (&b2);
	l.AddGate (&g);
	l.AddGate (&g1);
	l.AddGate (&g2);
	l.AddGate (&g3);
//	l.AddGate (&g4);
	l.AddFlightPath (&fp);
	l.AddFlightPath (&fp1);
	l.AddFlightPath (&fp2);

	r = new RadarScreen (&l);

	Boolean Crashed = False;

	r->Refresh();

	pid = t.NewId();

	p1 = new Plane (pid, g.NewPlaneCoords(), Prop, &g1);

	t.NewAirborne (p1);

	p1 = new Plane (t.NewId(), g1.NewPlaneCoords(), Jet, &g);

	t.NewAirborne (p1);


	p1 = new Plane (t.NewId(), g2.NewPlaneCoords(), Jet, &g);

	t.NewAirborne (p1);

	r->DisplayPlanes (&t);

	for (i = 0; i < 34; i++) {
		delay (500);


		if (i == 17)	{
			t.SearchAirborne ('a');
			t.FoundAirborne() -> AlterTargHeading (D270, AntiClockwise);

			t.SearchAirborne ('b');
			t.FoundAirborne() -> MakeCircle (AntiClockwise);
		}
		r->UnDisplayPlanes (&t);

		if (i % 2 == 0)	{
			t.StepJets();
		} else {
			t.StepAll();
		}

		r->DisplayPlanes (&t);

		if (!Crashed && t.Crashed ())	{
				cout << '\a';
			Crashed = True;
		}

	}

	textmode (C80);
	_setcursortype (_NORMALCURSOR);
	clrscr();

	return 0;
}