map[var] = known.value; if (!name.isEmpty()) { program.variableAt(known.value).setDebugName(name); knownValues.put(name + ":" + value, known);
private void renameOutgoingPhis(int successor, boolean allVersions) { int[] phiIndexes = phiIndexMap[successor]; List<Phi> phis = synthesizedPhisByBlock.get(successor); for (int j = 0; j < phis.size(); ++j) { Phi phi = phis.get(j); Variable originalVar = program.variableAt(phiIndexes[j]); Variable var = variableMap[phiIndexes[j]]; if (var != null) { List<Variable> versions = definedVersions.get(phiIndexes[j]); if (versions != null && allVersions) { for (Variable version : versions) { Incoming incoming = new Incoming(); incoming.setSource(currentBlock); incoming.setValue(version); phi.getIncomings().add(incoming); } } Variable sigmaVar = applySigmaRename(program.basicBlockAt(successor), originalVar); Incoming incoming = new Incoming(); incoming.setSource(currentBlock); incoming.setValue(sigmaVar != originalVar ? sigmaVar : var); phi.getIncomings().add(incoming); phi.getReceiver().setDebugName(var.getDebugName()); } } }
private Variable introduce(Variable var) { if (!usedDefinitions[var.getIndex()]) { usedDefinitions[var.getIndex()] = true; } else { Variable old = var; var = program.createVariable(); var.setDebugName(old.getDebugName()); var.setLabel(old.getLabel()); } return var; }
private void renameVariables(Program program, int[] varMap) { InstructionVariableMapper mapper = new InstructionVariableMapper(var -> program.variableAt(varMap[var.getIndex()])); for (int i = 0; i < program.basicBlockCount(); ++i) { BasicBlock block = program.basicBlockAt(i); mapper.apply(block); } String[] originalNames = getVariableNames(program, false); for (int i = 0; i < program.variableCount(); ++i) { program.variableAt(i).setDebugName(null); } for (int i = 0; i < program.variableCount(); ++i) { Variable var = program.variableAt(varMap[i]); if (originalNames[i] != null) { var.setDebugName(originalNames[i]); } } }
@Override public void visit(NullConstantInstruction insn) { var = program.createVariable(); var.setDebugName(insn.getReceiver().getDebugName()); var.setLabel(insn.getReceiver().getLabel()); NullConstantInstruction copy = new NullConstantInstruction(); copy.setReceiver(var); this.copy = copy; }
if (receiver >= 0) { Variable receiverVar = program.variableAt(receiver); receiverVar.setDebugName(debugName.getValue()); receiverVar.setLabel(debugName.getValue());
@Override public void visit(IntegerConstantInstruction insn) { var = program.createVariable(); var.setDebugName(insn.getReceiver().getDebugName()); var.setLabel(insn.getReceiver().getLabel()); IntegerConstantInstruction copy = new IntegerConstantInstruction(); copy.setConstant(insn.getConstant()); copy.setReceiver(var); this.copy = copy; }
@Override public void visit(ClassConstantInstruction insn) { var = program.createVariable(); var.setDebugName(insn.getReceiver().getDebugName()); var.setLabel(insn.getReceiver().getLabel()); ClassConstantInstruction copy = new ClassConstantInstruction(); copy.setConstant(insn.getConstant()); copy.setReceiver(var); this.copy = copy; }
@Override public void visit(FloatConstantInstruction insn) { var = program.createVariable(); var.setDebugName(insn.getReceiver().getDebugName()); var.setLabel(insn.getReceiver().getLabel()); FloatConstantInstruction copy = new FloatConstantInstruction(); copy.setConstant(insn.getConstant()); copy.setReceiver(var); this.copy = copy; }
@Override public void visit(LongConstantInstruction insn) { var = program.createVariable(); var.setDebugName(insn.getReceiver().getDebugName()); var.setLabel(insn.getReceiver().getLabel()); LongConstantInstruction copy = new LongConstantInstruction(); copy.setConstant(insn.getConstant()); copy.setReceiver(var); this.copy = copy; }
@Override public void visit(StringConstantInstruction insn) { var = program.createVariable(); var.setDebugName(insn.getReceiver().getDebugName()); var.setLabel(insn.getReceiver().getLabel()); StringConstantInstruction copy = new StringConstantInstruction(); copy.setConstant(insn.getConstant()); copy.setReceiver(var); this.copy = copy; } }
@Override public void visit(DoubleConstantInstruction insn) { var = program.createVariable(); var.setDebugName(insn.getReceiver().getDebugName()); var.setLabel(insn.getReceiver().getLabel()); DoubleConstantInstruction copy = new DoubleConstantInstruction(); copy.setConstant(insn.getConstant()); copy.setReceiver(var); this.copy = copy; }
private void parsePrologue() throws IOException, ListingParseException { while (true) { while (lexer.getToken() == ListingToken.EOL) { lexer.nextToken(); } if (lexer.getToken() != ListingToken.IDENTIFIER || !lexer.getTokenValue().equals("var")) { break; } lexer.nextToken(); expect(ListingToken.VARIABLE); String variableName = (String) lexer.getTokenValue(); if (variableMap.containsKey(variableName)) { throw new ListingParseException("Variable " + variableName + " already declared", lexer.getTokenStart()); } lexer.nextToken(); expectKeyword("as"); expect(ListingToken.IDENTIFIER); String variableAlias = (String) lexer.getTokenValue(); lexer.nextToken(); expectEofOrEol(); Variable variable = program.createVariable(); variable.setLabel(variableName); variable.setDebugName(variableAlias); variableMap.put(variableName, variable); } }
private Program createStubCopy(Program program) { Program copy = new Program(); for (int i = 0; i < program.basicBlockCount(); ++i) { copy.createBasicBlock(); } for (int i = 0; i < program.variableCount(); ++i) { Variable var = program.variableAt(i); copy.createVariable(); Variable varCopy = copy.variableAt(i); varCopy.setRegister(var.getRegister()); varCopy.setDebugName(var.getDebugName()); varCopy.setLabel(var.getLabel()); } return copy; }
preheaderPhi.setReceiver(program.createVariable()); preheaderPhi.getReceiver().setLabel(phi.getReceiver().getLabel()); preheaderPhi.getReceiver().setDebugName(phi.getReceiver().getDebugName()); preheader.getPhis().add(preheaderPhi);
public static Program copy(ProgramReader program) { Program copy = new Program(); for (int i = 0; i < program.variableCount(); ++i) { Variable var = copy.createVariable(); var.setDebugName(program.variableAt(i).getDebugName()); var.setLabel(program.variableAt(i).getLabel()); } for (int i = 0; i < program.basicBlockCount(); ++i) { copy.createBasicBlock(); } for (int i = 0; i < program.basicBlockCount(); ++i) { BasicBlockReader block = program.basicBlockAt(i); BasicBlock blockCopy = copy.basicBlockAt(i); copyBasicBlock(block, blockCopy); } return copy; }
Variable outgoingVar = program.createVariable(); variableToSourceMap.add(sigma.getValue().getIndex()); outgoingVar.setDebugName(sigma.getValue().getDebugName()); outgoingVar.setLabel(sigma.getValue().getLabel()); Outgoing outgoing = new Outgoing(outgoingVar, target);
@Override public void visit(AssignInstruction insn) { if (namesPreserved) { if (insn.getReceiver().getDebugName() != null && insn.getAssignee().getDebugName() != null) { if (!insn.getAssignee().getDebugName().equals(insn.getReceiver().getDebugName())) { return; } } } if (insn.getReceiver().getDebugName() != null) { insn.getAssignee().setDebugName(insn.getReceiver().getDebugName()); } if (insn.getReceiver().getLabel() != null) { insn.getAssignee().setLabel(insn.getReceiver().getLabel()); } map[insn.getReceiver().getIndex()] = map[insn.getAssignee().getIndex()]; eliminate = true; }
void processMemberMethods(ClassHolder cls) { for (MethodHolder method : cls.getMethods().toArray(new MethodHolder[0])) { if (method.hasModifier(ElementModifier.STATIC)) { continue; } if (method.getProgram() != null && method.getProgram().basicBlockCount() > 0) { ValueType[] staticSignature = getStaticSignature(method.getReference()); MethodHolder callerMethod = new MethodHolder(new MethodDescriptor(method.getName() + "$static", staticSignature)); callerMethod.getModifiers().add(ElementModifier.STATIC); Program program = ProgramUtils.copy(method.getProgram()); program.createVariable(); InstructionVariableMapper variableMapper = new InstructionVariableMapper(var -> program.variableAt(var.getIndex() + 1)); for (int i = program.variableCount() - 1; i > 0; --i) { program.variableAt(i).setDebugName(program.variableAt(i - 1).getDebugName()); program.variableAt(i).setLabel(program.variableAt(i - 1).getLabel()); } for (int i = 0; i < program.basicBlockCount(); ++i) { BasicBlock block = program.basicBlockAt(i); variableMapper.apply(block); } callerMethod.setProgram(program); ModelUtils.copyAnnotations(method.getAnnotations(), callerMethod.getAnnotations()); cls.addMethod(callerMethod); } } }
private void insertCopy(Incoming incoming, Map<BasicBlock, BasicBlock> blockMap) { Phi phi = incoming.getPhi(); Program program = phi.getBasicBlock().getProgram(); AssignInstruction copyInstruction = new AssignInstruction(); Variable firstCopy = program.createVariable(); firstCopy.setLabel(phi.getReceiver().getLabel()); firstCopy.setDebugName(phi.getReceiver().getDebugName()); copyInstruction.setReceiver(firstCopy); copyInstruction.setAssignee(incoming.getValue()); BasicBlock source = blockMap.get(incoming.getSource()); if (source == null) { source = incoming.getSource(); } else { incoming.setSource(source); } if (!(incoming.getSource().getLastInstruction() instanceof JumpInstruction)) { BasicBlock copyBlock = program.createBasicBlock(); JumpInstruction jumpInstruction = new JumpInstruction(); jumpInstruction.setLocation(incoming.getSource().getLastInstruction().getLocation()); jumpInstruction.setTarget(phi.getBasicBlock()); copyBlock.add(jumpInstruction); incoming.getSource().getLastInstruction().acceptVisitor(new BasicBlockMapper((int block) -> block == phi.getBasicBlock().getIndex() ? copyBlock.getIndex() : block)); blockMap.put(source, copyBlock); incoming.setSource(copyBlock); source = copyBlock; } source.getLastInstruction().insertPrevious(copyInstruction); incoming.setValue(copyInstruction.getReceiver()); }