1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
|
# ==================================================================================================================== #
# _____ ____ _ _ ____ _ ___ _____ _ #
# _ __ _ _| ____| _ \ / \ / \ / ___| | |_ _|_ _|__ ___ | | #
# | '_ \| | | | _| | | | |/ _ \ / _ \ | | | | | | | |/ _ \ / _ \| | #
# | |_) | |_| | |___| |_| / ___ \ / ___ \ | |___| |___ | | | | (_) | (_) | | #
# | .__/ \__, |_____|____/_/ \_\/_/ \_(_)____|_____|___| |_|\___/ \___/|_| #
# |_| |___/ #
# ==================================================================================================================== #
# Authors: #
# Patrick Lehmann #
# #
# License: #
# ==================================================================================================================== #
# Copyright 2017-2023 Patrick Lehmann - Boetzingen, Germany #
# Copyright 2014-2016 Technische Universität Dresden - Germany, Chair of VLSI-Design, Diagnostics and Architecture #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); #
# you may not use this file except in compliance with the License. #
# You may obtain a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
# #
# SPDX-License-Identifier: Apache-2.0 #
# ==================================================================================================================== #
#
"""This module contains the CLI abstraction layer for `GHDL <https://github.com/ghdl/ghdl>`__."""
from typing import Union, Iterable
from pyTooling.Decorators import export
from pyVHDLModel import VHDLVersion
from pyTooling.CLIAbstraction import CLIArgument, Executable
from pyTooling.CLIAbstraction.Argument import PathListArgument, StringArgument
from pyTooling.CLIAbstraction.Command import CommandArgument
from pyTooling.CLIAbstraction.Flag import ShortFlag, LongFlag
from pyTooling.CLIAbstraction.BooleanFlag import LongBooleanFlag
from pyTooling.CLIAbstraction.ValuedFlag import ShortValuedFlag, LongValuedFlag
from pyTooling.CLIAbstraction.KeyValueFlag import ShortKeyValueFlag
@export
class GHDL(Executable):
_executableNames = {
"Darwin": "ghdl",
"Linux": "ghdl",
"Windows": "ghdl.exe"
}
# XXX: overwrite __init__ and get backend variant
# XXX: check for compatible backends
@CLIArgument()
class CommandHelp(CommandArgument, name="help"):
"""Print help page(s)."""
@CLIArgument()
class CommandVersion(CommandArgument, name="version"):
"""Print version information."""
@CLIArgument()
class CommandSyntax(CommandArgument, name="syntax"):
"""Check syntax."""
@CLIArgument()
class CommandElaborationOrder(CommandArgument, name="elab-order"):
"""Display (elaboration) ordered source files."""
@CLIArgument()
class CommandAnalyze(CommandArgument, name="analyze"):
"""Analyze VHDL source file(s)."""
@CLIArgument()
class CommandElaborate(CommandArgument, name="elaborate"):
"""Elaborate design."""
@CLIArgument()
class CommandElaborationAndRun(CommandArgument, name="elab-run"):
"""Elaborate and simulate design."""
@CLIArgument()
class CommandRun(CommandArgument, name="run"):
"""Simulate design."""
@CLIArgument()
class CommandBind(CommandArgument, name="bind"):
"""Bind design unit."""
@CLIArgument()
class CommandLink(CommandArgument, name="link"):
"""Link design unit."""
@CLIArgument()
class CommandListLink(CommandArgument, name="list-link"):
"""List objects file to link a design unit."""
@CLIArgument()
class CommandCompile(CommandArgument, name="compile"):
"""Generate whole sequence to elaborate design from files."""
@CLIArgument()
class CommandGenerateDependencies(CommandArgument, name="gen-depends"):
"""Generate dependencies of design."""
@CLIArgument()
class CommandSynthesize(CommandArgument, name="synth"):
"""Synthesis from design unit."""
@CLIArgument()
class FlagVerbose(ShortFlag, name="v"):
"""Run in verbose mode (print more messages)."""
# Analyze and elaborate options
@CLIArgument()
class FlagVHDLStandard(LongValuedFlag, name="std"):
"""Set the used VHDL standard version."""
_value: VHDLVersion
def __init__(self, value: VHDLVersion):
if value is None:
raise ValueError(f"") # XXX: add message
self._value = value
@property
def Value(self) -> VHDLVersion:
return self._value
@Value.setter
def Value(self, value: VHDLVersion) -> None:
if value is None:
raise ValueError(f"") # XXX: add message
self._value = value
def AsArgument(self) -> Union[str, Iterable[str]]:
if self._name is None:
raise ValueError(f"") # XXX: add message
return self._pattern.format(self._name, str(self._value)[-2:])
@CLIArgument()
class FlagIEEEFlavor(LongValuedFlag, name="ieee"):
"""Set the used VHDL flavor."""
@CLIArgument()
class FlagSynopsys(ShortFlag, name="fsynopsys"):
"""Set used VHDL flavor to *Synopsys* and make Synopsys packages visible in library ``ìeee``."""
@CLIArgument()
class FlagRelaxed(ShortFlag, name="frelaxed"):
"""Relax some LRM rules."""
@CLIArgument()
class FlagExplicit(ShortFlag, name="fexplicit"): ...
@CLIArgument()
class FlagLibrary(LongValuedFlag, name="work"):
"""Set working library."""
@CLIArgument()
class FlagWorkingDirectory(LongValuedFlag, name="workdir"):
"""Set working directory."""
@CLIArgument()
class FlagMultiByteComments(LongFlag, name="mb-comments"):
"""Allow multi-byte comments."""
@CLIArgument()
class FlagSyntesisBindingRule(LongFlag, name="syn-binding"):
"""Enable synthesis binding rule."""
@CLIArgument()
class FlagSearchPath(ShortValuedFlag, name="P", pattern="-{0}{1}"):
"""Add search path."""
@CLIArgument()
class FlagTimeResolution(LongValuedFlag, name="time-resolution"):
"""Set base time resolution.
Allowed values are ``auto`` (default), ``fs``, ``ps``, ``ns``, ``us``, ``ms`` or ``sec``.
"""
@CLIArgument()
class FlagVitalChecks(LongBooleanFlag, name="vital-checks", pattern="-{0}", falsePattern="--no-{0}"):
"""Check VITAL restrictions."""
@CLIArgument()
class FlagWarnUnboundComponents(ShortFlag, name="binding", pattern="-W{0}"):
"""Warns for unbound components."""
@CLIArgument()
class FlagWarnReservedWords(ShortFlag, name="reserved", pattern="-W{0}"):
"""Warns if VHDL'93 reserved words are used in VHDL'87."""
@CLIArgument()
class FlagWarnRedefinedDesignUnits(ShortFlag, name="library", pattern="-W{0}"):
"""Warns for redefined design unit."""
@CLIArgument()
class FlagWarnNonVitalGenericNames(ShortFlag, name="vital-generic", pattern="-W{0}"):
"""Warns of non-vital generic names."""
@CLIArgument()
class FlagWarnElaborationChecks(ShortFlag, name="delayed-checks", pattern="-W{0}"):
"""Warns for checks performed at elaboration."""
@CLIArgument()
class FlagWarnUnnecessaryPackageBody(ShortFlag, name="body", pattern="-W{0}"):
"""Warns for unnecessary package body."""
@CLIArgument()
class FlagWarnOthersSpecifications(ShortFlag, name="specs", pattern="-W{0}"):
"""Warns if an all/others specification does not apply."""
@CLIArgument()
class FlagSyntesisBindingRule(ShortFlag, name="unused", pattern="-W{0}"):
"""Warns for unused subprograms."""
@CLIArgument()
class FlagSyntesisBindingRule(ShortFlag, name="error", pattern="-W{0}"):
"""Turns warnings into errors."""
@CLIArgument()
class OptionPath(PathListArgument):
"""Add VHDL file to analyze."""
@CLIArgument()
class OptionTopLevel(StringArgument):
"""Specify the toplevel design unit."""
@CLIArgument()
class OptionArchitecture(StringArgument):
"""Specify the architecture name, if the toplevel design unit is an entity."""
@CLIArgument()
class FlagGenerics(ShortKeyValueFlag, pattern="-{0}{1}={2}"):
"""Set a generic value."""
@CLIArgument()
class FlagAsserts(ShortValuedFlag, name="asserts"):
"""Select how assertions are handled.
It can be ``enable`` (the default), ``disable`` which disables all assertions and ``disable-at-0`` which disables
only at the start of simulation.
"""
@CLIArgument()
class FlagIEEEAsserts(ShortValuedFlag, name="ieee-asserts"):
"""Select how assertions are handled.
It can be ``enable`` (the default), ``disable`` which disables all assertions and ``disable-at-0`` which disables
only at the start of simulation.
"""
@CLIArgument()
class FlagStopTime(ShortValuedFlag, name="stop-time"):
"""Stop the simulation after a given simulation time.
The time is expressed as a time value, without any spaces. The time is the simulation time, not the real execution time.
"""
@CLIArgument()
class FlagMaxDeltaCycles(ShortValuedFlag, name="stop-delta"):
"""Stop the simulation after N delta cycles in the same current time."""
@CLIArgument()
class FlagDisplayDeltaCycles(ShortValuedFlag, name="disp-time"):
"""Display the time and delta cycle number as simulation advances."""
@CLIArgument()
class FlagUnbufferedIO(ShortValuedFlag, name="unbuffered"):
"""Disable buffering on STDOUT, STDERR and files opened in write or append mode (TEXTIO)."""
@CLIArgument()
class FlagReadWaveformOptionsFile(ShortValuedFlag, name="read-wave-opt"):
"""Filter signals to be dumped to the waveform file according to the wavefile option file provided."""
@CLIArgument()
class FlagWriteWaveformOptionsFile(ShortValuedFlag, name="write-wave-opt"):
"""If the wavefile option file doesn’t exist, creates it with all the signals of the design.
Otherwise, it throws an error, because it won’t erase an existing file.
"""
@CLIArgument()
class FlagGHWWaveformFile(ShortValuedFlag, name="wave"):
"""Write the waveforms into a GHDL Waveform (``*.ghw``) file.
Contrary to VCD files, any VHDL type can be dumped into a GHW file.
"""
def _CopyParameters(self, tool: "GHDL") -> None:
for key in self.__cliParameters__:
if self._NeedsParameterInitialization(key):
value = self.__cliParameters__[key].Value
tool.__cliParameters__[key] = key(value)
else:
tool.__cliParameters__[key] = key()
def _SetParameters(self, tool: "GHDL", std: VHDLVersion = None, ieee: str = None):
if std is not None:
tool[self.FlagVHDLStandard] = str(std)
if ieee is not None:
tool[self.FlagVHDLStandard] = ieee
def GetGHDLAsAnalyzer(self, std: VHDLVersion = None, ieee: str = None):
tool = GHDL(executablePath=self._executablePath)
tool[tool.CommandAnalyze] = True
self._CopyParameters(tool)
self._SetParameters(tool, std, ieee)
return tool
def GetGHDLAsElaborator(self, std: VHDLVersion = None, ieee: str = None):
tool = GHDL(executablePath=self._executablePath)
tool[tool.CommandElaborate] = True
self._CopyParameters(tool)
self._SetParameters(tool, std, ieee)
return tool
def GetGHDLAsSimulator(self, std: VHDLVersion = None, ieee: str = None):
tool = GHDL(executablePath=self._executablePath)
tool[tool.CommandRun] = True
self._CopyParameters(tool)
self._SetParameters(tool, std, ieee)
return tool
|