private Variable getVariable(int index) { while (index >= program.variableCount()) { program.createVariable(); } return program.variableAt(index); }
public ValueEmitter constantNull(ValueType type) { Variable var = program.createVariable(); NullConstantInstruction insn = new NullConstantInstruction(); insn.setReceiver(var); addInstruction(insn); return var(var, type); }
public ValueEmitter constant(int value) { Variable var = program.createVariable(); IntegerConstantInstruction insn = new IntegerConstantInstruction(); insn.setReceiver(var); insn.setConstant(value); addInstruction(insn); return var(var, ValueType.INTEGER); }
private static Variable unbox(Variable var, Class<?> boxed, Class<?> primitive) { InvokeInstruction insn = new InvokeInstruction(); insn.setInstance(var); insn.setType(InvocationType.VIRTUAL); insn.setMethod(new MethodReference(boxed, primitive.getName() + "Value", primitive)); var = generator.program.createVariable(); insn.setReceiver(var); generator.add(insn); return var; }
public ValueEmitter constant(long value) { Variable var = program.createVariable(); LongConstantInstruction insn = new LongConstantInstruction(); insn.setReceiver(var); insn.setConstant(value); addInstruction(insn); return var(var, ValueType.LONG); }
public ValueEmitter constant(ValueType value) { Variable var = program.createVariable(); ClassConstantInstruction insn = new ClassConstantInstruction(); insn.setReceiver(var); insn.setConstant(value); addInstruction(insn); return var(var, ValueType.object("java.lang.Class")); }
public ValueEmitter constant(String value) { Variable var = program.createVariable(); StringConstantInstruction insn = new StringConstantInstruction(); insn.setReceiver(var); insn.setConstant(value); addInstruction(insn); return var(var, ValueType.object("java.lang.String")); }
public ValueEmitter cloneArray() { Variable result = pe.getProgram().createVariable(); CloneArrayInstruction insn = new CloneArrayInstruction(); insn.setArray(variable); insn.setReceiver(result); pe.addInstruction(insn); return pe.var(result, type); }
private Variable unwrapArray(ValueType type, Variable array) { CastInstruction cast = new CastInstruction(); cast.setTargetType(ValueType.arrayOf(type)); cast.setValue(array); cast.setReceiver(program.createVariable()); add(cast); UnwrapArrayInstruction unwrap = new UnwrapArrayInstruction(asArrayType(type)); unwrap.setArray(cast.getReceiver()); unwrap.setReceiver(program.createVariable()); add(unwrap); return unwrap.getReceiver(); }
public ValueEmitter instanceOf(ValueType type) { Variable result = pe.getProgram().createVariable(); IsInstanceInstruction insn = new IsInstanceInstruction(); insn.setValue(variable); insn.setReceiver(result); insn.setType(type); pe.addInstruction(insn); return pe.var(result, ValueType.BOOLEAN); }
private Variable box(Variable var, Class<?> primitive, Class<?> wrapper) { InvokeInstruction insn = new InvokeInstruction(); insn.setMethod(new MethodReference(wrapper, "valueOf", primitive, wrapper)); insn.setType(InvocationType.SPECIAL); insn.setArguments(var); var = program.createVariable(); insn.setReceiver(var); add(insn); return var; }
public ValueEmitter construct(String className, ValueEmitter... arguments) { Variable var = program.createVariable(); ConstructInstruction insn = new ConstructInstruction(); insn.setReceiver(var); insn.setType(className); addInstruction(insn); ValueEmitter instance = var(var, ValueType.object(className)); instance.invokeSpecial("<init>", void.class, arguments); return instance; }
public ValueEmitter constructArray(ValueType type, ValueEmitter size) { Variable var = program.createVariable(); ConstructArrayInstruction insn = new ConstructArrayInstruction(); insn.setReceiver(var); insn.setSize(size.getVariable()); insn.setItemType(type); addInstruction(insn); return var(var, ValueType.arrayOf(type)); }
public ValueEmitter arrayLength() { if (!(type instanceof ValueType.Array)) { throw new EmitException("Can't get length of non-array type: " + type); } Variable result = pe.getProgram().createVariable(); ArrayLengthInstruction insn = new ArrayLengthInstruction(); insn.setArray(unwrapArray().variable); insn.setReceiver(result); pe.addInstruction(insn); return pe.var(result, ValueType.INTEGER); }
private ValueEmitter unwrapArray() { ValueType elementType = ((ValueType.Array) type).getItemType(); Variable result = pe.getProgram().createVariable(); UnwrapArrayInstruction insn = new UnwrapArrayInstruction(getArrayElementType(elementType)); insn.setArray(variable); insn.setReceiver(result); pe.addInstruction(insn); return pe.var(result, type); }
@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(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(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; } }
private ValueEmitter binaryOp(BinaryOperation op, ValueEmitter a, ValueEmitter b, ValueType type) { Variable var = pe.getProgram().createVariable(); PrimitiveType common = ((ValueType.Primitive) a.type).getKind(); BinaryInstruction insn = new BinaryInstruction(op, convertToNumeric(common)); insn.setFirstOperand(a.getVariable()); insn.setSecondOperand(b.getVariable()); insn.setReceiver(var); pe.addInstruction(insn); return pe.var(var, type); }