From 47c801d5d7b37b095dc886f8e2f9bf6e2046e1bb Mon Sep 17 00:00:00 2001 From: PurplePower <60787289+PurplePower@users.noreply.github.com> Date: Thu, 14 Aug 2025 21:57:07 +0800 Subject: [PATCH] updated anchors and autofiller --- lab3/src/main/scala/riscv/core/threestage/CPU.scala | 4 ++-- .../main/scala/riscv/core/threestage/Control.scala | 3 ++- misc/autoans.py | 11 ++++------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lab3/src/main/scala/riscv/core/threestage/CPU.scala b/lab3/src/main/scala/riscv/core/threestage/CPU.scala index c0753e8..d35cd69 100644 --- a/lab3/src/main/scala/riscv/core/threestage/CPU.scala +++ b/lab3/src/main/scala/riscv/core/threestage/CPU.scala @@ -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 diff --git a/lab3/src/main/scala/riscv/core/threestage/Control.scala b/lab3/src/main/scala/riscv/core/threestage/Control.scala index f14cf75..620c1c0 100644 --- a/lab3/src/main/scala/riscv/core/threestage/Control.scala +++ b/lab3/src/main/scala/riscv/core/threestage/Control.scala @@ -17,5 +17,6 @@ package riscv.core.threestage import chisel3._ class Control extends Module { - // Lab3(Flush) + // Lab3(ThreeStage) + // Lab3(ThreeStage) End } diff --git a/misc/autoans.py b/misc/autoans.py index dbc92a9..f9bae36 100644 --- a/misc/autoans.py +++ b/misc/autoans.py @@ -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)