fix(saolei): 修复被编辑器覆盖的 board_top 端口行; 自检脚本支持 -Fix; tcl 默认定义 SAOLEI_ROM

- cpu21_board_top.v: PS/2 例化里 .ev_valid_o 被一行 README 正文覆盖, 综合报
  [Synth 8-2715] non-printable character 0xe4 / syntax error near ...
- tools/check_rtl_text.ps1: 修掉块注释导致的漏报(board_top 就是被漏掉的那个);
  改为按 UTF-8 原始字节读写(保持中文/换行/BOM 不变); 整行正文可用 -Fix 自动删除
- create_project.tcl: 新增 use_saolei 开关并定义宏 SAOLEI_ROM (1=扫雷, 0=走马灯)
This commit is contained in:
2026-09-18 16:13:47 +08:00
parent df7b3aee6d
commit e4d58a3439
3 changed files with 43 additions and 11 deletions
+28 -9
View File
@@ -18,6 +18,11 @@
# powershell -ExecutionPolicy Bypass -File pipelined-cpu\tools\check_rtl_text.ps1
# Exit code 0 = clean, 1 = found something.
# =============================================================================
param(
# -Fix: 自动删除"整行都是粘贴进来的正文"的坏行(保守:只删不含 ; ( ) = 等代码标点的整行)。
# 被部分覆盖的行(例如某个端口行被改坏)只报告,需手工或 git 修。
[switch]$Fix
)
$ErrorActionPreference = 'Stop'
$srcs = Join-Path (Split-Path -Parent $PSScriptRoot) 'srcs'
@@ -28,31 +33,37 @@ $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
# 用 .NET 按 UTF-8 读原始字节:PS 5.1 的 Get-Content 会按 GBK 解码,中文会乱。
# 按行切开时保留行尾(\r\n / \n),写回时逐字节保持原样,不归一化换行/编码/BOM。
$bytes = [System.IO.File]::ReadAllBytes($f.FullName)
$text = [System.Text.Encoding]::UTF8.GetString($bytes)
$lines = @([regex]::Split($text, "(?<=\n)"))
$drop = @()
for ($i = 0; $i -lt $lines.Count; $i++) {
$line = $lines[$i]
$line = $lines[$i].TrimEnd("`r", "`n")
$lineNo = $i + 1
# ---- strip comments so we only look at code positions ----
# ---- 只去掉 // (或 .xdc 的 #) 之后的部分,其余按代码位置检查 ----
# 注意:这里不处理 /* */ 块注释(srcs 里没有块注释,之前因此漏报过坏行)
$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:")
# 整行只有正文(不含 ; ( ) = ` ' " 之类代码标点)⇒ 可以安全整行删掉
$onlyProse = ($trim -notmatch '[;()=`''"]')
$tag = if ($onlyProse) { ' [整行正文,可用 -Fix 删掉]' } else { ' [部分覆盖,需手工/git 修]' }
Write-Output ("!! $rel`:$lineNo non-ASCII text in code position${tag}:")
Write-Output (" " + $trim)
if ($Fix -and $onlyProse) { $drop += $i }
$bad++
continue
}
@@ -64,6 +75,12 @@ foreach ($f in $files) {
$bad++
}
}
if ($Fix -and $drop.Count -gt 0) {
$kept = for ($i = 0; $i -lt $lines.Count; $i++) { if ($drop -notcontains $i) { $lines[$i] } }
[System.IO.File]::WriteAllText($f.FullName, ($kept -join ''), (New-Object System.Text.UTF8Encoding($false)))
Write-Output (" -Fix: 已从 $rel 删除 " + $drop.Count + " 行(编码/换行保持不变),请重跑自检确认")
}
}
Write-Output ""
@@ -73,5 +90,7 @@ if ($bad -eq 0) {
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."
Write-Output "Hint1: 这类行通常是编辑器/工具粘贴进来的正文;整行正文可以用 -Fix 删掉:"
Write-Output " powershell -ExecutionPolicy Bypass -File tools\check_rtl_text.ps1 -Fix"
Write-Output "Hint2: 若报的是 [部分覆盖],对照 git diff 手工修(被编辑器保存覆盖时,先关掉那个标签页再改)。"
exit 1