summaryrefslogtreecommitdiff
path: root/chiselFrontend/src/main/scala/chisel3/core/Mem.scala
diff options
context:
space:
mode:
authorJim Lawson2017-04-25 08:44:35 -0700
committerGitHub2017-04-25 08:44:35 -0700
commit4a6396ca5ff9dfba9019552012bce459ef3c3b1e (patch)
tree940018ca04febec6f3e18b1f03700fa3f203708e /chiselFrontend/src/main/scala/chisel3/core/Mem.scala
parentd439ac0144826bb170c43ae71df9782cdd0d5749 (diff)
Remove explicit import of NotStrict - fixes #492 (#494)
* Remove explicit import of NotStrict - fixes #492 * Provide macro for MemBase.apply(). * Provide macro for MemBase.apply(). Since a macro cannot override an abstract method, provide a concrete apply method n VecLike() that we can override with a macro. * Remove concrete apply() in VecLike. Since MemBase no longer extends the trait VecLike, we do not require a concrete method to which we can apply a macro to extract the appropriate CompileOptions.
Diffstat (limited to 'chiselFrontend/src/main/scala/chisel3/core/Mem.scala')
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Mem.scala31
1 files changed, 15 insertions, 16 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Mem.scala b/chiselFrontend/src/main/scala/chisel3/core/Mem.scala
index f935e4ee..03c484b0 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Mem.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Mem.scala
@@ -7,13 +7,11 @@ import scala.language.experimental.macros
import chisel3.internal._
import chisel3.internal.Builder.pushCommand
import chisel3.internal.firrtl._
-import chisel3.internal.sourceinfo.{SourceInfo, DeprecatedSourceInfo, UnlocatableSourceInfo, MemTransform}
-// TODO: remove this once we have CompileOptions threaded through the macro system.
-import chisel3.core.ExplicitCompileOptions.NotStrict
+import chisel3.internal.sourceinfo.{SourceInfo, SourceInfoTransform, UnlocatableSourceInfo, MemTransform}
object Mem {
@deprecated("Mem argument order should be size, t; this will be removed by the official release", "chisel3")
- def apply[T <: Data](t: T, size: Int): Mem[T] = do_apply(size, t)(UnlocatableSourceInfo)
+ def apply[T <: Data](t: T, size: Int)(implicit compileOptions: CompileOptions): Mem[T] = do_apply(size, t)(UnlocatableSourceInfo, compileOptions)
/** Creates a combinational/asynchronous-read, sequential/synchronous-write [[Mem]].
*
@@ -21,7 +19,7 @@ object Mem {
* @param t data type of memory element
*/
def apply[T <: Data](size: Int, t: T): Mem[T] = macro MemTransform.apply[T]
- def do_apply[T <: Data](size: Int, t: T)(implicit sourceInfo: SourceInfo): Mem[T] = {
+ def do_apply[T <: Data](size: Int, t: T)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Mem[T] = {
val mt = t.chiselCloneType
Binding.bind(mt, NoDirectionBinder, "Error: fresh t")
// TODO(twigg): Remove need for this Binding
@@ -38,7 +36,9 @@ sealed abstract class MemBase[T <: Data](t: T, val length: Int) extends HasId {
/** Creates a read accessor into the memory with static addressing. See the
* class documentation of the memory for more detailed information.
*/
- def apply(idx: Int): T = {
+ def apply(x: Int): T = macro SourceInfoTransform.xArg
+
+ def do_apply(idx: Int)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): T = {
require(idx >= 0 && idx < length)
apply(idx.asUInt)
}
@@ -46,19 +46,19 @@ sealed abstract class MemBase[T <: Data](t: T, val length: Int) extends HasId {
/** 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(UnlocatableSourceInfo, idx, MemPortDirection.INFER)
+ def apply(idx: UInt)(implicit compileOptions: CompileOptions): T = makePort(UnlocatableSourceInfo, 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 read(idx: UInt): T = makePort(UnlocatableSourceInfo, idx, MemPortDirection.READ)
+ def read(idx: UInt)(implicit compileOptions: CompileOptions): T = makePort(UnlocatableSourceInfo, 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 = {
+ def write(idx: UInt, data: T)(implicit compileOptions: CompileOptions): Unit = {
implicit val sourceInfo = UnlocatableSourceInfo
makePort(UnlocatableSourceInfo, idx, MemPortDirection.WRITE) := data
}
@@ -72,7 +72,7 @@ sealed abstract class MemBase[T <: Data](t: T, val length: Int) extends HasId {
*
* @note this is only allowed if the memory's element data type is a Vec
*/
- def write(idx: UInt, data: T, mask: Seq[Bool]) (implicit evidence: T <:< Vec[_]): Unit = {
+ def write(idx: UInt, data: T, mask: Seq[Bool]) (implicit evidence: T <:< Vec[_], compileOptions: CompileOptions): Unit = {
implicit val sourceInfo = UnlocatableSourceInfo
val accessor = makePort(sourceInfo, idx, MemPortDirection.WRITE).asInstanceOf[Vec[Data]]
val dataVec = data.asInstanceOf[Vec[Data]]
@@ -86,9 +86,9 @@ sealed abstract class MemBase[T <: Data](t: T, val length: Int) extends HasId {
when (cond) { port := datum }
}
- private def makePort(sourceInfo: SourceInfo, idx: UInt, dir: MemPortDirection): T = {
+ private def makePort(sourceInfo: SourceInfo, idx: UInt, dir: MemPortDirection)(implicit compileOptions: CompileOptions): T = {
Binding.checkSynthesizable(idx, s"'idx' ($idx)")
- val i = Vec.truncateIndex(idx, length)(sourceInfo)
+ val i = Vec.truncateIndex(idx, length)(sourceInfo, compileOptions)
val port = pushCommand(
DefMemPort(sourceInfo,
@@ -113,7 +113,7 @@ sealed class Mem[T <: Data](t: T, length: Int) extends MemBase(t, length)
object SyncReadMem {
@deprecated("SeqMem/SyncReadMem argument order should be size, t; this will be removed by the official release", "chisel3")
- def apply[T <: Data](t: T, size: Int): SyncReadMem[T] = do_apply(size, t)(DeprecatedSourceInfo)
+ def apply[T <: Data](t: T, size: Int)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): SyncReadMem[T] = do_apply(size, t)
/** Creates a sequential/synchronous-read, sequential/synchronous-write [[SyncReadMem]].
*
@@ -122,7 +122,7 @@ object SyncReadMem {
*/
def apply[T <: Data](size: Int, t: T): SyncReadMem[T] = macro MemTransform.apply[T]
- def do_apply[T <: Data](size: Int, t: T)(implicit sourceInfo: SourceInfo): SyncReadMem[T] = {
+ def do_apply[T <: Data](size: Int, t: T)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): SyncReadMem[T] = {
val mt = t.chiselCloneType
Binding.bind(mt, NoDirectionBinder, "Error: fresh t")
// TODO(twigg): Remove need for this Binding
@@ -144,8 +144,7 @@ object SyncReadMem {
* result is undefined (unlike Vec, where the last assignment wins)
*/
sealed class SyncReadMem[T <: Data](t: T, n: Int) extends MemBase[T](t, n) {
- def read(addr: UInt, enable: Bool): T = {
- implicit val sourceInfo = UnlocatableSourceInfo
+ def read(addr: UInt, enable: Bool)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): T = {
val a = Wire(UInt())
var port: Option[T] = None
when (enable) {