diff options
| author | Chick Markley | 2019-05-13 18:08:25 -0700 |
|---|---|---|
| committer | GitHub | 2019-05-13 18:08:25 -0700 |
| commit | 89ef4d78e8f44f31df6530a6a4dee20d0ad0399f (patch) | |
| tree | fb7948f90429b41af789252751d80e347e1142dd /chiselFrontend/src/main/scala/chisel3/internal | |
| parent | df0e0b1cc4b566fc098ac3a6d34ec6d9a551d21d (diff) | |
RawModule with no reset should be able to use withClock method. (#1065)
* RawModule with no reset should be able to use withClock method.
- refactor ClockAndReset
- now has `clockOpt: Option[Clock]` and `resetOpt: Option[Reset]` constructor params
- convenience methods clock and reset tries to deref the option
- ClockAndReset.empty is factory method for (None, None)
- In Builder
- forcedClock does not check resetOpt now
- forcedReset does not check clockOpt now
- withClock no longer looks at resetOpt
- withReset no longer looks at clockOpt
- Module starts with empty ClockAndReset
* RawModule with no reset should be able to use withClock method.
Refactor again based on @ducky64 comments
- refactor away ClockAndReset, now builder just has a
- currentClock
- currentReset
- withClock, withRest, withClockAndReset just use these fields directly
* RawModule with no reset should be able to use withClock method.
- Fixed typo in withReset handler, now picks up new reset
Diffstat (limited to 'chiselFrontend/src/main/scala/chisel3/internal')
| -rw-r--r-- | chiselFrontend/src/main/scala/chisel3/internal/Builder.scala | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala b/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala index 1163171c..d825f39d 100644 --- a/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala +++ b/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala @@ -183,11 +183,13 @@ private[chisel3] class DynamicContext() { // Used to distinguish between no Module() wrapping, multiple wrappings, and rewrapping var readyForModuleConstr: Boolean = false var whenDepth: Int = 0 // Depth of when nesting - var currentClockAndReset: Option[ClockAndReset] = None + var currentClock: Option[Clock] = None + var currentReset: Option[Reset] = None val errors = new ErrorLog val namingStack = new internal.naming.NamingStack } +//scalastyle:off number.of.methods private[chisel3] object Builder { // All global mutable state must be referenced via dynamicContextVar!! private val dynamicContextVar = new DynamicVariable[Option[DynamicContext]](None) @@ -248,16 +250,22 @@ private[chisel3] object Builder { def whenDepth_=(target: Int): Unit = { dynamicContext.whenDepth = target } - def currentClockAndReset: Option[ClockAndReset] = dynamicContext.currentClockAndReset - def currentClockAndReset_=(target: Option[ClockAndReset]): Unit = { - dynamicContext.currentClockAndReset = target + def currentClock: Option[Clock] = dynamicContext.currentClock + def currentClock_=(newClock: Option[Clock]): Unit = { + dynamicContext.currentClock = newClock } - def forcedClockAndReset: ClockAndReset = currentClockAndReset match { - case Some(clockAndReset) => clockAndReset - case None => throwException("Error: No implicit clock and reset.") + + def currentReset: Option[Reset] = dynamicContext.currentReset + def currentReset_=(newReset: Option[Reset]): Unit = { + dynamicContext.currentReset = newReset } - def forcedClock: Clock = forcedClockAndReset.clock - def forcedReset: Reset = forcedClockAndReset.reset + + def forcedClock: Clock = currentClock.getOrElse( + throwException("Error: No implicit clock.") + ) + def forcedReset: Reset = currentReset.getOrElse( + throwException("Error: No implicit reset.") + ) // TODO(twigg): Ideally, binding checks and new bindings would all occur here // However, rest of frontend can't support this yet. |
