public void start() { if (!_mg.isAbstract() && !_mg.isNative()) { for (InstructionHandle ih = _mg.getInstructionList().getStart(); ih != null; ih = ih .getNext()) { final Instruction i = ih.getInstruction(); if (i instanceof BranchInstruction) { branch_map.put(i, ih); // memorize container } if (ih.hasTargeters()) { if (i instanceof BranchInstruction) { _out.println(" InstructionHandle ih_" + ih.getPosition() + ";"); } else { _out.print(" InstructionHandle ih_" + ih.getPosition() + " = "); } } else { _out.print(" "); } if (!visitInstruction(i)) { i.accept(this); } } updateBranchTargets(); updateExceptionHandlers(); } }
private void updateBranchTargets() { for (final BranchInstruction bi : branches) { final BranchHandle bh = (BranchHandle) branch_map.get(bi); final int pos = bh.getPosition(); final String name = bi.getName() + "_" + pos; int t_pos = bh.getTarget().getPosition(); _out.println(" " + name + ".setTarget(ih_" + t_pos + ");"); if (bi instanceof Select) { final InstructionHandle[] ihs = ((Select) bi).getTargets(); for (int j = 0; j < ihs.length; j++) { t_pos = ihs[j].getPosition(); _out.println(" " + name + ".setTarget(" + j + ", ih_" + t_pos + ");"); } } } }
public void translateDesynthesized(ClassGenerator classGen, MethodGenerator methodGen) { final Type tleft = _left.getType(); final InstructionList il = methodGen.getInstructionList(); if (tleft instanceof BooleanType) { _left.translate(classGen, methodGen); _right.translate(classGen, methodGen); _falseList.add(il.append(_op == Operators.EQ ? (BranchInstruction)new IF_ICMPNE(null) : (BranchInstruction)new IF_ICMPEQ(null))); } else if (tleft instanceof NumberType) { _left.translate(classGen, methodGen); _right.translate(classGen, methodGen); if (tleft instanceof RealType) { il.append(DCMPG); _falseList.add(il.append(_op == Operators.EQ ? (BranchInstruction)new IFNE(null) : (BranchInstruction)new IFEQ(null))); } else { _falseList.add(il.append(_op == Operators.EQ ? (BranchInstruction)new IF_ICMPNE(null) : (BranchInstruction)new IF_ICMPEQ(null))); } } else { translate(classGen, methodGen); desynthesize(classGen, methodGen); } }
public void translateDesynthesized(ClassGenerator classGen, MethodGenerator methodGen) { if (hasNodeSetArgs() || hasReferenceArgs()) { translate(classGen, methodGen); desynthesize(classGen, methodGen); } else { BranchInstruction bi = null; final InstructionList il = methodGen.getInstructionList(); _left.translate(classGen, methodGen); _right.translate(classGen, methodGen); // TODO: optimize if one of the args is 0 boolean tozero = false; Type tleft = _left.getType(); if (tleft instanceof RealType) { il.append(tleft.CMP(_op == Operators.LT || _op == Operators.LE)); tleft = Type.Int; tozero = true; } switch (_op) { case Operators.LT: bi = tleft.GE(tozero); break; case Operators.GT: bi = tleft.LE(tozero); break; case Operators.LE: bi = tleft.GT(tozero); break; case Operators.GE: bi = tleft.LT(tozero); break; default: ErrorMsg msg = new ErrorMsg(ErrorMsg.ILLEGAL_RELAT_OP_ERR,this); getParser().reportError(Constants.FATAL, msg); } _falseList.add(il.append(bi)); // must be backpatched } }
public BranchInstruction GT(boolean tozero) { return tozero ? (BranchInstruction) new IFGT(null) : (BranchInstruction) new IF_ICMPGT(null); }
public BranchInstruction GE(boolean tozero) { return tozero ? (BranchInstruction) new IFGE(null) : (BranchInstruction) new IF_ICMPGE(null); }
public BranchInstruction LT(boolean tozero) { return tozero ? (BranchInstruction) new IFLT(null) : (BranchInstruction) new IF_ICMPLT(null); }
public BranchInstruction LE(boolean tozero) { return tozero ? (BranchInstruction) new IFLE(null) : (BranchInstruction) new IF_ICMPLE(null); }
public BranchInstruction GT(boolean tozero) { return null; // should never be called }
public BranchInstruction GE(boolean tozero) { return null; // should never be called }
public BranchInstruction LT(boolean tozero) { return null; // should never be called }
public BranchInstruction LE(boolean tozero) { return null; // should never be called }
@Override public void visitBranchInstruction( final BranchInstruction bi ) { final BranchHandle bh = (BranchHandle) branch_map.get(bi); final int pos = bh.getPosition(); final String name = bi.getName() + "_" + pos; if (bi instanceof Select) { final Select s = (Select) bi; branches.add(bi); final StringBuilder args = new StringBuilder("new int[] { "); final int[] matchs = s.getMatchs(); for (int i = 0; i < matchs.length; i++) { args.append(matchs[i]); if (i < matchs.length - 1) { args.append(", "); } } args.append(" }"); _out.print("Select " + name + " = new " + bi.getName().toUpperCase(Locale.ENGLISH) + "(" + args + ", new InstructionHandle[] { "); for (int i = 0; i < matchs.length; i++) { _out.print("null"); if (i < matchs.length - 1) { _out.print(", "); } } _out.println(" }, null);"); } else { final int t_pos = bh.getTarget().getPosition(); String target; if (pos > t_pos) { target = "ih_" + t_pos; } else { branches.add(bi); target = "null"; } _out.println(" BranchInstruction " + name + " = _factory.createBranchInstruction(" + CONSTANT_PREFIX + bi.getName().toUpperCase(Locale.ENGLISH) + ", " + target + ");"); } if (bh.hasTargeters()) { _out.println(" ih_" + pos + " = il.append(" + name + ");"); } else { _out.println(" il.append(" + name + ");"); } }