From 0876cc985e6b41c9f0c994f6743e8065b4ecd1fd Mon Sep 17 00:00:00 2001 From: "Rodrigo A. Melo" Date: Thu, 22 Aug 2024 21:26:16 -0300 Subject: [PATCH 1/2] Adds support for extra options in the Python side --- pyfpga/ise.py | 2 +- pyfpga/project.py | 47 ++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/pyfpga/ise.py b/pyfpga/ise.py index 03eb8707..6cbc67b4 100644 --- a/pyfpga/ise.py +++ b/pyfpga/ise.py @@ -32,7 +32,7 @@ def _make_custom(self): self.data['speed'] = info['speed'] self.data['package'] = info['package'] - def add_slog(self, pathname): + def add_slog(self, pathname, options=None): """Add System Verilog file/s.""" raise NotImplementedError('ISE does not support SystemVerilog') diff --git a/pyfpga/project.py b/pyfpga/project.py index 86d9f267..ea8d7a8b 100644 --- a/pyfpga/project.py +++ b/pyfpga/project.py @@ -78,7 +78,7 @@ def add_include(self, path): raise NotADirectoryError(path) self.data.setdefault('includes', []).append(path.as_posix()) - def _add_file(self, pathname, hdl=None, lib=None): + def _add_file(self, pathname, hdl=None, lib=None, options=None): files = glob.glob(pathname, recursive=True) if len(files) == 0: raise FileNotFoundError(pathname) @@ -89,45 +89,55 @@ def _add_file(self, pathname, hdl=None, lib=None): attr['hdl'] = hdl if lib: attr['lib'] = lib + if options: + attr['opt'] = options self.data.setdefault('files', {})[path.as_posix()] = attr - def add_slog(self, pathname): + def add_slog(self, pathname, options=None): """Add System Verilog file/s. :param pathname: path to a SV file (glob compliant) :type pathname: str + :param options: extra options for the underlying command + :type options: str, optional :raises FileNotFoundError: when pathname is not found """ self.logger.debug('Executing add_slog') - self._add_file(pathname, 'slog') + self._add_file(pathname, 'slog', options) - def add_vhdl(self, pathname, lib=None): + def add_vhdl(self, pathname, lib=None, options=None): """Add VHDL file/s. :param pathname: path to a SV file (glob compliant) :type pathname: str :param lib: VHDL library name :type lib: str, optional + :param options: extra options for the underlying command + :type options: str, optional :raises FileNotFoundError: when pathname is not found """ self.logger.debug('Executing add_vhdl') - self._add_file(pathname, 'vhdl', lib) + self._add_file(pathname, 'vhdl', lib, options) - def add_vlog(self, pathname): + def add_vlog(self, pathname, options=None): """Add Verilog file/s. :param pathname: path to a SV file (glob compliant) :type pathname: str + :param options: extra options for the underlying command + :type options: str, optional :raises FileNotFoundError: when pathname is not found """ self.logger.debug('Executing add_vlog') - self._add_file(pathname, 'vlog') + self._add_file(pathname, 'vlog', options) - def add_cons(self, path): + def add_cons(self, path, options=None): """Add a constraint file. - :param pathname: path of a file + :param pathname: path to a constraint file :type pathname: str + :param options: extra options for the underlying command + :type options: str, optional :raises FileNotFoundError: if path is not found """ self.logger.debug('Executing add_cons') @@ -135,6 +145,8 @@ def add_cons(self, path): if not path.is_file(): raise FileNotFoundError(path) attr = {} + if options: + attr['opt'] = options self.data.setdefault('constraints', {})[path.as_posix()] = attr def add_param(self, name, value): @@ -200,6 +212,23 @@ def add_hook(self, stage, hook): raise ValueError('Invalid stage.') self.data.setdefault('hooks', {}).setdefault(stage, []).append(hook) + def add_options(self, command, options): + """Add options for the specified underlying command. + + :param command: command where to apply the options + :type command: str + :param options: extra options for the underlying command + :type options: str + :raises ValueError: when command is invalid + """ + self.logger.debug('Executing add_options') + commands = ['prj', 'syn', 'par', 'bit'] + if command not in commands: + raise ValueError('Invalid command.') + self.data.setdefault('options', {}).setdefault(command, []).append( + options + ) + def set_debug(self): """Enables debug messages.""" self.logger.setLevel(logging.DEBUG) From a150ac96dc772d06b98dcefc8de4ab1105683a47 Mon Sep 17 00:00:00 2001 From: "Rodrigo A. Melo" Date: Mon, 2 Sep 2024 21:48:24 -0300 Subject: [PATCH 2/2] project: renamed add_options as set_options --- pyfpga/project.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyfpga/project.py b/pyfpga/project.py index ea8d7a8b..e3e20607 100644 --- a/pyfpga/project.py +++ b/pyfpga/project.py @@ -212,8 +212,8 @@ def add_hook(self, stage, hook): raise ValueError('Invalid stage.') self.data.setdefault('hooks', {}).setdefault(stage, []).append(hook) - def add_options(self, command, options): - """Add options for the specified underlying command. + def set_options(self, command, options): + """Set extra options for the specified underlying command. :param command: command where to apply the options :type command: str