Files
risc-v-cpu/pipelined-cpu/tools/check_rtl_text.ps1
T
Alpha df7b3aee6d fix(rtl): 清除被工具反复注入到 .v 末尾的 README 残行; 新增 RTL 文本自检脚本
- cpu21_pointer.v / cpu21_ps2_mouse.v / cpu21_vga.v 末尾多出一行 README 正文
  (Tcl ...), 会导致 Vivado: ERROR: [Synth 8-2715] non-printable character 0xe4
- 新增 pipelined-cpu/tools/check_rtl_text.ps1: 综合前秒级自检, 检出代码位置上
  的非 ASCII 文本/粘贴进来的正文行
2026-09-18 16:02:02 +08:00

78 lines
3.1 KiB
PowerShell

# =============================================================================
# check_rtl_text.ps1 —— detect stray non-Verilog text in the RTL sources.
#
# WHY: this project's .v files were twice corrupted by a text tool that inserted a
# line of README prose into them ("Tcl ..." / a Chinese sentence), which made
# Vivado fail with
# ERROR: [Synth 8-2715] syntax error near "..." 'non-printable character 0xe4'
# and produced a cascade of bogus errors in the included ROM .vh. Running this
# script takes a second and catches it before spending a synthesis run.
#
# WHAT IT CHECKS
# 1) a line inside .v/.vh/.xdc that has non-ASCII characters *outside* a comment
# (i.e. real code position) -> corruption;
# 2) a line that looks like pasted prose/markdown (leading "|", "**", or a line
# that is bare text after `endmodule`).
#
# USAGE (from the repository root or from pipelined-cpu/):
# powershell -ExecutionPolicy Bypass -File pipelined-cpu\tools\check_rtl_text.ps1
# Exit code 0 = clean, 1 = found something.
# =============================================================================
$ErrorActionPreference = 'Stop'
$srcs = Join-Path (Split-Path -Parent $PSScriptRoot) 'srcs'
if (-not (Test-Path $srcs)) { Write-Output "ERROR: cannot find $srcs"; exit 2 }
$bad = 0
$files = Get-ChildItem -Recurse -Path $srcs -Include *.v, *.vh, *.xdc -File
foreach ($f in $files) {
$rel = $f.FullName.Substring($srcs.Length).TrimStart('\', '/')
$lines = @(Get-Content -LiteralPath $f.FullName)
$inBlockComment = $false
for ($i = 0; $i -lt $lines.Count; $i++) {
$line = $lines[$i]
$lineNo = $i + 1
# ---- strip comments so we only look at code positions ----
$code = $line
if ($f.Extension -eq '.xdc') {
$h = $code.IndexOf('#'); if ($h -ge 0) { $code = $code.Substring(0, $h) }
}
else {
$c = $code.IndexOf('//'); if ($c -ge 0) { $code = $code.Substring(0, $c) }
if ($inBlockComment) { $code = '' }
if ($line -match '/\*') { $inBlockComment = $true }
if ($line -match '\*/') { $inBlockComment = $false }
}
$trim = $line.Trim()
# ---- check 1: non-ASCII in code position ----
if ($code -match '[^\x00-\x7F]') {
Write-Output ("!! $rel`:$lineNo non-ASCII text in code position:")
Write-Output (" " + $trim)
$bad++
continue
}
# ---- check 2: pasted prose / markdown leftovers ----
if ($trim -match '^\||^\*\*|^#[^0-9#]' -and $f.Extension -ne '.xdc') {
Write-Output ("!! $rel`:$lineNo looks like pasted prose:")
Write-Output (" " + $trim)
$bad++
}
}
}
Write-Output ""
Write-Output ("scanned " + $files.Count + " files under srcs/")
if ($bad -eq 0) {
Write-Output "RTL text check: OK (no stray non-Verilog text found)."
exit 0
}
Write-Output ("RTL text check: FAILED, " + $bad + " suspicious line(s) - fix them before synthesis.")
Write-Output "Hint: such lines are usually injected by an editor/tool; remove them, then re-run this script."
exit 1