Skip to content

Commit 1a01fce

Browse files
committed
Improve output format
1 parent 56f1061 commit 1a01fce

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

python/src/mlogv32/scripts/debug.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
def main(
5656
host: str = "localhost",
5757
port: int = 5000,
58-
imitate_sail: bool = False,
58+
sail: bool = False,
5959
log_output: Path = Path("debug.log"),
6060
json_output: Path = Path("debug.json"),
6161
verbose: Annotated[bool, Option("-v", "--verbose")] = False,
@@ -85,7 +85,7 @@ def format_status(status: StatusResponse) -> str:
8585

8686
lines = [
8787
*(
88-
f"x{i}{'' if imitate_sail else f' ({REGISTER_NAMES[i]})'} <- 0x{value:08X}"
88+
f"x{i}{'' if sail else f' ({REGISTER_NAMES[i]})'} <- 0x{value:08X}"
8989
for i, value in enumerate(status.registers)
9090
),
9191
f"CSR mscratch <- 0x{status.mscratch:08X}",
@@ -100,12 +100,9 @@ def format_status(status: StatusResponse) -> str:
100100
f"state <- {state}",
101101
f"error_output: {status.error_output or '<empty>'}",
102102
"",
103-
f"{'[M]' if imitate_sail else 'pc'}:{f'0x{status.instruction or 0:#08X}' if imitate_sail else ''} 0x{status.pc or 0:08X}",
104-
*(
105-
[]
106-
if imitate_sail
107-
else [f"instruction: {status.instruction or 0:#034b}"]
108-
),
103+
f"{'[M]' if sail else 'pc'}: 0x{status.pc or 0:08X}"
104+
+ (f" (0x{status.instruction or 0:08X})" if sail else ""),
105+
*([] if sail else [f"instruction: {status.instruction or 0:#034b}"]),
109106
]
110107

111108
return "\n".join(lines)
@@ -120,7 +117,7 @@ def format_status(status: StatusResponse) -> str:
120117
result = [status]
121118

122119
prev_formatted = format_status(status)
123-
f.write(prev_formatted)
120+
f.write(prev_formatted + "\n")
124121

125122
if status.running:
126123
processor.unpause()
@@ -155,7 +152,7 @@ def format_status(status: StatusResponse) -> str:
155152
for i, (line, prev_line) in enumerate(
156153
zip(formatted.splitlines(), prev_formatted.splitlines())
157154
)
158-
if len(formatted.splitlines()) - i <= 3
155+
if len(formatted.splitlines()) - i <= (2 if sail else 3)
159156
or line != prev_line
160157
or line == ""
161158
)

0 commit comments

Comments
 (0)