Skip to content

Commit 9e08939

Browse files
authored
Promote FlatIO to package chisel3 (#3727)
Also change to an object (from a def) so that it shows up in ScalaDoc search.
1 parent a050b8c commit 9e08939

File tree

9 files changed

+61
-47
lines changed

9 files changed

+61
-47
lines changed

core/src/main/scala/chisel3/IO.scala

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package chisel3
22

33
import chisel3.internal.requireIsChiselType // Fix ambiguous import
44
import chisel3.internal.{throwException, Builder}
5-
import chisel3.experimental.SourceInfo
5+
import chisel3.experimental.{noPrefix, SourceInfo}
66
import chisel3.properties.{Class, Property}
7+
import chisel3.reflect.DataMirror.internal.chiselTypeClone
78

89
object IO {
910

@@ -62,3 +63,55 @@ object IO {
6263
iodefClone
6364
}
6465
}
66+
67+
/** The same as [[IO]] except there is no prefix when given a [[Record]] or
68+
* [[Bundle]]. For [[Element]] ([[UInt]], etc.) or [[Vec]] types, this is
69+
* the same as [[IO]].
70+
*
71+
* @example {{{
72+
* class MyBundle extends Bundle {
73+
* val foo = Input(UInt(8.W))
74+
* val bar = Output(UInt(8.W))
75+
* }
76+
* class MyModule extends Module {
77+
* val io = FlatIO(new MyBundle)
78+
* // input [7:0] foo,
79+
* // output [7:0] bar
80+
* }
81+
* }}}
82+
*/
83+
object FlatIO {
84+
def apply[T <: Data](gen: => T)(implicit sourceInfo: SourceInfo): T = noPrefix {
85+
import chisel3.experimental.dataview._
86+
def coerceDirection(d: Data) = {
87+
import chisel3.{SpecifiedDirection => SD}
88+
chisel3.reflect.DataMirror.specifiedDirectionOf(gen) match {
89+
case SD.Flip => Flipped(d)
90+
case SD.Input => Input(d)
91+
case SD.Output => Output(d)
92+
case _ => d
93+
}
94+
}
95+
96+
type R = T with Record
97+
gen match {
98+
case _: Element => IO(gen)
99+
case _: Vec[_] => IO(gen)
100+
case record: R =>
101+
val ports: Seq[Data] =
102+
record._elements.toSeq.reverse.map {
103+
case (name, data) =>
104+
val p = chisel3.IO(coerceDirection(chiselTypeClone(data).asInstanceOf[Data]))
105+
p.suggestName(name)
106+
p
107+
108+
}
109+
110+
implicit val dv: DataView[Seq[Data], R] = DataView.mapping(
111+
_ => chiselTypeClone(gen).asInstanceOf[R],
112+
(seq, rec) => seq.zip(rec._elements.toSeq.reverse).map { case (port, (_, field)) => port -> field }
113+
)
114+
ports.viewAs[R]
115+
}
116+
}
117+
}

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

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -81,43 +81,8 @@ package object experimental {
8181
type Direction = ActualDirection
8282
val Direction = ActualDirection
8383

84-
/** The same as [[IO]] except there is no prefix when given a [[Record]] or
85-
* [[Bundle]]. For [[Element]] ([[UInt]], etc.) or [[Vec]] types, this is
86-
* the same as [[IO]].
87-
*/
88-
def FlatIO[T <: Data](gen: => T)(implicit sourceInfo: SourceInfo): T = noPrefix {
89-
import dataview._
90-
def coerceDirection(d: Data) = {
91-
import chisel3.{SpecifiedDirection => SD}
92-
chisel3.reflect.DataMirror.specifiedDirectionOf(gen) match {
93-
case SD.Flip => Flipped(d)
94-
case SD.Input => Input(d)
95-
case SD.Output => Output(d)
96-
case _ => d
97-
}
98-
}
99-
100-
type R = T with Record
101-
gen match {
102-
case _: Element => IO(gen)
103-
case _: Vec[_] => IO(gen)
104-
case record: R =>
105-
val ports: Seq[Data] =
106-
record._elements.toSeq.reverse.map {
107-
case (name, data) =>
108-
val p = chisel3.IO(coerceDirection(chiselTypeClone(data).asInstanceOf[Data]))
109-
p.suggestName(name)
110-
p
111-
112-
}
113-
114-
implicit val dv: DataView[Seq[Data], R] = DataView.mapping(
115-
_ => chiselTypeClone(gen).asInstanceOf[R],
116-
(seq, rec) => seq.zip(rec._elements.toSeq.reverse).map { case (port, (_, field)) => port -> field }
117-
)
118-
ports.viewAs[R]
119-
}
120-
}
84+
@deprecated("FlatIO has moved to package chisel3", "Chisel 6.0")
85+
val FlatIO = chisel3.FlatIO
12186

12287
class dump extends chisel3.internal.naming.dump
12388
class treedump extends chisel3.internal.naming.treedump

docs/src/cookbooks/cookbook.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,6 @@ normal `val` prefix, you can use `FlatIO`:
727727

728728
```scala mdoc:silent:reset
729729
import chisel3._
730-
import chisel3.experimental.FlatIO
731730

732731
class MyBundle extends Bundle {
733732
val foo = Input(UInt(8.W))

src/main/scala/chisel3/FixedIOModule.scala

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

33
package chisel3
44

5-
import chisel3.experimental.{BaseModule, ExtModule, FlatIO, Param}
5+
import chisel3.experimental.{BaseModule, ExtModule, Param}
66

77
/** A module or external module whose IO is generated from a specific generator.
88
* This module may have no additional IO created other than what is specified

src/main/scala/chisel3/interface/Interface.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
package chisel3.interface
33

44
import chisel3.{BlackBox => _, Module => _, _}
5-
import chisel3.experimental.{BaseModule, FlatIO}
5+
import chisel3.experimental.BaseModule
66
import chisel3.experimental.dataview._
77
import chisel3.probe.define
88
import chisel3.reflect.DataMirror

src/main/scala/chisel3/util/circt/PlusArgsValue.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package chisel3.util.circt
55
import scala.language.reflectiveCalls
66

77
import chisel3._
8-
import chisel3.experimental.{FlatIO, IntrinsicModule}
8+
import chisel3.experimental.IntrinsicModule
99
import chisel3.internal.Builder
1010

1111
import circt.Intrinsic

src/test/scala/chiselTests/ExtModule.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
package chiselTests
44

55
import chisel3._
6-
import chisel3.experimental._
6+
import chisel3.experimental.ExtModule
77
import circt.stage.ChiselStage
88
import chisel3.testers.{BasicTester, TesterDriver}
99
import chisel3.reflect.DataMirror
@@ -12,8 +12,6 @@ import chisel3.reflect.DataMirror
1212
// in their own scope.
1313
package extmoduletests {
1414

15-
import chisel3.experimental.ExtModule
16-
1715
class BlackBoxInverter extends ExtModule {
1816
val in = IO(Input(Bool()))
1917
val out = IO(Output(Bool()))

src/test/scala/chiselTests/experimental/FlatIOSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package chiselTests.experimental
55
import chisel3._
66
import chisel3.util.Valid
77
import circt.stage.ChiselStage.emitCHIRRTL
8-
import chisel3.experimental.{Analog, FlatIO}
8+
import chisel3.experimental.Analog
99
import chiselTests.ChiselFlatSpec
1010

1111
class FlatIOSpec extends ChiselFlatSpec {

src/test/scala/chiselTests/properties/PropertySpec.scala

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

55
import chisel3._
6-
import chisel3.experimental.FlatIO
76
import chisel3.properties.{Class, Path, Property, PropertyType}
87
import chiselTests.{ChiselFlatSpec, MatchesAndOmits}
98
import circt.stage.ChiselStage

0 commit comments

Comments
 (0)