- frame_q[8:1][3] 是 Verilog-2001 非法写法(part-select 再取位), 综合报
[Synth 8-2599] range is not allowed in a prefix 与 [Synth 8-1008] frame_q is not a memory
-> 改为 frame_q[4] (= 数据字节 frame_q[8:1] 的 bit3)
- dx/dy 互换: 事件里把 dy 当 dx 上报
- 鼠标按键位错位: {2'b0, pkt_q[2], pkt_q[1]} 丢掉左键
-> {2'b0, pkt_q[2], pkt_q[1], pkt_q[0]} (对齐 cpu21_mmio / mmio.h: bit0=左键, bit1=右键, bit2=中键)
- tools/check_rtl_text.ps1: 修 tag 变量引用解析错、修块注释漏报、字符串中文误报
- create_project.tcl 头注: Vivado 版本改为 2020.2 (本机实测: 建工程 + 综合均通过)
99 lines
4.8 KiB
PowerShell
99 lines
4.8 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.
|
|
# =============================================================================
|
|
param(
|
|
# -Fix: 自动删除"整行都是粘贴进来的正文"的坏行(保守:只删不含 ; ( ) = 等代码标点的整行)。
|
|
# 被部分覆盖的行(例如某个端口行被改坏)只报告,需手工或 git 修。
|
|
[switch]$Fix
|
|
)
|
|
$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('\', '/')
|
|
# 用 .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].TrimEnd("`r", "`n")
|
|
$lineNo = $i + 1
|
|
|
|
# ---- 只去掉 // (或 .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) }
|
|
}
|
|
# 字符串字面量里的中文是合法的(如 $display("中文")),先去掉再判断
|
|
$code = $code -replace '"[^"]*"', '""'
|
|
|
|
$trim = $line.Trim()
|
|
|
|
# ---- check 1: non-ASCII in code position ----
|
|
if ($code -match '[^\x00-\x7F]') {
|
|
# 整行只有正文(不含 ; ( ) = ` ' " 之类代码标点)⇒ 可以安全整行删掉
|
|
$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
|
|
}
|
|
|
|
# ---- 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++
|
|
}
|
|
}
|
|
|
|
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 ""
|
|
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 "Hint1: 这类行通常是编辑器/工具粘贴进来的正文;整行正文可以用 -Fix 删掉:"
|
|
Write-Output " powershell -ExecutionPolicy Bypass -File tools\check_rtl_text.ps1 -Fix"
|
|
Write-Output "Hint2: 若报的是 [部分覆盖],对照 git diff 手工修(被编辑器保存覆盖时,先关掉那个标签页再改)。"
|
|
exit 1
|