Skip to content

Commit 0876cc9

Browse files
committed
Adds support for extra options in the Python side
1 parent 520cc50 commit 0876cc9

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

pyfpga/ise.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def _make_custom(self):
3232
self.data['speed'] = info['speed']
3333
self.data['package'] = info['package']
3434

35-
def add_slog(self, pathname):
35+
def add_slog(self, pathname, options=None):
3636
"""Add System Verilog file/s."""
3737
raise NotImplementedError('ISE does not support SystemVerilog')
3838

pyfpga/project.py

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def add_include(self, path):
7878
raise NotADirectoryError(path)
7979
self.data.setdefault('includes', []).append(path.as_posix())
8080

81-
def _add_file(self, pathname, hdl=None, lib=None):
81+
def _add_file(self, pathname, hdl=None, lib=None, options=None):
8282
files = glob.glob(pathname, recursive=True)
8383
if len(files) == 0:
8484
raise FileNotFoundError(pathname)
@@ -89,52 +89,64 @@ def _add_file(self, pathname, hdl=None, lib=None):
8989
attr['hdl'] = hdl
9090
if lib:
9191
attr['lib'] = lib
92+
if options:
93+
attr['opt'] = options
9294
self.data.setdefault('files', {})[path.as_posix()] = attr
9395

94-
def add_slog(self, pathname):
96+
def add_slog(self, pathname, options=None):
9597
"""Add System Verilog file/s.
9698
9799
:param pathname: path to a SV file (glob compliant)
98100
:type pathname: str
101+
:param options: extra options for the underlying command
102+
:type options: str, optional
99103
:raises FileNotFoundError: when pathname is not found
100104
"""
101105
self.logger.debug('Executing add_slog')
102-
self._add_file(pathname, 'slog')
106+
self._add_file(pathname, 'slog', options)
103107

104-
def add_vhdl(self, pathname, lib=None):
108+
def add_vhdl(self, pathname, lib=None, options=None):
105109
"""Add VHDL file/s.
106110
107111
:param pathname: path to a SV file (glob compliant)
108112
:type pathname: str
109113
:param lib: VHDL library name
110114
:type lib: str, optional
115+
:param options: extra options for the underlying command
116+
:type options: str, optional
111117
:raises FileNotFoundError: when pathname is not found
112118
"""
113119
self.logger.debug('Executing add_vhdl')
114-
self._add_file(pathname, 'vhdl', lib)
120+
self._add_file(pathname, 'vhdl', lib, options)
115121

116-
def add_vlog(self, pathname):
122+
def add_vlog(self, pathname, options=None):
117123
"""Add Verilog file/s.
118124
119125
:param pathname: path to a SV file (glob compliant)
120126
:type pathname: str
127+
:param options: extra options for the underlying command
128+
:type options: str, optional
121129
:raises FileNotFoundError: when pathname is not found
122130
"""
123131
self.logger.debug('Executing add_vlog')
124-
self._add_file(pathname, 'vlog')
132+
self._add_file(pathname, 'vlog', options)
125133

126-
def add_cons(self, path):
134+
def add_cons(self, path, options=None):
127135
"""Add a constraint file.
128136
129-
:param pathname: path of a file
137+
:param pathname: path to a constraint file
130138
:type pathname: str
139+
:param options: extra options for the underlying command
140+
:type options: str, optional
131141
:raises FileNotFoundError: if path is not found
132142
"""
133143
self.logger.debug('Executing add_cons')
134144
path = Path(path).resolve()
135145
if not path.is_file():
136146
raise FileNotFoundError(path)
137147
attr = {}
148+
if options:
149+
attr['opt'] = options
138150
self.data.setdefault('constraints', {})[path.as_posix()] = attr
139151

140152
def add_param(self, name, value):
@@ -200,6 +212,23 @@ def add_hook(self, stage, hook):
200212
raise ValueError('Invalid stage.')
201213
self.data.setdefault('hooks', {}).setdefault(stage, []).append(hook)
202214

215+
def add_options(self, command, options):
216+
"""Add options for the specified underlying command.
217+
218+
:param command: command where to apply the options
219+
:type command: str
220+
:param options: extra options for the underlying command
221+
:type options: str
222+
:raises ValueError: when command is invalid
223+
"""
224+
self.logger.debug('Executing add_options')
225+
commands = ['prj', 'syn', 'par', 'bit']
226+
if command not in commands:
227+
raise ValueError('Invalid command.')
228+
self.data.setdefault('options', {}).setdefault(command, []).append(
229+
options
230+
)
231+
203232
def set_debug(self):
204233
"""Enables debug messages."""
205234
self.logger.setLevel(logging.DEBUG)

0 commit comments

Comments
 (0)