summaryrefslogtreecommitdiff
path: root/chiselFrontend/src
diff options
context:
space:
mode:
Diffstat (limited to 'chiselFrontend/src')
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala30
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Assert.scala24
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/BiConnect.scala8
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Binder.scala2
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Binding.scala2
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Bits.scala46
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/BlackBox.scala28
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Data.scala38
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Mem.scala10
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Module.scala29
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/MonoConnect.scala8
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Printf.scala12
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Reg.scala13
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/SeqUtils.scala6
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/When.scala10
-rw-r--r--chiselFrontend/src/main/scala/chisel3/internal/Builder.scala54
-rw-r--r--chiselFrontend/src/main/scala/chisel3/internal/Error.scala8
-rw-r--r--chiselFrontend/src/main/scala/chisel3/internal/SourceInfo.scala4
-rw-r--r--chiselFrontend/src/main/scala/chisel3/internal/firrtl/IR.scala14
19 files changed, 189 insertions, 157 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
index 1eef5d69..a453d5e0 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
@@ -1,21 +1,21 @@
// See LICENSE for license details.
-package Chisel
+package chisel3.core
import scala.collection.immutable.ListMap
import scala.collection.mutable.{ArrayBuffer, HashSet, LinkedHashMap}
import scala.language.experimental.macros
-import internal._
-import internal.Builder.pushCommand
-import internal.firrtl._
-import internal.sourceinfo.{SourceInfo, DeprecatedSourceInfo, VecTransform, SourceInfoTransform}
+import chisel3.internal._
+import chisel3.internal.Builder.pushCommand
+import chisel3.internal.firrtl._
+import chisel3.internal.sourceinfo.{SourceInfo, DeprecatedSourceInfo, VecTransform, SourceInfoTransform}
/** An abstract class for data types that solely consist of (are an aggregate
* of) other Data objects.
*/
sealed abstract class Aggregate(dirArg: Direction) extends Data(dirArg) {
- private[Chisel] def cloneTypeWidth(width: Width): this.type = cloneType
+ private[core] def cloneTypeWidth(width: Width): this.type = cloneType
def width: Width = flatten.map(_.width).reduce(_ + _)
}
@@ -163,8 +163,8 @@ sealed class Vec[T <: Data] private (gen: => T, val length: Int)
Vec(length, gen).asInstanceOf[this.type]
private val t = gen
- private[Chisel] def toType: String = s"${t.toType}[$length]"
- private[Chisel] lazy val flatten: IndexedSeq[Bits] =
+ private[chisel3] def toType: String = s"${t.toType}[$length]"
+ private[chisel3] lazy val flatten: IndexedSeq[Bits] =
(0 until length).flatMap(i => this.apply(i).flatten)
for ((elt, i) <- self zipWithIndex)
@@ -315,7 +315,7 @@ class Bundle extends Aggregate(NO_DIR) {
/** Returns a list of elements in this Bundle.
*/
- private[Chisel] lazy val namedElts = {
+ private[core] lazy val namedElts = {
val nameMap = LinkedHashMap[String, Data]()
val seen = HashSet[Data]()
for (m <- getClass.getMethods.sortWith(_.getName < _.getName)) {
@@ -331,17 +331,17 @@ class Bundle extends Aggregate(NO_DIR) {
}
ArrayBuffer(nameMap.toSeq:_*) sortWith {case ((an, a), (bn, b)) => (a._id > b._id) || ((a eq b) && (an > bn))}
}
- private[Chisel] def toType = {
+ private[chisel3] def toType = {
def eltPort(elt: Data): String = {
val flipStr = if (elt.isFlip) "flip " else ""
s"${flipStr}${elt.getRef.name} : ${elt.toType}"
}
s"{${namedElts.reverse.map(e => eltPort(e._2)).mkString(", ")}}"
}
- private[Chisel] lazy val flatten = namedElts.flatMap(_._2.flatten)
- private[Chisel] def addElt(name: String, elt: Data): Unit =
+ private[chisel3] lazy val flatten = namedElts.flatMap(_._2.flatten)
+ private[core] def addElt(name: String, elt: Data): Unit =
namedElts += name -> elt
- private[Chisel] override def _onModuleClose: Unit = // scalastyle:ignore method.name
+ private[chisel3] override def _onModuleClose: Unit = // scalastyle:ignore method.name
for ((name, elt) <- namedElts) { elt.setRef(this, _namespace.name(name)) }
override def cloneType : this.type = {
@@ -372,6 +372,6 @@ class Bundle extends Aggregate(NO_DIR) {
}
}
-private[Chisel] object Bundle {
- val keywords = List("flip", "asInput", "asOutput", "cloneType", "toBits")
+private[core] object Bundle {
+ val keywords = List("flip", "asInput", "asOutput", "cloneType", "toBits", "newType")
}
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Assert.scala b/chiselFrontend/src/main/scala/chisel3/core/Assert.scala
index c086f014..9e792a51 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Assert.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Assert.scala
@@ -1,14 +1,14 @@
// See LICENSE for license details.
-package Chisel
+package chisel3.core
import scala.reflect.macros.blackbox.Context
import scala.language.experimental.macros
-import internal._
-import internal.Builder.pushCommand
-import internal.firrtl._
-import internal.sourceinfo.SourceInfo
+import chisel3.internal._
+import chisel3.internal.Builder.pushCommand
+import chisel3.internal.firrtl._
+import chisel3.internal.sourceinfo.SourceInfo
object assert { // scalastyle:ignore object.name
/** Checks for a condition to be valid in the circuit at all times. If the
@@ -71,3 +71,17 @@ object assert { // scalastyle:ignore object.name
Predef.assert(cond, "")
}
}
+
+object stop { // scalastyle:ignore object.name
+ /** Terminate execution with a failure code. */
+ def apply(code: Int)(implicit sourceInfo: SourceInfo): Unit = {
+ when (!Builder.forcedModule.reset) {
+ pushCommand(Stop(sourceInfo, Node(Builder.forcedModule.clock), code))
+ }
+ }
+
+ /** Terminate execution, indicating success. */
+ def apply()(implicit sourceInfo: SourceInfo): Unit = {
+ stop(0)
+ }
+}
diff --git a/chiselFrontend/src/main/scala/chisel3/core/BiConnect.scala b/chiselFrontend/src/main/scala/chisel3/core/BiConnect.scala
index 42d85bfb..cb76159a 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/BiConnect.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/BiConnect.scala
@@ -1,9 +1,9 @@
-package Chisel
+package chisel3.core
-import internal.Builder.pushCommand
-import internal.firrtl.Connect
+import chisel3.internal.Builder.pushCommand
+import chisel3.internal.firrtl.Connect
import scala.language.experimental.macros
-import internal.sourceinfo.{SourceInfo, DeprecatedSourceInfo, UnlocatableSourceInfo, WireTransform, SourceInfoTransform}
+import chisel3.internal.sourceinfo.{SourceInfo, DeprecatedSourceInfo, UnlocatableSourceInfo, WireTransform, SourceInfoTransform}
/**
* BiConnect.connect executes a bidirectional connection element-wise.
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Binder.scala b/chiselFrontend/src/main/scala/chisel3/core/Binder.scala
index ca074527..c7346dce 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Binder.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Binder.scala
@@ -1,4 +1,4 @@
-package Chisel
+package chisel3.core
/**
* A Binder is a function from UnboundBinding to some Binding.
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Binding.scala b/chiselFrontend/src/main/scala/chisel3/core/Binding.scala
index 949ac9cd..d8d9ebd2 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Binding.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Binding.scala
@@ -1,4 +1,4 @@
-package Chisel
+package chisel3.core
/**
* The purpose of a Binding is to indicate what type of hardware 'entity' a
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala
index bc8cc8e2..e6a4be71 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala
@@ -1,15 +1,15 @@
// See LICENSE for license details.
-package Chisel
+package chisel3.core
import scala.language.experimental.macros
-import internal._
-import internal.Builder.pushOp
-import internal.firrtl._
-import internal.sourceinfo.{SourceInfo, DeprecatedSourceInfo, SourceInfoTransform, SourceInfoWhiteboxTransform,
+import chisel3.internal._
+import chisel3.internal.Builder.pushOp
+import chisel3.internal.firrtl._
+import chisel3.internal.sourceinfo.{SourceInfo, DeprecatedSourceInfo, SourceInfoTransform, SourceInfoWhiteboxTransform,
UIntTransform, MuxTransform}
-import firrtl.PrimOp._
+import chisel3.internal.firrtl.PrimOp._
/** Element is a leaf data type: it cannot contain other Data objects. Example
* uses are for representing primitive data types, like integers and bits.
@@ -25,9 +25,9 @@ sealed abstract class Bits(dirArg: Direction, width: Width, override val litArg:
// Arguments for: self-checking code (can't do arithmetic on bits)
// Arguments against: generates down to a FIRRTL UInt anyways
- private[Chisel] def fromInt(x: BigInt, w: Int): this.type
+ private[chisel3] def fromInt(x: BigInt, w: Int): this.type
- private[Chisel] def flatten: IndexedSeq[Bits] = IndexedSeq(this)
+ private[chisel3] def flatten: IndexedSeq[Bits] = IndexedSeq(this)
def cloneType: this.type = cloneTypeWidth(width)
@@ -118,16 +118,16 @@ sealed abstract class Bits(dirArg: Direction, width: Width, override val litArg:
final def do_apply(x: BigInt, y: BigInt)(implicit sourceInfo: SourceInfo): UInt =
apply(x.toInt, y.toInt)
- private[Chisel] def unop[T <: Data](sourceInfo: SourceInfo, dest: T, op: PrimOp): T =
+ private[core] def unop[T <: Data](sourceInfo: SourceInfo, dest: T, op: PrimOp): T =
pushOp(DefPrim(sourceInfo, dest, op, this.ref))
- private[Chisel] def binop[T <: Data](sourceInfo: SourceInfo, dest: T, op: PrimOp, other: BigInt): T =
+ private[core] def binop[T <: Data](sourceInfo: SourceInfo, dest: T, op: PrimOp, other: BigInt): T =
pushOp(DefPrim(sourceInfo, dest, op, this.ref, ILit(other)))
- private[Chisel] def binop[T <: Data](sourceInfo: SourceInfo, dest: T, op: PrimOp, other: Bits): T =
+ private[core] def binop[T <: Data](sourceInfo: SourceInfo, dest: T, op: PrimOp, other: Bits): T =
pushOp(DefPrim(sourceInfo, dest, op, this.ref, other.ref))
- private[Chisel] def compop(sourceInfo: SourceInfo, op: PrimOp, other: Bits): Bool =
+ private[core] def compop(sourceInfo: SourceInfo, op: PrimOp, other: Bits): Bool =
pushOp(DefPrim(sourceInfo, Bool(), op, this.ref, other.ref))
- private[Chisel] def redop(sourceInfo: SourceInfo, op: PrimOp): Bool =
+ private[core] def redop(sourceInfo: SourceInfo, op: PrimOp): Bool =
pushOp(DefPrim(sourceInfo, Bool(), op, this.ref))
/** Returns this wire zero padded up to the specified width.
@@ -356,13 +356,13 @@ abstract trait Num[T <: Data] {
/** A data type for unsigned integers, represented as a binary bitvector.
* Defines arithmetic operations between other integer types.
*/
-sealed class UInt private[Chisel] (dir: Direction, width: Width, lit: Option[ULit] = None)
+sealed class UInt private[core] (dir: Direction, width: Width, lit: Option[ULit] = None)
extends Bits(dir, width, lit) with Num[UInt] {
- private[Chisel] override def cloneTypeWidth(w: Width): this.type =
+ private[core] override def cloneTypeWidth(w: Width): this.type =
new UInt(dir, w).asInstanceOf[this.type]
- private[Chisel] def toType = s"UInt$width"
+ private[core] def toType = s"UInt$width"
- override private[Chisel] def fromInt(value: BigInt, width: Int): this.type =
+ override private[chisel3] def fromInt(value: BigInt, width: Int): this.type =
UInt(value, width).asInstanceOf[this.type]
override def := (that: Data)(implicit sourceInfo: SourceInfo): Unit = that match {
@@ -482,7 +482,7 @@ sealed class UInt private[Chisel] (dir: Direction, width: Width, lit: Option[ULi
}
// This is currently a factory because both Bits and UInt inherit it.
-private[Chisel] sealed trait UIntFactory {
+private[core] sealed trait UIntFactory {
/** Create a UInt type with inferred width. */
def apply(): UInt = apply(NO_DIR, Width())
/** Create a UInt type or port with fixed width. */
@@ -535,16 +535,16 @@ object UInt extends UIntFactory
sealed class SInt private (dir: Direction, width: Width, lit: Option[SLit] = None)
extends Bits(dir, width, lit) with Num[SInt] {
- private[Chisel] override def cloneTypeWidth(w: Width): this.type =
+ private[core] override def cloneTypeWidth(w: Width): this.type =
new SInt(dir, w).asInstanceOf[this.type]
- private[Chisel] def toType = s"SInt$width"
+ private[chisel3] def toType = s"SInt$width"
override def := (that: Data)(implicit sourceInfo: SourceInfo): Unit = that match {
case _: SInt => this connect that
case _ => this badConnect that
}
- override private[Chisel] def fromInt(value: BigInt, width: Int): this.type =
+ override private[chisel3] def fromInt(value: BigInt, width: Int): this.type =
SInt(value, width).asInstanceOf[this.type]
final def unary_- (): SInt = macro SourceInfoTransform.noArg
@@ -666,12 +666,12 @@ object SInt {
/** A data type for booleans, defined as a single bit indicating true or false.
*/
sealed class Bool(dir: Direction, lit: Option[ULit] = None) extends UInt(dir, Width(1), lit) {
- private[Chisel] override def cloneTypeWidth(w: Width): this.type = {
+ private[core] override def cloneTypeWidth(w: Width): this.type = {
require(!w.known || w.get == 1)
new Bool(dir).asInstanceOf[this.type]
}
- override private[Chisel] def fromInt(value: BigInt, width: Int): this.type = {
+ override private[chisel3] def fromInt(value: BigInt, width: Int): this.type = {
require((value == 0 || value == 1) && width == 1)
Bool(value == 1).asInstanceOf[this.type]
}
diff --git a/chiselFrontend/src/main/scala/chisel3/core/BlackBox.scala b/chiselFrontend/src/main/scala/chisel3/core/BlackBox.scala
index b634f021..f2d9558d 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/BlackBox.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/BlackBox.scala
@@ -1,10 +1,10 @@
// See LICENSE for license details.
-package Chisel
+package chisel3.core
-import internal.Builder.pushCommand
-import internal.firrtl.{ModuleIO, DefInvalid}
-import internal.sourceinfo.SourceInfo
+import chisel3.internal.Builder.pushCommand
+import chisel3.internal.firrtl.{ModuleIO, DefInvalid}
+import chisel3.internal.sourceinfo.SourceInfo
/** Defines a black box, which is a module that can be referenced from within
* Chisel, but is not defined in the emitted Verilog. Useful for connecting
@@ -24,23 +24,31 @@ abstract class BlackBox extends Module {
// The body of a BlackBox is empty, the real logic happens in firrtl/Emitter.scala
// Bypass standard clock, reset, io port declaration by flattening io
// TODO(twigg): ? Really, overrides are bad, should extend BaseModule....
- override private[Chisel] def ports = io.elements.toSeq
+ override private[core] def ports = io.elements.toSeq
// Do not do reflective naming of internal signals, just name io
- override private[Chisel] def setRefs(): this.type = {
- for ((name, port) <- ports) {
- port.setRef(ModuleIO(this, _namespace.name(name)))
- }
+ override private[core] def setRefs(): this.type = {
// setRef is not called on the actual io.
// There is a risk of user improperly attempting to connect directly with io
// Long term solution will be to define BlackBox IO differently as part of
// it not descending from the (current) Module
+ for ((name, port) <- ports) {
+ port.setRef(ModuleIO(this, _namespace.name(name)))
+ }
+ // We need to call forceName and onModuleClose on all of the sub-elements
+ // of the io bundle, but NOT on the io bundle itself.
+ // Doing so would cause the wrong names to be assigned, since their parent
+ // is now the module itself instead of the io bundle.
+ for (id <- _ids; if id ne io) {
+ id.forceName(default="T", _namespace)
+ id._onModuleClose
+ }
this
}
// Don't setup clock, reset
// Cann't invalide io in one bunch, must invalidate each part separately
- override private[Chisel] def setupInParent(implicit sourceInfo: SourceInfo): this.type = _parent match {
+ override private[core] def setupInParent(implicit sourceInfo: SourceInfo): this.type = _parent match {
case Some(p) => {
// Just init instance inputs
for((_,port) <- ports) pushCommand(DefInvalid(sourceInfo, port.ref))
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Data.scala b/chiselFrontend/src/main/scala/chisel3/core/Data.scala
index d16843f7..fcdc86bb 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Data.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Data.scala
@@ -1,13 +1,13 @@
// See LICENSE for license details.
-package Chisel
+package chisel3.core
import scala.language.experimental.macros
-import internal._
-import internal.Builder.pushCommand
-import internal.firrtl._
-import internal.sourceinfo.{SourceInfo, DeprecatedSourceInfo, UnlocatableSourceInfo, WireTransform, SourceInfoTransform}
+import chisel3.internal._
+import chisel3.internal.Builder.pushCommand
+import chisel3.internal.firrtl._
+import chisel3.internal.sourceinfo.{SourceInfo, DeprecatedSourceInfo, UnlocatableSourceInfo, WireTransform, SourceInfoTransform}
sealed abstract class Direction(name: String) {
override def toString: String = name
@@ -38,9 +38,9 @@ abstract class Data(dirArg: Direction) extends HasId {
// Sucks this is mutable state, but cloneType doesn't take a Direction arg
private var isFlipVar = dirArg == INPUT
private var dirVar = dirArg
- private[Chisel] def isFlip = isFlipVar
+ private[core] def isFlip = isFlipVar
- private[Chisel] def overrideDirection(newDir: Direction => Direction,
+ private[core] def overrideDirection(newDir: Direction => Direction,
newFlip: Boolean => Boolean): this.type = {
this.isFlipVar = newFlip(this.isFlipVar)
for (field <- this.flatten)
@@ -51,16 +51,16 @@ abstract class Data(dirArg: Direction) extends HasId {
def asOutput: this.type = cloneType.overrideDirection(_ => OUTPUT, _ => false)
def flip(): this.type = cloneType.overrideDirection(_.flip, !_)
- private[Chisel] def badConnect(that: Data)(implicit sourceInfo: SourceInfo): Unit =
+ private[core] def badConnect(that: Data)(implicit sourceInfo: SourceInfo): Unit =
throwException(s"cannot connect ${this} and ${that}")
- private[Chisel] def connect(that: Data)(implicit sourceInfo: SourceInfo): Unit =
+ private[core] def connect(that: Data)(implicit sourceInfo: SourceInfo): Unit =
pushCommand(Connect(sourceInfo, this.lref, that.ref))
- private[Chisel] def bulkConnect(that: Data)(implicit sourceInfo: SourceInfo): Unit =
+ private[core] def bulkConnect(that: Data)(implicit sourceInfo: SourceInfo): Unit =
pushCommand(BulkConnect(sourceInfo, this.lref, that.lref))
- private[Chisel] def lref: Node = Node(this)
- private[Chisel] def ref: Arg = if (isLit) litArg.get else lref
- private[Chisel] def cloneTypeWidth(width: Width): this.type
- private[Chisel] def toType: String
+ private[core] def lref: Node = Node(this)
+ private[chisel3] def ref: Arg = if (isLit) litArg.get else lref
+ private[core] def cloneTypeWidth(width: Width): this.type
+ private[chisel3] def toType: String
def := (that: Data)(implicit sourceInfo: SourceInfo): Unit = this badConnect that
@@ -71,7 +71,7 @@ abstract class Data(dirArg: Direction) extends HasId {
def litValue(): BigInt = litArg.get.num
def isLit(): Boolean = litArg.isDefined
- def width: Width
+ private[core] def width: Width
final def getWidth: Int = width.get
// While this being in the Data API doesn't really make sense (should be in
@@ -83,7 +83,7 @@ abstract class Data(dirArg: Direction) extends HasId {
// currently don't exist (while this information may be available during
// FIRRTL emission, it would break directionality querying from Chisel, which
// does get used).
- private[Chisel] def flatten: IndexedSeq[Bits]
+ private[chisel3] def flatten: IndexedSeq[Bits]
/** Creates an new instance of this type, unpacking the input Bits into
* structured data.
@@ -150,9 +150,9 @@ object Clock {
// TODO: Document this.
sealed class Clock(dirArg: Direction) extends Element(dirArg, Width(1)) {
def cloneType: this.type = Clock(dirArg).asInstanceOf[this.type]
- private[Chisel] override def flatten: IndexedSeq[Bits] = IndexedSeq()
- private[Chisel] def cloneTypeWidth(width: Width): this.type = cloneType
- private[Chisel] def toType = "Clock"
+ private[chisel3] override def flatten: IndexedSeq[Bits] = IndexedSeq()
+ private[core] def cloneTypeWidth(width: Width): this.type = cloneType
+ private[chisel3] def toType = "Clock"
override def := (that: Data)(implicit sourceInfo: SourceInfo): Unit = that match {
case _: Clock => this connect that
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Mem.scala b/chiselFrontend/src/main/scala/chisel3/core/Mem.scala
index e34d5499..38f5ef14 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Mem.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Mem.scala
@@ -1,13 +1,13 @@
// See LICENSE for license details.
-package Chisel
+package chisel3.core
import scala.language.experimental.macros
-import internal._
-import internal.Builder.pushCommand
-import internal.firrtl._
-import internal.sourceinfo.{SourceInfo, DeprecatedSourceInfo, UnlocatableSourceInfo, MemTransform}
+import chisel3.internal._
+import chisel3.internal.Builder.pushCommand
+import chisel3.internal.firrtl._
+import chisel3.internal.sourceinfo.{SourceInfo, DeprecatedSourceInfo, UnlocatableSourceInfo, MemTransform}
object Mem {
@deprecated("Mem argument order should be size, t; this will be removed by the official release", "chisel3")
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Module.scala b/chiselFrontend/src/main/scala/chisel3/core/Module.scala
index e2101538..5d510112 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Module.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Module.scala
@@ -1,15 +1,16 @@
// See LICENSE for license details.
-package Chisel
+package chisel3.core
import scala.collection.mutable.{ArrayBuffer, HashSet}
import scala.language.experimental.macros
-import internal._
-import internal.Builder.pushCommand
-import internal.Builder.dynamicContext
-import internal.firrtl._
-import internal.sourceinfo.{SourceInfo, InstTransform, UnlocatableSourceInfo}
+import chisel3.internal._
+import chisel3.internal.Builder.pushCommand
+import chisel3.internal.Builder.dynamicContext
+import chisel3.internal.firrtl._
+import chisel3.internal.firrtl.{Command, Component, DefInstance, DefInvalid, ModuleIO}
+import chisel3.internal.sourceinfo.{SourceInfo, InstTransform, UnlocatableSourceInfo}
object Module {
/** A wrapper method that all Module instantiations must be wrapped in
@@ -52,9 +53,9 @@ extends HasId {
def this(_reset: Bool) = this(None, Option(_reset))
def this(_clock: Clock, _reset: Bool) = this(Option(_clock), Option(_reset))
- private[Chisel] val _namespace = Builder.globalNamespace.child
- private[Chisel] val _commands = ArrayBuffer[Command]()
- private[Chisel] val _ids = ArrayBuffer[HasId]()
+ private[core] val _namespace = Builder.globalNamespace.child
+ private[chisel3] val _commands = ArrayBuffer[Command]()
+ private[core] val _ids = ArrayBuffer[HasId]()
dynamicContext.currentModule = Some(this)
/** Name of the instance. */
@@ -67,18 +68,18 @@ extends HasId {
val clock = Clock(INPUT)
val reset = Bool(INPUT)
- private[Chisel] def addId(d: HasId) { _ids += d }
+ private[chisel3] def addId(d: HasId) { _ids += d }
- private[Chisel] def ports: Seq[(String,Data)] = Vector(
+ private[core] def ports: Seq[(String,Data)] = Vector(
("clk", clock), ("reset", reset), ("io", io)
)
- private[Chisel] def computePorts = for((name, port) <- ports) yield {
+ private[core] def computePorts = for((name, port) <- ports) yield {
val bundleDir = if (port.isFlip) INPUT else OUTPUT
Port(port, if (port.dir == NO_DIR) bundleDir else port.dir)
}
- private[Chisel] def setupInParent(implicit sourceInfo: SourceInfo): this.type = {
+ private[core] def setupInParent(implicit sourceInfo: SourceInfo): this.type = {
_parent match {
case Some(p) => {
pushCommand(DefInvalid(sourceInfo, io.ref)) // init instance inputs
@@ -90,7 +91,7 @@ extends HasId {
}
}
- private[Chisel] def setRefs(): this.type = {
+ private[core] def setRefs(): this.type = {
for ((name, port) <- ports) {
port.setRef(ModuleIO(this, _namespace.name(name)))
}
diff --git a/chiselFrontend/src/main/scala/chisel3/core/MonoConnect.scala b/chiselFrontend/src/main/scala/chisel3/core/MonoConnect.scala
index 27da965b..64c71cb2 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/MonoConnect.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/MonoConnect.scala
@@ -1,9 +1,9 @@
-package Chisel
+package chisel3.core
-import internal.Builder.pushCommand
-import internal.firrtl.Connect
+import chisel3.internal.Builder.pushCommand
+import chisel3.internal.firrtl.Connect
import scala.language.experimental.macros
-import internal.sourceinfo.{SourceInfo, DeprecatedSourceInfo, UnlocatableSourceInfo, WireTransform, SourceInfoTransform}
+import chisel3.internal.sourceinfo.{SourceInfo, DeprecatedSourceInfo, UnlocatableSourceInfo, WireTransform, SourceInfoTransform}
/**
* MonoConnect.connect executes a mono-directional connection element-wise.
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Printf.scala b/chiselFrontend/src/main/scala/chisel3/core/Printf.scala
index f068f637..b0a3c955 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Printf.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Printf.scala
@@ -1,13 +1,13 @@
// See LICENSE for license details.
-package Chisel
+package chisel3.core
import scala.language.experimental.macros
-import internal._
-import internal.Builder.pushCommand
-import internal.firrtl._
-import internal.sourceinfo.SourceInfo
+import chisel3.internal._
+import chisel3.internal.Builder.pushCommand
+import chisel3.internal.firrtl._
+import chisel3.internal.sourceinfo.SourceInfo
object printf { // scalastyle:ignore object.name
/** Prints a message in simulation.
@@ -29,7 +29,7 @@ object printf { // scalastyle:ignore object.name
}
}
- private[Chisel] def printfWithoutReset(fmt: String, data: Bits*)(implicit sourceInfo: SourceInfo) {
+ private[core] def printfWithoutReset(fmt: String, data: Bits*)(implicit sourceInfo: SourceInfo) {
val clock = Builder.dynamicContext.currentModule.get.clock
pushCommand(Printf(sourceInfo, Node(clock), fmt, data.map((d: Bits) => d.ref)))
}
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Reg.scala b/chiselFrontend/src/main/scala/chisel3/core/Reg.scala
index c8faa5c9..14ae9650 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Reg.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Reg.scala
@@ -1,14 +1,15 @@
// See LICENSE for license details.
-package Chisel
+package chisel3.core
-import internal._
-import internal.Builder.pushCommand
-import internal.firrtl._
-import internal.sourceinfo.{SourceInfo, UnlocatableSourceInfo}
+import chisel3.internal._
+import chisel3.internal.Builder.pushCommand
+import chisel3.internal.firrtl._
+import chisel3.internal.sourceinfo.{SourceInfo, UnlocatableSourceInfo}
object Reg {
- private[Chisel] 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) {
t.cloneType
} else if (next ne null) {
diff --git a/chiselFrontend/src/main/scala/chisel3/core/SeqUtils.scala b/chiselFrontend/src/main/scala/chisel3/core/SeqUtils.scala
index 9a15fd5f..91cb9e89 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/SeqUtils.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/SeqUtils.scala
@@ -1,12 +1,12 @@
// See LICENSE for license details.
-package Chisel
+package chisel3.core
import scala.language.experimental.macros
-import internal.sourceinfo.{SourceInfo, SourceInfoTransform}
+import chisel3.internal.sourceinfo.{SourceInfo, SourceInfoTransform}
-private[Chisel] object SeqUtils {
+private[chisel3] object SeqUtils {
/** Equivalent to Cat(r(n-1), ..., r(0)) */
def asUInt[T <: Bits](in: Seq[T]): UInt = macro SourceInfoTransform.inArg
diff --git a/chiselFrontend/src/main/scala/chisel3/core/When.scala b/chiselFrontend/src/main/scala/chisel3/core/When.scala
index 90b3d1a5..196e7903 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/When.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/When.scala
@@ -1,13 +1,13 @@
// See LICENSE for license details.
-package Chisel
+package chisel3.core
import scala.language.experimental.macros
-import internal._
-import internal.Builder.pushCommand
-import internal.firrtl._
-import internal.sourceinfo.{SourceInfo}
+import chisel3.internal._
+import chisel3.internal.Builder.pushCommand
+import chisel3.internal.firrtl._
+import chisel3.internal.sourceinfo.{SourceInfo}
object when { // scalastyle:ignore object.name
/** Create a `when` condition block, where whether a block of logic is
diff --git a/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala b/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala
index d0e28b7c..0e0a88cc 100644
--- a/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala
+++ b/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala
@@ -1,29 +1,35 @@
// See LICENSE for license details.
-package Chisel.internal
+package chisel3.internal
import scala.util.DynamicVariable
import scala.collection.mutable.{ArrayBuffer, HashMap}
-import Chisel._
-import Chisel.internal.firrtl._
+import chisel3._
+import core._
+import firrtl._
-private[Chisel] class Namespace(parent: Option[Namespace], keywords: Set[String]) {
- private var i = 0L
- private val names = collection.mutable.HashSet[String]()
+private[chisel3] class Namespace(parent: Option[Namespace], keywords: Set[String]) {
+ private val names = collection.mutable.HashMap[String, Long]()
+ for (keyword <- keywords)
+ names(keyword) = 1
- private def rename(n: String) = { i += 1; s"${n}_${i}" }
+ private def rename(n: String): String = {
+ val index = names.getOrElse(n, 1L)
+ val tryName = s"${n}_${index}"
+ names(n) = index + 1
+ if (this contains tryName) rename(n) else tryName
+ }
def contains(elem: String): Boolean = {
- keywords.contains(elem) || names.contains(elem) ||
- parent.map(_ contains elem).getOrElse(false)
+ names.contains(elem) || parent.map(_ contains elem).getOrElse(false)
}
def name(elem: String): String = {
if (this contains elem) {
name(rename(elem))
} else {
- names += elem
+ names(elem) = 1
elem
}
}
@@ -32,7 +38,7 @@ private[Chisel] class Namespace(parent: Option[Namespace], keywords: Set[String]
def child: Namespace = child(Set())
}
-private[Chisel] class IdGen {
+private[chisel3] class IdGen {
private var counter = -1L
def next: Long = {
counter += 1
@@ -40,12 +46,12 @@ private[Chisel] class IdGen {
}
}
-private[Chisel] trait HasId {
- private[Chisel] def _onModuleClose {} // scalastyle:ignore method.name
- private[Chisel] val _parent = Builder.dynamicContext.currentModule
+private[chisel3] trait HasId {
+ private[chisel3] def _onModuleClose {} // scalastyle:ignore method.name
+ private[chisel3] val _parent = Builder.dynamicContext.currentModule
_parent.foreach(_.addId(this))
- private[Chisel] val _id = Builder.idGen.next
+ private[chisel3] val _id = Builder.idGen.next
override def hashCode: Int = _id.toInt
override def equals(that: Any): Boolean = that match {
case x: HasId => _id == x._id
@@ -62,12 +68,12 @@ private[Chisel] trait HasId {
for(hook <- postname_hooks) { hook(name) }
this
}
- private[Chisel] def addPostnameHook(hook: String=>Unit): Unit = postname_hooks += hook
+ private[chisel3] def addPostnameHook(hook: String=>Unit): Unit = postname_hooks += hook
// Uses a namespace to convert suggestion into a true name
// Will not do any naming if the reference already assigned.
// (e.g. tried to suggest a name to part of a Bundle)
- private[Chisel] def forceName(default: =>String, namespace: Namespace): Unit =
+ private[chisel3] def forceName(default: =>String, namespace: Namespace): Unit =
if(_ref.isEmpty) {
val candidate_name = suggested_name.getOrElse(default)
val available_name = namespace.name(candidate_name)
@@ -75,14 +81,14 @@ private[Chisel] trait HasId {
}
private var _ref: Option[Arg] = None
- private[Chisel] def setRef(imm: Arg): Unit = _ref = Some(imm)
- private[Chisel] def setRef(parent: HasId, name: String): Unit = setRef(Slot(Node(parent), name))
- private[Chisel] def setRef(parent: HasId, index: Int): Unit = setRef(Index(Node(parent), ILit(index)))
- private[Chisel] def setRef(parent: HasId, index: UInt): Unit = setRef(Index(Node(parent), index.ref))
- private[Chisel] def getRef: Arg = _ref.get
+ private[chisel3] def setRef(imm: Arg): Unit = _ref = Some(imm)
+ private[chisel3] def setRef(parent: HasId, name: String): Unit = setRef(Slot(Node(parent), name))
+ private[chisel3] def setRef(parent: HasId, index: Int): Unit = setRef(Index(Node(parent), ILit(index)))
+ private[chisel3] def setRef(parent: HasId, index: UInt): Unit = setRef(Index(Node(parent), index.ref))
+ private[chisel3] def getRef: Arg = _ref.get
}
-private[Chisel] class DynamicContext {
+private[chisel3] class DynamicContext {
val idGen = new IdGen
val globalNamespace = new Namespace(None, Set())
val components = ArrayBuffer[Component]()
@@ -90,7 +96,7 @@ private[Chisel] class DynamicContext {
val errors = new ErrorLog
}
-private[Chisel] object Builder {
+private[chisel3] object Builder {
// All global mutable state must be referenced via dynamicContextVar!!
private val dynamicContextVar = new DynamicVariable[Option[DynamicContext]](None)
diff --git a/chiselFrontend/src/main/scala/chisel3/internal/Error.scala b/chiselFrontend/src/main/scala/chisel3/internal/Error.scala
index 6c4c0880..7ae0580f 100644
--- a/chiselFrontend/src/main/scala/chisel3/internal/Error.scala
+++ b/chiselFrontend/src/main/scala/chisel3/internal/Error.scala
@@ -1,20 +1,20 @@
// See LICENSE for license details.
-package Chisel.internal
+package chisel3.internal
import scala.collection.mutable.ArrayBuffer
-import Chisel._
+import chisel3.core._
class ChiselException(message: String, cause: Throwable) extends Exception(message, cause)
-private[Chisel] object throwException {
+private[chisel3] object throwException {
def apply(s: String, t: Throwable = null): Nothing =
throw new ChiselException(s, t)
}
/** Records and reports runtime errors and warnings. */
-private[Chisel] class ErrorLog {
+private[chisel3] class ErrorLog {
def hasErrors: Boolean = errors.exists(_.isFatal)
/** Log an error message */
diff --git a/chiselFrontend/src/main/scala/chisel3/internal/SourceInfo.scala b/chiselFrontend/src/main/scala/chisel3/internal/SourceInfo.scala
index 66bfc7a4..5e3bf33e 100644
--- a/chiselFrontend/src/main/scala/chisel3/internal/SourceInfo.scala
+++ b/chiselFrontend/src/main/scala/chisel3/internal/SourceInfo.scala
@@ -12,7 +12,7 @@
// writers to append source locator information at the point of a library
// function invocation.
-package Chisel.internal.sourceinfo
+package chisel3.internal.sourceinfo
import scala.language.experimental.macros
import scala.reflect.macros.blackbox.Context
@@ -42,7 +42,7 @@ object SourceInfoMacro {
def generate_source_info(c: Context): c.Tree = {
import c.universe._
val p = c.enclosingPosition
- q"_root_.Chisel.internal.sourceinfo.SourceLine(${p.source.file.name}, ${p.line}, ${p.column})"
+ q"_root_.chisel3.internal.sourceinfo.SourceLine(${p.source.file.name}, ${p.line}, ${p.column})"
}
}
diff --git a/chiselFrontend/src/main/scala/chisel3/internal/firrtl/IR.scala b/chiselFrontend/src/main/scala/chisel3/internal/firrtl/IR.scala
index 62784cee..64d7d5fd 100644
--- a/chiselFrontend/src/main/scala/chisel3/internal/firrtl/IR.scala
+++ b/chiselFrontend/src/main/scala/chisel3/internal/firrtl/IR.scala
@@ -1,9 +1,11 @@
// See LICENSE for license details.
-package Chisel.internal.firrtl
-import Chisel._
-import Chisel.internal._
-import Chisel.internal.sourceinfo.{SourceInfo, NoSourceInfo}
+package chisel3.internal.firrtl
+
+import chisel3._
+import core._
+import chisel3.internal._
+import chisel3.internal.sourceinfo.{SourceInfo, NoSourceInfo}
case class PrimOp(val name: String) {
override def toString: String = name
@@ -53,8 +55,8 @@ case class Node(id: HasId) extends Arg {
}
abstract class LitArg(val num: BigInt, widthArg: Width) extends Arg {
- private[Chisel] def forcedWidth = widthArg.known
- private[Chisel] def width: Width = if (forcedWidth) widthArg else Width(minWidth)
+ private[chisel3] def forcedWidth = widthArg.known
+ private[chisel3] def width: Width = if (forcedWidth) widthArg else Width(minWidth)
protected def minWidth: Int
if (forcedWidth) {