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
|
# ==============================================================================
# Authors:
# Patrick Lehmann
#
# ==============================================================================
# Copyright (C) 2017-2021 Patrick Lehmann - Boetzingen, Germany
# Copyright (C) 2015-2016 Patrick Lehmann - Dresden, Germany
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <gnu.org/licenses>.
# ==============================================================================
# .SYNOPSIS
# Script to compile the simulation libraries from Xilinx ISE for GHDL on Windows.
#
# .DESCRIPTION
# This CmdLet:
# (1) creates a subdirectory in the current working directory
# (2) compiles all Xilinx ISE simulation libraries and packages
# - unisim (incl. secureip)
# - unimacro
# - simprim (incl. secureip)
# - xilinxcorelib
#
[CmdletBinding()]
param(
# Show the embedded help page(s)
[switch]$Help = $false,
# Compile all libraries and packages.
[switch]$All = $false,
# Compile the Xilinx simulation library.
[switch]$Unisim = $false,
# Compile the Xilinx macro library.
[switch]$Unimacro = $false,
# Compile the Xilinx post-map simulation library.
[switch]$Simprim = $false,
# Compile the Xilinx CoreLib simulation library.
[switch]$CoreLib = $false,
# Compile the Xilinx secureip library.
[switch]$SecureIP = $false,
# Clean up directory before analyzing.
[switch]$Clean = $false,
# Set VHDL Standard to '93
[switch]$VHDL93 = $false,
# Set VHDL Standard to '08
[switch]$VHDL2008 = $false,
# Skip warning messages. (Show errors only.)
[switch]$SuppressWarnings = $false,
# Halt on errors.
[switch]$HaltOnError = $false,
# Set vendor library source directory.
[string]$Source = "",
# Set output directory name.
[string]$Output = "",
# Set path to GHDL's executable, e.g. <MyGHDLPath>/bin/ghdl.exe
[string]$GHDL = ""
)
# ---------------------------------------------
# save working directory
$WorkingDir = Get-Location
# set default values
$EnableDebug = [bool]$PSCmdlet.MyInvocation.BoundParameters["Debug"]
$EnableVerbose = [bool]$PSCmdlet.MyInvocation.BoundParameters["Verbose"] -or $EnableDebug
# load modules from GHDL's 'vendors' library directory
$EnableVerbose -and (Write-Host "Loading modules..." -ForegroundColor Gray ) | Out-Null
$EnableDebug -and (Write-Host " Import-Module $PSScriptRoot\config.psm1 -Verbose:`$$false -Debug:`$$false -ArgumentList `"XilinxISE`"" -ForegroundColor DarkGray ) | Out-Null
Import-Module $PSScriptRoot\config.psm1 -Verbose:$false -ArgumentList "XilinxISE"
$EnableDebug -and (Write-Host " Import-Module $PSScriptRoot\shared.psm1 -Verbose:`$$false -Debug:`$$false -ArgumentList @(`"Xilinx ISE`", `"$WorkingDir`")" -ForegroundColor DarkGray ) | Out-Null
Import-Module $PSScriptRoot\shared.psm1 -Verbose:$false -ArgumentList @("Xilinx ISE", "$WorkingDir")
# Display help if no command was selected
$Help = $Help -or (-not ($All -or $Unisim -or $Simprim -or $Unimacro -or $CoreLib -or $Clean))
if ($Help)
{ Get-Help $MYINVOCATION.MyCommand.Path -Detailed
Exit-CompileScript
}
if ($All)
{ $Unisim = $true
$Simprim = $true
$Unimacro = $true
$CoreLib = $true
$SecureIP = $true
}
function Get-XilinxISEDirectory
{ if (Test-Path env:XILINX)
{ return $env:XILINX + "\" + (Get-VendorToolSourceDirectory) }
else
{ $EnvSourceDir = ""
foreach ($Drive in Get-PSDrive -PSProvider 'FileSystem')
{ $Path = $Drive.Name + ":\" + "Xilinx"
if (Test-Path $Path -PathType Container)
{ foreach ($Major in 14..12)
{ foreach ($Minor in 7..1)
{ $Dir = $Path + "\" + $Major + "." + $Minor + "\ISE_DS"
if (Test-Path $Dir -PathType Container)
{ $EnvSourceDir = $Dir + "\" + (Get-VendorToolSourceDirectory)
return $EnvSourceDir
}
}
}
}
}
}
}
$SourceDirectory = Get-SourceDirectory $Source (Get-XilinxISEDirectory)
$DestinationDirectory = Get-DestinationDirectory $Output
$GHDLBinary = Get-GHDLBinary $GHDL
# create "Altera" directory and change to it
New-DestinationDirectory $DestinationDirectory
cd $DestinationDirectory
if ($VHDL2008)
{ Write-Host "Not all Xilinx primitives are VHDL-2008 compatible! Setting HaltOnError to FALSE." -ForegroundColor Red
$HaltOnError = $false
}
$VHDLVersion,$VHDLStandard,$VHDLFlavor = Get-VHDLVariables -VHDL93:$VHDL93 -VHDL2008:$VHDL2008
# define global GHDL Options
$Analyze_Parameters = @(
"--std=$VHDLStandard",
"-fexplicit",
"-frelaxed-rules",
"--mb-comments",
"-Wbinding"
)
if (-not $EnableDebug)
{ $Analyze_Parameters += @(
"-Wno-hide"
)
}
if (-not ($EnableVerbose -or $EnableDebug))
{ $Analyze_Parameters += @(
"-Wno-library",
"-Wno-others",
"-Wno-static"
)
}
$Analyze_Parameters += @(
"--ieee=$VHDLFlavor",
"--no-vital-checks",
"-P$DestinationDirectory"
)
# extract data from configuration
# $SourceDir = $InstallationDirectory["AlteraQuartus"] + "\quartus\eda\sim_lib"
$StopCompiling = $false
$ErrorCount = 0
# Cleanup directories
# ==============================================================================
if ($Clean)
{ Write-Host "[ERROR]: '-Clean' is not implemented!" -ForegroundColor Red
Exit-CompileScript -1
Write-Host "Cleaning up vendor directory ..." -ForegroundColor Yellow
rm *.cf
}
# Library UniSim
# ==============================================================================
# compile unisim packages
if ((-not $StopCompiling) -and $Unisim)
{ $Library = "unisim"
$Files = @(
"unisims\unisim_VPKG.vhd",
"unisims\unisim_VCOMP.vhd"
)
$SourceFiles = $Files | % { "$SourceDirectory\$_" }
$ErrorCount += Start-PackageCompilation $GHDLBinary $Analyze_Parameters $DestinationDirectory $Library $VHDLVersion $SourceFiles $SuppressWarnings $HaltOnError -Verbose:$EnableVerbose -Debug:$EnableDebug
$StopCompiling = $HaltOnError -and ($ErrorCount -ne 0)
}
# compile unisim primitives
if ((-not $StopCompiling) -and $Unisim)
{ $Library = "unisim"
$SourceFiles = dir "$SourceDirectory\unisims\primitive\*.vhd*"
$ErrorCount += Start-PrimitiveCompilation $GHDLBinary $Analyze_Parameters $DestinationDirectory $Library $VHDLVersion $SourceFiles $SuppressWarnings $HaltOnError -Verbose:$EnableVerbose -Debug:$EnableDebug
$StopCompiling = $HaltOnError -and ($ErrorCount -ne 0)
}
# compile unisim secureip primitives
if ((-not $StopCompiling) -and $Unisim -and $SecureIP)
{ $Library = "secureip"
$SourceFiles = dir "$SourceDirectory\unisims\secureip\*.vhd*"
$ErrorCount += Start-PrimitiveCompilation $GHDLBinary $Analyze_Parameters $DestinationDirectory $Library $VHDLVersion $SourceFiles $SuppressWarnings $HaltOnError -Verbose:$EnableVerbose -Debug:$EnableDebug
$StopCompiling = $HaltOnError -and ($ErrorCount -ne 0)
}
# Library UNIMACRO
# ==============================================================================
# compile unimacro packages
if ((-not $StopCompiling) -and $Unimacro)
{ $Library = "unimacro"
$Files = @(
"unimacro\unimacro_VCOMP.vhd"
)
$SourceFiles = $Files | % { "$SourceDirectory\$_" }
$ErrorCount += Start-PackageCompilation $GHDLBinary $Analyze_Parameters $DestinationDirectory $Library $VHDLVersion $SourceFiles $SuppressWarnings $HaltOnError -Verbose:$EnableVerbose -Debug:$EnableDebug
$StopCompiling = $HaltOnError -and ($ErrorCount -ne 0)
}
# compile unimacro macros
if ((-not $StopCompiling) -and $Unimacro)
{ $Library = "unimacro"
$SourceFiles = dir "$SourceDirectory\unimacro\*_MACRO.vhd*"
$ErrorCount += Start-PrimitiveCompilation $GHDLBinary $Analyze_Parameters $DestinationDirectory $Library $VHDLVersion $SourceFiles $SuppressWarnings $HaltOnError -Verbose:$EnableVerbose -Debug:$EnableDebug
$StopCompiling = $HaltOnError -and ($ErrorCount -ne 0)
}
# Library SIMPRIM
# ==============================================================================
# compile simprim packages
if ((-not $StopCompiling) -and $Simprim)
{ $Library = "simprim"
$Files = (
"simprims\simprim_Vpackage.vhd",
"simprims\simprim_Vcomponents.vhd"
)
$SourceFiles = $Files | % { "$SourceDirectory\$_" }
$ErrorCount += Start-PackageCompilation $GHDLBinary $Analyze_Parameters $DestinationDirectory $Library $VHDLVersion $SourceFiles $SuppressWarnings $HaltOnError -Verbose:$EnableVerbose -Debug:$EnableDebug
$StopCompiling = $HaltOnError -and ($ErrorCount -ne 0)
}
# compile simprim primitives
if ((-not $StopCompiling) -and $Simprim)
{ $Library = "simprim"
$SourceFiles = dir "$SourceDirectory\simprims\primitive\other\*.vhd*"
$ErrorCount += Start-PrimitiveCompilation $GHDLBinary $Analyze_Parameters $DestinationDirectory $Library $VHDLVersion $SourceFiles $SuppressWarnings $HaltOnError -Verbose:$EnableVerbose -Debug:$EnableDebug
$StopCompiling = $HaltOnError -and ($ErrorCount -ne 0)
}
# compile simprim secureip primitives
if ((-not $StopCompiling) -and $Simprim -and $SecureIP)
{ $Library = "secureip"
$SourceFiles = dir "$SourceDirectory\simprims\secureip\other\*.vhd*"
$ErrorCount += Start-PrimitiveCompilation $GHDLBinary $Analyze_Parameters $DestinationDirectory $Library $VHDLVersion $SourceFiles $SuppressWarnings $HaltOnError -Verbose:$EnableVerbose -Debug:$EnableDebug
$StopCompiling = $HaltOnError -and ($ErrorCount -ne 0)
}
# Library XilinxCoreLib
# ==============================================================================
# compile CoreLib primitives
if ((-not $StopCompiling) -and $CoreLib)
{ $Library = "xilinxcorelib"
$AnalyzeFile = "$SourceDirectory\XilinxCoreLib\vhdl_analyze_order"
if (-not (Test-Path $AnalyzeFile -PathType Leaf))
{ Write-Host "[ERROR]: Analyze file '$AnalyzeFile' not found!"
Exit-CompileScript -1
}
$AnalyzeOrder = Get-Content $AnalyzeFile -Encoding Ascii
$SourceFiles = @()
foreach ($line in $AnalyzeOrder)
{ if (-not ($line.StartsWith("#") -or ($line -eq "")))
{ $SourceFiles += "$SourceDirectory\XilinxCoreLib\$line" }
}
$ErrorCount += Start-PrimitiveCompilation $GHDLBinary $Analyze_Parameters $DestinationDirectory $Library $VHDLVersion $SourceFiles $SuppressWarnings $HaltOnError -Verbose:$EnableVerbose -Debug:$EnableDebug
$StopCompiling = $HaltOnError -and ($ErrorCount -ne 0)
}
Write-Host "--------------------------------------------------------------------------------"
Write-Host "Compiling Xilinx ISE libraries " -NoNewline
if ($ErrorCount -gt 0)
{ Write-Host "[FAILED]" -ForegroundColor Red }
else
{ Write-Host "[SUCCESSFUL]" -ForegroundColor Green }
Exit-CompileScript
|