Skip to content

Commit c28063d

Browse files
committed
Merge branch '3.0.1' into 3.0.x
2 parents 78bfa07 + 5cc147f commit c28063d

39 files changed

+429
-106
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
**Note: for support questions, you are strongly advised to use [Stack Overflow](https://stackoverflow.com/questions/tagged/chisel)**.
2+
3+
This repository's issues are reserved for feature requests and bug reports.
4+
5+
* **Type of issue**
6+
- [ ] Bug report
7+
- [ ] Feature request
8+
- [ ] Other enhancement
9+
10+
* **If the current behavior is a bug, please provide the steps to reproduce the problem:**
11+
* **What is the current behavior?**
12+
* **What is the expected behavior?**
13+
* **Please tell us about your environment:**
14+
(examples)
15+
- version: `3.0-SNAPSHOT`
16+
- OS: `Linux knight 4.4.0-92-generic #115-Ubuntu SMP Thu Aug 10 09:04:33 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux`
17+
18+
* **What is the use case for changing the behavior?**
19+
20+
* **Impact**
21+
- [ ] no functional change
22+
- [ ] API addition (no impact on existing code)
23+
- [ ] API modification
24+
- [ ] unknown
25+
26+
* **Development Phase**
27+
- [ ] request
28+
- [ ] proposal
29+
30+
* **Other information** (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. Stack Overflow, gitter, etc)

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
* **Related issue** (if applicable)
2+
3+
* **Type of change**
4+
- [ ] Bug report
5+
- [ ] Feature request
6+
- [ ] Other enhancement
7+
8+
* **Impact**
9+
- [ ] no functional change
10+
- [ ] API addition (no impact on existing code)
11+
- [ ] API modification
12+
13+
* **Development Phase**
14+
- [ ] proposal
15+
- [ ] implementation
16+
17+
* **Release Notes**
18+
19+
Text from here to the end of the body will be considered for inclusion in the release notes for the version containing this pull request.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ generated/
44
.idea
55
target/
66
*.iml
7+
*.swp
8+
test_run_dir

build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def javacOptionsVersion(scalaVersion: String): Seq[String] = {
3232

3333
lazy val commonSettings = Seq (
3434
organization := "edu.berkeley.cs",
35-
version := "3.0.0",
35+
version := "3.0.1",
3636
git.remoteRepo := "git@github.com:freechipsproject/chisel3.git",
3737
autoAPIMappings := true,
3838
scalaVersion := "2.11.11",
@@ -92,7 +92,7 @@ lazy val publishSettings = Seq (
9292
}
9393
)
9494

95-
val defaultVersions = Map("firrtl" -> "1.0.0")
95+
val defaultVersions = Map("firrtl" -> "1.0.+")
9696

9797
lazy val chiselSettings = Seq (
9898
name := "chisel3",

chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,13 @@ object Vec extends VecFactory
118118
/** A vector (array) of [[Data]] elements. Provides hardware versions of various
119119
* collection transformation functions found in software array implementations.
120120
*
121-
* Careful consideration should be given over the use of [[Vec]] vs [[Seq]] or some other scala collection. In
122-
* general [[Vec]] only needs to be used when there is a need to express the hardware collection in a [[Reg]]
123-
* or IO [[Bundle]] or when access to elements of the array is indexed via a hardware signal.
121+
* Careful consideration should be given over the use of [[Vec]] vs
122+
* [[scala.collection.immutable.Seq Seq]] or some other Scala collection. In general [[Vec]] only
123+
* needs to be used when there is a need to express the hardware collection in a [[Reg]] or IO
124+
* [[Bundle]] or when access to elements of the array is indexed via a hardware signal.
124125
*
125-
* Example of indexing into a [[Vec]] using a hardware address and where the [[Vec]] is defined in an IO [[Bundle]]
126+
* Example of indexing into a [[Vec]] using a hardware address and where the [[Vec]] is defined in
127+
* an IO [[Bundle]]
126128
*
127129
* {{{
128130
* val io = IO(new Bundle {
@@ -174,7 +176,9 @@ sealed class Vec[T <: Data] private[core] (gen: => T, val length: Int)
174176
* @note the length of this Vec must match the length of the input Seq
175177
*/
176178
def <> (that: Seq[T])(implicit sourceInfo: SourceInfo, moduleCompileOptions: CompileOptions): Unit = {
177-
require(this.length == that.length)
179+
if (this.length != that.length) {
180+
Builder.error("Vec and Seq being bulk connected have different lengths!")
181+
}
178182
for ((a, b) <- this zip that)
179183
a <> b
180184
}
@@ -468,7 +472,7 @@ abstract class Record(private[chisel3] implicit val compileOptions: CompileOptio
468472
}
469473
/** Default "pretty-print" implementation
470474
* Analogous to printing a Map
471-
* Results in "$className(elt0.name -> elt0.value, ...)"
475+
* Results in "`\$className(elt0.name -> elt0.value, ...)`"
472476
*/
473477
def toPrintable: Printable = toPrintableHelper(elements.toList)
474478
}
@@ -581,7 +585,7 @@ class Bundle(implicit compileOptions: CompileOptions) extends Record {
581585

582586
/** Default "pretty-print" implementation
583587
* Analogous to printing a Map
584-
* Results in "Bundle(elt0.name -> elt0.value, ...)"
588+
* Results in "`Bundle(elt0.name -> elt0.value, ...)`"
585589
* @note The order is reversed from the order of elements in order to print
586590
* the fields in the order they were defined
587591
*/

chiselFrontend/src/main/scala/chisel3/core/Bits.scala

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,12 @@ sealed abstract class Bits(width: Width, override val litArg: Option[LitArg])
308308

309309
/** Default print as [[Decimal]] */
310310
final def toPrintable: Printable = Decimal(this)
311+
312+
protected final def validateShiftAmount(x: Int): Int = {
313+
if (x < 0)
314+
Builder.error(s"Negative shift amounts are illegal (got $x)")
315+
x
316+
}
311317
}
312318

313319
// REVIEW TODO: Further discussion needed on what Num actually is.
@@ -494,13 +500,13 @@ sealed class UInt private[core] (width: Width, lit: Option[ULit] = None)
494500
def do_unary_! (implicit sourceInfo: SourceInfo, compileOptions: CompileOptions) : Bool = this === 0.U(1.W)
495501

496502
override def do_<< (that: Int)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): UInt =
497-
binop(sourceInfo, UInt(this.width + that), ShiftLeftOp, that)
503+
binop(sourceInfo, UInt(this.width + that), ShiftLeftOp, validateShiftAmount(that))
498504
override def do_<< (that: BigInt)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): UInt =
499505
this << that.toInt
500506
override def do_<< (that: UInt)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): UInt =
501507
binop(sourceInfo, UInt(this.width.dynamicShiftLeft(that.width)), DynamicShiftLeftOp, that)
502508
override def do_>> (that: Int)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): UInt =
503-
binop(sourceInfo, UInt(this.width.shiftRight(that)), ShiftRightOp, that)
509+
binop(sourceInfo, UInt(this.width.shiftRight(that)), ShiftRightOp, validateShiftAmount(that))
504510
override def do_>> (that: BigInt)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): UInt =
505511
this >> that.toInt
506512
override def do_>> (that: UInt)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): UInt =
@@ -662,13 +668,13 @@ sealed class SInt private[core] (width: Width, lit: Option[SLit] = None)
662668
}
663669

