/** * Creates a method class$(String) which is used * during SomeClass.class instruction * * @param generatedClassName the instance class name */ protected void createHelperMethodForDotClassCalls(String generatedClassName) { InstructionList il = new InstructionList(); MethodGen method = new MethodGen(Constants.ACC_STATIC, new ObjectType("java.lang.Class"), new Type[]{Type.STRING}, new String[]{"arg0"}, "class$", generatedClassName, il, constantsPool); InstructionHandle ih0 = il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); il.append(factory.createInvoke("java.lang.Class", "forName", new ObjectType("java.lang.Class"), new Type[]{Type.STRING}, Constants.INVOKESTATIC)); InstructionHandle ih4 = il.append(InstructionFactory.createReturn(Type.OBJECT)); InstructionHandle ih5 = il.append(InstructionFactory.createStore(Type.OBJECT, 1)); il.append(factory.createNew("java.lang.NoClassDefFoundError")); il.append(InstructionConstants.DUP); il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); il.append(factory.createInvoke("java.lang.Throwable", "getMessage", Type.STRING, Type.NO_ARGS, Constants.INVOKEVIRTUAL)); il.append(factory.createInvoke("java.lang.NoClassDefFoundError", "<init>", Type.VOID, new Type[]{Type.STRING}, Constants.INVOKESPECIAL)); il.append(InstructionConstants.ATHROW); method.addExceptionHandler(ih0, ih4, ih5, new ObjectType("java.lang.ClassNotFoundException")); method.setMaxStack(); method.setMaxLocals(); classGen.addMethod(method.getMethod()); il.dispose(); }
public void storeLocal(int pc, int slot) { boolean isupval = pi.isUpvalueAssign(pc, slot); int index = findSlotIndex( slot, isupval ); if (isupval) { boolean isupcreate = pi.isUpvalueCreate(pc, slot); if ( isupcreate ) { append(factory.createInvoke(classname, "newupe", TYPE_LOCALUPVALUE, ARG_TYPES_NONE, Constants.INVOKESTATIC)); append(InstructionConstants.DUP); append(new ASTORE(index)); } else { append(new ALOAD(index)); } append(InstructionConstants.SWAP); append(new PUSH(cp, 0)); append(InstructionConstants.SWAP); append(InstructionConstants.AASTORE); } else { append(new ASTORE(index)); } }
@Override public void generateInitField(InstructionList il, InstructionFactory ifact, GenScope scope) { RequiredQueueJVMGen jvmQ = this; ClassGen cg = scope.getClassGen(); il.append(ifact.createNew(jvmQ.getType().getClassName())); il.append(new DUP()); il.append(ifact.createConstant(jvmQ.getName())); // il.append(InstructionConstants.THIS); /* il.append(ifact.createInvoke(jvmQ.getClassName(), "<init>", Type.VOID, new Type[] { Type.STRING, DefaultTypes.QoolTransformation }, Constants.INVOKESPECIAL)); */ // required queues do not take a qool transformation, but just delegates in one il.append(ifact.createInvoke(jvmQ.getClassName(), "<init>", Type.VOID, new Type[] { Type.STRING }, Constants.INVOKESPECIAL)); // Set the field il.append(InstructionConstants.THIS); il.append(InstructionConstants.SWAP); il.append( ifact.createPutField(cg.getClassName(), jvmQ.getFieldName(), jvmQ.getType()) ); }
private void createObserverCreatorMethod(ClassGen cg, ObserverDescription observer, String observerClassName) { final String methodName = "create" + observer.getName(); InstructionList il = new InstructionList(); InstructionFactory ifact = new InstructionFactory(cg); MethodGen mg = new MethodGen(Constants.ACC_PUBLIC, new ObjectType(observerClassName), new Type[] { } , null, methodName, cg.getClassName(), il, cg.getConstantPool()); il.append(ifact.createNew(observerClassName)); il.append(InstructionConstants.DUP); il.append(InstructionConstants.THIS); il.append(ifact.createInvoke(observerClassName, "<init>", Type.VOID, new Type[] { DefaultTypes.QoolTransformation }, Constants.INVOKESPECIAL)); il.append(InstructionFactory.ARETURN); mg.setMaxLocals(); mg.setMaxStack(); cg.addMethod(mg.getMethod()); }
@Override public void generateInitField(InstructionList il, InstructionFactory ifact, GenScope scope) { LocalQueueJVMGen jvmQ = this; ClassGen cg = scope.getClassGen(); il.append(ifact.createNew(jvmQ.getType().getClassName())); il.append(new DUP()); il.append(ifact.createConstant(jvmQ.getName())); il.append(InstructionConstants.THIS); il.append(ifact.createInvoke(jvmQ.getClassName(), "<init>", Type.VOID, new Type[] { Type.STRING, DefaultTypes.QoolTransformation }, Constants.INVOKESPECIAL)); // Stack: queue il.append(InstructionConstants.THIS); il.append(InstructionConstants.SWAP); il.append( ifact.createPutField(cg.getClassName(), jvmQ.getFieldName(), jvmQ.getType()) ); }
public void genContinuableCallCode(GenScope transformationScope, ClassGen cg, MethodGen mg) { InstructionList il = mg.getInstructionList(); InstructionFactory ifact = new InstructionFactory(cg); il.append(InstructionConstants.THIS); il.append(ifact.createConstant(getSegmentClassName())); transformationScope.generateGetTransformation(); transformationScope.generateGetModelManager(); il.append(ifact.createInvoke(DefaultTypes.QoolTransformation.getClassName(), "startSegment", Type.VOID, new Type[] { Type.STRING, DefaultTypes.IdcTransformation, DefaultTypes.ModelManager }, Constants.INVOKEVIRTUAL)); /* il.append(ifact.createConstant(getSegmentClassName())); transformationScope.generateGetTransformation(); transformationScope.generateGetModelManager(); il.append(ifact.createInvoke(DefaultTypes.RuntimeUtil.getClassName(), "startSegment", Type.VOID, new Type[] { Type.STRING, DefaultTypes.IdcTransformation, DefaultTypes.ModelManager }, Constants.INVOKESTATIC)); */ }
private void createStartMethod(GenScope scope, ClassGen cg) { InstructionList il = new InstructionList(); InstructionFactory ifact = new InstructionFactory(cg); MethodGen startMg = new MethodGen(Constants.ACC_PUBLIC,// access flags Type.VOID, // return type null, null, // arg // names START_METHOD, null, // method, class il, cg.getConstantPool()); scope.processMethod(startMg); il.append(InstructionConstants.RETURN); startMg.setMaxLocals(); startMg.setMaxStack(); cg.addMethod(startMg.getMethod()); }
protected void generateStreamer(ConstantPoolGen cp, InstructionList il, InstructionFactory factory, String className, boolean hasHeader) { il.append(InstructionConstants.ALOAD_0); il.append(InstructionConstants.ALOAD_1); il.append(InstructionConstants.DUP2); il.append(factory.createInvoke("org.dianahep.root4j.core.RootInput", "readInt", Type.INT, Type.NO_ARGS, INVOKEINTERFACE)); il.append(InstructionConstants.DUP_X1); il.append(factory.createPutField(className, "fN", Type.INT)); il.append(new NEWARRAY(Type.FLOAT)); il.append(InstructionConstants.DUP_X1); il.append(factory.createInvoke("org.dianahep.root4j.core.RootInput", "readFixedArray", Type.VOID, arrayArgType, INVOKEINTERFACE)); il.append(factory.createPutField(className, "fArray", RootType.FLOATARRAY)); }
protected void generateStreamer(ConstantPoolGen cp, InstructionList il, InstructionFactory factory, String className, boolean hasHeader) { il.append(InstructionConstants.ALOAD_0); il.append(InstructionConstants.ALOAD_1); il.append(InstructionConstants.DUP2); il.append(factory.createInvoke("org.dianahep.root4j.core.RootInput", "readInt", Type.INT, Type.NO_ARGS, INVOKEINTERFACE)); il.append(InstructionConstants.DUP_X1); il.append(factory.createPutField(className, "fN", Type.INT)); il.append(new NEWARRAY(Type.CHAR)); il.append(InstructionConstants.DUP_X1); il.append(factory.createInvoke("org.dianahep.root4j.core.RootInput", "readFixedArray", Type.VOID, arrayArgType, INVOKEINTERFACE)); il.append(factory.createPutField(className, "fArray", RootType.CHARARRAY)); }
protected void generateStreamer(ConstantPoolGen cp, InstructionList il, InstructionFactory factory, String className, boolean hasHeader) { il.append(InstructionConstants.ALOAD_0); il.append(InstructionConstants.ALOAD_1); il.append(InstructionConstants.DUP2); il.append(factory.createInvoke("org.dianahep.root4j.core.RootInput", "readInt", Type.INT, Type.NO_ARGS, INVOKEINTERFACE)); il.append(InstructionConstants.DUP_X1); il.append(factory.createPutField(className, "fN", Type.INT)); il.append(new NEWARRAY(Type.DOUBLE)); il.append(InstructionConstants.DUP_X1); il.append(factory.createInvoke("org.dianahep.root4j.core.RootInput", "readFixedArray", Type.VOID, arrayArgType, INVOKEINTERFACE)); il.append(factory.createPutField(className, "fArray", RootType.DOUBLEARRAY)); }
protected void generateStreamer(ConstantPoolGen cp, InstructionList il, InstructionFactory factory, String className, boolean hasHeader) { il.append(InstructionConstants.ALOAD_0); il.append(InstructionConstants.ALOAD_1); il.append(InstructionConstants.DUP2); il.append(factory.createInvoke("org.dianahep.root4j.core.RootInput", "readInt", Type.INT, Type.NO_ARGS, INVOKEINTERFACE)); il.append(InstructionConstants.DUP_X1); il.append(factory.createPutField(className, "fN", Type.INT)); il.append(new NEWARRAY(Type.INT)); il.append(InstructionConstants.DUP_X1); il.append(factory.createInvoke("org.dianahep.root4j.core.RootInput", "readFixedArray", Type.VOID, arrayArgType, INVOKEINTERFACE)); il.append(factory.createPutField(className, "fArray", RootType.INTARRAY)); }
public void generateReadCode(InstructionList il, InstructionFactory factory, ConstantPoolGen cp, String className) { if (pointer) { ((GenericRootClass) varClass).generateReadPointerCode(il, factory, cp); } else if (dim == 0) { varClass.generateReadCode(il, factory, cp); } else if (varCounter == null) { ((IntrinsicRootClass) varClass).generateReadArrayCode(il, factory, cp, 1, new int[]{index}); } else { BasicMember varMember = getMember(varCounter); if (varMember == null) throw new RuntimeException("Cannot find variable counter "+varCounter); Type varMemberType = varMember.getJavaType(); il.append(InstructionConstants.ALOAD_0); il.append(factory.createInvoke(className, nameMangler.mangleMember(varCounter), varMemberType, Type.NO_ARGS, INVOKESPECIAL)); if (varMemberType != Type.INT && varMemberType != Type.BYTE && varMemberType != Type.CHAR && varMemberType != Type.SHORT) il.append(factory.createCast(varMemberType, Type.INT)); BasicType type = (BasicType) varClass.getJavaType(); il.append(new NEWARRAY(type)); il.append(InstructionConstants.DUP_X1); Type[] arrayArgType = new Type[] { new ArrayType(type, 1) }; il.append(factory.createInvoke("org.dianahep.root4j.core.RootInput", "readFixedArray", Type.VOID, arrayArgType, INVOKEINTERFACE)); } if (varClass.getConvertMethod() != null) { il.append(factory.createInvoke("org.dianahep.root4j.interfaces." + varClass.getClassName(), varClass.getConvertMethod(), varClass.getJavaTypeForMethod(), Type.NO_ARGS, INVOKEINTERFACE)); } }
private static void generateMethods(RootClass k, ConstantPoolGen cp, InstructionList il, InstructionFactory factory, ClassGen cg, String className, String clonesClassName) { RootMember[] members = k.getMembers(); for (int i = 0; i < members.length; i++) { BasicMember member = (BasicMember) members[i]; Type type = member.getJavaType(); Type arrayType = new ArrayType(type, 1); MethodGen mg = new MethodGen(ACC_PUBLIC, type, null, null, nameMangler.mangleMember(member.getName()), className, il, cp); il.append(InstructionConstants.ALOAD_0); il.append(factory.createGetField(className, "clones", new ObjectType(clonesClassName))); il.append(InstructionConstants.ALOAD_0); il.append(factory.createGetField(className, "index", Type.INT)); il.append(factory.createInvoke(clonesClassName, nameMangler.mangleMember(member.getName()), type, new Type[] { Type.INT }, INVOKEVIRTUAL)); il.append(InstructionFactory.createReturn(type)); mg.setMaxStack(); mg.setMaxLocals(); cg.addMethod(mg.getMethod()); il.dispose(); } }
/** * Inject common exception catch blocks */ public void injectCommonExceptionCatchBlock(InstructionList il, MethodGen method, int variableIndex) { il.append(new INSTANCEOF(constantsPool.addClass(new ObjectType("java.lang.RuntimeException")))); BranchInstruction b1 = InstructionFactory.createBranchInstruction(Constants.IFEQ, null); il.append(b1); il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex)); il.append(factory.createCheckCast(new ObjectType("java.lang.RuntimeException"))); il.append(InstructionConstants.ATHROW); InstructionHandle ih1 = il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex)); il.append(new INSTANCEOF(constantsPool.addClass(new ObjectType("java.lang.Error")))); BranchInstruction b2 = InstructionFactory.createBranchInstruction(Constants.IFEQ, null); il.append(b2); il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex)); il.append(factory.createCheckCast(new ObjectType("java.lang.Error"))); il.append(InstructionConstants.ATHROW); InstructionHandle ih2 = il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex)); il.append(factory.createInvoke("java.lang.Throwable", "printStackTrace", Type.VOID, Type.NO_ARGS, Constants.INVOKEVIRTUAL)); il.append(factory.createNew("org.codehaus.jremoting.client.InvocationException")); il.append(InstructionConstants.DUP); il.append(factory.createNew("java.lang.StringBuffer")); il.append(InstructionConstants.DUP); il.append(new PUSH(constantsPool, "Should never get here: ")); il.append(factory.createInvoke("java.lang.StringBuffer", "<init>", Type.VOID, new Type[]{Type.STRING}, Constants.INVOKESPECIAL)); il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex)); il.append(factory.createInvoke("java.lang.Throwable", "getMessage", Type.STRING, Type.NO_ARGS, Constants.INVOKEVIRTUAL)); il.append(factory.createInvoke("java.lang.StringBuffer", "append", Type.STRINGBUFFER, new Type[]{Type.STRING}, Constants.INVOKEVIRTUAL)); il.append(factory.createInvoke("java.lang.StringBuffer", "toString", Type.STRING, Type.NO_ARGS, Constants.INVOKEVIRTUAL)); il.append(factory.createInvoke("org.codehaus.jremoting.client.InvocationException", "<init>", Type.VOID, new Type[]{Type.STRING}, Constants.INVOKESPECIAL)); il.append(InstructionConstants.ATHROW); b1.setTarget(ih1); b2.setTarget(ih2); }
private boolean change1(MethodGen mg) { InstructionList il = mg.getInstructionList(); InstructionFinder f = new InstructionFinder(il); String pat = "[LDC_W|LDC] INVOKEVIRTUAL IFNE ICONST_1 GOTO ICONST_0"; boolean changed = false; for(Iterator j = f.search(pat, new IsLdcClass()); j.hasNext(); ) { InstructionHandle[] match = (InstructionHandle[]) j.next(); // replace // LDC_W <class> // INVOKEVIRTUAL Class.desiredAssertionStatus // IFNE // ICONST_1 // goto // ICONST_0 // with // ICONST_1 changed = true; match[0].setInstruction(InstructionConstants.ICONST_1); try { il.delete(match[1], match[5]); // System.out.println(il); } catch (TargetLostException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } return changed; }
public void loadLocal(int pc, int slot) { boolean isupval = pi.isUpvalueRefer(pc, slot); int index = findSlotIndex( slot, isupval ); append(new ALOAD(index)); if (isupval) { append(new PUSH(cp, 0)); append(InstructionConstants.AALOAD); } }
public void loadUpvalue(int upindex) { boolean isrw = pi.isReadWriteUpvalue( pi.upvals[upindex] ); append(InstructionConstants.THIS); if ( isrw ) { append(factory.createFieldAccess(classname, upvalueName(upindex), TYPE_LOCALUPVALUE, Constants.GETFIELD)); append(new PUSH(cp,0)); append(InstructionConstants.AALOAD); } else { append(factory.createFieldAccess(classname, upvalueName(upindex), TYPE_LUAVALUE, Constants.GETFIELD)); } }
public void storeUpvalue(int pc, int upindex, int slot) { boolean isrw = pi.isReadWriteUpvalue( pi.upvals[upindex] ); append(InstructionConstants.THIS); if ( isrw ) { append(factory.createFieldAccess(classname, upvalueName(upindex), TYPE_LOCALUPVALUE, Constants.GETFIELD)); append(new PUSH(cp,0)); loadLocal(pc, slot); append(InstructionConstants.AASTORE); } else { loadLocal(pc, slot); append(factory.createFieldAccess(classname, upvalueName(upindex), TYPE_LUAVALUE, Constants.PUTFIELD)); } }
public void loadArrayArgs(int pc, int firstslot, int nargs) { append(new PUSH(cp, nargs)); append(new ANEWARRAY(cp.addClass(STR_LUAVALUE))); for ( int i=0; i<nargs; i++ ) { append(InstructionConstants.DUP); append(new PUSH(cp, i)); loadLocal(pc, firstslot++); append(new AASTORE()); } }
public void closureInitUpvalueFromUpvalue(String protoname, int newup, int upindex) { boolean isrw = pi.isReadWriteUpvalue( pi.upvals[upindex] ); Type uptype = isrw? (Type) TYPE_LOCALUPVALUE: (Type) TYPE_LUAVALUE; String srcname = upvalueName(upindex); String destname = upvalueName(newup); append(InstructionConstants.THIS); append(factory.createFieldAccess(classname, srcname, uptype, Constants.GETFIELD)); append(factory.createFieldAccess(protoname, destname, uptype, Constants.PUTFIELD)); }
private boolean visitInstruction( Instruction i ) { short opcode = i.getOpcode(); if ((InstructionConstants.INSTRUCTIONS[opcode] != null) && !(i instanceof ConstantPushInstruction) && !(i instanceof ReturnInstruction)) { // Handled below _out.println("il.append(InstructionConstants." + i.getName().toUpperCase(Locale.ENGLISH) + ");"); return true; } return false; }
public static void print(InstructionList il, InstructionFactory ifact) { ObjectType p_stream = new ObjectType("java.io.PrintStream"); il.append(ifact.createFieldAccess("java.lang.System", "out", p_stream, Constants.GETSTATIC)); il.append(InstructionConstants.SWAP); il.append(ifact.createInvoke("java.io.PrintStream", "println", Type.VOID, new Type[] { Type.OBJECT }, Constants.INVOKEVIRTUAL)); }
public static void printBoolean(InstructionList il, InstructionFactory ifact) { ObjectType p_stream = new ObjectType("java.io.PrintStream"); il.append(ifact.createFieldAccess("java.lang.System", "out", p_stream, Constants.GETSTATIC)); il.append(InstructionConstants.SWAP); il.append(ifact.createInvoke("java.io.PrintStream", "println", Type.VOID, new Type[] { Type.BOOLEAN }, Constants.INVOKEVIRTUAL)); }
@Override public void genCreate(Create c, GenScope scope) { InstructionList il = scope.getInstructionList(); InstructionFactory ifact = scope.getInstructionFactory(); CreationMechanismJVMGen creation = (CreationMechanismJVMGen) description.getCreationMechanism(c); VariableParameter[] variables = creation.sortConstructorVariablesParameters(c.getConstructorParameters()); String javaClassName = description.getJavaClass(c.getClassName()); il.append(ifact.createNew(javaClassName)); il.append(InstructionConstants.DUP); Type[] constructorTypes = new Type[variables.length]; for(int i = 0; i < variables.length; i++) { String constructorTypeStr = variables[i].featureMapping.getConstructorType(); constructorTypes[i] = computeParamType(constructorTypeStr); scope.loadVariable( scope.getRealVariable(variables[i].var), il); castIfNeeded(il, ifact, constructorTypeStr); } il.append(ifact.createInvoke(javaClassName, "<init>", Type.VOID, constructorTypes, Constants.INVOKESPECIAL)); il.append(InstructionConstants.DUP); scope.generateGetModel(modelName); il.append(ifact.createCheckCast(DefaultTypes.ApiModel)); il.append(InstructionConstants.SWAP); il.append(ifact.createInvoke(DefaultTypes.ApiModel.getClassName(), "addObject", Type.VOID, new Type[] { Type.OBJECT }, Constants.INVOKEVIRTUAL)); }
/** * The requirement is that the value to be set must be on the top of the stack * * @param scope * @param javaClassName * @param setterMethod * @param paramType * @param il * @param ifact * @param realReceptor */ private void genMonovaluedSet(GenScope scope, String javaClassName, Method setterMethod, InstructionList il, InstructionFactory ifact, Variable realReceptor, Type returnType) { String paramType = setterMethod.getParameterTypes().get(0); // push receptor scope.loadVariable(realReceptor, il); // push value // scope.loadVariable(realValue, il); il.append(InstructionConstants.SWAP); // cast to the expected type (this is needed because scope.newLocalVariable() usually takes Type.OBJECT) // also needed to convert to primitive types castIfNeeded(il, ifact, paramType); // invoke setter Type pType = computeParamType(paramType); il.append(ifact.createInvoke(javaClassName, setterMethod.getName(), returnType, new Type[] { pType }, Constants.INVOKEVIRTUAL)); if ( returnType != Type.VOID ) { il.append(InstructionConstants.POP); } }
private void createConstructor(GenScope scope, ClassGen cg) { InstructionList il = new InstructionList(); InstructionFactory ifact = new InstructionFactory(cg); // Call super il.append(InstructionConstants.THIS); il.append(new INVOKESPECIAL(cg.getConstantPool().addMethodref(cg.getSuperclassName(), "<init>", "()V"))); // Instantiate and register each transformation to be executed for (TransformationExecution exec : getExecutions()) { // TODO: Ensure the name obtained with "getTransformationName" is the one of the generated transformation (weak link now!) String transformationClassName = exec.getTransformationName(); // TODO: Find out the class package name!! transformationClassName = "eclectic." + transformationClassName; il.append(ifact.createNew(transformationClassName)); il.append(new DUP()); il.append(ifact.createInvoke(transformationClassName, "<init>", Type.VOID, new Type[] { }, Constants.INVOKESPECIAL)); il.append(InstructionConstants.THIS); il.append(InstructionConstants.SWAP); il.append(ifact.createInvoke(cg.getClassName(), "register", Type.VOID, new Type[] { DefaultTypes.IdcTransformation }, Constants.INVOKEVIRTUAL)); } il.append(InstructionConstants.RETURN); MethodGen mg = new MethodGen(Constants.ACC_PUBLIC, Type.VOID, new Type[] { } , null, "<init>", cg.getClassName(), il, cg.getConstantPool()); mg.setMaxStack(); cg.addMethod(mg.getMethod()); }
@Override public void generate(GenScope scope) { InstructionList il = scope.getInstructionList(); InstructionFactory ifact = scope.getInstructionFactory(); LocalVariableGen lvg = scope.newLocalVariable(this, Type.OBJECT); // Null initialization of the result il.append(InstructionConstants.ACONST_NULL); il.append(new ASTORE(lvg.getIndex())); generateWithNoVar(scope); il.append(new ASTORE(lvg.getIndex())); }
/** * A new IdcMetaclass object is created to wrap de * real metaclass providing additional functionality. * * <pre> * NEW IdcMetaclass * DUP * LDC <<model_name>> * LDC <<class_name>> * INVOKESPECIAL IdcMetaclass.<init> * ASTORE !!#variable!! * </pre> */ @Override public void generate(GenScope scope) { InstructionList il = scope.getInstructionList(); InstructionFactory ifact = scope.getInstructionFactory(); ConstantPoolGen cpg = scope.getConstantPool(); LocalVariableGen lvg = null; if ( getKind() == ReadMetaKind.METACLASS) { lvg = scope.newLocalVariable(this, DefaultTypes.IdcMetaclass); lvg.setStart(il.append(ifact.createNew(DefaultTypes.IdcMetaclass))); il.append(new DUP()); // il.append(new LDC(cpg.addString(getModel().getName()))); scope.generateGetTransformation(); scope.generateGetModel(getModel().getName()); // CommonGen.generateGetModel(getModel().getName(), il, ifact, scope); il.append(new LDC(cpg.addString(getClassName()))); il.append(ifact.createInvoke(DefaultTypes.IdcMetaclass.getClassName(), "<init>", Type.VOID, new Type[] { DefaultTypes.IdcTransformation, DefaultTypes.IModel, Type.STRING }, Constants.INVOKESPECIAL)); } else if ( getKind() == ReadMetaKind.THIS_TRANSFORMATION_OBJECT || getKind() == ReadMetaKind.THIS_TRANSFORMATION_METHOD_HANDLER ) { lvg = scope.newLocalVariable(this, DefaultTypes.IdcTransformation); lvg.setStart(il.append(InstructionConstants.NOP)); scope.generateGetTransformation(); } else if ( getKind() == ReadMetaKind.MODEL ){ lvg = scope.newLocalVariable(this, DefaultTypes.IModel); lvg.setStart(il.append(InstructionConstants.NOP)); scope.generateGetModel(getModel().getName()); } else { throw new IllegalArgumentException(); } il.append(new ASTORE(lvg.getIndex())); }
private void createConstructor(GenScope scope, ClassGen closureClass) { InstructionList il = new InstructionList(); il.append(InstructionConstants.THIS); // Push `this' il.append(new INVOKESPECIAL(closureClass.getConstantPool().addMethodref(closureClass.getSuperclassName(), "<init>", "()V"))); il.append(InstructionConstants.THIS); // Push `this' il.append(scope.getInstructionFactory().createConstant(this.getFormalParameters().size())); il.append(scope.getInstructionFactory().createPutField(DefaultTypes.IClosure.getClassName(), "numParameters_", Type.INT)); il.append(InstructionConstants.THIS); // Push `this' il.append(new ALOAD(1)); // first parameter il.append(scope.getInstructionFactory().createPutField(DefaultTypes.IClosure.getClassName(), "transformation_", DefaultTypes.IdcTransformation)); il.append(InstructionConstants.THIS); // Push `this' il.append(new ALOAD(2)); // second parameter il.append(scope.getInstructionFactory().createPutField(DefaultTypes.IClosure.getClassName(), "modelManager_", DefaultTypes.ModelManager)); // TODO: It would be nice to have cross-checking between code being generated and framework code /* il.append(InstructionConstants.THIS); // Push `this' il.append(new ALOAD(1)); // first parameter il.append(scope.getInstructionFactory().createPutField(DefaultTypes.IClosure.getClassName(), "modelManager_", DefaultTypes.ModelManager)); */ il.append(InstructionConstants.RETURN); MethodGen mg = new MethodGen(Constants.ACC_PUBLIC, Type.VOID, new Type[] { DefaultTypes.IdcTransformation, DefaultTypes.ModelManager } , null, "<init>", closureClass.getClassName(), il, closureClass.getConstantPool()); // mg.setMaxStack(3); mg.setMaxStack(); closureClass.addMethod(mg.getMethod()); }
private MethodGen createRunMethod(ClassGen closureClass, ClosureScope scope, GenScope parentScope) { InstructionList il = new InstructionList(); MethodGen mg = new MethodGen(Constants.ACC_PUBLIC,// access flags Type.VOID, Type.NO_ARGS, new String[] {}, "run", closureClass.getClassName(), // method, class il, closureClass.getConstantPool()); scope.processMethod(mg); InstructionFactory ifact = scope.getInstructionFactory(); il.append(InstructionFactory.THIS); for(int i = 0; i < formalParameters.size(); i++) { il.append(InstructionFactory.THIS); // with this, I get class-circularity-error // il.append(ifact.createGetField(DefaultTypes.RunnableClosure.getClassName(), "params", DefaultTypes.ArrayList)); il.append(ifact.createGetField(closureClass.getClassName(), "params", DefaultTypes.ArrayList)); il.append(new ICONST(i)); il.append(ifact.createInvoke(DefaultTypes.ArrayList.getClassName(), "get", Type.OBJECT, new Type[] { Type.INT }, Constants.INVOKEVIRTUAL)); } il.append(ifact.createInvoke(closureClass.getClassName(), "call", Type.OBJECT, getParameterTypes(), Constants.INVOKEVIRTUAL)); il.append(InstructionFactory.THIS); il.append(InstructionConstants.SWAP); il.append(ifact.createPutField(closureClass.getClassName(), "result", Type.OBJECT)); InstructionHandle end = il.append(InstructionConstants.RETURN); // TODO: Line numbers mg.setMaxStack(); mg.setMaxLocals(); return mg; }
private void createConstructor(GenScope scope, ClassGen cg) { InstructionList il = new InstructionList(); InstructionFactory ifact = new InstructionFactory(cg); MethodGen mg = new MethodGen(Constants.ACC_PUBLIC, Type.VOID, new Type[] { } , null, "<init>", cg.getClassName(), il, cg.getConstantPool()); scope.processMethod(mg); // call super il.append(InstructionConstants.THIS); // Push `this' il.append(new INVOKESPECIAL(cg.getConstantPool().addMethodref(cg.getSuperclassName(), "<init>", "()V"))); // Set name il.append( InstructionConstants.THIS ); il.append( ifact.createConstant(this.getName()) ); il.append( ifact.createPutField(cg.getClassName(), "name", Type.STRING) ); Collection<Queue> queues = CommonGen.allQueues(this); for (Queue q : queues) { QueueJVMGen jvmQ = (QueueJVMGen) q; jvmQ.generateInitField(il, ifact, scope); } il.append(InstructionConstants.RETURN); mg.setMaxStack(); cg.addMethod(mg.getMethod()); }
private void createConfigureMethod(GenScope scope, ClassGen cg) { InstructionList il = new InstructionList(); InstructionFactory ifact = new InstructionFactory(cg); MethodGen startMg = new MethodGen(Constants.ACC_PUBLIC,// access flags Type.VOID, // return type null, null, // arg // names CommonGen.CONFIGURE_METHOD, null, // method, class il, cg.getConstantPool()); scope.processMethod(startMg); // todo: call pre?? // configure depedendent queues Collection<Queue> queues = CommonGen.getImportedQueues(this); for (Queue q : queues) { RequiredQueueJVMGen jvmQ = (RequiredQueueJVMGen) q; jvmQ.generateConfigure(il, ifact, scope); } // register methods for(MethodDefinition m : getMethods()) { MethodDefinitionJVMGen mdJvm = (MethodDefinitionJVMGen) m; il.append(InstructionConstants.THIS); il.append(ifact.createConstant( m.getName() )); il.append(ifact.createConstant( m.getType().getModel().getName() ) ); il.append(ifact.createConstant( m.getType().getClassifierName()) ); il.append(ifact.createConstant( mdJvm.getMethodClassName()) ); il.append(ifact.createInvoke(MethodLibraryBase.class.getName(), "registerMethod", Type.VOID, new Type[] { Type.STRING, Type.STRING, Type.STRING, Type.STRING, }, Constants.INVOKEVIRTUAL)); } il.append(InstructionConstants.RETURN); startMg.setMaxLocals(); startMg.setMaxStack(); cg.addMethod(startMg.getMethod()); }
private void createConstructor(GenScope scope, ClassGen cg) { InstructionList il = new InstructionList(); InstructionFactory ifact = new InstructionFactory(cg); MethodGen mg = new MethodGen(Constants.ACC_PUBLIC, Type.VOID, new Type[] { } , null, "<init>", cg.getClassName(), il, cg.getConstantPool()); scope.processMethod(mg); // call super il.append(InstructionConstants.THIS); // Push `this' il.append(new INVOKESPECIAL(cg.getConstantPool().addMethodref(cg.getSuperclassName(), "<init>", "()V"))); // Set name il.append( InstructionConstants.THIS ); il.append( ifact.createConstant(this.getName()) ); il.append( ifact.createPutField(cg.getClassName(), "name", Type.STRING) ); Collection<Queue> queues = CommonGen.getImportedQueues(this); for (Queue q : queues) { QueueJVMGen jvmQ = (QueueJVMGen) q; jvmQ.generateInitField(il, ifact, scope); } il.append(InstructionConstants.RETURN); mg.setMaxStack(); cg.addMethod(mg.getMethod()); }
private void generateMethods(RootClass k, ConstantPoolGen cp, InstructionList il, InstructionFactory factory, ClassGen cg, String className) { RootMember[] members = k.getMembers(); for (int i = 0; i < members.length; i++) { BasicMember member = (BasicMember) members[i]; TLeaf leaf = (TLeaf) lMap.get(member); if (leaf == null) continue; String leafClassName = leaf.getClass().getName(); Type type = member.getJavaType(); Type arrayType = new ArrayType(type, 1); MethodGen mg = new MethodGen(ACC_PUBLIC, type, new Type[] { Type.INT }, new String[] { "index" }, nameMangler.mangleMember(member.getName()), className, il, cp); il.append(InstructionConstants.ALOAD_0); il.append(factory.createGetField(className, member.getName(), arrayType)); il.append(InstructionFactory.DUP); BranchHandle bh = il.append(new IFNONNULL(null)); il.append(InstructionFactory.POP); il.append(factory.createGetStatic(className, member.getName() + "Leaf", new ObjectType(leafClassName))); il.append(InstructionConstants.ALOAD_0); il.append(factory.createGetField("org.dianahep.root4j.core.Clones2", "hollowIndex", Type.LONG)); // BasicRootClass varClass = (BasicRootClass) member.getType(); il.append(factory.createInvoke(leafClassName, "setPosition", new ObjectType("org.dianahep.root4j.core.RootInput"), new Type[] { Type.LONG }, INVOKEVIRTUAL)); il.append(InstructionConstants.ALOAD_0); il.append(factory.createGetField("org.dianahep.root4j.core.Clones2", "size", Type.INT)); il.append((Instruction) factory.createNewArray(type, (short) 1)); il.append(InstructionConstants.DUP_X1); il.append(factory.createInvoke("org.dianahep.root4j.core.RootInput", "readFixedArray", Type.VOID, new Type[] { arrayType }, INVOKEINTERFACE)); il.append(InstructionConstants.DUP); il.append(InstructionConstants.ALOAD_0); il.append(InstructionConstants.SWAP); il.append(factory.createPutField(className, member.getName(), arrayType)); bh.setTarget(il.append(InstructionConstants.ILOAD_1)); il.append(InstructionFactory.createArrayLoad(type)); il.append(InstructionFactory.createReturn(type)); mg.setMaxStack(); mg.setMaxLocals(); cg.addMethod(mg.getMethod()); il.dispose(); } }