示例#1
0
文件: main.c 项目: leec1/yess
int main(int argc, char * argv[]) {
    if (argc < 2) {
        printf("Please provide a filename.\n");
        return 0;
    }

    if (!openFile(argv[1])) {
        printf("Failed to open file.\nUsage: yess <filename>.yo\n");
        return 0;
    }
    
    initialize();
    
    if (!load()) {
        dumpMemory();
        return 0;
    }
    
    while(!stop) {
        stop = writebackStage(&fwd);
        memoryStage(&fwd);
        executeStage(&fwd);
        decodeStage(&fwd);
        fetchStage(&fwd);
        clockCount++;
    }

    printf("\nTotal clock cycles = %d\n", clockCount);

    return 0;
}
示例#2
0
        void run() {
            ScopedTransaction transaction(&_txn, MODE_IX);
            Lock::DBLock lk(_txn.lockState(), nsToDatabaseSubstring(ns()), MODE_X);
            Client::Context ctx(&_txn, ns());
            Database* db = ctx.db();
            Collection* coll = db->getCollection(&_txn, ns());
            if (!coll) {
                WriteUnitOfWork wuow(&_txn);
                coll = db->createCollection(&_txn, ns());
                wuow.commit();
            }

            WorkingSet ws;

            // Add an object to the DB.
            insert(BSON("foo" << 5));
            set<DiskLoc> locs;
            getLocs(&locs, coll);
            ASSERT_EQUALS(size_t(1), locs.size());

            // Create a mock stage that returns the WSM.
            auto_ptr<MockStage> mockStage(new MockStage(&ws));

            // Mock data.
            {
                WorkingSetMember mockMember;
                mockMember.state = WorkingSetMember::LOC_AND_IDX;
                mockMember.loc = *locs.begin();

                // State is loc and index, shouldn't be able to get the foo data inside.
                BSONElement elt;
                ASSERT_FALSE(mockMember.getFieldDotted("foo", &elt));
                mockStage->pushBack(mockMember);
            }

            // Make the filter.
            BSONObj filterObj = BSON("foo" << 6);
            StatusWithMatchExpression swme = MatchExpressionParser::parse(filterObj);
            verify(swme.isOK());
            auto_ptr<MatchExpression> filterExpr(swme.getValue());

            // Matcher requires that foo==6 but we only have data with foo==5.
            auto_ptr<FetchStage> fetchStage(
                     new FetchStage(&_txn, &ws, mockStage.release(), filterExpr.get(), coll));

            // First call should return a fetch request as it's not in memory.
            WorkingSetID id = WorkingSet::INVALID_ID;
            PlanStage::StageState state;

            // Normally we'd return the object but we have a filter that prevents it.
            state = fetchStage->work(&id);
            ASSERT_EQUALS(PlanStage::NEED_TIME, state);

            // No more data to fetch, so, EOF.
            state = fetchStage->work(&id);
            ASSERT_EQUALS(PlanStage::IS_EOF, state);
        }
示例#3
0
        void run() {
            Client::WriteContext ctx(&_txn, ns());
            Database* db = ctx.ctx().db();
            Collection* coll = db->getCollection(&_txn, ns());
            if (!coll) {
                WriteUnitOfWork wuow(&_txn);
                coll = db->createCollection(&_txn, ns());
                wuow.commit();
            }

            WorkingSet ws;

            // Add an object to the DB.
            insert(BSON("foo" << 5));
            set<DiskLoc> locs;
            getLocs(&locs, coll);
            ASSERT_EQUALS(size_t(1), locs.size());

            // Create a mock stage that returns the WSM.
            auto_ptr<MockStage> mockStage(new MockStage(&ws));

            // Mock data.
            {
                WorkingSetMember mockMember;
                mockMember.state = WorkingSetMember::LOC_AND_UNOWNED_OBJ;
                mockMember.loc = *locs.begin();
                mockMember.obj = coll->docFor(&_txn, mockMember.loc);
                // Points into our DB.
                mockStage->pushBack(mockMember);

                mockMember.state = WorkingSetMember::OWNED_OBJ;
                mockMember.loc = DiskLoc();
                mockMember.obj = BSON("foo" << 6);
                ASSERT_TRUE(mockMember.obj.isOwned());
                mockStage->pushBack(mockMember);
            }

            auto_ptr<FetchStage> fetchStage(new FetchStage(&_txn, &ws, mockStage.release(),
                                                           NULL, coll));

            WorkingSetID id = WorkingSet::INVALID_ID;
            PlanStage::StageState state;

            // Don't bother doing any fetching if an obj exists already.
            state = fetchStage->work(&id);
            ASSERT_EQUALS(PlanStage::ADVANCED, state);
            state = fetchStage->work(&id);
            ASSERT_EQUALS(PlanStage::ADVANCED, state);

            // No more data to fetch, so, EOF.
            state = fetchStage->work(&id);
            ASSERT_EQUALS(PlanStage::IS_EOF, state);
        }
示例#4
0
文件: main.c 项目: vanhineam/Y86
int main(int argc, char * argv[])
{
  argc -= setDebugOptions(argc, argv);

  initialize();

  bool loadError = !load(argc, argv);
  if (loadError)
  {
    dumpMemory();
    return 1;
  }

  unsigned int clockCount = 0;
  bool stop = FALSE;
  
  pipelineForward forward;
  clearBuffer((char*)&forward, sizeof(pipelineForward));

  while(!stop)
  {
    dumpStage(DBG_WRITEBACK_STAGE);
    stop = writebackStage(&forward);

    dumpStage(DBG_MEMORY_STAGE);
    memoryStage(&forward);

    dumpStage(DBG_EXECUTE_STAGE);
    executeStage(&forward);

    dumpStage(DBG_DECODE_STAGE);
    decodeStage(forward);

    dumpStage(DBG_FETCH_STAGE);
    fetchStage();

    ++clockCount;
  }

  printf("\nTotal clock cycles = %d\n", clockCount);

  return 0;
}
示例#5
0
int main(int argv, char * args[]){
    initialize(); 
    if(!load(argv, args)){
        dumpMemory();
        exit(0);
    }

    int clockCount = 0;
    bool stop = false;
    forwardType forward; //added for lab7
    statusType status;//lab 9
    while(!stop){
        stop = writebackStage(&forward, &status);
        memoryStage(&forward, &status);
        executeStage(&forward, status);
        decodeStage(forward);
        fetchStage(forward);
        clockCount++;
    }

    printf("\nTotal clock cycles = %d\n", clockCount);
}