public boolean calculateLiveIN() { boolean bChanges = false; mapRegistersToVariables(); // The last lastLive set is a copy of liveOUT LiveSet lastLive = new LiveSet(getLiveOut()); for (int i = getLines().getNumItems() - 1; i >= 0; i--) { Line line = getLines().getItemAtIndex(i); // Copy the last live set line.getLiveSet().copy(lastLive); if (Line.Type.INSTRUCTION == line.getType()) { Instruction instr = (Instruction) line; Argument arg2 = instr.getArgument2(); // If this is a SW instruction, then remove the // target variable from the live set if (0 == instr.getInstruction().compareTo("sw")) { // Remove the mapping to the variable line.getLiveSet().remove(arg2.getName()); // See if Argument1 is mapped to a variable if (instr.getMapRegToValue().containsKey(instr.getArgument1().getName())) { String strVal = instr.getMapRegToValue().get(instr.getArgument1().getName()); // Mark the variable as live line.getLiveSet().add(strVal); } } // If this is a LW instruction, then add the loaded // variable to the live set else if (0 == instr.getInstruction().compareTo("lw") || 0 == instr.getInstruction().compareTo("li")) { line.getLiveSet().add(arg2.getName()); } else if (!instr.getIsJump() && 0 != instr.getInstruction().compareTo("syscall") && 0 != instr.getInstruction().compareTo("move") && 0 != instr.getInstruction().compareTo("li")) { // See if Argument2 is mapped to a variable if (instr.getMapRegToValue().containsKey(instr.getArgument2().getName())) { String strVal = instr.getMapRegToValue().get(instr.getArgument2().getName()); // Mark the variable as live line.getLiveSet().add(strVal); } // See if Argument3 is mapped to a variable if (instr.getMapRegToValue().containsKey(instr.getArgument3().getName())) { String strVal = instr.getMapRegToValue().get(instr.getArgument3().getName()); // Mark the variable as live line.getLiveSet().add(strVal); } } else if (0 == instr.getInstruction().compareTo("move")) { // See if Argument2 is mapped to a variable if (instr.getMapRegToValue().containsKey(instr.getArgument2().getName())) { String strVal = instr.getMapRegToValue().get(instr.getArgument2().getName()); // Mark the variable as live line.getLiveSet().add(strVal); } } } lastLive = line.getLiveSet(); } getLiveIn().copy(lastLive); return bChanges; }