Skip to content

Commit ff0d5bc

Browse files
committed
Improve support for the synthetic scope above the top module.
1 parent 9e6e50a commit ff0d5bc

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

example/.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
],
55
"rtlDebugger.watchList": [
66
{
7-
"id": "data"
7+
"id": "top data"
88
}
99
],
1010
"rtlDebugger.variableOptions": {

example/design_sim.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int main(int argc, char **argv) {
1313
}
1414

1515
cxxrtl_design::p_top top;
16-
cxxrtl::agent<cxxrtl_design::p_top> agent(cxxrtl::spool("spool.bin"), top);
16+
cxxrtl::agent<cxxrtl_design::p_top> agent(cxxrtl::spool("spool.bin"), top, "top ");
1717

1818
std::string uri = agent.start_debugging(cxxrtl::tcp_link());
1919
fprintf(stderr, "Simulation started on %s\n", uri.c_str());

src/debug/session.ts

+17
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,23 @@ export class Session {
108108
scope: scopeName,
109109
});
110110
this.rootScopeDesc = response.scopes[scopeName];
111+
if (this.rootScopeDesc === undefined) {
112+
// This can happen if the root scope has never been defined anywhere, i.e. if it
113+
// is synthesized for the simulation, e.g. by passing `"top "` as the last argument
114+
// to the CXXRTL agent constructor.
115+
this.rootScopeDesc = {
116+
type: 'module',
117+
definition: {
118+
src: null,
119+
name: null,
120+
attributes: {}
121+
},
122+
instantiation: {
123+
src: null,
124+
attributes: {}
125+
},
126+
};
127+
}
111128
}
112129
return Scope.fromCXXRTL(
113130
scopeName,

src/ui/sidebar.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class ScopeTreeItem extends TreeItem {
161161
constructor(
162162
provider: TreeDataProvider,
163163
readonly scope: Scope,
164+
readonly hasSiblings: boolean,
164165
) {
165166
super(provider);
166167
}
@@ -183,19 +184,23 @@ class ScopeTreeItem extends TreeItem {
183184
}
184185
treeItem.command = this.scope.location.asOpenCommand();
185186
}
186-
if ((await this.scope.scopes).length > 0 || (await this.scope.variables).length > 0) {
187-
treeItem.collapsibleState = vscode.TreeItemCollapsibleState.Collapsed;
187+
const [subScopes, variables] = await Promise.all([this.scope.scopes, this.scope.variables]);
188+
if (subScopes.length > 0 || variables.length > 0) {
189+
treeItem.collapsibleState = this.hasSiblings ?
190+
vscode.TreeItemCollapsibleState.Collapsed :
191+
vscode.TreeItemCollapsibleState.Expanded;
188192
}
189193
return treeItem;
190194
}
191195
}
192196

193197
override async getChildren(): Promise<TreeItem[]> {
198+
const [subScopes, variables] = await Promise.all([this.scope.scopes, this.scope.variables]);
194199
const children = [];
195-
for (const scope of await this.scope.scopes) {
196-
children.push(new ScopeTreeItem(this.provider, scope));
200+
for (const scope of subScopes) {
201+
children.push(new ScopeTreeItem(this.provider, scope, subScopes.length > 1));
197202
}
198-
for (const variable of await this.scope.variables) {
203+
for (const variable of variables) {
199204
if (variable instanceof ScalarVariable) {
200205
children.push(new ScalarTreeItem(this.provider, variable.designation(),
201206
variable.width > 1 ? 'canWatch|canSetRadix' : 'canWatch'));
@@ -281,7 +286,7 @@ export class TreeDataProvider implements vscode.TreeDataProvider<TreeItem> {
281286
if (session !== null) {
282287
this.observer = new Observer(session, 'sidebar');
283288
this.watchTreeItem = new WatchTreeItem(this);
284-
this.scopeTreeItem = new ScopeTreeItem(this, await session.getRootScope());
289+
this.scopeTreeItem = new ScopeTreeItem(this, await session.getRootScope(), false);
285290
} else {
286291
this.observer?.dispose();
287292
this.observer = null;

0 commit comments

Comments
 (0)