config: Add Current as a parameter type
authorAndreas Hansson <andreas.hansson@arm.com>
Thu, 9 Oct 2014 21:52:00 +0000 (17:52 -0400)
committerAndreas Hansson <andreas.hansson@arm.com>
Thu, 9 Oct 2014 21:52:00 +0000 (17:52 -0400)
This patch adds the Python parameter type Current, which is used for
the DRAM power modelling (to start with). With this addition we avoid
implicit unit assumptions.

src/python/m5/params.py
src/python/m5/util/convert.py

index 6c4a61d6ae1056ff201c143c5208444b708da856..f16cabaffb33a987b6c6fead6d809bac620fa451 100644 (file)
@@ -1485,6 +1485,31 @@ class Voltage(float,ParamValue):
     def ini_str(self):
         return '%f' % self.getValue()
 
+class Current(float, ParamValue):
+    cxx_type = 'double'
+    ex_str = "1mA"
+    cmd_line_settable = False
+
+    def __new__(cls, value):
+        # convert to current
+        val = convert.toCurrent(value)
+        return super(cls, Current).__new__(cls, val)
+
+    def __call__(self, value):
+        val = convert.toCurrent(value)
+        self.__init__(val)
+        return value
+
+    def __str__(self):
+        return str(self.getValue())
+
+    def getValue(self):
+        value = float(self)
+        return value
+
+    def ini_str(self):
+        return '%f' % self.getValue()
+
 class NetworkBandwidth(float,ParamValue):
     cxx_type = 'float'
     ex_str = "1Gbps"
index 26f351e994acf0655548df223e05af1623fa5bc9..351ee1ee0f8a242f3f43be2bfd8a51007c947408 100644 (file)
@@ -311,3 +311,11 @@ def toVoltage(value):
 
     raise ValueError, "cannot convert '%s' to voltage" % value
 
+def toCurrent(value):
+    if not isinstance(value, str):
+        raise TypeError, "wrong type '%s' should be str" % type(value)
+
+    if value.endswith('A'):
+        return toFloat(value[:-1])
+
+    raise ValueError, "cannot convert '%s' to current" % value