verilator.ps1 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. $ErrorActionPreference = "Stop"
  2. try {
  3. if ([string]::IsNullOrWhiteSpace($env:OSS_CAD_SUITE_ROOT)) {
  4. throw "OSS_CAD_SUITE_ROOT is not set"
  5. }
  6. if ([string]::IsNullOrWhiteSpace($env:VERILATOR)) {
  7. throw "VERILATOR is not set"
  8. }
  9. if (-not [System.IO.Path]::IsPathRooted($env:OSS_CAD_SUITE_ROOT)) {
  10. throw "OSS_CAD_SUITE_ROOT must be absolute"
  11. }
  12. if (-not [System.IO.Path]::IsPathRooted($env:VERILATOR)) {
  13. throw "VERILATOR must be absolute"
  14. }
  15. $ExpectedBin = [System.IO.Path]::GetFullPath(
  16. (Join-Path $env:OSS_CAD_SUITE_ROOT "bin")
  17. ).TrimEnd("\")
  18. $Native = [System.IO.Path]::GetFullPath($env:VERILATOR)
  19. $NativeItem = Get-Item -LiteralPath $Native -ErrorAction Stop
  20. if ($NativeItem.PSIsContainer) {
  21. throw "VERILATOR must name a file"
  22. }
  23. if (($NativeItem.Attributes -band [System.IO.FileAttributes]::ReparsePoint) -ne 0) {
  24. throw "VERILATOR cannot be a reparse point"
  25. }
  26. if ($NativeItem.Name -notin @("verilator_bin.exe", "verilator.exe")) {
  27. throw "VERILATOR must name verilator_bin.exe or verilator.exe"
  28. }
  29. if (-not [string]::Equals(
  30. $NativeItem.DirectoryName.TrimEnd("\"),
  31. $ExpectedBin,
  32. [System.StringComparison]::OrdinalIgnoreCase
  33. )) {
  34. throw "VERILATOR must be under OSS_CAD_SUITE_ROOT\bin"
  35. }
  36. } catch {
  37. [Console]::Error.WriteLine("Unsafe Verilator configuration: $($_.Exception.Message)")
  38. exit 126
  39. }
  40. & $Native @args
  41. exit $LASTEXITCODE