updated anchors and autofiller

This commit is contained in:
PurplePower
2025-08-14 21:57:07 +08:00
parent c6ff02a058
commit 47c801d5d7
3 changed files with 8 additions and 10 deletions

View File

@@ -31,10 +31,10 @@ class CPU extends Module {
val clint = Module(new CLINT)
val csr_regs = Module(new CSR)
// Lab3(Flush)
// Lab3(ThreeStage)
if2id.io.flush := false.B
id2ex.io.flush := false.B
// Lab3(Flush) End
// Lab3(ThreeStage) End
regs.io.write_enable := id2ex.io.output_regs_write_enable
regs.io.write_address := id2ex.io.output_regs_write_address

View File

@@ -17,5 +17,6 @@ package riscv.core.threestage
import chisel3._
class Control extends Module {
// Lab3(Flush)
// Lab3(ThreeStage)
// Lab3(ThreeStage) End
}

View File

@@ -152,7 +152,7 @@ class CodeFiller:
begin_idx = end_idx = None
anchor_indent = ""
for i, line in enumerate(lines):
if begin_anchor.strip() in line.strip():
if begin_anchor.strip() == line.strip():
begin_idx = i
# Extract indentation from the begin anchor line
for char in line:
@@ -160,7 +160,7 @@ class CodeFiller:
anchor_indent += char
else:
break
if end_anchor.strip() in line.strip():
if end_anchor.strip() == line.strip():
end_idx = i
break
if begin_idx is None:
@@ -168,7 +168,7 @@ class CodeFiller:
if end_idx is None:
raise ValueError(f"End anchor '{end_anchor}' not found in file")
if end_idx <= begin_idx:
raise ValueError(f"End anchor '{end_anchor}' found before begin anchor '{begin_anchor}'")
raise ValueError(f"End anchor '{end_anchor}' @ {end_idx=} found before begin anchor '{begin_anchor} @ {begin_idx=}'")
# Build new lines
new_lines = lines[:begin_idx+1]
@@ -198,10 +198,7 @@ class CodeFiller:
# Check if file exists
if not file_path.exists():
print(f" Warning: Target file does not exist, creating new file")
file_path.parent.mkdir(parents=True, exist_ok=True)
with open(file_path, 'w', encoding='utf-8') as f:
f.write('')
raise FileNotFoundError(f"Target file '{file_path}' does not exist")
# Create backup
self._backup_file(file_path)