X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Flaunch%2FMachineRegister.java;h=e470420474359bb38dd78423d8680ce374da0186;hb=9f4b106057a7b291aa880620dc80faa9cb7fc8f3;hp=f8d343f4e2dc57f420e47c637c0379a6157b41cf;hpb=30779f58b602f508ae3b8048bdb576191f7d9980;p=Mograsim.git diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MachineRegister.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MachineRegister.java index f8d343f4..e4704204 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MachineRegister.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MachineRegister.java @@ -3,6 +3,7 @@ package net.mograsim.plugin.launch; import java.util.Arrays; import java.util.function.Consumer; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.DebugEvent; @@ -17,6 +18,7 @@ import org.eclipse.debug.core.model.IValue; import org.eclipse.swt.SWT; import net.mograsim.logic.core.types.BitVector; +import net.mograsim.logic.core.types.BitVectorFormatter; import net.mograsim.machine.Machine; import net.mograsim.machine.registers.Register; import net.mograsim.plugin.MograsimActivator; @@ -95,14 +97,17 @@ public class MachineRegister extends PlatformObject implements IRegister public String getValueString() { - return getMachine().getRegister(machineRegister).toString(); + return BitVectorFormatter.formatAsString(getMachine().getRegister(machineRegister)); } @Override public void setValue(String expression) throws DebugException { - // TODO exception handling - getMachine().setRegister(machineRegister, BitVector.parse(expression)); + BitVector bitvector = BitVectorFormatter.parseUserBitVector(expression, machineRegister.getWidth()); + if (bitvector == null) + throw new DebugException( + new Status(IStatus.ERROR, MograsimActivator.PLUGIN_ID, "Couldn't parse value string: " + expression, null)); + getMachine().setRegister(machineRegister, bitvector); } @Override @@ -122,16 +127,7 @@ public class MachineRegister extends PlatformObject implements IRegister @Override public boolean verifyValue(String expression) throws DebugException { - // TODO do this prettier; also check length too - try - { - BitVector.parse(expression); - } - catch (@SuppressWarnings("unused") Exception e) - { - return false; - } - return true; + return BitVectorFormatter.parseUserBitVector(expression, machineRegister.getWidth()) != null; } @Override