Ejemplo n.º 1
0
 private Code readEmpty(
     int opcode,
     boolean wideBase,
     boolean wideRest,
     int offset,
     HashMap<Integer, Code.Label> labels)
     throws IOException {
   switch (opcode) {
     case Code.OPCODE_const:
       {
         int target = readBase(wideBase);
         int idx = readRest(wideRest);
         Constant c = constantPool[idx];
         return Code.Const(target, c);
       }
     case Code.OPCODE_goto:
       {
         int target = readTarget(wideRest, offset);
         Code.Label lab = findLabel(target, labels);
         return Code.Goto(lab.label);
       }
     case Code.OPCODE_nop:
       return Code.Nop;
     case Code.OPCODE_returnv:
       return Code.Return();
   }
   throw new RuntimeException("unknown opcode encountered (" + opcode + ")");
 }
Ejemplo n.º 2
0
 private Code readUnaryOp(
     int opcode,
     boolean wideBase,
     boolean wideRest,
     int offset,
     HashMap<Integer, Code.Label> labels)
     throws IOException {
   int operand = readBase(wideBase);
   int typeIdx = readRest(wideRest);
   Type type = typePool[typeIdx];
   switch (opcode) {
     case Code.OPCODE_debug:
       return Code.Debug(operand);
     case Code.OPCODE_ifis:
       {
         int resultIdx = readRest(wideRest);
         Type result = typePool[resultIdx];
         int target = readTarget(wideRest, offset);
         Code.Label l = findLabel(target, labels);
         return Code.IfIs(type, operand, result, l.label);
       }
     case Code.OPCODE_throw:
       return Code.Throw(type, operand);
     case Code.OPCODE_return:
       return Code.Return(type, operand);
     case Code.OPCODE_switch:
       {
         ArrayList<Pair<Constant, String>> cases = new ArrayList<Pair<Constant, String>>();
         int target = readTarget(wideRest, offset);
         Code.Label defaultLabel = findLabel(target, labels);
         int nCases = readRest(wideRest);
         for (int i = 0; i != nCases; ++i) {
           int constIdx = readRest(wideRest);
           Constant constant = constantPool[constIdx];
           target = readTarget(wideRest, offset);
           Code.Label l = findLabel(target, labels);
           cases.add(new Pair<Constant, String>(constant, l.label));
         }
         return Code.Switch(type, operand, defaultLabel.label, cases);
       }
   }
   throw new RuntimeException("unknown opcode encountered (" + opcode + ")");
 }