private DalvOps() {
// This space intentionally left blank.
}
+
+ /**
+ * Determines if the given opcode has the right "shape" to be
+ * valid. This includes the range {@code 0x00..0xfe}, the range
+ * {@code 0x00ff..0xffff} where the low-order byte is {@code
+ * 0xff}, and the special opcode values {@code SPECIAL_FORMAT} and
+ * {@code NO_NEXT}. Note that not all of the opcode values that
+ * pass this test are in fact used. This method is meant to
+ * perform a quick check to reject blatantly wrong values (e.g.
+ * when validating arguments).
+ *
+ * @param opcode the opcode value
+ * @return {@code true} iff the value has the right "shape" to be
+ * possibly valid
+ */
+ public static boolean isValidShape(int opcode) {
+ // Note: SPECIAL_FORMAT == NO_NEXT.
+ if ((opcode >= SPECIAL_FORMAT) && (opcode <= 0xff)) {
+ return true;
+ }
+
+ if ((opcode >= 0xff) && (opcode <= 0xffff)
+ && ((opcode & 0xff) == 0xff)) {
+ return true;
+ }
+
+ return false;
+ }
}
* Representation of an opcode.
*/
public final class Dop {
- /**
- * {@code DalvOps.MIN_VALUE..DalvOps.MAX_VALUE;} the opcode value
- * itself
- */
+ /** {@code DalvOps.isValid();} the opcode value itself */
private final int opcode;
- /**
- * {@code DalvOps.MIN_VALUE..DalvOps.MAX_VALUE;} the opcode family
- */
+ /** {@code DalvOps.isValid();} the opcode family */
private final int family;
/**
- * {@code DalvOps.MIN_VALUE..DalvOps.MAX_VALUE;} what opcode (by
- * number) to try next when attempting to match an opcode to
- * particular arguments; {@code DalvOps.NO_NEXT} to indicate that
- * this is the last opcode to try in a particular chain
+ * {@code DalvOps.isValid();} what opcode (by number) to try next
+ * when attempting to match an opcode to particular arguments;
+ * {@code DalvOps.NO_NEXT} to indicate that this is the last
+ * opcode to try in a particular chain
*/
private final int nextOpcode;
/**
* Constructs an instance.
*
- * @param opcode {@code DalvOps.MIN_VALUE..DalvOps.MAX_VALUE;} the opcode
- * value itself
- * @param family {@code DalvOps.MIN_VALUE..DalvOps.MAX_VALUE;} the
- * opcode family
- * @param nextOpcode {@code DalvOps.NO_NEXT..DalvOps.MAX_VALUE;}
- * what opcode (by number) to try next when attempting to match an
- * opcode to particular arguments; {@code DalvOps.NO_NEXT} to
- * indicate that this is the last opcode to try in a particular
- * chain
+ * @param opcode {@code DalvOps.isValid();} the opcode value
+ * itself
+ * @param family {@code DalvOps.isValid();} the opcode family
+ * @param nextOpcode {@code DalvOps.isValid();} what opcode (by
+ * number) to try next when attempting to match an opcode to
+ * particular arguments; {@code DalvOps.NO_NEXT} to indicate that
+ * this is the last opcode to try in a particular chain
* @param format {@code non-null;} the instruction format
* @param hasResult whether the opcode has a result register; if so it
* is always the first register
*/
public Dop(int opcode, int family, int nextOpcode, InsnFormat format,
boolean hasResult, String name) {
- if ((opcode < DalvOps.MIN_VALUE) || (opcode > DalvOps.MAX_VALUE)) {
+ if (!DalvOps.isValidShape(opcode)) {
throw new IllegalArgumentException("bogus opcode");
}
- if ((family < DalvOps.MIN_VALUE) || (family > DalvOps.MAX_VALUE)) {
+ if (!DalvOps.isValidShape(family)) {
throw new IllegalArgumentException("bogus family");
}
- if ((nextOpcode < DalvOps.MIN_VALUE)
- || (nextOpcode > DalvOps.MAX_VALUE)) {
+ if (!DalvOps.isValidShape(nextOpcode)) {
throw new IllegalArgumentException("bogus nextOpcode");
}