Skip to content

Commit

Permalink
suppress nvc shared variable warning within Scala execution
Browse files Browse the repository at this point in the history
  • Loading branch information
soronpo committed Oct 1, 2024
1 parent ce986f3 commit ec6c16b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
28 changes: 27 additions & 1 deletion lib/src/main/scala/dfhdl/tools/toolsCore/NVC.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import dfhdl.compiler.analysis.*
import java.nio.file.Paths
import java.io.FileWriter
import java.io.File.separatorChar
import scala.sys.process.*
import scala.collection.mutable

object NVC extends VHDLLinter:
val toolName: String = "NVC"
Expand Down Expand Up @@ -57,9 +59,33 @@ object NVC extends VHDLLinter:
throw new java.lang.IllegalArgumentException(
"Current backend is not supported for NVC linting."
)
// A mutable buffer to accumulate warning lines
val warningBuffer = mutable.ListBuffer[String]()
var insideWarning = false

// Create a process logger to suppress the shared variable warning
val warningSuppressLogger = ProcessLogger(
(out: String) => println(out), // stdout - print directly
(err: String) =>
if (err.startsWith("** Warning: shared variable RAM must have protected type"))
// Start accumulating lines that belong to the warning
insideWarning = true
warningBuffer += err
else if (insideWarning)
// Keep accumulating warning lines until we hit the end of the warning
warningBuffer += err
if (err.trim.endsWith("^"))
// End of the warning block
insideWarning = false
warningBuffer.clear() // Clear the buffer, effectively discarding the warning
else
// If it's not part of the warning, print the stderr line normally
println(err)
)
exec(
cd,
s"--std=$std -a --relaxed ${filesCmdPart(cd)}"
s"--std=$std -a --relaxed ${filesCmdPart(cd)}",
Some(warningSuppressLogger)
)
end lint
end NVC
11 changes: 8 additions & 3 deletions lib/src/main/scala/dfhdl/tools/toolsCore/Tool.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import dfhdl.options.LinterOptions
import dfhdl.options.BuilderOptions
import dfhdl.options.OnError
import java.io.IOException
import scala.sys.process.*

trait Tool:
val toolName: String
Expand Down Expand Up @@ -55,15 +56,19 @@ trait Tool:
}
preCheckDone = true

final protected def exec[D <: Design](cd: CompiledDesign[D], cmd: String)(using
final protected def exec[D <: Design](
cd: CompiledDesign[D],
cmd: String,
logger: Option[ProcessLogger] = None
)(using
co: CompilerOptions,
to: ToolOptions
): CompiledDesign[D] =
import scala.sys.process.*
preCheck()
val pwd = new java.io.File(co.topCommitPath(cd.stagedDB))
val fullExec = s"$runExec $cmd"
val errCode = Process(fullExec, pwd).!
val process = Process(fullExec, pwd)
val errCode = logger.map(process.!).getOrElse(process.!)
if (errCode != 0)
error(s"${toolName} exited with the error code ${errCode} attempting to run:\n$fullExec")
cd
Expand Down

0 comments on commit ec6c16b

Please sign in to comment.