diff options
| author | Andrew Waterman | 2015-07-16 17:24:18 -0700 |
|---|---|---|
| committer | Andrew Waterman | 2015-07-16 17:24:18 -0700 |
| commit | e1c38eafd0d8f1413cc26a911d3751679e33fe4b (patch) | |
| tree | 374ef744e976e3fd45a4565f2c85dde2308917cc /src | |
| parent | 9477032c1c2fcd432aca0c423dbe5330cd95a221 (diff) | |
Add read/write methods to Vec/Mem/SeqMem
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/scala/Core.scala | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/main/scala/Core.scala b/src/main/scala/Core.scala index f2f62243..5b502057 100644 --- a/src/main/scala/Core.scala +++ b/src/main/scala/Core.scala @@ -408,11 +408,15 @@ object Mem { } class Mem[T <: Data](val t: T, val n: Int) /* with VecLike[T] */ { // TODO: VECLIKE - def apply(idx: Bits): T = { + def apply(idx: UInt): T = { val x = t.cloneType pushCommand(DefAccessor(x.defd.cid, Alias(t.cid), NO_DIR, idx.ref)) x } + + def read(idx: UInt): T = apply(idx) + def write(idx: UInt, data: T): Unit = apply(idx) := data + def name = getRefForId(t.cid).name def debugName = t.mod.debugName + "." + getRefForId(t.cid).debugName } @@ -427,11 +431,15 @@ object SeqMem { } class SeqMem[T <: Data](val t: T, val n: Int) /* with VecLike[T] */ { // TODO: VECLIKE - def apply(idx: Bits): T = { + def apply(idx: UInt): T = { val x = t.cloneType pushCommand(DefAccessor(x.defd.cid, Alias(t.cid), NO_DIR, idx.ref)) x } + + def read(idx: UInt): T = apply(idx) + def write(idx: UInt, data: T): Unit = apply(idx) := data + def name = getRefForId(t.cid).name def debugName = t.mod.debugName + "." + getRefForId(t.cid).debugName } @@ -516,11 +524,14 @@ class Vec[T <: Data](val elts: Iterable[T], dirArg: Direction = NO_DIR) extends } def length: Int = self.size + + def read(idx: UInt): T = apply(idx) + def write(idx: UInt, data: T): Unit = apply(idx) := data } trait VecLike[T <: Data] extends collection.IndexedSeq[T] { - // def read(idx: UInt): T - // def write(idx: UInt, data: T): Unit + def read(idx: UInt): T + def write(idx: UInt, data: T): Unit def apply(idx: UInt): T def forall(p: T => Bool): Bool = (this map p).fold(Bool(true))(_&&_) |
