Skip to content

Commit

Permalink
Improve verilog import to allow comments in IO definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
cavearr committed Jan 22, 2025
1 parent 351d535 commit 2af3897
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions app/scripts/services/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1752,9 +1752,10 @@ angular.module('icestudio')
metaBlock.inouts = inouts.join(", ");
}

// Remove IO definitions from module body
const allIORegex = /\b(input|output|inout)\s+[^\n;]+;/g;
moduleBody = moduleBody.replace(allIORegex, "").trim();
// Remove IO definitions from module body, including adjacent comments
const allIORegex = /^\s*\b(input|output|inout)\b[^\n]*$/gm;

moduleBody = moduleBody.replace(allIORegex, "").trim();

let fullModuleBody = headerComments;
if (moduleHeaderComments) {
Expand All @@ -1767,8 +1768,12 @@ angular.module('icestudio')
return metaBlock;
}

function removeComments(code) {
return code.replace(/\/\/.*|\/\*[\s\S]*?\*\//g, '');
}
//-- Verilog 1995 IO definition from module body
function processSignals(regex, block) {
block=removeComments(block);
return [...block.matchAll(regex)].flatMap((match) => {
const range = match[2]?.trim() || "";
const names = match[3]
Expand All @@ -1784,6 +1789,7 @@ angular.module('icestudio')
//-- ANSI Verilog IO definition extractor from module header
function extractIO(regex, header) {
if (!header) { return []; }
header=removeComments(header);
const matches = [...header.matchAll(regex)];
return matches.map((match) => {
const range = match[2]?.trim() || "";
Expand Down

0 comments on commit 2af3897

Please sign in to comment.