コード例 #1
0
ファイル: GenJava.java プロジェクト: deepakworld07/xmlvm.svn
  private void createMethod(Element method) throws IllegalXMLVMException {
    il = new InstructionList();
    instructionHandlerManager = new InstructionHandlerManager(il);
    String methodName = method.getAttributeValue("name");

    Element signature = method.getChild("signature", nsXMLVM);
    Type retType = collectReturnType(signature);
    Type[] argTypes = collectArgumentTypes(signature);
    short accessFlags = getAccessFlags(method);

    if (methodName.equals(
        ".cctor")) // Same concept, different names in .net/JVM.  Note we are doing init of statics
                   // for a class
    {
      System.out.println("Changed name to clinit");
      methodName = "<clinit>";
      accessFlags = 0x8; // static
    }

    MethodGen m =
        new MethodGen(
            accessFlags, retType, argTypes, null, methodName, fullQualifiedClassName, il, _cp);
    Element code = method.getChild("code", nsXMLVM);
    createCode(code);
    instructionHandlerManager.checkConsistency();
    m.setMaxLocals();
    m.setMaxStack();
    _cg.addMethod(m.getMethod());
    il.dispose();
  }
コード例 #2
0
ファイル: GenJava.java プロジェクト: deepakworld07/xmlvm.svn
 private void createCode(Element code) throws IllegalXMLVMException {
   List<Element> instructions = code.getChildren();
   for (Element inst : instructions) {
     String name = inst.getName();
     String opcMethodName =
         "createInstruction" + name.substring(0, 1).toUpperCase() + name.substring(1);
     Class appClazz;
     Method opcMeth;
     Class[] paramTypes = {Element.class};
     Object[] params = {inst};
     appClazz = this.getClass();
     Object newInstr = null;
     try {
       opcMeth = appClazz.getMethod(opcMethodName, paramTypes);
       newInstr = opcMeth.invoke(this, params);
     } catch (NoSuchMethodException ex) {
       throw new IllegalXMLVMException(
           "Illegal instruction 1, unable to find method "
               + opcMethodName
               + " for '"
               + name
               + "'");
     } catch (InvocationTargetException ex) {
       ex.printStackTrace();
       throw new IllegalXMLVMException("Illegal instruction 2 '" + name + "'");
     } catch (IllegalAccessException ex) {
       throw new IllegalXMLVMException("Illegal instruction 3 '" + name + "'");
     }
     if (newInstr != null) {
       InstructionHandle ih = null;
       if (newInstr instanceof BranchInstruction) ih = il.append((BranchInstruction) newInstr);
       else if (newInstr instanceof CompoundInstruction)
         ih = il.append((CompoundInstruction) newInstr);
       else if (newInstr instanceof Instruction) ih = il.append((Instruction) newInstr);
       instructionHandlerManager.registerInstructionHandle(ih);
     }
   }
 }
コード例 #3
0
ファイル: GenJava.java プロジェクト: deepakworld07/xmlvm.svn
 public Instruction createInstructionIfne(Element inst) {
   int id = Integer.parseInt(inst.getAttributeValue("label"));
   BranchInstruction bi = new IFNE(null);
   instructionHandlerManager.registerBranchInstruction(bi, id);
   return bi;
 }
コード例 #4
0
ファイル: GenJava.java プロジェクト: deepakworld07/xmlvm.svn
 public Instruction createInstructionLabel(Element inst) throws IllegalXMLVMException {
   int id = Integer.parseInt(inst.getAttributeValue("id"));
   instructionHandlerManager.setLabelID(id);
   return null;
 }