Skip to content

Commit 1b15196

Browse files
committed
Support for source code positions
1 parent f60a89e commit 1b15196

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
66
### Added
77

88
- Support for Yosys 0.10 cells `$adffe`, `$sdff`, `$sdffe`, `$sdffce`, `$adlatch`, `$sr`, `$dffsr`, `$dffsre`
9+
- Support for source code positions
910

1011
### Changed
1112

src/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,18 @@ function decode_json_constant(param: Yosys.JsonConstant, bits: number): string {
350350
return param;
351351
}
352352

353+
function parse_source_positions(str: string): object[] {
354+
const ret = [];
355+
for (const entry of str.split('|')) {
356+
const colonIdx = entry.lastIndexOf(':');
357+
const name = entry.slice(0, colonIdx);
358+
const pos = entry.slice(colonIdx+1);
359+
const [from, to] = pos.split('-').map(s => s.split('.').map(v => Number(v))).map(([line, column]) => ({line, column}));
360+
ret.push({name, from, to});
361+
}
362+
return ret;
363+
}
364+
353365
function yosys_to_digitaljs(data: Yosys.Output, portmaps: Portmaps, options: Options = {}): {[key: string]: Digitaljs.Module} {
354366
const out = {};
355367
for (const [name, mod] of Object.entries(data.modules)) {
@@ -518,6 +530,9 @@ function yosys_to_digitaljs_mod(name: string, mod: Yosys.Module, portmaps: Portm
518530
dev.type = 'Subcircuit';
519531
dev.celltype = cell.type;
520532
}
533+
if (typeof cell.attributes == 'object' && cell.attributes.src) {
534+
dev.source_positions = parse_source_positions(cell.attributes.src);
535+
}
521536
const dname = add_device(dev);
522537
function match_port(con: Net, nsig: Yosys.JsonConstant, sz: number) {
523538
const sig = decode_json_number(nsig);

0 commit comments

Comments
 (0)