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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
|
# ==============================================================================
# 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 Lattice Diamond for GHDL on Windows.
#
# .DESCRIPTION
# This CmdLet:
# (1) creates a subdirectory in the current working directory
# (2) compiles all Lattice Diamond simulation libraries and packages
# o Lattice device libraries:
# - EC, ECP, ECP2, ECP3, ECP5U
# - LPTM, LPTM2
# - MachXO, MachXO2, MachXO3L, MachXO3D
# - SC, SCM
# - XP, XP2
#
[CmdletBinding()]
param(
# Show the embedded help page(s)
[switch]$Help = $false,
# Compile all libraries and packages.
[switch]$All = $false,
# Compile the Lattice EC device libraries
[switch]$ec = $false,
# Compile the Lattice ECP device libraries
[switch]$ecp = $false,
# Compile the Lattice ECP2 device libraries
[switch]$ecp2 = $false,
# Compile the Lattice ECP3 device libraries
[switch]$ecp3 = $false,
# Compile the Lattice ECP5U device libraries
[switch]$ecp5u = $false,
# Compile the Lattice LPTM device libraries
[switch]$lptm = $false,
# Compile the Lattice LPTM2 device libraries
[switch]$lptm2 = $false,
# Compile the Lattice MachXO device libraries
[switch]$MachXO = $false,
# Compile the Lattice MachXO2 device libraries
[switch]$MachXO2 = $false,
# Compile the Lattice MachXO3L device libraries
[switch]$MachXO3L = $false,
# Compile the Lattice MachXO3D device libraries
[switch]$MachXO3D = $false,
# Compile the Lattice SC device libraries
[switch]$sc = $false,
# Compile the Lattice SCM device libraries
[switch]$scm = $false,
# Compile the Lattice XP device libraries
[switch]$xp = $false,
# Compile the Lattice XP2 device libraries
[switch]$xp2 = $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 GHDL binary directory.
[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 `"LatticeDiamond`"" -ForegroundColor DarkGray ) | Out-Null
Import-Module $PSScriptRoot\config.psm1 -Verbose:$false -ArgumentList "LatticeDiamond"
$EnableDebug -and (Write-Host " Import-Module $PSScriptRoot\shared.psm1 -Verbose:`$$false -Debug:`$$false -ArgumentList @(`"Lattice Diamond`", `"$WorkingDir`")" -ForegroundColor DarkGray ) | Out-Null
Import-Module $PSScriptRoot\shared.psm1 -Verbose:$false -ArgumentList @("Lattice Diamond", "$WorkingDir")
# Display help if no command was selected
$Help = $Help -or (-not ($All -or
($ec -or $ecp -or $ecp2 -or $ecp3 -or $ecp5u) -or
($lptm -or $lptm2) -or
($MachXO -or $MachXO2 -or $MachXO3L -or $MachXO3D) -or
($sc -or $scm) -or
($xp -or $xp2) -or
$Clean))
if ($Help)
{ Get-Help $MYINVOCATION.MyCommand.Path -Detailed
Exit-CompileScript
}
if ($All)
{ $ec = $true
$ecp = $true
$ecp2 = $true
$ecp3 = $true
$ecp5u = $true
$lptm = $true
$lptm2 = $true
$MachXO = $true
$MachXO2 = $true
$MachXO3L = $true
$MachXO3D = $true
$sc = $true
$scm = $true
$xp = $true
$xp2 = $true
}
function Get-LatticeDiamondDirectory
{ if (Test-Path env:FOUNDRY)
{ return $FOUNDRY + "\..\" + (Get-VendorToolSourceDirectory) }
else
{ $EnvSourceDir = ""
foreach ($Drive in Get-PSDrive -PSProvider 'FileSystem')
{ $Path = $Drive.Name + ":\" + "Lattice\Diamond"
if (Test-Path $Path -PathType Container)
{ foreach ($Major in 4..3)
{ foreach ($Minor in 9..0)
{ $Dir = $Path + "\" + $Major + "." + $Minor + "_x64"
if (Test-Path $Dir -PathType Container)
{ $EnvSourceDir = $Dir + "\" + (Get-VendorToolSourceDirectory)
return $EnvSourceDir
}
}
}
}
}
}
}
$SourceDirectory = Get-SourceDirectory $Source (Get-LatticeDiamondDirectory)
$DestinationDirectory = Get-DestinationDirectory $Output
$GHDLBinary = Get-GHDLBinary $GHDL
# create "Lattice" directory and change to it
New-DestinationDirectory $DestinationDirectory
cd $DestinationDirectory
$VHDLVersion,$VHDLStandard,$VHDLFlavor = Get-VHDLVariables $VHDL93 $VHDL2008
# define global GHDL Options
$Analyze_Parameters = @(
"-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",
"--std=$VHDLStandard",
"-P$DestinationDirectory"
)
$StopCompiling = $false
$ErrorCount = 0
$FileLists = @{
"ec" = @("ORCA_CMB.vhd", "ORCA_SEQ.vhd", "ORCACOMP.vhd", "ORCA_LUT.vhd", "ORCA_MISC.vhd", "ORCA_CNT.vhd", "ORCA_IO.vhd", "ORCA_MEM.vhd");
"ecp" = @("ORCA_CMB.vhd", "ORCA_SEQ.vhd", "ORCACOMP.vhd", "ORCA_LUT.vhd", "ORCA_MISC.vhd", "ORCA_CNT.vhd", "ORCA_IO.vhd", "ORCA_MEM.vhd");
"ecp2" = @("ECP2_CMB.vhd", "ECP2_SEQ.vhd", "ECP2COMP.vhd", "ECP2_CNT.vhd", "ECP2_IO.vhd", "ECP2_LUT.vhd", "ECP2_MEM.vhd", "ECP2_MISC.vhd", "ECP2_MULT.vhd", "ECP2_SL.vhd");
"ecp3" = @("ECP3_CMB.vhd", "ECP3_SEQ.vhd", "ECP3COMP.vhd", "ECP3_CNT.vhd", "ECP3_IO.vhd", "ECP3_LUT.vhd", "ECP3_MEM.vhd", "ECP3_MISC.vhd", "ECP3_MULT.vhd", "ECP3_SL.vhd");
"ecp5u" = @("ECP5U_CMB.vhd", "ECP5U_SEQ.vhd", "ECP5UCOMP.vhd", "ECP5U_IO.vhd", "ECP5U_LUT.vhd", "ECP5U_MEM.vhd", "ECP5U_MISC.vhd", "ECP5U_SL.vhd", "gsr_pur_assign.vhd");
"lptm" = @("MACHXO_CMB.vhd", "MACHXO_SEQ.vhd", "MACHXOCOMP.vhd", "MACHXO_CNT.vhd", "MACHXO_IO.vhd", "MACHXO_LUT.vhd", "MACHXO_MEM.vhd", "MACHXO_MISC.vhd");
"lptm2" = @("MACHXO2_CMB.vhd", "MACHXO2_SEQ.vhd", "MACHXO2COMP.vhd", "gsr_pur_assign.vhd", "MACHXO2_CNT.vhd", "MACHXO2_IO.vhd", "MACHXO2_LUT.vhd", "MACHXO2_MEM.vhd", "MACHXO2_MISC.vhd");
"machxo" = @("MACHXO_CMB.vhd", "MACHXO_SEQ.vhd", "MACHXOCOMP.vhd", "MACHXO_CNT.vhd", "MACHXO_IO.vhd", "MACHXO_LUT.vhd", "MACHXO_MEM.vhd", "MACHXO_MISC.vhd");
"machxo2" = @("MACHXO2_CMB.vhd", "MACHXO2_SEQ.vhd", "MACHXO2COMP.vhd", "MACHXO2_CNT.vhd", "gsr_pur_assign.vhd", "MACHXO2_IO.vhd", "MACHXO2_LUT.vhd", "MACHXO2_MEM.vhd", "MACHXO2_MISC.vhd");
"machxo3l" = @("MACHXO3L_CMB.vhd", "MACHXO3L_SEQ.vhd", "MACHXO3LCOMP.vhd", "gsr_pur_assign.vhd", "MACHXO3L_CNT.vhd", "MACHXO3L_IO.vhd", "MACHXO3L_LUT.vhd", "MACHXO3L_MEM.vhd", "MACHXO3L_MISC.vhd");
"machxo3d" = @("MACHXO3D_CMB.vhd", "MACHXO3D_SEQ.vhd", "MACHXO3DCOMP.vhd", "gsr_pur_assign.vhd", "MACHXO3D_CNT.vhd", "MACHXO3D_IO.vhd", "MACHXO3D_LUT.vhd", "MACHXO3D_MEM.vhd", "MACHXO3D_MISC.vhd");
"sc" = @("ORCA_CMB.vhd", "ORCA_SEQ.vhd", "ORCACOMP.vhd", "ORCA_CNT.vhd", "ORCA_IO.vhd", "ORCA_MEM.vhd", "ORCA_MIS.vhd", "ORCA_SL.vhd");
"scm" = @("ORCA_CMB.vhd", "ORCA_SEQ.vhd", "ORCACOMP.vhd", "ORCA_CNT.vhd", "ORCA_IO.vhd", "ORCA_MEM.vhd", "ORCA_MIS.vhd", "ORCA_SL.vhd");
"xp" = @("ORCA_CMB.vhd", "ORCA_SEQ.vhd", "ORCACOMP.vhd", "ORCA_LUT.vhd", "ORCA_MISC.vhd", "ORCA_CNT.vhd", "ORCA_IO.vhd", "ORCA_MEM.vhd");
"xp2" = @("XP2_CMB.vhd", "XP2_SEQ.vhd", "XP2COMP.vhd", "XP2_CNT.vhd", "XP2_IO.vhd", "XP2_LUT.vhd", "XP2_MEM.vhd", "XP2_MISC.vhd", "XP2_MULT.vhd", "XP2_SL.vhd")
}
# 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
}
# Lattice EC library
# ==============================================================================
if ((-not $StopCompiling) -and $ec)
{ $Library = "ec"
$SourceFiles = $FileLists[$Library] | % { "$SourceDirectory\$Library\src\$_" }
$ErrorCount += Start-PackageCompilation $GHDLBinary $Analyze_Parameters $DestinationDirectory $Library $VHDLVersion $SourceFiles $SuppressWarnings $HaltOnError -Verbose:$EnableVerbose -Debug:$EnableDebug
$StopCompiling = $HaltOnError -and ($ErrorCount -ne 0)
}
# Lattice ECP library
# ==============================================================================
if ((-not $StopCompiling) -and $ecp)
{ $Library = "ecp"
$SourceFiles = $FileLists[$Library] | % { "$SourceDirectory\$Library\src\$_" }
$ErrorCount += Start-PackageCompilation $GHDLBinary $Analyze_Parameters $DestinationDirectory $Library $VHDLVersion $SourceFiles $SuppressWarnings $HaltOnError -Verbose:$EnableVerbose -Debug:$EnableDebug
$StopCompiling = $HaltOnError -and ($ErrorCount -ne 0)
}
# Lattice ECP2 library
# ==============================================================================
if ((-not $StopCompiling) -and $ecp2)
{ $Library = "ecp2"
$SourceFiles = $FileLists[$Library] | % { "$SourceDirectory\$Library\src\$_" }
$ErrorCount += Start-PackageCompilation $GHDLBinary $Analyze_Parameters $DestinationDirectory $Library $VHDLVersion $SourceFiles $SuppressWarnings $HaltOnError -Verbose:$EnableVerbose -Debug:$EnableDebug
$StopCompiling = $HaltOnError -and ($ErrorCount -ne 0)
}
# Lattice ECP3 library
# ==============================================================================
if ((-not $StopCompiling) -and $ecp3)
{ $Library = "ecp3"
$SourceFiles = $FileLists[$Library] | % { "$SourceDirectory\$Library\src\$_" }
$ErrorCount += Start-PackageCompilation $GHDLBinary $Analyze_Parameters $DestinationDirectory $Library $VHDLVersion $SourceFiles $SuppressWarnings $HaltOnError -Verbose:$EnableVerbose -Debug:$EnableDebug
$StopCompiling = $HaltOnError -and ($ErrorCount -ne 0)
}
# Lattice ECP5U library
# ==============================================================================
if ((-not $StopCompiling) -and $ecp5u)
{ $Library = "ecp5u"
$SourceFiles = $FileLists[$Library] | % { "$SourceDirectory\$Library\src\$_" }
$ErrorCount += Start-PackageCompilation $GHDLBinary $Analyze_Parameters $DestinationDirectory $Library $VHDLVersion $SourceFiles $SuppressWarnings $HaltOnError -Verbose:$EnableVerbose -Debug:$EnableDebug
$StopCompiling = $HaltOnError -and ($ErrorCount -ne 0)
}
# Lattice LPTM library
# ==============================================================================
if ((-not $StopCompiling) -and $lptm)
{ $Library = "lptm"
$SourceFiles = $FileLists[$Library] | % { "$SourceDirectory\$Library\src\$_" }
$ErrorCount += Start-PackageCompilation $GHDLBinary $Analyze_Parameters $DestinationDirectory $Library $VHDLVersion $SourceFiles $SuppressWarnings $HaltOnError -Verbose:$EnableVerbose -Debug:$EnableDebug
$StopCompiling = $HaltOnError -and ($ErrorCount -ne 0)
}
# Lattice LPTM2 library
# ==============================================================================
if ((-not $StopCompiling) -and $lptm2)
{ $Library = "lptm2"
$SourceFiles = $FileLists[$Library] | % { "$SourceDirectory\$Library\src\$_" }
$ErrorCount += Start-PackageCompilation $GHDLBinary $Analyze_Parameters $DestinationDirectory $Library $VHDLVersion $SourceFiles $SuppressWarnings $HaltOnError -Verbose:$EnableVerbose -Debug:$EnableDebug
$StopCompiling = $HaltOnError -and ($ErrorCount -ne 0)
}
# Lattice MachXO library
# ==============================================================================
if ((-not $StopCompiling) -and $MachXO)
{ $Library = "MachXO"
$SourceFiles = $FileLists[$Library] | % { "$SourceDirectory\$Library\src\$_" }
$ErrorCount += Start-PackageCompilation $GHDLBinary $Analyze_Parameters $DestinationDirectory $Library $VHDLVersion $SourceFiles $SuppressWarnings $HaltOnError -Verbose:$EnableVerbose -Debug:$EnableDebug
$StopCompiling = $HaltOnError -and ($ErrorCount -ne 0)
}
# Lattice MachXO2 library
# ==============================================================================
if ((-not $StopCompiling) -and $MachXO2)
{ $Library = "MachXO2"
$SourceFiles = $FileLists[$Library] | % { "$SourceDirectory\$Library\src\$_" }
$ErrorCount += Start-PackageCompilation $GHDLBinary $Analyze_Parameters $DestinationDirectory $Library $VHDLVersion $SourceFiles $SuppressWarnings $HaltOnError -Verbose:$EnableVerbose -Debug:$EnableDebug
$StopCompiling = $HaltOnError -and ($ErrorCount -ne 0)
}
# Lattice MachXO3L library
# ==============================================================================
if ((-not $StopCompiling) -and $machxo3l)
{ $Library = "machxo3l"
$SourceFiles = $FileLists[$Library] | % { "$SourceDirectory\$Library\src\$_" }
$ErrorCount += Start-PackageCompilation $GHDLBinary $Analyze_Parameters $DestinationDirectory $Library $VHDLVersion $SourceFiles $SuppressWarnings $HaltOnError -Verbose:$EnableVerbose -Debug:$EnableDebug
$StopCompiling = $HaltOnError -and ($ErrorCount -ne 0)
}
# Lattice MachXO3D library
# ==============================================================================
if ((-not $StopCompiling) -and $machxo3d)
{ $Library = "machxo3d"
$SourceFiles = $FileLists[$Library] | % { "$SourceDirectory\$Library\src\$_" }
$ErrorCount += Start-PackageCompilation $GHDLBinary $Analyze_Parameters $DestinationDirectory $Library $VHDLVersion $SourceFiles $SuppressWarnings $HaltOnError -Verbose:$EnableVerbose -Debug:$EnableDebug
$StopCompiling = $HaltOnError -and ($ErrorCount -ne 0)
}
# Lattice SC library
# ==============================================================================
if ((-not $StopCompiling) -and $sc)
{ $Library = "sc"
$SourceFiles = $FileLists[$Library] | % { "$SourceDirectory\$Library\src\$_" }
$ErrorCount += Start-PackageCompilation $GHDLBinary $Analyze_Parameters $DestinationDirectory $Library $VHDLVersion $SourceFiles $SuppressWarnings $HaltOnError -Verbose:$EnableVerbose -Debug:$EnableDebug
$StopCompiling = $HaltOnError -and ($ErrorCount -ne 0)
}
# Lattice SCM library
# ==============================================================================
if ((-not $StopCompiling) -and $scm)
{ $Library = "scm"
$SourceFiles = $FileLists[$Library] | % { "$SourceDirectory\$Library\src\$_" }
$ErrorCount += Start-PackageCompilation $GHDLBinary $Analyze_Parameters $DestinationDirectory $Library $VHDLVersion $SourceFiles $SuppressWarnings $HaltOnError -Verbose:$EnableVerbose -Debug:$EnableDebug
$StopCompiling = $HaltOnError -and ($ErrorCount -ne 0)
}
# Lattice XP library
# ==============================================================================
if ((-not $StopCompiling) -and $xp)
{ $Library = "xp"
$SourceFiles = $FileLists[$Library] | % { "$SourceDirectory\$Library\src\$_" }
$ErrorCount += Start-PackageCompilation $GHDLBinary $GHDLOptions $DestinationDirectory $Library $VHDLVersion $SourceFiles $SuppressWarnings $HaltOnError -Verbose:$EnableVerbose -Debug:$EnableDebug
$StopCompiling = $HaltOnError -and ($ErrorCount -ne 0)
}
# Lattice XP2 library
# ==============================================================================
if ((-not $StopCompiling) -and $xp2)
{ $Library = "xp2"
$SourceFiles = $FileLists[$Library] | % { "$SourceDirectory\$Library\src\$_" }
$ErrorCount += Start-PackageCompilation $GHDLBinary $GHDLOptions $DestinationDirectory $Library $VHDLVersion $SourceFiles $SuppressWarnings $HaltOnError -Verbose:$EnableVerbose -Debug:$EnableDebug
$StopCompiling = $HaltOnError -and ($ErrorCount -ne 0)
}
Write-Host "--------------------------------------------------------------------------------"
Write-Host "Compiling Lattice libraries " -NoNewline
if ($ErrorCount -gt 0)
{ Write-Host "[FAILED]" -ForegroundColor Red }
else
{ Write-Host "[SUCCESSFUL]" -ForegroundColor Green }
Exit-CompileScript
|