protected AstTranslator(IClassLoader loader, Map<Object, CAstEntity> namedEntityResolver, ArrayOpHandler arrayOpHandler) { this.loader = loader; this.namedEntityResolver = namedEntityResolver; this.arrayOpHandler = arrayOpHandler!=null? arrayOpHandler: this; this.insts = loader.getInstructionFactory(); }
protected AstTranslator(IClassLoader loader, Map<Object, CAstEntity> namedEntityResolver, ArrayOpHandler arrayOpHandler) { this.loader = loader; this.namedEntityResolver = namedEntityResolver; this.arrayOpHandler = arrayOpHandler!=null? arrayOpHandler: this; this.insts = loader.getInstructionFactory(); }
/** * correct pi instructions with appropriate basic block numbers. we assume for now that pi instructions are always associated * with the normal "fall-thru" exit edge. */ private void updatePiInstrs(int normalSuccNodeNumber) { for (int i = 0; i < pis.size(); i++) { SSAPiInstruction pi = pis.get(i); SSAInstructionFactory insts = getMethod().getDeclaringClass().getClassLoader().getInstructionFactory(); pis.set(i, insts.PiInstruction(SSAInstruction.NO_INDEX, pi.getDef(), pi.getVal(), getGraphNodeId(), normalSuccNodeNumber, pi.getCause())); } }
/** * correct pi instructions with appropriate basic block numbers. we assume for now that pi instructions are always associated * with the normal "fall-thru" exit edge. */ private void updatePiInstrs(int normalSuccNodeNumber) { for (int i = 0; i < pis.size(); i++) { SSAPiInstruction pi = pis.get(i); SSAInstructionFactory insts = getMethod().getDeclaringClass().getClassLoader().getInstructionFactory(); pis.set(i, insts.PiInstruction(SSAInstruction.NO_INDEX, pi.getDef(), pi.getVal(), getGraphNodeId(), normalSuccNodeNumber, pi.getCause())); } }
@Override protected SSAPhiInstruction repairPhiDefs(SSAPhiInstruction phi, int[] newDefs) { return (SSAPhiInstruction) phi.copyForSSA(CFG.getMethod().getDeclaringClass().getClassLoader().getInstructionFactory(), newDefs, null); }
@Override protected SSAPhiInstruction repairPhiDefs(SSAPhiInstruction phi, int[] newDefs) { return (SSAPhiInstruction) phi.copyForSSA(CFG.getMethod().getDeclaringClass().getClassLoader().getInstructionFactory(), newDefs, null); }
@Override public SSANewInstruction addAllocation(TypeReference T) { if (cha.isSubclassOf(cha.lookupClass(T), cha.lookupClass(declaringClass.getClassLoader().getLanguage().getRootType()))) { int instance = nextLocal++; NewSiteReference ref = NewSiteReference.make(statements.size(), T); SSANewInstruction result = getDeclaringClass().getClassLoader().getInstructionFactory().NewInstruction(statements.size(), instance, ref); statements.add(result); return result; } else { return super.addAllocation(T); } }
@Override public SSANewInstruction addAllocation(TypeReference T) { if (cha.isSubclassOf(cha.lookupClass(T), cha.lookupClass(declaringClass.getClassLoader().getLanguage().getRootType()))) { int instance = nextLocal++; NewSiteReference ref = NewSiteReference.make(statements.size(), T); SSANewInstruction result = getDeclaringClass().getClassLoader().getInstructionFactory().NewInstruction(statements.size(), instance, ref); statements.add(result); return result; } else { return super.addAllocation(T); } }
private SSAInstruction undo(SSAInstruction inst, int use, int val) { int c = getNumberOfUses(inst); int[] newUses = new int[c]; for (int i = 0; i < c; i++) { if (i == use) newUses[i] = val; else newUses[i] = getUse(inst, i); } return inst.copyForSSA(CFG.getMethod().getDeclaringClass().getClassLoader().getInstructionFactory(), null, newUses); }
private SSAInstruction undo(SSAInstruction inst, int use, int val) { int c = getNumberOfUses(inst); int[] newUses = new int[c]; for (int i = 0; i < c; i++) { if (i == use) newUses[i] = val; else newUses[i] = getUse(inst, i); } return inst.copyForSSA(CFG.getMethod().getDeclaringClass().getClassLoader().getInstructionFactory(), null, newUses); }
private IMethod makeNullaryNumberCall(IClass cls) { JSInstructionFactory insts = (JSInstructionFactory)cls.getClassLoader().getInstructionFactory(); MethodReference ref = AstMethodReference.fnReference(JavaScriptTypes.Number); JavaScriptSummary S = new JavaScriptSummary(ref, 1); S.addConstant(Integer.valueOf(2), new ConstantValue(0.0)); S.addStatement(insts.ReturnInstruction(S.getNumberOfStatements(), 2, false)); S.getNextProgramCounter(); return new JavaScriptConstructor(ref, S, cls, cha.lookupClass(JavaScriptTypes.Number)); }
private IMethod makeNullaryNumberCall(IClass cls) { JSInstructionFactory insts = (JSInstructionFactory)cls.getClassLoader().getInstructionFactory(); MethodReference ref = AstMethodReference.fnReference(JavaScriptTypes.Number); JavaScriptSummary S = new JavaScriptSummary(ref, 1); S.addConstant(Integer.valueOf(2), new ConstantValue(0.0)); S.addStatement(insts.ReturnInstruction(S.getNumberOfStatements(), 2, false)); S.getNextProgramCounter(); return new JavaScriptConstructor(ref, S, cls, cha.lookupClass(JavaScriptTypes.Number)); }
private IMethod makeUnaryObjectConstructor(IClass cls) { JSInstructionFactory insts = (JSInstructionFactory)cls.getClassLoader().getInstructionFactory(); MethodReference ref = JavaScriptMethods.makeCtorReference(JavaScriptTypes.Object); JavaScriptSummary S = new JavaScriptSummary(ref, 2); S.addStatement(insts.ReturnInstruction(S.getNumberOfStatements(), 2, false)); S.getNextProgramCounter(); return new JavaScriptConstructor(ref, S, cls, cha.lookupClass(JavaScriptTypes.Object)); }
private IMethod makeNullaryStringCall(IClass cls) { JSInstructionFactory insts = (JSInstructionFactory)cls.getClassLoader().getInstructionFactory(); MethodReference ref = AstMethodReference.fnReference(JavaScriptTypes.String); JavaScriptSummary S = new JavaScriptSummary(ref, 1); S.addConstant(Integer.valueOf(2), new ConstantValue("")); S.addConstant(Integer.valueOf(3), new ConstantValue(0)); S.addStatement(insts.PutInstruction(S.getNumberOfStatements(), 2, 3, "length")); S.getNextProgramCounter(); S.addStatement(insts.ReturnInstruction(S.getNumberOfStatements(), 2, false)); S.getNextProgramCounter(); return new JavaScriptConstructor(ref, S, cls, cha.lookupClass(JavaScriptTypes.String)); }
private IMethod makeNullaryStringCall(IClass cls) { JSInstructionFactory insts = (JSInstructionFactory)cls.getClassLoader().getInstructionFactory(); MethodReference ref = AstMethodReference.fnReference(JavaScriptTypes.String); JavaScriptSummary S = new JavaScriptSummary(ref, 1); S.addConstant(Integer.valueOf(2), new ConstantValue("")); S.addConstant(Integer.valueOf(3), new ConstantValue(0)); S.addStatement(insts.PutInstruction(S.getNumberOfStatements(), 2, 3, "length")); S.getNextProgramCounter(); S.addStatement(insts.ReturnInstruction(S.getNumberOfStatements(), 2, false)); S.getNextProgramCounter(); return new JavaScriptConstructor(ref, S, cls, cha.lookupClass(JavaScriptTypes.String)); }
private SSABuilder(IBytecodeMethod method, SSACFG cfg, ShrikeCFG scfg, SSAInstruction[] instructions, SymbolTable symbolTable, boolean buildLocalMap, SSAPiNodePolicy piNodePolicy) { super(scfg); localMap = buildLocalMap ? new SSA2LocalMap(scfg, instructions.length, cfg.getNumberOfNodes()) : null; init(new SymbolTableMeeter(symbolTable, cfg, scfg), new SymbolicPropagator(scfg, instructions, symbolTable, localMap, cfg, piNodePolicy)); this.method = method; this.symbolTable = symbolTable; this.insts = method.getDeclaringClass().getClassLoader().getInstructionFactory(); this.bytecodeIndirections = method.getIndirectionData(); this.ssaIndirections = new ShrikeIndirectionData(instructions.length); assert cfg != null : "Null CFG"; }
private IMethod makeUnaryNumberCall(IClass cls) { JSInstructionFactory insts = (JSInstructionFactory)cls.getClassLoader().getInstructionFactory(); MethodReference ref = AstMethodReference.fnReference(JavaScriptTypes.Number); JavaScriptSummary S = new JavaScriptSummary(ref, 2); S.addStatement(insts.GetInstruction(S.getNumberOfStatements(), 4, 2, "toNumber")); S.getNextProgramCounter(); CallSiteReference cs = new DynamicCallSiteReference(JavaScriptTypes.CodeBody, S.getNextProgramCounter()); S.addStatement(insts.Invoke(S.getNumberOfStatements(), 4, 5, new int[] { 2 }, 6, cs)); S.addStatement(insts.ReturnInstruction(S.getNumberOfStatements(), 5, false)); S.getNextProgramCounter(); return new JavaScriptConstructor(ref, S, cls, cha.lookupClass(JavaScriptTypes.Number)); }
private IMethod makeUnaryStringCall(IClass cls) { JSInstructionFactory insts = (JSInstructionFactory)cls.getClassLoader().getInstructionFactory(); MethodReference ref = AstMethodReference.fnReference(JavaScriptTypes.String); JavaScriptSummary S = new JavaScriptSummary(ref, 2); S.addStatement(insts.GetInstruction(S.getNumberOfStatements(), 4, 2, "toString")); S.getNextProgramCounter(); CallSiteReference cs = new DynamicCallSiteReference(JavaScriptTypes.CodeBody, S.getNextProgramCounter()); S.addStatement(insts.Invoke(S.getNumberOfStatements(), 4, 5, new int[] { 2 }, 6, cs)); S.addStatement(insts.ReturnInstruction(S.getNumberOfStatements(), 5, false)); S.getNextProgramCounter(); return new JavaScriptConstructor(ref, S, cls, cha.lookupClass(JavaScriptTypes.String)); }
private IMethod makeUnaryNumberCall(IClass cls) { JSInstructionFactory insts = (JSInstructionFactory)cls.getClassLoader().getInstructionFactory(); MethodReference ref = AstMethodReference.fnReference(JavaScriptTypes.Number); JavaScriptSummary S = new JavaScriptSummary(ref, 2); S.addStatement(insts.GetInstruction(S.getNumberOfStatements(), 4, 2, "toNumber")); S.getNextProgramCounter(); CallSiteReference cs = new DynamicCallSiteReference(JavaScriptTypes.CodeBody, S.getNextProgramCounter()); S.addStatement(insts.Invoke(S.getNumberOfStatements(), 4, 5, new int[] { 2 }, 6, cs)); S.addStatement(insts.ReturnInstruction(S.getNumberOfStatements(), 5, false)); S.getNextProgramCounter(); return new JavaScriptConstructor(ref, S, cls, cha.lookupClass(JavaScriptTypes.Number)); }
private IMethod makeUnaryStringCall(IClass cls) { JSInstructionFactory insts = (JSInstructionFactory)cls.getClassLoader().getInstructionFactory(); MethodReference ref = AstMethodReference.fnReference(JavaScriptTypes.String); JavaScriptSummary S = new JavaScriptSummary(ref, 2); S.addStatement(insts.GetInstruction(S.getNumberOfStatements(), 4, 2, "toString")); S.getNextProgramCounter(); CallSiteReference cs = new DynamicCallSiteReference(JavaScriptTypes.CodeBody, S.getNextProgramCounter()); S.addStatement(insts.Invoke(S.getNumberOfStatements(), 4, 5, new int[] { 2 }, 6, cs)); S.addStatement(insts.ReturnInstruction(S.getNumberOfStatements(), 5, false)); S.getNextProgramCounter(); return new JavaScriptConstructor(ref, S, cls, cha.lookupClass(JavaScriptTypes.String)); }