From 815b1c3cb311b7f4dfb7a2f00e0e2d62795bdc6b Mon Sep 17 00:00:00 2001 From: Jack Date: Fri, 11 Nov 2016 14:37:03 -0800 Subject: Add checks for misuse or omission of Module() Implemented by adding a Boolean to check for alternating invocations of object Module.apply and the constructor of abstract class Module. Fixes #192 --- src/test/scala/chiselTests/Module.scala | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/test/scala/chiselTests/Module.scala') diff --git a/src/test/scala/chiselTests/Module.scala b/src/test/scala/chiselTests/Module.scala index 7a4050db..c902d073 100644 --- a/src/test/scala/chiselTests/Module.scala +++ b/src/test/scala/chiselTests/Module.scala @@ -69,6 +69,22 @@ class ModuleWhen extends Module { } otherwise { io.s.out := io.s.in } } +class ModuleForgetWrapper extends Module { + val io = IO(new SimpleIO) + val inst = new PlusOne +} + +class ModuleDoubleWrap extends Module { + val io = IO(new SimpleIO) + val inst = Module(Module(new PlusOne)) +} + +class ModuleRewrap extends Module { + val io = IO(new SimpleIO) + val inst = Module(new PlusOne) + val inst2 = Module(inst) +} + class ModuleSpec extends ChiselPropSpec { property("ModuleVec should elaborate") { @@ -88,4 +104,22 @@ class ModuleSpec extends ChiselPropSpec { } ignore("ModuleWhenTester should return the correct result") { } + + property("Forgetting a Module() wrapper should result in an error") { + (the [ChiselException] thrownBy { + elaborate { new ModuleForgetWrapper } + }).getMessage should include("attempted to instantiate a Module without wrapping it") + } + + property("Double wrapping a Module should result in an error") { + (the [ChiselException] thrownBy { + elaborate { new ModuleDoubleWrap } + }).getMessage should include("Called Module() twice without instantiating a Module") + } + + property("Rewrapping an already instantiated Module should result in an error") { + (the [ChiselException] thrownBy { + elaborate { new ModuleRewrap } + }).getMessage should include("This is probably due to rewrapping a Module instance") + } } -- cgit v1.2.3