diff options
| author | Chick Markley | 2016-02-08 22:32:07 -0800 |
|---|---|---|
| committer | Chick Markley | 2016-02-08 22:32:07 -0800 |
| commit | c2db03d0a752e084c1ca452ee477c88d930d0bc6 (patch) | |
| tree | 797721dd0054bd5accb1e695398e950d51c3e873 /src/main/scala | |
| parent | 271bc0c5cf17d86203347e17c2082a495cd5d530 (diff) | |
| parent | cd269f1ebb9a0626d47ecd53b133174bc3a4cd38 (diff) | |
Merge pull request #95 from ucb-bar/flipped
Add Flipped trait; fix DeqIO, this fix looks good to go
Diffstat (limited to 'src/main/scala')
| -rw-r--r-- | src/main/scala/Chisel/Data.scala | 24 | ||||
| -rw-r--r-- | src/main/scala/Chisel/util/Decoupled.scala | 3 |
2 files changed, 15 insertions, 12 deletions
diff --git a/src/main/scala/Chisel/Data.scala b/src/main/scala/Chisel/Data.scala index 0ac3ee32..2ae9ec63 100644 --- a/src/main/scala/Chisel/Data.scala +++ b/src/main/scala/Chisel/Data.scala @@ -19,6 +19,11 @@ object debug { // scalastyle:ignore object.name def apply (arg: Data): Data = arg } +/** Mixing in this trait flips the direction of an Aggregate. */ +trait Flipped extends Data { + this.overrideDirection(_.flip, !_) +} + /** This forms the root of the type system for wire data types. The data value * must be representable as some number (need not be known at Chisel compile * time) of bits, and must have methods to pack / unpack structured data to / @@ -32,17 +37,16 @@ abstract class Data(dirArg: Direction) extends HasId { private var dirVar = dirArg private[Chisel] def isFlip = isFlipVar - private def cloneWithDirection(newDir: Direction => Direction, - newFlip: Boolean => Boolean): this.type = { - val res = this.cloneType - res.isFlipVar = newFlip(res.isFlipVar) - for ((me, it) <- this.flatten zip res.flatten) - (it: Data).dirVar = newDir((me: Data).dirVar) - res + private[Chisel] def overrideDirection(newDir: Direction => Direction, + newFlip: Boolean => Boolean): this.type = { + this.isFlipVar = newFlip(this.isFlipVar) + for (field <- this.flatten) + (field: Data).dirVar = newDir((field: Data).dirVar) + this } - def asInput: this.type = cloneWithDirection(_ => INPUT, _ => true) - def asOutput: this.type = cloneWithDirection(_ => OUTPUT, _ => false) - def flip(): this.type = cloneWithDirection(_.flip, !_) + def asInput: this.type = cloneType.overrideDirection(_ => INPUT, _ => true) + def asOutput: this.type = cloneType.overrideDirection(_ => OUTPUT, _ => false) + def flip(): this.type = cloneType.overrideDirection(_.flip, !_) private[Chisel] def badConnect(that: Data): Unit = throwException(s"cannot connect ${this} and ${that}") diff --git a/src/main/scala/Chisel/util/Decoupled.scala b/src/main/scala/Chisel/util/Decoupled.scala index ca000af9..23a08d52 100644 --- a/src/main/scala/Chisel/util/Decoupled.scala +++ b/src/main/scala/Chisel/util/Decoupled.scala @@ -33,9 +33,8 @@ class EnqIO[T <: Data](gen: T) extends DecoupledIO(gen) } /** An I/O bundle for dequeuing data with valid/ready handshaking */ -class DeqIO[T <: Data](gen: T) extends DecoupledIO(gen) +class DeqIO[T <: Data](gen: T) extends DecoupledIO(gen) with Flipped { - flip() ready := Bool(false) def deq(b: Boolean = false): T = { ready := Bool(true); bits } override def cloneType: this.type = { new DeqIO(gen).asInstanceOf[this.type]; } |
