Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7d7fe67

Browse files
committed
Implement configurable radix.
1 parentde28e8a commit7d7fe67

File tree

7 files changed

+149
-26
lines changed

7 files changed

+149
-26
lines changed

‎example/.vscode/settings.json‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,14 @@
22
"rtlDebugger.command": [
33
"${workspaceFolder}/design_sim"
44
],
5-
"rtlDebugger.watchList": []
5+
"rtlDebugger.watchList": [
6+
{
7+
"id":"data"
8+
}
9+
],
10+
"rtlDebugger.variableOptions": {
11+
"data": {
12+
"radix":16
13+
}
14+
}
615
}

‎package.json‎

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@
5959
"default":"Verilog",
6060
"markdownDescription":"Specifies the display format for variables."
6161
},
62+
"rtlDebugger.variableOptions": {
63+
"type":"object",
64+
"patternProperties": {
65+
"": {
66+
"type":"object",
67+
"properties": {
68+
"radix":"number"
69+
}
70+
}
71+
}
72+
},
6273
"rtlDebugger.watchList": {
6374
"type":"array",
6475
"items": {
@@ -117,6 +128,26 @@
117128
"title":"Step Backward",
118129
"icon":"$(debug-step-back)"
119130
},
131+
{
132+
"command":"rtlDebugger.setRadix.2",
133+
"category":"RTL Debugger",
134+
"title":"Use Radix 2"
135+
},
136+
{
137+
"command":"rtlDebugger.setRadix.8",
138+
"category":"RTL Debugger",
139+
"title":"Use Radix 8"
140+
},
141+
{
142+
"command":"rtlDebugger.setRadix.10",
143+
"category":"RTL Debugger",
144+
"title":"Use Radix 10"
145+
},
146+
{
147+
"command":"rtlDebugger.setRadix.16",
148+
"category":"RTL Debugger",
149+
"title":"Use Radix 16"
150+
},
120151
{
121152
"command":"rtlDebugger.watchVariable",
122153
"category":"RTL Debugger",
@@ -223,18 +254,46 @@
223254
}
224255
],
225256
"view/item/context": [
257+
{
258+
"submenu":"rtlDebugger.setRadix",
259+
"when":"view == rtlDebugger.sidebar && viewItem =~ /canSetRadix/"
260+
},
226261
{
227262
"command":"rtlDebugger.watchVariable",
228-
"when":"view == rtlDebugger.sidebar && viewItem ==canWatch",
263+
"when":"view == rtlDebugger.sidebar && viewItem =~ /canWatch/",
229264
"group":"inline"
230265
},
231266
{
232267
"command":"rtlDebugger.unWatchVariable",
233-
"when":"view == rtlDebugger.sidebar && viewItem ==inWatchList",
268+
"when":"view == rtlDebugger.sidebar && viewItem =~ /inWatchList/",
234269
"group":"inline"
235270
}
271+
],
272+
"rtlDebugger.setRadix": [
273+
{
274+
"command":"rtlDebugger.setRadix.2",
275+
"group":"radix@2"
276+
},
277+
{
278+
"command":"rtlDebugger.setRadix.8",
279+
"group":"radix@8"
280+
},
281+
{
282+
"command":"rtlDebugger.setRadix.10",
283+
"group":"radix@10"
284+
},
285+
{
286+
"command":"rtlDebugger.setRadix.16",
287+
"group":"radix@16"
288+
}
236289
]
237-
}
290+
},
291+
"submenus": [
292+
{
293+
"id":"rtlDebugger.setRadix",
294+
"label":"Radix"
295+
}
296+
]
238297
},
239298
"scripts": {
240299
"lint":"eslint --fix",

‎src/debug/options.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import*asvscodefrom'vscode';
2+
3+
exportinterfaceIVariableOptions{
4+
radix?:2|8|10|16
5+
}
6+
7+
exportinterfaceIVariableOptionStore{
8+
get(id:string):IVariableOptions;
9+
set(id:string,options:IVariableOptions):void;
10+
update(id:string,options:IVariableOptions):void;
11+
}
12+
13+
exportconstglobalVariableOptions:IVariableOptionStore={
14+
get(id:string):IVariableOptions{
15+
constoptionStore:{[id:string]:IVariableOptions}=
16+
vscode.workspace.getConfiguration('rtlDebugger').get('variableOptions')||{};
17+
returnoptionStore[id]||{};
18+
},
19+
20+
set(id:string,options:IVariableOptions):void{
21+
constoptionStore:{[id:string]:IVariableOptions}=
22+
vscode.workspace.getConfiguration('rtlDebugger').get('variableOptions')||{};
23+
optionStore[id]=options;
24+
vscode.workspace.getConfiguration('rtlDebugger').update('variableOptions',optionStore);
25+
},
26+
27+
update(id:string,addedOptions:IVariableOptions):void{
28+
constoptions=Object.fromEntries(Object.entries(this.get(id)));
29+
Object.assign(options,addedOptions);
30+
this.set(id,options);
31+
}
32+
};

‎src/debug/watch.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface IWatchList {
1515
onDidChange(callback:(items:IWatchItem[])=>any):vscode.Disposable;
1616
}
1717

18-
exportconstwatchList:IWatchList={
18+
exportconstglobalWatchList:IWatchList={
1919
get():IWatchItem[]{
2020
returnvscode.workspace.getConfiguration('rtlDebugger').get('watchList')||[];
2121
},
@@ -37,7 +37,7 @@ export const watchList: IWatchList = {
3737
onDidChange(callback:(items:IWatchItem[])=>any):vscode.Disposable{
3838
returnvscode.workspace.onDidChangeConfiguration((event)=>{
3939
if(event.affectsConfiguration('rtlDebugger.watchList')){
40-
callback(watchList.get());
40+
callback(globalWatchList.get());
4141
}
4242
});
4343
},

‎src/extension.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import*asvscodefrom'vscode';
2-
import{watchList}from'./debug/watch';
2+
import{globalWatchList}from'./debug/watch';
33
import{CXXRTLDebugger}from'./debugger';
44
import*assidebarfrom'./ui/sidebar';
55
import{inputTime}from'./ui/input';
6+
import{globalVariableOptions}from'./debug/options';
67

78
exportfunctionactivate(context:vscode.ExtensionContext){
89
constrtlDebugger=newCXXRTLDebugger();
@@ -50,10 +51,19 @@ export function activate(context: vscode.ExtensionContext) {
5051
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.stepForward',()=>
5152
rtlDebugger.session!.stepForward()));
5253

54+
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.setRadix.2',(treeItem)=>
55+
globalVariableOptions.update(treeItem.designation.variable.cxxrtlIdentifier,{radix:2})));
56+
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.setRadix.8',(treeItem)=>
57+
globalVariableOptions.update(treeItem.designation.variable.cxxrtlIdentifier,{radix:8})));
58+
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.setRadix.10',(treeItem)=>
59+
globalVariableOptions.update(treeItem.designation.variable.cxxrtlIdentifier,{radix:10})));
60+
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.setRadix.16',(treeItem)=>
61+
globalVariableOptions.update(treeItem.designation.variable.cxxrtlIdentifier,{radix:16})));
62+
5363
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.watchVariable',(treeItem)=>
54-
watchList.append(treeItem.getWatchItem())));
64+
globalWatchList.append(treeItem.getWatchItem())));
5565
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.unWatchVariable',(treeItem)=>
56-
watchList.remove(treeItem.metadata.index)));
66+
globalWatchList.remove(treeItem.metadata.index)));
5767