664670
override def do_<< (that: Int)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): SInt =
665-
binop(sourceInfo, SInt(this.width + that), ShiftLeftOp, that)
671+
binop(sourceInfo, SInt(this.width + that), ShiftLeftOp, validateShiftAmount(that))
666672
override def do_<< (that: BigInt)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): SInt =
667673
this << that.toInt
668674
override def do_<< (that: UInt)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): SInt =
669675
binop(sourceInfo, SInt(this.width.dynamicShiftLeft(that.width)), DynamicShiftLeftOp, that)
670676
override def do_>> (that: Int)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): SInt =
671-
binop(sourceInfo, SInt(this.width.shiftRight(that)), ShiftRightOp, that)
677+
binop(sourceInfo, SInt(this.width.shiftRight(that)), ShiftRightOp, validateShiftAmount(that))
672678
override def do_>> (that: BigInt)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): SInt =
673679
this >> that.toInt
674680
override def do_>> (that: UInt)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): SInt =
@@ -924,13 +930,13 @@ sealed class FixedPoint private (width: Width, val binaryPoint: BinaryPoint, lit
924930
}
925931

926932
override def do_<< (that: Int)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): FixedPoint =
927-
binop(sourceInfo, FixedPoint(this.width + that, this.binaryPoint), ShiftLeftOp, that)
933+
binop(sourceInfo, FixedPoint(this.width + that, this.binaryPoint), ShiftLeftOp, validateShiftAmount(that))
928934
override def do_<< (that: BigInt)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): FixedPoint =
929935
(this << that.toInt).asFixedPoint(this.binaryPoint)
930936
override def do_<< (that: UInt)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): FixedPoint =
931937
binop(sourceInfo, FixedPoint(this.width.dynamicShiftLeft(that.width), this.binaryPoint), DynamicShiftLeftOp, that)
932938
override def do_>> (that: Int)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): FixedPoint =
933-
binop(sourceInfo, FixedPoint(this.width.shiftRight(that), this.binaryPoint), ShiftRightOp, that)
939+
binop(sourceInfo, FixedPoint(this.width.shiftRight(that), this.binaryPoint), ShiftRightOp, validateShiftAmount(that))
934940
override def do_>> (that: BigInt)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): FixedPoint =
935941
(this >> that.toInt).asFixedPoint(this.binaryPoint)
936942
override def do_>> (that: UInt)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): FixedPoint =

