set parameters using python style (and auto-detection)
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 28 Mar 2020 23:10:42 +0000 (23:10 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 28 Mar 2020 23:10:42 +0000 (23:10 +0000)
experiments7/doAlu16.py
experiments7/utils.py

index 724bb9c2b0a91d11d9f5be48dd7b7d507862f4bc..1c1b61605ec9422ce9e88af57501fdbe6d9ac197 100755 (executable)
@@ -7,7 +7,7 @@ import CRL
 import Cfg
 from Hurricane import Box
 from coriolis2.settings import af
-from utils import Module, SessionManager
+from utils import Module, SessionManager, Config
 
 import symbolic.cmos  # do not remove
 
@@ -15,32 +15,30 @@ BIT_WIDTH = 16
 
 
 def coriolis_setup():
-    Cfg.Configuration.pushDefaultPriority(Cfg.Parameter.Priority.UserFile)
-    Cfg.getParamBool('misc.catchCore').setBool(False)
-    Cfg.getParamBool('misc.info').setBool(False)
-    Cfg.getParamBool('misc.paranoid').setBool(False)
-    Cfg.getParamBool('misc.bug').setBool(False)
-    Cfg.getParamBool('misc.logMode').setBool(True)
-    Cfg.getParamBool('misc.verboseLevel1').setBool(True)
-    Cfg.getParamBool('misc.verboseLevel2').setBool(True)
-    Cfg.getParamEnumerate('etesian.effort').setInt(2)
-    Cfg.getParamPercentage('etesian.spaceMargin').setPercentage(20.0)
-    Cfg.getParamPercentage('etesian.aspectRatio').setPercentage(100.0)
-    Cfg.getParamBool('etesian.uniformDensity').setBool(True)
-    Cfg.getParamInt('anabatic.edgeLenght').setInt(24)
-    Cfg.getParamInt('anabatic.edgeWidth').setInt(8)
-    Cfg.getParamString('anabatic.topRoutingLayer').setString('METAL5')
-    Cfg.getParamInt('katana.searchHalo').setInt(30)
-    Cfg.getParamInt('katana.eventsLimit').setInt(1000000)
-    Cfg.getParamInt('katana.hTracksReservedLocal').setInt(7)
-    Cfg.getParamInt('katana.vTracksReservedLocal').setInt(6)
-
-    env = af.getEnvironment()
-    env.setCLOCK('^clk$|m_clock')
-    env.setPOWER('vdd')
-    env.setGROUND('vss')
-
-    Cfg.Configuration.popDefaultPriority()
+    with Config(Cfg.Parameter.Priority.UserFile) as cfg:
+        cfg.misc_catchCore = False
+        cfg.misc_info = False
+        cfg.misc_paranoid = False
+        cfg.misc_bug = False
+        cfg.misc_logMode = True
+        cfg.misc_verboseLevel1 = True
+        cfg.misc_verboseLevel2 = True
+        cfg.etesian_effort = 2
+        cfg.etesian_spaceMargin = "20.0%"
+        cfg.etesian_aspectRatio = "100.0%"
+        cfg.etesian_uniformDensity = True
+        cfg.anabatic_edgeLenght = 24
+        cfg.anabatic_edgeWidth = 8
+        cfg.anabatic_topRoutingLayer = 'METAL5'
+        cfg.katana_searchHalo = 30
+        cfg.katana_eventsLimit = 1000000
+        cfg.katana_hTracksReservedLocal = 7
+        cfg.katana_vTracksReservedLocal = 6
+
+        env = af.getEnvironment()
+        env.setCLOCK('^clk$|m_clock')
+        env.setPOWER('vdd')
+        env.setGROUND('vss')
 
 
 class AddSub(Module):
index 13b7e1b1ec342fbb0271c749bd5c5108e7a28632..60057f63810942bcfce160234db1c9eafe0ba5ba 100644 (file)
@@ -3,6 +3,7 @@ from __future__ import print_function
 
 import Anabatic
 import CRL
+import Cfg
 import Etesian
 import Katana
 from Hurricane import (
@@ -315,3 +316,36 @@ class Module(object):
         """ Main routine. """
 
         raise NotImplementedError('You need to implement the `build` method.')
+
+class Config:
+
+    def __init__(self, priority=None):
+        self._priority = priority
+
+    def __enter__(self):
+        if self._priority is not None:
+            Cfg.Configuration.pushDefaultPriority(self._priority)
+        return self
+
+    def __setattr__(self, attr, val):
+        if attr.startswith("_"):
+            self.__dict__[attr] = val
+            return
+        attr = attr.replace("_", ".")
+        if isinstance(val, bool):
+            Cfg.getParamBool(attr).setBool(val)
+        elif isinstance(val, int):
+            p = Cfg.getParamInt(attr) # all params have a type
+            if p.type == 'Enumerate':
+                Cfg.getParamEnumerate(attr).setInt(val)
+            else:
+                Cfg.getParamInt(attr).setInt(val)
+        elif '%' in val:
+            Cfg.getParamPercentage(attr).setPercentage(float(val[:-1]))
+        else:
+            Cfg.getParamString(attr).setString(val)
+
+    def __exit__(self, *args):
+        if self._priority is not None:
+            Cfg.Configuration.popDefaultPriority()
+