5868
// For an unknown reason, the `vscode.open` command (which does the exact same thing) ignores the options.
5969
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.openDocument',

‎src/model/styling.ts‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import*asvscodefrom'vscode';
22

33
import{MemoryVariable,ScalarVariable,Variable}from'./variable';
4+
import{globalVariableOptions}from'../debug/options';
45

56
exportenumDisplayStyle{
67
Python='Python',
@@ -65,26 +66,35 @@ export function* memoryRowIndices(variable: MemoryVariable): Generator<number> {
6566
}
6667
}
6768

68-
exportfunctionvariableValue(style:DisplayStyle,variable:Variable,value:bigint|undefined,base:2|8|10|16=10):string{
69+
exportfunctionvariableValue(style:DisplayStyle,variable:Variable,value:bigint|undefined,radix?:2|8|10|16):string{
6970
if(value===undefined){
7071
return'...';
71-
}elseif(variable.width===1){
72+
}
73+
74+
// There is a bug in CXXRTL that occasionally causes out-of-bounds bits to be set.
75+
// Ideally it should be fixed there, but for now let's work around it here, for usability.
76+
value&=(1n<<BigInt(variable.width))-1n;
77+
78+
if(variable.width===1){
7279
returnvalue.toString();
7380
}else{
81+
if(radix===undefined){
82+
radix=globalVariableOptions.get(variable.cxxrtlIdentifier).radix??10;
83+
}
7484
switch(style){
7585
caseDisplayStyle.Python:
76-
switch(base){
86+
switch(radix){
7787
case2:return`0b${value.toString(2)}`;
7888
case8:return`0o${value.toString(8)}`;
7989
case10:returnvalue.toString(10);
8090
case16:return`0x${value.toString(16)}`;
8191
}
8292

8393
caseDisplayStyle.Verilog:
84-
return`${base}'${value.toString(base)}`;
94+
return`${radix}'${value.toString(radix)}`;
8595

8696
caseDisplayStyle.VHDL:
87-
switch(base){
97+
switch(radix){
8898
case2:return`B"${value.toString(2)}"`;
8999
case8:return`O"${value.toString(8)}"`;
90100
case10:returnvalue.toString(10);

‎src/ui/sidebar.ts‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { DisplayStyle, variableDescription, variableBitIndices, memoryRowIndices
66
import{CXXRTLDebugger}from'../debugger';
77
import{Observer}from'../debug/observer';
88
import{Designation,MemoryRangeDesignation,MemoryRowDesignation,ScalarDesignation}from'../model/sample';
9-
import{IWatchItem,watchList}from'../debug/watch';
9+
import{IWatchItem,globalWatchList}from'../debug/watch';
1010
import{Session}from'../debug/session';
1111

1212
abstractclassTreeItem{
@@ -37,7 +37,7 @@ class BitTreeItem extends TreeItem {
3737
provider:TreeDataProvider,
3838
readonlydesignation:ScalarDesignation|MemoryRowDesignation,
3939
readonlybitIndex:number,
40-
readonlycontextValue?:string,
40+
readonlycontextValue:string='',
4141
){
4242
super(provider);
4343
}
@@ -81,7 +81,7 @@ class ScalarTreeItem extends TreeItem {
8181
constructor(
8282
provider:TreeDataProvider,
8383
readonlydesignation:ScalarDesignation|MemoryRowDesignation,
84-
readonlycontextValue?:string,
84+
readonlycontextValue:string='',
8585
){
8686
super(provider);
8787
}
@@ -127,7 +127,7 @@ class ArrayTreeItem extends TreeItem {
127127
constructor(
128128
provider:TreeDataProvider,
129129
readonlydesignation:MemoryRangeDesignation,
130-
readonlycontextValue?:string,
130+
readonlycontextValue:string='',
131131
){
132132
super(provider);
133133
}
@@ -197,10 +197,11 @@ class ScopeTreeItem extends TreeItem {
197197
}
198198
for(constvariableofawaitthis.scope.variables){
199199
if(variableinstanceofScalarVariable){
200-
children.push(newScalarTreeItem(this.provider,variable.designation(),'canWatch'));
200+
children.push(newScalarTreeItem(this.provider,variable.designation(),
201+
variable.width>1 ?'canWatch|canSetRadix' :'canWatch'));
201202
}
202203
if(variableinstanceofMemoryVariable){
203-
children.push(newArrayTreeItem(this.provider,variable.designation(),'canWatch'));
204+
children.push(newArrayTreeItem(this.provider,variable.designation(),'canWatch|canSetRadix'));
204205
}
205206
}
206207
returnchildren;
@@ -215,7 +216,7 @@ class WatchTreeItem extends TreeItem {
215216
}
216217

217218
overrideasyncgetTreeItem():Promise<vscode.TreeItem>{
218-
if(watchList.get().length>0){
219+
if(globalWatchList.get().length>0){
219220
returnnewvscode.TreeItem('Watch',vscode.TreeItemCollapsibleState.Expanded);
220221
}else{
221222
returnnewvscode.TreeItem('Watch (empty)');
@@ -224,7 +225,7 @@ class WatchTreeItem extends TreeItem {
224225

225226
overrideasyncgetChildren():Promise<TreeItem[]>{
226227
constchildren=[];
227-
for(const[index,watchItem]ofwatchList.get().entries()){
228+
for(const[index,watchItem]ofglobalWatchList.get().entries()){
228229
constvariable=awaitthis.provider.getVariable(watchItem.id);
229230
if(variable===null){
230231
continue;
@@ -241,10 +242,11 @@ class WatchTreeItem extends TreeItem {
241242
}
242243
lettreeItem;
243244
if(designationinstanceofMemoryRangeDesignation){
244-
treeItem=newArrayTreeItem(this.provider,designation,'inWatchList');
245+
treeItem=newArrayTreeItem(this.provider,designation,'inWatchList|canSetRadix');
245246
}elseif(designationinstanceofScalarDesignation||designationinstanceofMemoryRowDesignation){
246247
if(watchItem.bit===undefined){
247-
treeItem=newScalarTreeItem(this.provider,designation,'inWatchList');
248+
treeItem=newScalarTreeItem(this.provider,designation,
249+
designation.variable.width>1 ?'inWatchList|canSetRadix' :'inWatchList');
248250
}else{
249251
treeItem=newBitTreeItem(this.provider,designation,watchItem.bit,'inWatchList');
250252
}
@@ -269,7 +271,8 @@ export class TreeDataProvider implements vscode.TreeDataProvider<TreeItem> {
269271

270272
constructor(rtlDebugger:CXXRTLDebugger){
271273
vscode.workspace.onDidChangeConfiguration((event)=>{
272-
if(event.affectsConfiguration('rtlDebugger.displayStyle')){
274+
if(event.affectsConfiguration('rtlDebugger.displayStyle')||
275+
event.affectsConfiguration('rtlDebugger.variableOptions')){
273276
this._onDidChangeTreeData.fire(null);
274277
}
275278
});
@@ -287,7 +290,7 @@ export class TreeDataProvider implements vscode.TreeDataProvider<TreeItem> {
287290
}
288291
this._onDidChangeTreeData.fire(null);
289292
});
290-
watchList.onDidChange((_items)=>{
293+
globalWatchList.onDidChange((_items)=>{
291294
if(this.watchTreeItem!==null){
292295
this._onDidChangeTreeData.fire(this.watchTreeItem);
293296
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp