Skip to content

Commit 4f7a54c

Browse files
committed
Pad binary, octal, and hex variable values to match the width.
1 parent 822af7a commit 4f7a54c

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

src/extension.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as vscode from 'vscode';
2-
import { globalWatchList } from './debug/watch';
32
import { CXXRTLDebugger } from './debugger';
43
import * as sidebar from './ui/sidebar';
5-
import { inputTime } from './ui/input';
4+
import { globalWatchList } from './debug/watch';
65
import { globalVariableOptions } from './debug/options';
6+
import { inputTime } from './ui/input';
77

88
export function activate(context: vscode.ExtensionContext) {
99
const rtlDebugger = new CXXRTLDebugger();

src/model/styling.ts

+19-12
Original file line numberDiff line numberDiff line change
@@ -81,29 +81,36 @@ export function variableValue(style: DisplayStyle, variable: Variable, value: bi
8181
if (radix === undefined) {
8282
radix = globalVariableOptions.get(variable.cxxrtlIdentifier).radix ?? 10;
8383
}
84+
let stringValue;
85+
switch (radix) {
86+
case 2: stringValue = value.toString(2) .padStart(variable.width / 1, '0');
87+
case 8: stringValue = value.toString(8) .padStart(variable.width / 3, '0');
88+
case 10: stringValue = value.toString(10);
89+
case 16: stringValue = value.toString(16).padStart(variable.width / 4, '0');
90+
}
8491
switch (style) {
8592
case DisplayStyle.Python:
8693
switch (radix) {
87-
case 2: return `0b${value.toString(2)}`;
88-
case 8: return `0o${value.toString(8)}`;
89-
case 10: return value.toString(10);
90-
case 16: return `0x${value.toString(16)}`;
94+
case 2: return `0b${stringValue}`;
95+
case 8: return `0o${stringValue}`;
96+
case 10: return stringValue;
97+
case 16: return `0x${stringValue}`;
9198
}
9299

93100
case DisplayStyle.Verilog:
94101
switch (radix) {
95-
case 2: return `${variable.width}'b${value.toString(2)}`;
96-
case 8: return `${variable.width}'o${value.toString(8)}`;
97-
case 10: return `${variable.width}'d${value.toString(10)}`;
98-
case 16: return `${variable.width}'h${value.toString(16)}`;
102+
case 2: return `${variable.width}'b${stringValue}`;
103+
case 8: return `${variable.width}'o${stringValue}`;
104+
case 10: return `${variable.width}'d${stringValue}`;
105+
case 16: return `${variable.width}'h${stringValue}`;
99106
}
100107

101108
case DisplayStyle.VHDL:
102109
switch (radix) {
103-
case 2: return `B"${value.toString(2)}"`;
104-
case 8: return `O"${value.toString(8)}"`;
105-
case 10: return value.toString(10);
106-
case 16: return `X"${value.toString(16)}"`;
110+
case 2: return `B"${stringValue}"`;
111+
case 8: return `O"${stringValue}"`;
112+
case 10: return stringValue;
113+
case 16: return `X"${stringValue}"`;
107114
}
108115
}
109116
}

0 commit comments

Comments
 (0)