From 49053b352e5ed73da759f06d9c828c152fada440 Mon Sep 17 00:00:00 2001 From: Keerthan Jaic Date: Tue, 15 Mar 2016 12:53:59 -0400 Subject: [PATCH] support some options in the convert method --- myhdl/_block.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/myhdl/_block.py b/myhdl/_block.py index ae2e9742..7132cd2f 100644 --- a/myhdl/_block.py +++ b/myhdl/_block.py @@ -202,14 +202,41 @@ class _BlockInstance(object): def analyzeConversion(self): return myhdl.conversion.analyze(self) - def convert(self, hdl='Verilog'): + def convert(self, hdl='Verilog', **kwargs): + """Converts this BlockInstance to another HDL + + Args: + hdl (Optional[str]): Target HDL. Defaults to Verilog + path (Optional[str]): Destination folder. Defaults to current + working dir. + name (Optional[str]): Module and output file name. Defaults to + `self.mod.__name__` + trace(Optional[bool]): Verilog only. Whether the testbench should + dump all signal waveforms. Defaults to False. + tb (Optional[bool]): Verilog only. Specifies whether a testbench + should be created. Defaults to True. + timescale(Optional[str]): Verilog only. Defaults to '1ns/10ps' + """ if hdl.lower() == 'vhdl': - return myhdl.conversion._toVHDL.toVHDL(self) + converter = myhdl.conversion._toVHDL.toVHDL elif hdl.lower() == 'verilog': - return myhdl.conversion._toVerilog.toVerilog(self) + converter = myhdl.conversion._toVerilog.toVerilog else: raise BlockInstanceError('unknown hdl %s' % hdl) + conv_attrs = { + 'name': self.mod.__name__, + } + conv_attrs['directory'] = kwargs.pop('path', '') + if hdl.lower() == 'verilog': + conv_attrs['no_testbench'] = not kwargs.pop('tb', True) + conv_attrs['timescale'] = kwargs.pop('timescale', '1ns/10ps') + conv_attrs['trace'] = kwargs.pop('trace', False) + conv_attrs.update(kwargs) + for k, v in conv_attrs.items(): + setattr(converter, k, v) + return converter(self) + def run(self, duration=None, quiet=0): if self.sim is None: self.sim = myhdl._Simulation.Simulation(self)