bool CmdInstrument::onClientVM(DebuggerClient *client) { if (DebuggerCommand::onClient(client)) return true; if (client->argCount() == 1) { if (client->argValue(1) == "list" || client->argValue(1) == "l") { listInst(client); return true; } if (client->argValue(1) == "clear" || client->argValue(1) == "c") { clearInst(client); return true; } } if (client->argCount() < 2 || client->argValue(1) == "help") { return help(client); } std::string loc = client->argValue(1); std::string file = client->argValue(2); std::string desc; if (client->argCount() >= 3) { desc = client->argValue(3); } Variant code = f_file_get_contents(file.c_str()); if (code.isNull()) { client->error("Unable to read from file %s", file.c_str()); return false; } m_instPoints = client->getInstPoints(); if (loc == "here") { InstPointInfoPtr ipi(new InstPointInfo()); ipi->setLocHere(); ipi->m_code = code.toString(); ipi->m_desc = desc; m_instPoints->push_back(ipi); } else if (loc.rfind("()") == loc.size() - 2){ InstPointInfoPtr ipi(new InstPointInfo()); ipi->setLocFuncEntry(loc.substr(0, loc.size() - 2)); ipi->m_code = code.toString(); ipi->m_desc = desc; m_instPoints->push_back(ipi); } else { client->error("Not implemented\n"); return true; } m_type = ActionWrite; CmdInstrumentPtr instCmdPtr = client->xend<CmdInstrument>(this); if (!instCmdPtr->m_enabled) { client->error("Instrumentation is not enabled on the server"); } client->setInstPoints(instCmdPtr->m_ips); CmdInstrument::PrintInstPoints(client); return true; }
int main(int argc, char *argv[]) { InstInfo curInst[5]; InstInfo newInst; InstInfo * saved; int instnum = 0; int maxpc; int count=0; int cycles; // total cycles in the pipeline int needsFetch = 1; // fetching flag, 1 to fetch, 0 not to fetch int stall = 0; // stall flag, 1 to stall, 0 not to stall int isTaken = 0; int i=0; int j=0; FILE *program; if (argc != 2) { printf("Usage: sim filename\n"); exit(0); } maxpc = load(argv[1]); cycles = maxpc + 4;//**************************change to + 4 for REAL output if(debug)printf("cycles : %d \n" , cycles); if(debug)printLoad(maxpc); // initialize 5 instructions with 0 for(i=0; i<5; i++){ pipelineInsts[i]= &curInst[i]; pipelineInsts[i]->inst=0; if(debug)printf("DEBUG: pipelineInsts[%d]: %d\n", i, pipelineInsts[i]->inst); } do{ doStage(needsFetch, &stall, &cycles, &count); // doStage calls stage functions saved = pipelineInsts[4]; // save the unused pointer for reuse // setting needsFetch flag if(count < maxpc) needsFetch = 1; else needsFetch = 0; if(debug)printf("DEBUG: stall value: %d\n", stall); // if stall is not being set if(!stall){ if(debug)printf("DEBUG: no stall\n"); if(debug)printf("DEBUG: not stall before, pipelineInst[0] ----> %d, %s\n", pipelineInsts[0]->inst, pipelineInsts[0]->string); printP2(pipelineInsts[0], pipelineInsts[1], pipelineInsts[2], pipelineInsts[3], pipelineInsts[4], count); //shift down 4 instructions for(i=4; i>0; i--){ pipelineInsts[i]=pipelineInsts[i-1]; } //printf("DEBUG: no stall, swap....\n"); //printP2(pipelineInsts[0], pipelineInsts[1], pipelineInsts[2], pipelineInsts[3], pipelineInsts[4], count); //saved->inst = 0; // reset inst = 0 pipelineInsts[0] = saved; // reuse the unused inst pointer clearInst(pipelineInsts[0]); if(debug)printf("DEBUG: not stall after, pipelineInst[0] ----> %d, %s\n", pipelineInsts[0]->inst, pipelineInsts[0]->string); } // if stall is being set else{ if(debug)printf("DEBUG: stall before, pipelineInst[0] ----> %d, %s\n", pipelineInsts[0]->inst, pipelineInsts[0]->string); if(debug)printf("DEBUG: stalls\n"); printP2(pipelineInsts[0], pipelineInsts[1], pipelineInsts[2], pipelineInsts[3], pipelineInsts[4], count); pipelineInsts[4] = pipelineInsts[3]; // shift down memory stage pipelineInsts[3] = pipelineInsts[2]; // shitf down execute stage saved->inst = 0; // reset the unused inst to be 0 pipelineInsts[2] = saved; // stall the execute stage clearInst(pipelineInsts[2]); stall = 0; // reset stall flag cycles++; if(debug)printf("DEBUG: stall after, pipelineInst[0] ----> %d, %s\n", pipelineInsts[0]->inst, pipelineInsts[0]->string); //printf("DEBUG: stall, swap....\n"); //printP2(pipelineInsts[0], pipelineInsts[1], pipelineInsts[2], pipelineInsts[3], pipelineInsts[4], count); } count++; // increment count for cycles }while(count < cycles); // put in your own variables printf("Cycles: %d\n", count); printf("Instructions Executed: %d\n", maxpc); exit(0); }