Skip to content

Commit

Permalink
Pad binary, octal, and hex variable values to match the width.
Browse files Browse the repository at this point in the history
  • Loading branch information
whitequark committed Oct 26, 2024
1 parent 822af7a commit 4f7a54c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as vscode from 'vscode';
import { globalWatchList } from './debug/watch';
import { CXXRTLDebugger } from './debugger';
import * as sidebar from './ui/sidebar';
import { inputTime } from './ui/input';
import { globalWatchList } from './debug/watch';
import { globalVariableOptions } from './debug/options';
import { inputTime } from './ui/input';

export function activate(context: vscode.ExtensionContext) {
const rtlDebugger = new CXXRTLDebugger();
Expand Down
31 changes: 19 additions & 12 deletions src/model/styling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,29 +81,36 @@ export function variableValue(style: DisplayStyle, variable: Variable, value: bi
if (radix === undefined) {
radix = globalVariableOptions.get(variable.cxxrtlIdentifier).radix ?? 10;
}
let stringValue;
switch (radix) {
case 2: stringValue = value.toString(2) .padStart(variable.width / 1, '0');
case 8: stringValue = value.toString(8) .padStart(variable.width / 3, '0');
case 10: stringValue = value.toString(10);
case 16: stringValue = value.toString(16).padStart(variable.width / 4, '0');
}
switch (style) {
case DisplayStyle.Python:
switch (radix) {
case 2: return `0b${value.toString(2)}`;
case 8: return `0o${value.toString(8)}`;
case 10: return value.toString(10);
case 16: return `0x${value.toString(16)}`;
case 2: return `0b${stringValue}`;
case 8: return `0o${stringValue}`;
case 10: return stringValue;
case 16: return `0x${stringValue}`;
}

case DisplayStyle.Verilog:
switch (radix) {
case 2: return `${variable.width}'b${value.toString(2)}`;
case 8: return `${variable.width}'o${value.toString(8)}`;
case 10: return `${variable.width}'d${value.toString(10)}`;
case 16: return `${variable.width}'h${value.toString(16)}`;
case 2: return `${variable.width}'b${stringValue}`;
case 8: return `${variable.width}'o${stringValue}`;
case 10: return `${variable.width}'d${stringValue}`;
case 16: return `${variable.width}'h${stringValue}`;
}

case DisplayStyle.VHDL:
switch (radix) {
case 2: return `B"${value.toString(2)}"`;
case 8: return `O"${value.toString(8)}"`;
case 10: return value.toString(10);
case 16: return `X"${value.toString(16)}"`;
case 2: return `B"${stringValue}"`;
case 8: return `O"${stringValue}"`;
case 10: return stringValue;
case 16: return `X"${stringValue}"`;
}
}
}
Expand Down

0 comments on commit 4f7a54c

Please sign in to comment.