Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix - adding external modules was broken (bug introduced in #1635) #1649

Merged
merged 1 commit into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/scala/chisel3/aop/injecting/InjectingAspect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ abstract class InjectorAspect[T <: RawModule, M <: RawModule](
case m: firrtl.ir.Module if m.name == module.name =>
stmts += m.body
Nil
case other: firrtl.ir.Module =>
case other: firrtl.ir.DefModule =>
Seq(other)
}

Expand Down
32 changes: 32 additions & 0 deletions src/test/scala/chiselTests/aop/InjectionSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ object InjectionHierarchy {
})
}

class SubmoduleC extends experimental.ExtModule with util.HasExtModuleInline {
val io = IO(new Bundle {
val in = Input(Bool())
})
//scalastyle:off regex
setInline("SubmoduleC.v", s"""
|module SubmoduleC(
| input io_in
|);
|endmodule
""".stripMargin)
}

class AspectTester(results: Seq[Int]) extends BasicTester {
val values = VecInit(results.map(_.U))
val counter = RegInit(0.U(results.length.W))
Expand Down Expand Up @@ -81,6 +94,17 @@ class InjectionSpec extends ChiselFlatSpec with Utils {
}
)

val addingExternalModules = InjectingAspect(
{dut: SubmoduleManipulationTester => Seq(dut)},
{_: SubmoduleManipulationTester =>
// By creating a second SubmoduleA, the module names would conflict unless they were uniquified
val moduleSubmoduleC = Module(new SubmoduleC)
//if we're here then we've elaborated correctly
stop()
}
)


"Test" should "pass if inserted the correct values" in {
assertTesterPasses{ new AspectTester(Seq(0, 1, 2)) }
}
Expand Down Expand Up @@ -110,4 +134,12 @@ class InjectionSpec extends ChiselFlatSpec with Utils {
Seq(duplicateSubmoduleAspect) ++ TesterDriver.verilatorOnly
)
}

"Adding external modules" should "work" in {
assertTesterPasses(
{ new SubmoduleManipulationTester},
Nil,
Seq(addingExternalModules) ++ TesterDriver.verilatorOnly
)
}
}