Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add back Int forms of Mem do_apply methods #1082

Merged
merged 1 commit into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions chiselFrontend/src/main/scala/chisel3/core/Mem.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ object Mem {
pushCommand(DefMemory(sourceInfo, mem, mt, size))
mem
}

/** @group SourceInfoTransformMacro */
def do_apply[T <: Data](size: Int, t: T)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Mem[T] =
do_apply(BigInt(size), t)(sourceInfo, compileOptions)
}

sealed abstract class MemBase[T <: Data](t: T, val length: BigInt) extends HasId with NamedComponent with SourceInfoDoc {
Expand All @@ -66,6 +70,10 @@ sealed abstract class MemBase[T <: Data](t: T, val length: BigInt) extends HasId
apply(idx.asUInt)
}

/** @group SourceInfoTransformMacro */
def do_apply(idx: Int)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): T =
do_apply(BigInt(idx))(sourceInfo, compileOptions)

/** Creates a read/write accessor into the memory with dynamic addressing.
* See the class documentation of the memory for more detailed information.
*/
Expand Down Expand Up @@ -175,6 +183,10 @@ object SyncReadMem {
pushCommand(DefSeqMemory(sourceInfo, mem, mt, size))
mem
}

/** @group SourceInfoTransformMacro */
def do_apply[T <: Data](size: Int, t: T)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): SyncReadMem[T] =
do_apply(BigInt(size), t)(sourceInfo, compileOptions)
}

/** A sequential/synchronous-read, sequential/synchronous-write memory.
Expand Down
12 changes: 12 additions & 0 deletions src/test/scala/chiselTests/Mem.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,16 @@ class MemorySpec extends ChiselPropSpec {
val cmem = compile(new HugeCMemTester(size))
cmem should include (s"reg /* sparse */ [7:0] mem [0:$addrWidth'd${size-1}];")
}

property("Implicit conversions with Mem indices should work") {
"""
|import chisel3._
|import chisel3.util.ImplicitConversions._
|class MyModule extends Module {
| val io = IO(new Bundle {})
| val mem = Mem(32, UInt(8.W))
| mem(0) := 0.U
|}
|""".stripMargin should compile
}
}