summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/Chisel/Core.scala28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/main/scala/Chisel/Core.scala b/src/main/scala/Chisel/Core.scala
index e0e2dd6a..1540513f 100644
--- a/src/main/scala/Chisel/Core.scala
+++ b/src/main/scala/Chisel/Core.scala
@@ -172,6 +172,9 @@ sealed class SeqMem[T <: Data](t: T, n: Int) extends MemBase[T](t, n) {
}
object Vec {
+ def apply[T <: Data](n: Int, gen: T): Vec[T] = new Vec(gen.cloneType, n)
+
+ @deprecated("Chisel3 vec argument order should be n, gen - this will be removed by Chisel3 official release", "now")
def apply[T <: Data](gen: T, n: Int): Vec[T] = new Vec(gen.cloneType, n)
/** Returns a new *Vec* from a sequence of *Data* nodes.
*/
@@ -763,15 +766,26 @@ class Bundle extends Aggregate(NO_DIR) {
for ((name, elt) <- namedElts) { elt.setRef(this, _namespace.name(name)) }
override def cloneType : this.type = {
+ // If the user did not provide a cloneType method, try invoking one of
+ // the following constructors, not all of which necessarily exist:
+ // - A zero-parameter constructor
+ // - A one-paramater constructor, with null as the argument
+ // - A one-parameter constructor for a nested Bundle, with the enclosing
+ // parent Module as the argument
+ val constructor = this.getClass.getConstructors.head
try {
- val constructor = this.getClass.getConstructors.head
- val res = constructor.newInstance(Seq.fill(constructor.getParameterTypes.size)(null):_*)
- res.asInstanceOf[this.type]
+ val args = Seq.fill(constructor.getParameterTypes.size)(null)
+ constructor.newInstance(args:_*).asInstanceOf[this.type]
} catch {
- case npe: java.lang.reflect.InvocationTargetException if npe.getCause.isInstanceOf[java.lang.NullPointerException] =>
- Builder.error(s"Parameterized Bundle ${this.getClass} needs cloneType method. You are probably using an anonymous Bundle object that captures external state and hence is un-cloneTypeable")
- this
- case npe: java.lang.reflect.InvocationTargetException =>
+ case e: java.lang.reflect.InvocationTargetException if e.getCause.isInstanceOf[java.lang.NullPointerException] =>
+ try {
+ constructor.newInstance(_parent.get).asInstanceOf[this.type]
+ } catch {
+ case _: java.lang.reflect.InvocationTargetException =>
+ Builder.error(s"Parameterized Bundle ${this.getClass} needs cloneType method. You are probably using an anonymous Bundle object that captures external state and hence is un-cloneTypeable")
+ this
+ }
+ case _: java.lang.reflect.InvocationTargetException =>
Builder.error(s"Parameterized Bundle ${this.getClass} needs cloneType method")
this
}