import { Diagnostic } from 'vscode-languageserver/node' ; import { TextDocument } from 'vscode-languageserver-textdocument' ; import * as child from 'child_process' ; import { DocumentCompiler } from './DocumentCompiler' ; import { DiagnosticData , isDiagnosticDataUndefined } from './DiagnosticData' ; /**
 * VCS Compiler class contains functionality for compiling SystemVerilog/Verilog files using VCS simulator.
 * Generates and takes in predefined runtime arguments,
 * and eventually parses the errors/warnings in `stdout` into `Diagnostic` array mapped to each unique document's uri.
 */ export class VCSCompiler extends DocumentCompiler { param _error param stdout param _stderr param compiledDocument param documentFilePath param collection returns public parseDiagnostics ( _error , stdout , _stderr , compiledDocument , documentFilePath , collection ) { if ( stdout === undefined || stdout == null || ! compiledDocument ) { return ; } const regexError = new RegExp ( `(.*)-\\[(.*)\\] (.*)"?${ documentFilePath }"?, ([0-9]+)(.*)` ) ; stdout = stdout . replace ( /\r\n/g , '\n' ) . trim ( ) ; const errors = stdout . split ( /\n\n/g ) ; const visitedDocuments = new Map < string , boolean > ( ) ; for ( let i = 0 ; i < errors . length ; i ++ ) { const error = this . formatError ( errors [ i ] ) ; const diagnosticData = new DiagnosticData ( ) ; let matches ; if ( ( matches = regexError . exec ( error ) ) ) { diagnosticData . filePath = documentFilePath ; diagnosticData . line = parseInt ( matches [ 4 ] , 10 ) - 1 ; diagnosticData . diagnosticSeverity = this . getDiagnosticSeverity ( matches [ 1 ] ) ; const problem = [ ] ; problem . push ( `[${ matches [ 2 ] . replace ( /^\W+|\W+$/g , '' ) }]: ` ) ; problem . push ( `${ matches [ 3 ] . replace ( /^\W+|\W+$/g , '' ) }. ` ) ; problem . push ( `${ matches [ 5 ] . replace ( /^\W+|\W+$/g , '' ) }.` ) ; diagnosticData . problem = problem . join ( '' ) . trim ( ) ; } if ( ! isDiagnosticDataUndefined ( diagnosticData ) ) { if ( visitedDocuments . has ( diagnosticData . filePath ) ) { this . publishDiagnosticForDocument ( compiledDocument , false , diagnosticData , collection ) ; } else { this . publishDiagnosticForDocument ( compiledDocument , true , diagnosticData , collection ) ; visitedDocuments . set ( diagnosticData . filePath , true ) ; } } } } param error returns formatError ( error ) { error = error . trim ( ) ; let regex = new RegExp ( '( +)?,( +)?\n' , 'g' ) ; error = error . replace ( regex , ', ' ) ; regex = new RegExp ( '( +)?\n( +)?' , 'g' ) ; error = error . replace ( regex , '. ' ) ; error = error . replace ( / +/g , ' ' ) ; return error . trim ( ) ; } }