|
3 | 3 | TARGET_NAME = "IPrefetchPipe" |
4 | 4 |
|
5 | 5 |
|
| 6 | +def _extract_signals_with_ports(verilog_file: str, output_file: str) -> None: |
| 7 | + """Export both internal declarations and IO ports for mem-direct access.""" |
| 8 | + import os |
| 9 | + import re |
| 10 | + |
| 11 | + decl = re.compile( |
| 12 | + r"^\s*(?:(input|output|inout)\s+)?(?:(wire|reg|logic)\s+)?(\[[^\]]+\]\s+)?" |
| 13 | + r"([A-Za-z_][\w$]*(?:\s*,\s*[A-Za-z_][\w$]*)*)\s*(?:[,;]|=)" |
| 14 | + ) |
| 15 | + |
| 16 | + seen = set() |
| 17 | + extracted = [] |
| 18 | + |
| 19 | + with open(verilog_file, "r", encoding="utf-8") as f: |
| 20 | + for raw in f: |
| 21 | + line = raw.strip() |
| 22 | + if not line or line.startswith("//"): |
| 23 | + continue |
| 24 | + m = decl.match(raw) |
| 25 | + if not m: |
| 26 | + continue |
| 27 | + direction, sig_type, width, names = m.groups() |
| 28 | + # Skip non-declaration statements accidentally matched. |
| 29 | + if direction is None and sig_type is None: |
| 30 | + continue |
| 31 | + signal_type = sig_type or "wire" |
| 32 | + if signal_type == "reg": |
| 33 | + signal_type = "logic" |
| 34 | + width = (width or "").strip() |
| 35 | + for name in [x.strip() for x in names.split(",")]: |
| 36 | + if name.startswith("_GEN") or name in seen: |
| 37 | + continue |
| 38 | + seen.add(name) |
| 39 | + if width: |
| 40 | + extracted.append(f' - "{signal_type} {width} {name}"') |
| 41 | + else: |
| 42 | + extracted.append(f' - "{signal_type} {name}"') |
| 43 | + |
| 44 | + module_name = os.path.splitext(os.path.basename(verilog_file))[0] |
| 45 | + with open(output_file, "w", encoding="utf-8") as f: |
| 46 | + f.write(f"{module_name}:\n") |
| 47 | + f.write("\n".join(extracted)) |
| 48 | + f.write("\n") |
| 49 | + |
| 50 | + |
6 | 51 | def build(cfg): |
7 | | - # additional internal signal files |
8 | | - internal_signals_path = "scripts/icache_related/icache_iprefetchpipe_internals.yaml" |
| 52 | + # Use mem-direct mode and export a complete internal list so |
| 53 | + # GetInternalSignal(use_vpi=False) can be used safely in tests. |
| 54 | + import os |
| 55 | + from tempfile import NamedTemporaryFile |
| 56 | + from comm import get_rtl_dir |
9 | 57 |
|
10 | 58 | # verilator arguments |
11 | 59 | verilator_args = "--x-initial;0" |
12 | 60 |
|
13 | | - return picker_export(TARGET_NAME, cfg, internal_file=internal_signals_path, vflags=verilator_args) |
| 61 | + with NamedTemporaryFile("w+", prefix=TARGET_NAME, suffix=".yaml") as internal: |
| 62 | + internal_signals_path = internal.name |
| 63 | + rtl_file = get_rtl_dir(f"{TARGET_NAME}.sv", cfg=cfg) |
| 64 | + if not os.path.exists(rtl_file): |
| 65 | + rtl_file = get_rtl_dir(f"{TARGET_NAME}.v", cfg=cfg) |
| 66 | + _extract_signals_with_ports(rtl_file, internal_signals_path) |
| 67 | + return picker_export( |
| 68 | + TARGET_NAME, |
| 69 | + cfg, |
| 70 | + access_mode=1, |
| 71 | + internal_file=internal_signals_path, |
| 72 | + vflags=verilator_args, |
| 73 | + ) |
14 | 74 |
|
15 | 75 |
|
16 | 76 | def line_coverage_files(cfg): |
|
0 commit comments