chiselFrontend/src/main/scala/chisel3/core/BlackBox.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ abstract class ExtModule(val params: Map[String, Param] = Map.empty[String, Para
8080
component
8181
}
8282

83-
private[core] def initializeInParent() {
83+
private[core] def initializeInParent(parentCompileOptions: CompileOptions): Unit = {
8484
implicit val sourceInfo = UnlocatableSourceInfo
8585

8686
for (x <- getModulePorts) {
@@ -165,7 +165,7 @@ abstract class BlackBox(val params: Map[String, Param] = Map.empty[String, Param
165165
component
166166
}
167167

168-
private[core] def initializeInParent() {
168+
private[core] def initializeInParent(parentCompileOptions: CompileOptions): Unit = {
169169
for ((_, port) <- io.elements) {
170170
pushCommand(DefInvalid(UnlocatableSourceInfo, port.ref))
171171
}

chiselFrontend/src/main/scala/chisel3/core/ChiselAnnotation.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ case class ChiselAnnotation(component: InstanceId, transformClass: Class[_ <: Tr
4545
* }
4646
* }}}
4747
*
48-
* @note Calling this on Data creates an annotation that Chisel emits to a separate annotations
49-
* file. This file must be passed to Firrtl independently of the .fir file.
50-
* [[chisel3.Driver.execute]] will do this automatically.
48+
* @note Calling this on [[Data]] creates an annotation that Chisel emits to a separate annotations
49+
* file. This file must be passed to FIRRTL independently of the `.fir` file. The execute methods
50+
* in [[chisel3.Driver]] will pass the annotations to FIRRTL automatically.
5151
*/
5252
object dontTouch { // scalastyle:ignore object.name
5353
/** Marks a signal to be preserved in Chisel and Firrtl

chiselFrontend/src/main/scala/chisel3/core/Data.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,13 +451,20 @@ object WireInit {
451451
apply(model, init)
452452
}
453453

454-
def apply[T <: Data](t: T, init: T)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): T = {
454+
private def applyImpl[T <: Data](t: T, init: Data)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): T = {
455455
implicit val noSourceInfo = UnlocatableSourceInfo
456456
val x = Wire(t)
457457
requireIsHardware(init, "wire initializer")
458458
x := init
459459
x
460460
}
461+
462+
def apply[T <: Data](t: T, init: T)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): T = {
463+
applyImpl(t, init)
464+
}
465+
def apply[T <: Data](t: T, init: DontCare.type)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): T = {
466+
applyImpl(t, init)
467+
}
461468
}
462469

463470
/** RHS (source) for Invalidate API.

chiselFrontend/src/main/scala/chisel3/core/Mem.scala

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,18 @@ sealed abstract class MemBase[T <: Data](t: T, val length: Int) extends HasId {
4646
/** Creates a read/write accessor into the memory with dynamic addressing.
4747
* See the class documentation of the memory for more detailed information.
4848
*/
49-
def apply(idx: UInt)(implicit compileOptions: CompileOptions): T = makePort(UnlocatableSourceInfo, idx, MemPortDirection.INFER)
49+
def apply(x: UInt): T = macro SourceInfoTransform.xArg
50+
51+
def do_apply(idx: UInt)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): T =
52+
makePort(sourceInfo, idx, MemPortDirection.INFER)
5053

5154
/** Creates a read accessor into the memory with dynamic addressing. See the
5255
* class documentation of the memory for more detailed information.
5356
*/
54-
def read(idx: UInt)(implicit compileOptions: CompileOptions): T = makePort(UnlocatableSourceInfo, idx, MemPortDirection.READ)
57+
def read(x: UInt): T = macro SourceInfoTransform.xArg
58+
59+
def do_read(idx: UInt)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): T =
60+
makePort(sourceInfo, idx, MemPortDirection.READ)
5561

5662
/** Creates a write accessor into the memory.
5763
*
@@ -144,7 +150,9 @@ object SyncReadMem {
144150
* result is undefined (unlike Vec, where the last assignment wins)
145151
*/
146152
sealed class SyncReadMem[T <: Data](t: T, n: Int) extends MemBase[T](t, n) {
147-
def read(addr: UInt, enable: Bool)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): T = {
153+
def read(x: UInt, en: Bool): T = macro SourceInfoTransform.xEnArg
154+
155+
def do_read(addr: UInt, enable: Bool)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): T = {
148156
val a = Wire(UInt())
149157
var port: Option[T] = None
150158
when (enable) {

chiselFrontend/src/main/scala/chisel3/core/Module.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ object Module {
2323
*/
2424
def apply[T <: BaseModule](bc: => T): T = macro InstTransform.apply[T]
2525

26-
def do_apply[T <: BaseModule](bc: => T)(implicit sourceInfo: SourceInfo): T = {
26+
def do_apply[T <: BaseModule](bc: => T)
27+
(implicit sourceInfo: SourceInfo,
28+
compileOptions: CompileOptions): T = {
2729
if (Builder.readyForModuleConstr) {
2830
throwException("Error: Called Module() twice without instantiating a Module." +
2931
sourceInfo.makeMessage(" See " + _))
@@ -62,7 +64,7 @@ object Module {
6264
// Handle connections at enclosing scope
6365
if(!Builder.currentModule.isEmpty) {
6466
pushCommand(DefInstance(sourceInfo, module, component.ports))
65-
module.initializeInParent()
67+
module.initializeInParent(compileOptions)
6668
}
6769
module
6870
}
@@ -124,7 +126,7 @@ abstract class BaseModule extends HasId {
124126

125127
/** Sets up this module in the parent context
126128
*/
127-
private[core] def initializeInParent()
129+
private[core] def initializeInParent(parentCompileOptions: CompileOptions): Unit
128130

129131
//
130132
// Chisel Internals

chiselFrontend/src/main/scala/chisel3/core/Printable.scala

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,39 @@ import java.util.{
1414

1515
/** Superclass of things that can be printed in the resulting circuit
1616
*
17-
* Usually created using the custom string interpolator p"..."
18-
* TODO Add support for names of Modules
19-
* Currently impossible because unpack is called before the name is selected
20-
* Could be implemented by adding a new format specifier to Firrtl (eg. %m)
21-
* TODO Should we provide more functions like map and mkPrintable?
17+
* Usually created using the custom string interpolator `p"..."`. Printable string interpolation is
18+
* similar to [[https://docs.scala-lang.org/overviews/core/string-interpolation.html String
19+
* interpolation in Scala]] For example:
20+
* {{{
21+
* printf(p"The value of wire = \$wire\n")
22+
* }}}
23+
* This is equivalent to writing:
24+
* {{{
25+
* printf(p"The value of wire = %d\n", wire)
26+
* }}}
27+
* All Chisel data types have a method `.toPrintable` that gives a default pretty print that can be
28+
* accessed via `p"..."`. This works even for aggregate types, for example:
29+
* {{{
30+
* val myVec = VecInit(5.U, 10.U, 13.U)
31+
* printf(p"myVec = \$myVec\n")
32+
* // myVec = Vec(5, 10, 13)
33+
*
34+
* val myBundle = Wire(new Bundle {
35+
* val foo = UInt()
36+
* val bar = UInt()
37+
* })
38+
* myBundle.foo := 3.U
39+
* myBundle.bar := 11.U
40+
* printf(p"myBundle = \$myBundle\n")
41+
* // myBundle = Bundle(a -> 3, b -> 11)
42+
* }}}
43+
* Users can override the default behavior of `.toPrintable` in custom [[Bundle]] and [[Record]]
44+
* types.
2245
*/
46+
// TODO Add support for names of Modules
47+
// Currently impossible because unpack is called before the name is selected
48+
// Could be implemented by adding a new format specifier to Firrtl (eg. %m)
49+
// TODO Should we provide more functions like map and mkPrintable?
2350
sealed abstract class Printable {
2451
/** Unpack into format String and a List of String arguments (identifiers)
2552
* @note This must be called after elaboration when Chisel nodes actually

0 commit comments

Comments
 (0)