diff options
Diffstat (limited to 'src/python/m5/util')
-rw-r--r-- | src/python/m5/util/convert.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/python/m5/util/convert.py b/src/python/m5/util/convert.py index 79f3f985e..26f351e99 100644 --- a/src/python/m5/util/convert.py +++ b/src/python/m5/util/convert.py @@ -299,3 +299,15 @@ def toIpWithPort(value): if not 0 <= int(port) <= 0xffff: raise ValueError, 'invalid port %s' % port return (ip, int(port)) + +def toVoltage(value): + if not isinstance(value, str): + raise TypeError, "wrong type '%s' should be str" % type(value) + + if value.endswith('mV'): + return float(value[:-2]) * milli + elif value.endswith('V'): + return float(value[:-1]) + + raise ValueError, "cannot convert '%s' to voltage" % value + |