summaryrefslogtreecommitdiff
path: root/chiselFrontend
diff options
context:
space:
mode:
authorJim Lawson2016-07-25 13:37:53 -0700
committerJim Lawson2016-07-25 13:37:53 -0700
commit3624751e2e63ba9f107c795529edfe48cf8340b2 (patch)
tree951deec27b8a75d9d9c0eec0aee6fa08f80f9ae0 /chiselFrontend
parent50518f43cbd9c783633714a26ecdb0f2f18a1142 (diff)
parent54cd58cbb435170dd2ed67dafe1cb1d769a799e8 (diff)
Merge branch 'master' into sdtwigg_connectwrap_renamechisel3
Diffstat (limited to 'chiselFrontend')
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Bits.scala3
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Data.scala1
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Module.scala32
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Reg.scala3
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/SeqUtils.scala12
5 files changed, 34 insertions, 17 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala
index 07c113fd..20ac0e4a 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala
@@ -36,6 +36,7 @@ abstract class Element(private[core] val width: Width) extends Data {
def dir: Direction = binding.direction.get
private[chisel3] final def allElements: Seq[Element] = Seq(this)
+ def widthKnown: Boolean = width.known
}
/** A data type for values represented by a single bitvector. Provides basic
@@ -521,7 +522,7 @@ private[core] sealed trait UIntFactory {
/** Create a UInt port with specified width. */
def width(width: Width): UInt = new UInt(width)
/** Create a UInt with a specified width - compatibility with Chisel2. */
- def apply(dummy: Direction, width: Int): UInt = apply(Width(width))
+ def apply(dummy: Option[Direction] = None, width: Int): UInt = apply(Width(width))
/** Create a UInt literal with fixed width. */
def apply(value: BigInt, width: Int): UInt = Lit(value, Width(width))
/** Create a UInt literal with inferred width. */
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Data.scala b/chiselFrontend/src/main/scala/chisel3/core/Data.scala
index fee5c01c..9e362fa6 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Data.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Data.scala
@@ -208,7 +208,6 @@ object Wire {
Binding.checkSynthesizable(init, s"'init' ($init)")
x := init
}
-
x
}
}
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Module.scala b/chiselFrontend/src/main/scala/chisel3/core/Module.scala
index e8474e39..a593f539 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Module.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Module.scala
@@ -2,7 +2,7 @@
package chisel3.core
-import scala.collection.mutable.{ArrayBuffer, HashSet}
+import scala.collection.mutable.ArrayBuffer
import scala.language.experimental.macros
import chisel3.internal._
@@ -136,13 +136,35 @@ extends HasId {
}
// Suggest names to nodes using runtime reflection
- val valNames = HashSet[String](getClass.getDeclaredFields.map(_.getName):_*)
+ def getValNames(c: Class[_]): Set[String] = {
+ if (c == classOf[Module]) Set()
+ else getValNames(c.getSuperclass) ++ c.getDeclaredFields.map(_.getName)
+ }
+ val valNames = getValNames(this.getClass)
def isPublicVal(m: java.lang.reflect.Method) =
m.getParameterTypes.isEmpty && valNames.contains(m.getName)
+
+ /** Recursively suggests names to supported "container" classes
+ * Arbitrary nestings of supported classes are allowed so long as the
+ * innermost element is of type HasId
+ * Currently supported:
+ * - Iterable
+ * - Option
+ * (Note that Map is Iterable[Tuple2[_,_]] and thus excluded)
+ */
+ def nameRecursively(prefix: String, nameMe: Any): Unit =
+ nameMe match {
+ case (id: HasId) => id.suggestName(prefix)
+ case Some(elt) => nameRecursively(prefix, elt)
+ case (iter: Iterable[_]) if iter.hasDefiniteSize =>
+ for ((elt, i) <- iter.zipWithIndex) {
+ nameRecursively(s"${prefix}_${i}", elt)
+ }
+ case _ => // Do nothing
+ }
val methods = getClass.getMethods.sortWith(_.getName > _.getName)
- for (m <- methods; if isPublicVal(m)) m.invoke(this) match {
- case (id: HasId) => id.suggestName(m.getName)
- case _ =>
+ for (m <- methods if isPublicVal(m)) {
+ nameRecursively(m.getName, m.invoke(this))
}
// For Module instances we haven't named, suggest the name of the Module
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Reg.scala b/chiselFrontend/src/main/scala/chisel3/core/Reg.scala
index c1693531..f5706833 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Reg.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Reg.scala
@@ -8,8 +8,7 @@ import chisel3.internal.firrtl._
import chisel3.internal.sourceinfo.{SourceInfo, UnlocatableSourceInfo}
object Reg {
- private[core] def makeType[T <: Data](t: T = null, next: T = null,
-init: T = null): T = {
+ private[core] def makeType[T <: Data](t: T = null, next: T = null, init: T = null): T = {
if (t ne null) {
Binding.checkUnbound(t, s"t ($t) must be unbound Type. Try using cloneType?")
t.chiselCloneType
diff --git a/chiselFrontend/src/main/scala/chisel3/core/SeqUtils.scala b/chiselFrontend/src/main/scala/chisel3/core/SeqUtils.scala
index b06fd7a5..f4eec422 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/SeqUtils.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/SeqUtils.scala
@@ -23,14 +23,10 @@ private[chisel3] object SeqUtils {
/** Counts the number of true Bools in a Seq */
def count(in: Seq[Bool]): UInt = macro SourceInfoTransform.inArg
- def do_count(in: Seq[Bool])(implicit sourceInfo: SourceInfo): UInt = {
- if (in.size == 0) {
- UInt.Lit(0)
- } else if (in.size == 1) {
- in.head
- } else {
- count(in.slice(0, in.size/2)) + (UInt.Lit(0) ## count(in.slice(in.size/2, in.size)))
- }
+ def do_count(in: Seq[Bool])(implicit sourceInfo: SourceInfo): UInt = in.size match {
+ case 0 => UInt.Lit(0)
+ case 1 => in.head
+ case n => count(in take n/2) +& count(in drop n/2)
}
/** Returns data value corresponding to first true predicate */