/** * construct a new monitor * * @param s Simulator */ Monitor(Simulator s) { simulator = s; program = s.getProgram(); labelLookup = new HashMap(); profiles = new LinkedList(); procedureProbe = new ProcedureProbe(); sleepCycles = 0; sleepProbe = new SleepProbe(); // find all sleep opcodes in the program findSleep(); // scan all labels and put the in the list setupLabels(); // startup values lastChange = 0; currentMode = nearestLabel(0); // scan each basic block and find the corresponding label, e.g. procedure Iterator it = program.getCFG().getSortedBlockIterator(); int address; int size; while (it.hasNext()) { Block block = (Block) it.next(); size = block.getSize(); address = block.getAddress(); if (size > 0 && program.readInstr(address) != null) { labelLookup.put(new Integer(address), nearestLabel(address)); s.insertProbe(procedureProbe, address); } } }
/** find all sleep opcodes in the program */ private void findSleep() { int i = 0; while (i < program.program_length) { LegacyInstr instr = (LegacyInstr) program.readInstr(i); if (instr != null) { if ("sleep".equals(instr.properties.name)) { simulator.insertProbe(sleepProbe, i); } i += instr.getSize(); } else i += 1; } }