Skip to content

Commit 327aca1

Browse files
committed
[ChiselSim][svsim] Switch to shouldIncludeFile
Change both ChiselSim and svsim to no longer use the `filter` function of `LayerControl`. Migrate both to use `shouldIncludeFile` partial function. The latter is a much better API as it reserves the handling of files that are outside the domain of the filter to ChiselSim and svsim. Signed-off-by: Schuyler Eldridge <[email protected]>
1 parent 4250ac6 commit 327aca1

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

src/main/scala-2/chisel3/simulator/EphemeralSimulator.scala

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,27 @@ object EphemeralSimulator extends PeekPokeAPI {
2323
layerControl: LayerControl.Type = LayerControl.EnableAll
2424
)(body: (T) => Unit
2525
): Unit = {
26-
makeSimulator(layerControl).simulate(module, layerControl)({ module => body(module.wrapped) }).result
26+
makeSimulator().simulate(module, layerControl)({ module => body(module.wrapped) }).result
2727
}
2828

29-
private class DefaultSimulator(val workspacePath: String, layerControl: LayerControl.Type)
30-
extends SingleBackendSimulator[verilator.Backend] {
29+
private class DefaultSimulator(val workspacePath: String) extends SingleBackendSimulator[verilator.Backend] {
3130
val backend = verilator.Backend.initializeFromProcessEnvironment()
3231
val tag = "default"
33-
val commonCompilationSettings = CommonCompilationSettings(
34-
fileFilter = layerControl.filter
35-
)
32+
val commonCompilationSettings = CommonCompilationSettings()
3633
val backendSpecificCompilationSettings = verilator.Backend.CompilationSettings()
3734

3835
// Try to clean up temporary workspace if possible
3936
sys.addShutdownHook {
4037
(new Directory(new File(workspacePath))).deleteRecursively()
4138
}
4239
}
43-
private def makeSimulator(layerControl: LayerControl.Type): DefaultSimulator = {
40+
private def makeSimulator(): DefaultSimulator = {
4441
// TODO: Use ProcessHandle when we can drop Java 8 support
4542
// val id = ProcessHandle.current().pid().toString()
4643
val id = java.lang.management.ManagementFactory.getRuntimeMXBean().getName()
4744
val className = getClass().getName().stripSuffix("$")
4845
new DefaultSimulator(
49-
workspacePath = Files.createTempDirectory(s"${className}_${id}_").toString,
50-
layerControl = layerControl
46+
workspacePath = Files.createTempDirectory(s"${className}_${id}_").toString
5147
)
5248
}
5349
}

src/main/scala-2/chisel3/simulator/Simulator.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,12 @@ trait Simulator {
128128

129129
processBackends(
130130
compiler,
131-
commonCompilationSettings.copy(verilogPreprocessorDefines =
132-
commonCompilationSettings.verilogPreprocessorDefines ++ layerControl.preprocessorDefines(elaboratedModule)
131+
commonCompilationSettings.copy(
132+
verilogPreprocessorDefines =
133+
commonCompilationSettings.verilogPreprocessorDefines ++ layerControl.preprocessorDefines(
134+
elaboratedModule
135+
),
136+
fileFilter = commonCompilationSettings.fileFilter.orElse(layerControl.shouldIncludeFile(elaboratedModule))
133137
)
134138
)
135139
compiler.results.toSeq

src/test/scala/chiselTests/ChiselSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ trait ChiselRunners extends Assertions {
6363
VerilogPreprocessorDefine("STOP_COND", s"!${Workspace.testbenchModuleName}.reset")
6464
) ++ layerControl.preprocessorDefines(elaboratedModule),
6565
includeDirs = Some(Seq(workspace.primarySourcesPath)),
66-
fileFilter = layerControl.filter
66+
fileFilter = layerControl.shouldIncludeFile(elaboratedModule)
6767
)
6868
},
6969
verilator.Backend

svsim/src/main/scala/Backend.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ case class CommonCompilationSettings(
1515
libraryExtensions: Option[Seq[String]] = None,
1616
libraryPaths: Option[Seq[String]] = None,
1717
includeDirs: Option[Seq[String]] = None,
18-
fileFilter: File => Boolean = _ => true)
18+
fileFilter: PartialFunction[File, Boolean] = PartialFunction.empty)
1919
object CommonCompilationSettings {
2020
object VerilogPreprocessorDefine {
2121
def apply(name: String, value: String) = new VerilogPreprocessorDefine(name, Some(value))

svsim/src/main/scala/Workspace.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ final class Workspace(
318318
.flatMap(p => Files.walk(Paths.get(p)).iterator().asScala.toSeq)
319319
.map(_.toFile)
320320
.filter(_.isFile)
321-
.filter(commonSettings.fileFilter)
321+
.filter(commonSettings.fileFilter.orElse { case _ => true })
322322
.map { file => workingDirectory.toPath().relativize(file.toPath()).toString() }
323323

324324
val traceFileStem = (backendSpecificSettings match {

0 commit comments

Comments
 (0)