Skip to content

Commit 3d65cce

Browse files
authored
Move dontTouch, RawModule, and MultiIOModule out of experimental (#1162)
* Move dontTouch out of experimental package. * Move RawModule, MultiIOModule out of experimental. * Respond to comments - Move LagacyModule from experimental to internal. *NOTE*: At some point, these module definitions (especially those in separate packages) should be moved to individual files at the appropriate location in the source tree. The current organization is purely to support comparison with prior versions. * Fix up a few more imports.
1 parent cafc468 commit 3d65cce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+133
-145
lines changed

chiselFrontend/src/main/scala/chisel3/Annotation.scala

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
package chisel3.experimental
44

55
import scala.language.existentials
6-
import chisel3.internal.{Builder, InstanceId}
6+
import chisel3.internal.{Builder, InstanceId, LegacyModule}
77
import chisel3.{CompileOptions, Data}
88
import firrtl.Transform
99
import firrtl.annotations._
@@ -21,7 +21,7 @@ trait ChiselAnnotation {
2121

2222
/** Mixin for [[ChiselAnnotation]] that instantiates an associated FIRRTL Transform when this Annotation is present
2323
* during a run of
24-
* [[Driver$.execute(args:Array[String],dut:()=>chisel3\.experimental\.RawModule)* Driver.execute]].
24+
* [[Driver$.execute(args:Array[String],dut:()=>chisel3\.RawModule)* Driver.execute]].
2525
* Automatic Transform instantiation is *not* supported when the Circuit and Annotations are serialized before invoking
2626
* FIRRTL.
2727
*/
@@ -45,40 +45,6 @@ object annotate { // scalastyle:ignore object.name
4545
}
4646
}
4747

48-
/** Marks that a signal should not be removed by Chisel and Firrtl optimization passes
49-
*
50-
* @example {{{
51-
* class MyModule extends Module {
52-
* val io = IO(new Bundle {
53-
* val a = Input(UInt(32.W))
54-
* val b = Output(UInt(32.W))
55-
* })
56-
* io.b := io.a
57-
* val dead = io.a +% 1.U // normally dead would be pruned by DCE
58-
* dontTouch(dead) // Marking it as such will preserve it
59-
* }
60-
* }}}
61-
*
62-
* @note Calling this on [[Data]] creates an annotation that Chisel emits to a separate annotations
63-
* file. This file must be passed to FIRRTL independently of the `.fir` file. The execute methods
64-
* in [[chisel3.Driver]] will pass the annotations to FIRRTL automatically.
65-
*/
66-
object dontTouch { // scalastyle:ignore object.name
67-
/** Marks a signal to be preserved in Chisel and Firrtl
68-
*
69-
* @note Requires the argument to be bound to hardware
70-
* @param data The signal to be marked
71-
* @return Unmodified signal `data`
72-
*/
73-
def apply[T <: Data](data: T)(implicit compileOptions: CompileOptions): T = {
74-
if (compileOptions.checkSynthesizable) {
75-
requireIsHardware(data, "Data marked dontTouch")
76-
}
77-
annotate(new ChiselAnnotation { def toFirrtl = DontTouchAnnotation(data.toNamed) })
78-
data
79-
}
80-
}
81-
8248
/** Marks that a module to be ignored in Dedup Transform in Firrtl pass
8349
*
8450
* @example {{{
@@ -119,7 +85,7 @@ object dontTouch { // scalastyle:ignore object.name
11985
object doNotDedup { // scalastyle:ignore object.name
12086
/** Marks a module to be ignored in Dedup Transform in Firrtl
12187
*
122-
* @param data The module to be marked
88+
* @param module The module to be marked
12389
* @return Unmodified signal `module`
12490
*/
12591
def apply[T <: LegacyModule](module: T)(implicit compileOptions: CompileOptions): Unit = {

chiselFrontend/src/main/scala/chisel3/Attach.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
package chisel3.experimental
44

5+
import chisel3.RawModule
56
import chisel3.internal._
67
import chisel3.internal.Builder.pushCommand
78
import chisel3.internal.firrtl._

chiselFrontend/src/main/scala/chisel3/Module.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ package experimental {
121121
}
122122

123123
package internal {
124-
import chisel3.experimental.{BaseModule, MultiIOModule}
124+
import chisel3.experimental.BaseModule
125125

126126
object BaseModule {
127127
private[chisel3] class ClonePorts (elts: Data*)(implicit compileOptions: CompileOptions) extends Record {

chiselFrontend/src/main/scala/chisel3/ModuleAspect.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
package chisel3
44

55
import chisel3.internal.Builder
6-
import chisel3.experimental.RawModule
76

87
/** Used by Chisel Aspects to inject Chisel code into modules, after they have been elaborated.
98
* This is an internal API - don't use!

chiselFrontend/src/main/scala/chisel3/RawModule.scala

Lines changed: 54 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// See LICENSE for license details.
22

3-
package chisel3.experimental
3+
package chisel3
44

55
import scala.collection.mutable.{ArrayBuffer, HashMap}
66
import scala.collection.JavaConversions._
77
import scala.language.experimental.macros
88

9-
import chisel3._
9+
import chisel3.experimental.BaseModule
1010
import chisel3.internal._
1111
import chisel3.internal.Builder._
1212
import chisel3.internal.firrtl._
@@ -162,68 +162,71 @@ abstract class MultiIOModule(implicit moduleCompileOptions: CompileOptions)
162162
}
163163
}
164164

165-
/** Legacy Module class that restricts IOs to just io, clock, and reset, and provides a constructor
166-
* for threading through explicit clock and reset.
167-
*
168-
* While this class isn't planned to be removed anytime soon (there are benefits to restricting
169-
* IO), the clock and reset constructors will be phased out. Recommendation is to wrap the module
170-
* in a withClock/withReset/withClockAndReset block, or directly hook up clock or reset IO pins.
171-
*/
172-
abstract class LegacyModule(implicit moduleCompileOptions: CompileOptions)
165+
package internal {
166+
167+
/** Legacy Module class that restricts IOs to just io, clock, and reset, and provides a constructor
168+
* for threading through explicit clock and reset.
169+
*
170+
* While this class isn't planned to be removed anytime soon (there are benefits to restricting
171+
* IO), the clock and reset constructors will be phased out. Recommendation is to wrap the module
172+
* in a withClock/withReset/withClockAndReset block, or directly hook up clock or reset IO pins.
173+
*/
174+
abstract class LegacyModule(implicit moduleCompileOptions: CompileOptions)
173175
extends MultiIOModule {
174-
// These are to be phased out
175-
protected var override_clock: Option[Clock] = None
176-
protected var override_reset: Option[Bool] = None
176+
// These are to be phased out
177+
protected var override_clock: Option[Clock] = None
178+
protected var override_reset: Option[Bool] = None
177179

178-
// IO for this Module. At the Scala level (pre-FIRRTL transformations),
179-
// connections in and out of a Module may only go through `io` elements.
180-
def io: Record
180+
// IO for this Module. At the Scala level (pre-FIRRTL transformations),
181+
// connections in and out of a Module may only go through `io` elements.
182+
def io: Record
181183

182-
// Allow access to bindings from the compatibility package
183-
protected def _compatIoPortBound() = portsContains(io)// scalastyle:ignore method.name
184+
// Allow access to bindings from the compatibility package
185+
protected def _compatIoPortBound() = portsContains(io)// scalastyle:ignore method.name
184186

185-
protected override def nameIds(rootClass: Class[_]): HashMap[HasId, String] = {
186-
val names = super.nameIds(rootClass)
187+
protected override def nameIds(rootClass: Class[_]): HashMap[HasId, String] = {
188+
val names = super.nameIds(rootClass)
187189

188-
// Allow IO naming without reflection
189-
names.put(io, "io")
190-
names.put(clock, "clock")
191-
names.put(reset, "reset")
190+
// Allow IO naming without reflection
191+
names.put(io, "io")
192+
names.put(clock, "clock")
193+
names.put(reset, "reset")
192194

193-
names
194-
}
195+
names
196+
}
195197

196-
private[chisel3] override def namePorts(names: HashMap[HasId, String]): Unit = {
197-
for (port <- getModulePorts) {
198-
// This should already have been caught
199-
if (!names.contains(port)) throwException(s"Unable to name port $port in $this")
200-
val name = names(port)
201-
port.setRef(ModuleIO(this, _namespace.name(name)))
198+
private[chisel3] override def namePorts(names: HashMap[HasId, String]): Unit = {
199+
for (port <- getModulePorts) {
200+
// This should already have been caught
201+
if (!names.contains(port)) throwException(s"Unable to name port $port in $this")
202+
val name = names(port)
203+
port.setRef(ModuleIO(this, _namespace.name(name)))
204+
}
202205
}
203-
}
204206

205-
private[chisel3] override def generateComponent(): Component = {
206-
_compatAutoWrapPorts() // pre-IO(...) compatibility hack
207+
private[chisel3] override def generateComponent(): Component = {
208+
_compatAutoWrapPorts() // pre-IO(...) compatibility hack
207209

208-
// Restrict IO to just io, clock, and reset
209-
require(io != null, "Module must have io")
210-
require(portsContains(io), "Module must have io wrapped in IO(...)")
211-
require((portsContains(clock)) && (portsContains(reset)), "Internal error, module did not have clock or reset as IO") // scalastyle:ignore line.size.limit
212-
require(portsSize == 3, "Module must only have io, clock, and reset as IO")
210+
// Restrict IO to just io, clock, and reset
211+
require(io != null, "Module must have io")
212+
require(portsContains(io), "Module must have io wrapped in IO(...)")
213+
require((portsContains(clock)) && (portsContains(reset)), "Internal error, module did not have clock or reset as IO") // scalastyle:ignore line.size.limit
214+
require(portsSize == 3, "Module must only have io, clock, and reset as IO")
213215

214-
super.generateComponent()
215-
}
216+
super.generateComponent()
217+
}
216218

217-
private[chisel3] override def initializeInParent(parentCompileOptions: CompileOptions): Unit = {
218-
// Don't generate source info referencing parents inside a module, since this interferes with
219-
// module de-duplication in FIRRTL emission.
220-
implicit val sourceInfo = UnlocatableSourceInfo
219+
private[chisel3] override def initializeInParent(parentCompileOptions: CompileOptions): Unit = {
220+
// Don't generate source info referencing parents inside a module, since this interferes with
221+
// module de-duplication in FIRRTL emission.
222+
implicit val sourceInfo = UnlocatableSourceInfo
221223

222-
if (!parentCompileOptions.explicitInvalidate) {
223-
pushCommand(DefInvalid(sourceInfo, io.ref))
224-
}
224+
if (!parentCompileOptions.explicitInvalidate) {
225+
pushCommand(DefInvalid(sourceInfo, io.ref))
226+
}
225227

226-
clock := override_clock.getOrElse(Builder.forcedClock)
227-
reset := override_reset.getOrElse(Builder.forcedReset)
228+
clock := override_clock.getOrElse(Builder.forcedClock)
229+
reset := override_reset.getOrElse(Builder.forcedReset)
230+
}
228231
}
229232
}

chiselFrontend/src/main/scala/chisel3/aop/Aspect.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
package chisel3.aop
44

5-
import chisel3.experimental.RawModule
5+
import chisel3.RawModule
66
import firrtl.annotations.{Annotation, NoTargetAnnotation}
77
import firrtl.options.Unserializable
88
import firrtl.AnnotationSeq

chiselFrontend/src/main/scala/chisel3/core/package.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,17 @@ package object core {
6262

6363
// These provide temporary compatibility for those who foolishly imported from chisel3.core
6464
@deprecated("Avoid importing from chisel3.core, these are not public APIs and may change at any time. " +
65-
" Use chisel3.experimental.RawModule instead. This alias will be removed in 3.3.", "since the beginning of time")
66-
type RawModule = chisel3.experimental.RawModule
65+
" Use chisel3.RawModule instead. This alias will be removed in 3.3.", "since the beginning of time")
66+
type RawModule = chisel3.RawModule
6767
@deprecated("Avoid importing from chisel3.core, these are not public APIs and may change at any time. " +
68-
"Use chisel3.experimental.MultiIOModule instead. This alias will be removed in 3.3.", "since the beginning of time")
69-
type MultiIOModule = chisel3.experimental.MultiIOModule
68+
"Use chisel3.MultiIOModule instead. This alias will be removed in 3.3.", "since the beginning of time")
69+
type MultiIOModule = chisel3.MultiIOModule
7070
@deprecated("Avoid importing from chisel3.core, these are not public APIs and may change at any time. " +
71-
" Use chisel3.experimental.RawModule instead. This alias will be removed in 3.3.", "since the beginning of time")
72-
type UserModule = chisel3.experimental.RawModule
71+
" Use chisel3.RawModule instead. This alias will be removed in 3.3.", "since the beginning of time")
72+
type UserModule = chisel3.RawModule
7373
@deprecated("Avoid importing from chisel3.core, these are not public APIs and may change at any time. " +
74-
"Use chisel3.experimental.MultiIOModule instead. This alias will be removed in 3.3.", "since the beginning of time")
75-
type ImplicitModule = chisel3.experimental.MultiIOModule
74+
"Use chisel3.MultiIOModule instead. This alias will be removed in 3.3.", "since the beginning of time")
75+
type ImplicitModule = chisel3.MultiIOModule
7676

7777
@deprecated("Use the version in chisel3._", "3.2")
7878
val Bits = chisel3.Bits
@@ -213,8 +213,8 @@ package object core {
213213
@deprecated("Use the version in chisel3._", "3.2")
214214
val withReset = chisel3.withReset
215215

216-
@deprecated("Use the version in chisel3.experimental._", "3.2")
217-
val dontTouch = chisel3.experimental.dontTouch
216+
@deprecated("Use the version in chisel3._", "3.2")
217+
val dontTouch = chisel3.dontTouch
218218

219219
@deprecated("Use the version in chisel3.experimental._", "3.2")
220220
type BaseModule = chisel3.experimental.BaseModule
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package chisel3
2+
3+
import chisel3.experimental.{ChiselAnnotation, annotate, requireIsHardware}
4+
import firrtl.transforms.DontTouchAnnotation
5+
6+
/** Marks that a signal should not be removed by Chisel and Firrtl optimization passes
7+
*
8+
* @example {{{
9+
* class MyModule extends Module {
10+
* val io = IO(new Bundle {
11+
* val a = Input(UInt(32.W))
12+
* val b = Output(UInt(32.W))
13+
* })
14+
* io.b := io.a
15+
* val dead = io.a +% 1.U // normally dead would be pruned by DCE
16+
* dontTouch(dead) // Marking it as such will preserve it
17+
* }
18+
* }}}
19+
* @note Calling this on [[Data]] creates an annotation that Chisel emits to a separate annotations
20+
* file. This file must be passed to FIRRTL independently of the `.fir` file. The execute methods
21+
* in [[chisel3.Driver]] will pass the annotations to FIRRTL automatically.
22+
*/
23+
object dontTouch { // scalastyle:ignore object.name
24+
/** Marks a signal to be preserved in Chisel and Firrtl
25+
*
26+
* @note Requires the argument to be bound to hardware
27+
* @param data The signal to be marked
28+
* @return Unmodified signal `data`
29+
*/
30+
def apply[T <: Data](data: T)(implicit compileOptions: CompileOptions): T = {
31+
if (compileOptions.checkSynthesizable) {
32+
requireIsHardware(data, "Data marked dontTouch")
33+
}
34+
annotate(new ChiselAnnotation { def toFirrtl = DontTouchAnnotation(data.toNamed) })
35+
data
36+
}
37+
}

chiselFrontend/src/main/scala/chisel3/experimental/Analog.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package chisel3.experimental
55
import chisel3.internal.firrtl.Width
66
import chisel3.internal.sourceinfo.SourceInfo
77
import chisel3.internal._
8-
import chisel3.{ActualDirection, Bits, CompileOptions, Data, Element, PString, Printable, SpecifiedDirection, UInt}
8+
import chisel3.{ActualDirection, Bits, CompileOptions, Data, Element, PString, Printable, RawModule, SpecifiedDirection, UInt}
99

1010
import scala.collection.mutable
1111

chiselFrontend/src/main/scala/chisel3/internal/BiConnect.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
package chisel3.internal
44

55
import chisel3._
6-
import chisel3.experimental.{Analog, BaseModule, RawModule, attach}
6+
import chisel3.experimental.{Analog, BaseModule, attach}
77
import chisel3.internal.Builder.pushCommand
88
import chisel3.internal.firrtl.{Connect, DefInvalid}
99
import scala.language.experimental.macros

chiselFrontend/src/main/scala/chisel3/internal/Binding.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
package chisel3.internal
44

55
import chisel3._
6-
import chisel3.experimental.{BaseModule, RawModule}
6+
import chisel3.experimental.BaseModule
77
import chisel3.internal.firrtl.LitArg
88

99
/** Requires that a node is hardware ("bound")

chiselFrontend/src/main/scala/chisel3/internal/MonoConnect.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
package chisel3.internal
44

55
import chisel3._
6-
import chisel3.experimental.{Analog, BaseModule, EnumType, FixedPoint, RawModule, UnsafeEnum}
6+
import chisel3.experimental.{Analog, BaseModule, EnumType, FixedPoint, UnsafeEnum}
77
import chisel3.internal.Builder.pushCommand
88
import chisel3.internal.firrtl.{Connect, DefInvalid}
99
import scala.language.experimental.macros

chiselFrontend/src/main/scala/chisel3/internal/firrtl/IR.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package chisel3.internal.firrtl
55
import chisel3._
66
import chisel3.internal._
77
import chisel3.internal.sourceinfo.SourceInfo
8-
import chisel3.experimental.{BaseModule, ChiselAnnotation, Param, RawModule}
8+
import chisel3.experimental.{BaseModule, ChiselAnnotation, Param}
99

1010
// scalastyle:off number.of.types
1111

chiselFrontend/src/main/scala/chisel3/package.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ package object chisel3 { // scalastyle:ignore package.object.name
142142

143143
type InstanceId = internal.InstanceId
144144

145-
type Module = chisel3.experimental.LegacyModule
145+
type Module = chisel3.internal.LegacyModule
146146

147147
/** Implicit for custom Printable string interpolator */
148148
implicit class PrintableHelper(val sc: StringContext) extends AnyVal {

src/main/scala/chisel3/Driver.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
package chisel3
44

55
import chisel3.internal.ErrorLog
6-
import chisel3.experimental.RawModule
76
import internal.firrtl._
87
import firrtl._
98
import firrtl.options.{Phase, PhaseManager, StageError}

src/main/scala/chisel3/aop/injecting/InjectingAspect.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
package chisel3.aop.injecting
44

5-
import chisel3.{Module, ModuleAspect, experimental, withClockAndReset}
5+
import chisel3.{Module, ModuleAspect, experimental, withClockAndReset, RawModule, MultiIOModule}
66
import chisel3.aop._
7-
import chisel3.experimental.RawModule
87
import chisel3.internal.Builder
98
import chisel3.internal.firrtl.DefModule
109
import chisel3.stage.DesignAnnotation
@@ -36,7 +35,7 @@ case class InjectingAspect[T <: RawModule,
3635
RunFirrtlTransformAnnotation(new InjectingTransform) +: modules.map { module =>
3736
val (chiselIR, _) = Builder.build(Module(new ModuleAspect(module) {
3837
module match {
39-
case x: experimental.MultiIOModule => withClockAndReset(x.clock, x.reset) { injection(module) }
38+
case x: MultiIOModule => withClockAndReset(x.clock, x.reset) { injection(module) }
4039
case x: RawModule => injection(module)
4140
}
4241
}))

0 commit comments

Comments
 (0)