[dvsim] Simplify factory methods for FlowCfg
It turns out that there's a neat way to do this in Python, rather than
repeating the boilerplate in each subclass.
Signed-off-by: Rupert Swarbrick <rswarbrick@lowrisc.org>
diff --git a/util/dvsim/FlowCfg.py b/util/dvsim/FlowCfg.py
index 4d6cef1..1167225 100644
--- a/util/dvsim/FlowCfg.py
+++ b/util/dvsim/FlowCfg.py
@@ -99,11 +99,11 @@
log.error("Parse error!\n%s", self.cfgs)
sys.exit(1)
- @staticmethod
- def create_instance(flow_cfg_file, proj_root, args):
- '''Create a new instance of this class as with given parameters.
+ def create_instance(self, flow_cfg_file):
+ '''Create a new instance of this class for the given config file.
+
'''
- return FlowCfg(flow_cfg_file, proj_root, args)
+ return type(self)(flow_cfg_file, self.proj_root, self.args)
def kill(self):
'''kill running processes and jobs gracefully
@@ -254,18 +254,14 @@
cfg_file = subst_wildcards(entry,
self.__dict__,
ignore_error=True)
- self.cfgs.append(
- self.create_instance(cfg_file, self.proj_root,
- self.args))
+ self.cfgs.append(self.create_instance(cfg_file))
elif type(entry) is dict:
# Treat this as a cfg expanded in-line
temp_cfg_file = self._conv_inline_cfg_to_hjson(entry)
if not temp_cfg_file:
continue
- self.cfgs.append(
- self.create_instance(temp_cfg_file, self.proj_root,
- self.args))
+ self.cfgs.append(self.create_instance(temp_cfg_file))
# Delete the temp_cfg_file once the instance is created
try:
diff --git a/util/dvsim/LintCfg.py b/util/dvsim/LintCfg.py
index 3184aab..773f534 100644
--- a/util/dvsim/LintCfg.py
+++ b/util/dvsim/LintCfg.py
@@ -50,12 +50,6 @@
else:
self.results_title = self.name.upper() + " Lint Results"
- @staticmethod
- def create_instance(flow_cfg_file, proj_root, args):
- '''Create a new instance of this class as with given parameters.
- '''
- return LintCfg(flow_cfg_file, proj_root, args)
-
def gen_results_summary(self):
'''
Gathers the aggregated results from all sub configs
diff --git a/util/dvsim/OneShotCfg.py b/util/dvsim/OneShotCfg.py
index a82db23..be5b6e6 100644
--- a/util/dvsim/OneShotCfg.py
+++ b/util/dvsim/OneShotCfg.py
@@ -120,12 +120,6 @@
# Run some post init checks
super().__post_init__()
- @staticmethod
- def create_instance(flow_cfg_file, proj_root, args):
- '''Create a new instance of this class as with given parameters.
- '''
- return OneShotCfg(flow_cfg_file, proj_root, args)
-
# Purge the output directories. This operates on self.
def _purge(self):
if self.scratch_path:
diff --git a/util/dvsim/SimCfg.py b/util/dvsim/SimCfg.py
index 7d43d9a..1afa573 100644
--- a/util/dvsim/SimCfg.py
+++ b/util/dvsim/SimCfg.py
@@ -167,12 +167,6 @@
# Run some post init checks
super().__post_init__()
- @staticmethod
- def create_instance(flow_cfg_file, proj_root, args):
- '''Create a new instance of this class as with given parameters.
- '''
- return SimCfg(flow_cfg_file, proj_root, args)
-
def kill(self):
'''kill running processes and jobs gracefully
'''
diff --git a/util/dvsim/SynCfg.py b/util/dvsim/SynCfg.py
index a901a4d..e3acd62 100644
--- a/util/dvsim/SynCfg.py
+++ b/util/dvsim/SynCfg.py
@@ -26,12 +26,6 @@
# Set the title for synthesis results.
self.results_title = self.name.upper() + " Synthesis Results"
- @staticmethod
- def create_instance(flow_cfg_file, proj_root, args):
- '''Create a new instance of this class as with given parameters.
- '''
- return SynCfg(flow_cfg_file, proj_root, args)
-
def gen_results_summary(self):
'''
Gathers the aggregated results from all sub configs