- // TODO support hex
- // TODO exception handling
- getMachine().setRegister(machineRegister, BitVector.parse(expression));
+ BitVector bitvector = parseValue(expression);
+ if (bitvector == null)
+ throw new DebugException(
+ new Status(IStatus.ERROR, MograsimActivator.PLUGIN_ID, "Couldn't parse value string: " + expression, null));
+ getMachine().setRegister(machineRegister, bitvector);
+ }
+
+ private BitVector parseValue(String expression)
+ {
+ BitVector bitvector = null;
+ if (expression.matches("0x[0-9a-fA-F]+"))
+ // TODO should we check for overflows?
+ bitvector = BitVector.from(new BigInteger(expression.substring(2), 16), machineRegister.getWidth());
+ else if (expression.length() == machineRegister.getWidth())
+ // TODO do this without exceptions
+ try
+ {
+ bitvector = BitVector.parse(expression);
+ }
+ catch (@SuppressWarnings("unused") NullPointerException x)
+ {
+ // ignore
+ }
+ if (bitvector == null)
+ try
+ {
+ // TODO should we check for overflows?
+ bitvector = BitVector.from(new BigInteger(expression), machineRegister.getWidth());
+ }
+ catch (@SuppressWarnings("unused") NumberFormatException x)
+ {
+ // ignore
+ }
+ return bitvector;