예제 #1
0
 //
 // used for relative branch targets (ie $+5, $-12, ...)
 //
 void plantRelativeGoto(String name, int val) throws jasError {
   InsnInfo insn = InsnInfo.get(name);
   if (insn.args.equals("label")) {
     bufferInsn(new Insn(insn.opcode, val, true));
   } else { // forward the request for "normal" instructions
     plant(name, val);
   }
 }
예제 #2
0
  //
  // used for ldc <quoted-string>
  //
  void plantString(String name, String val) throws jasError {
    InsnInfo insn = InsnInfo.get(name);
    autoNumber();
    flushInsnBuffer();

    if (name.startsWith("ldc")) {
      bufferInsn(new Insn(insn.opcode, new StringCP(val)));
    } else {
      throw new jasError("Bad arguments for instruction " + name);
    }
  }
예제 #3
0
  //
  // used for iinc
  //
  void plant(String name, int v1, int v2) throws jasError {
    InsnInfo insn = InsnInfo.get(name);
    autoNumber();
    flushInsnBuffer();

    if (insn.args.equalsIgnoreCase("ii")) {
      bufferInsn(new IincInsn(v1, v2, insn.args.charAt(0) == 'I'));
    } else {
      throw new jasError("Bad arguments for instruction " + name);
    }
  }
예제 #4
0
  //
  // used for instructions that take no arguments
  //
  void plant(String name) throws jasError {
    InsnInfo insn = InsnInfo.get(name);
    autoNumber();
    flushInsnBuffer();

    if (insn.args.equals("")) {
      bufferInsn(new Insn(insn.opcode));
    } else {
      throw new jasError("Missing arguments for instruction " + name);
    }
  }
예제 #5
0
  //
  // used for instructions that take a field and a signature as parameters
  // (e.g. getstatic, putstatic)
  //
  void plant(String name, String v1, String v2) throws jasError {
    InsnInfo info = InsnInfo.get(name);
    CodeAttr code = _getCode();
    autoNumber();
    flushInsnBuffer();

    if (info.args.equals("field")) {
      String split[] = ScannerUtils.splitClassField(v1);
      if (split[1] == null) throw new jasError("can't extract field from " + v1);
      bufferInsn(new Insn(info.opcode, new FieldCP(split[0], split[1], v2)));
    } else {
      throw new jasError("Bad arguments for instruction " + name);
    }
  }
예제 #6
0
  //
  // used for instructions that take a word as a parameter
  // (e.g. branches, newarray, invokemethod)
  //
  void plant(String name, String val) throws jasError {
    InsnInfo insn = InsnInfo.get(name);
    CodeAttr code = _getCode();
    autoNumber();
    flushInsnBuffer();

    if (insn.args.equals("method")) {
      String split[] = ScannerUtils.splitClassMethodSignature(val);
      bufferInsn(new Insn(insn.opcode, new MethodCP(split[0], split[1], split[2])));
    } else if (insn.args.equals("interface")) {
      String split[] = ScannerUtils.splitClassMethodSignature(val);
      bufferInsn(
          new InvokeinterfaceInsn(
              new InterfaceCP(split[0], split[1], split[2]),
              ScannerUtils.getArgumentsAndReturnSizes(split[2]) >> 2));
    } else if (name.startsWith("ldc")) {
      bufferInsn(new Insn(insn.opcode, new ClassCP(val)));
    } else if (insn.args.equals("atype")) {
      int atype = 0;
      if (val.equals("boolean")) {
        atype = 4;
      } else if (val.equals("char")) {
        atype = 5;
      } else if (val.equals("float")) {
        atype = 6;
      } else if (val.equals("double")) {
        atype = 7;
      } else if (val.equals("byte")) {
        atype = 8;
      } else if (val.equals("short")) {
        atype = 9;
      } else if (val.equals("int")) {
        atype = 10;
      } else if (val.equals("long")) {
        atype = 11;
      } else {
        throw new jasError("Bad array type: " + name);
      }
      bufferInsn(new Insn(insn.opcode, atype, false));
    } else if (insn.args.indexOf("label") >= 0) {
      bufferInsn(new Insn(insn.opcode, getLabel(val), scanner.line_num));
    } else if (insn.args.equals("class")) {
      bufferInsn(new Insn(insn.opcode, new ClassCP(val)));
    } else {
      throw new jasError("(gloups)Bad arguments for instruction " + name);
    }
  }
예제 #7
0
  //
  // used for instructions that take an integer parameter
  // (branches are part of this, the int is converted to a label)
  //
  void plant(String name, int val) throws jasError {
    InsnInfo insn = InsnInfo.get(name);
    CodeAttr code = _getCode();
    autoNumber();
    flushInsnBuffer();

    if (insn.args.equalsIgnoreCase("i")) {
      bufferInsn(new Insn(insn.opcode, val, insn.args.charAt(0) == 'I'));
    } else if (name.startsWith("ldc")) {
      bufferInsn(new Insn(insn.opcode, new IntegerCP(val)));
    } else if (insn.args.equals("label")) {
      plant(name, String.valueOf(val)); // the target is not signed
      // assume it is a label
    } else {
      throw new jasError("Bad arguments for instruction " + name);
    }
  }
예제 #8
0
  //
  // used for invokeinterface and multianewarray
  //
  void plant(String name, String val, int nargs) throws jasError {
    InsnInfo insn = InsnInfo.get(name);
    CodeAttr code = _getCode();
    autoNumber();
    flushInsnBuffer();

    if (insn.args.equals("interface")) {
      String split[] = ScannerUtils.splitClassMethodSignature(val);
      bufferInsn(
          new InvokeinterfaceInsn(
              new InterfaceCP(split[0], split[1], split[2]),
              ScannerUtils.getArgumentsAndReturnSizes(split[2]) >> 2));

    } else if (insn.args.equals("marray")) {
      bufferInsn(new MultiarrayInsn(new ClassCP(val), nargs));
    } else {
      throw new jasError("Bad arguments for instruction " + name);
    }
  }
예제 #9
0
  //
  // used for ldc and other instructions that take a numeric argument
  //
  void plant(String name, Number val) throws jasError {
    InsnInfo insn = InsnInfo.get(name);
    CodeAttr code = _getCode();
    autoNumber();
    flushInsnBuffer();

    if (insn.args.equalsIgnoreCase("i") && (val instanceof Integer)) {
      bufferInsn(new Insn(insn.opcode, val.intValue(), insn.args.charAt(0) == 'I'));
    } else if (name.startsWith("ldc")) {
      if (val instanceof Integer) {
        bufferInsn(new Insn(insn.opcode, new IntegerCP(val.intValue())));
      } else if (val instanceof Float) {
        bufferInsn(new Insn(insn.opcode, new FloatCP(val.floatValue())));
      } else if (val instanceof Long) {
        bufferInsn(new Insn(insn.opcode, new LongCP(val.longValue())));
      } else if (val instanceof Double) {
        bufferInsn(new Insn(insn.opcode, new DoubleCP(val.doubleValue())));
      }
    } else {
      throw new jasError("Bad arguments for instruction " + name);
    }
  }