summaryrefslogtreecommitdiff
path: root/chiselFrontend/src/main/scala/chisel3/core/MultiClock.scala
diff options
context:
space:
mode:
Diffstat (limited to 'chiselFrontend/src/main/scala/chisel3/core/MultiClock.scala')
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/MultiClock.scala42
1 files changed, 29 insertions, 13 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/MultiClock.scala b/chiselFrontend/src/main/scala/chisel3/core/MultiClock.scala
index 6af4da41..aaa03d78 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/MultiClock.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/MultiClock.scala
@@ -2,14 +2,9 @@
package chisel3.core
-import scala.language.experimental.macros
-
import chisel3.internal._
-import chisel3.internal.Builder.pushCommand
-import chisel3.internal.firrtl._
-import chisel3.internal.sourceinfo.{SourceInfo}
-private[chisel3] final case class ClockAndReset(clock: Clock, reset: Reset)
+import scala.language.experimental.macros
object withClockAndReset { // scalastyle:ignore object.name
/** Creates a new Clock and Reset scope
@@ -21,11 +16,17 @@ object withClockAndReset { // scalastyle:ignore object.name
*/
def apply[T](clock: Clock, reset: Reset)(block: => T): T = {
// Save parentScope
- val parentScope = Builder.currentClockAndReset
- Builder.currentClockAndReset = Some(ClockAndReset(clock, reset))
+ val parentClock = Builder.currentClock
+ val parentReset = Builder.currentReset
+
+ Builder.currentClock = Some(clock)
+ Builder.currentReset = Some(reset)
+
val res = block // execute block
+
// Return to old scope
- Builder.currentClockAndReset = parentScope
+ Builder.currentClock = parentClock
+ Builder.currentReset = parentReset
res
}
}
@@ -37,8 +38,15 @@ object withClock { // scalastyle:ignore object.name
* @param block the block of code to run with new implicit Clock
* @return the result of the block
*/
- def apply[T](clock: Clock)(block: => T): T =
- withClockAndReset(clock, Module.reset)(block)
+ def apply[T](clock: Clock)(block: => T): T = {
+ // Save parentScope
+ val parentClock = Builder.currentClock
+ Builder.currentClock = Some(clock)
+ val res = block // execute block
+ // Return to old scope
+ Builder.currentClock = parentClock
+ res
+ }
}
object withReset { // scalastyle:ignore object.name
@@ -48,7 +56,15 @@ object withReset { // scalastyle:ignore object.name
* @param block the block of code to run with new implicit Reset
* @return the result of the block
*/
- def apply[T](reset: Reset)(block: => T): T =
- withClockAndReset(Module.clock, reset)(block)
+ def apply[T](reset: Reset)(block: => T): T = {
+ // Save parentScope
+ val parentReset = Builder.currentReset
+ Builder.currentReset = Some(reset)
+ val res = block // execute block
+ // Return to old scope
+ Builder.currentReset = parentReset
+ res
+ }
+
}