diff options
| author | Andrew Waterman | 2016-01-17 17:20:49 -0800 |
|---|---|---|
| committer | Andrew Waterman | 2016-01-23 21:14:19 -0800 |
| commit | 34a1abcd81bd3b2d7d264468345572009edfad27 (patch) | |
| tree | 0dbaa05d8142d370d4df35d6999416325e1c0c99 /src/main/scala/Chisel/Mem.scala | |
| parent | 86a6c6bcdc349f40dcc31bce1931dc7c427da674 (diff) | |
Implement first draft of new FIRRTL changes
Diffstat (limited to 'src/main/scala/Chisel/Mem.scala')
| -rw-r--r-- | src/main/scala/Chisel/Mem.scala | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/src/main/scala/Chisel/Mem.scala b/src/main/scala/Chisel/Mem.scala index c24e368c..3bbb1151 100644 --- a/src/main/scala/Chisel/Mem.scala +++ b/src/main/scala/Chisel/Mem.scala @@ -18,7 +18,7 @@ object Mem { def apply[T <: Data](size: Int, t: T): Mem[T] = { val mt = t.cloneType val mem = new Mem(mt, size) - pushCommand(DefMemory(mem, mt, size, Node(mt._parent.get.clock))) // TODO multi-clock + pushCommand(DefMemory(mem, mt, size)) // TODO multi-clock mem } } @@ -31,20 +31,24 @@ sealed abstract class MemBase[T <: Data](t: T, val length: Int) extends HasId wi */ def apply(idx: Int): T = apply(UInt(idx)) + /** Creates a read/write accessor into the memory with dynamic addressing. + * See the class documentation of the memory for more detailed information. + */ + def apply(idx: UInt): T = makePort(idx, MemPortDirection.INFER) + /** Creates a read accessor into the memory with dynamic addressing. See the * class documentation of the memory for more detailed information. */ - def apply(idx: UInt): T = - pushCommand(DefAccessor(t.cloneType, Node(this), NO_DIR, idx.ref)).id - - def read(idx: UInt): T = apply(idx) + def read(idx: UInt): T = makePort(idx, MemPortDirection.READ) /** Creates a write accessor into the memory. * * @param idx memory element index to write into * @param data new data to write */ - def write(idx: UInt, data: T): Unit = apply(idx) := data + def write(idx: UInt, data: T): Unit = { + makePort(idx, MemPortDirection.WRITE) := data + } /** Creates a masked write accessor into the memory. * @@ -56,12 +60,18 @@ sealed abstract class MemBase[T <: Data](t: T, val length: Int) extends HasId wi * @note this is only allowed if the memory's element data type is a Vec */ def write(idx: UInt, data: T, mask: Vec[Bool]) (implicit evidence: T <:< Vec[_]): Unit = { - // REVIEW TODO: error checking to detect zip length mismatch? - - val accessor = apply(idx).asInstanceOf[Vec[Data]] - for (((cond, port), datum) <- mask zip accessor zip data.asInstanceOf[Vec[Data]]) + val accessor = makePort(idx, MemPortDirection.WRITE).asInstanceOf[Vec[Data]] + val dataVec = data.asInstanceOf[Vec[Data]] + if (accessor.length != dataVec.length) + Builder.error(s"Mem write data must contain ${accessor.length} elements (found ${dataVec.length})") + if (accessor.length != mask.length) + Builder.error(s"Mem write mask must contain ${accessor.length} elements (found ${mask.length})") + for (((cond, port), datum) <- mask zip accessor zip dataVec) when (cond) { port := datum } } + + private def makePort(idx: UInt, dir: MemPortDirection): T = + pushCommand(DefMemPort(t.cloneType, Node(this), dir, idx.ref, Node(idx._parent.get.clock))).id } /** A combinational-read, sequential-write memory. @@ -87,7 +97,7 @@ object SeqMem { def apply[T <: Data](size: Int, t: T): SeqMem[T] = { val mt = t.cloneType val mem = new SeqMem(mt, size) - pushCommand(DefSeqMemory(mem, mt, size, Node(mt._parent.get.clock))) // TODO multi-clock + pushCommand(DefSeqMemory(mem, mt, size)) // TODO multi-clock mem } } |
