Skip to content

Commit d717ddc

Browse files
committed
Merge branch 'master' into release
2 parents a5e07f4 + 6a57642 commit d717ddc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+506
-255
lines changed

Makefile

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ c_resources_dir := src/main/resources
2525

2626
test_outs := $(addprefix $(targetDir)/, $(addsuffix .out, $(test_results)))
2727

28-
.PHONY: smoke publish-local check clean jenkins-build coverage scaladoc test checkstyle compile
28+
.PHONY: smoke publish-local pubishLocal check clean jenkins-build coverage scaladoc test checkstyle compile
2929

30-
default: publish-local
30+
default: publishLocal
3131

3232
smoke compile:
3333
$(SBT) $(SBT_FLAGS) compile
3434

35-
publish-local:
36-
$(SBT) $(SBT_FLAGS) publish-local
35+
publish-local publishLocal:
36+
$(SBT) $(SBT_FLAGS) publishLocal
3737

3838
test:
3939
$(SBT) $(SBT_FLAGS) test
@@ -69,7 +69,7 @@ site:
6969
# We need to run the coverage tests last, since Jenkins will fail the build if it can't find their results.
7070
jenkins-build: clean
7171
$(SBT) $(SBT_FLAGS) test
72-
$(SBT) $(SBT_FLAGS) clean publish-local
72+
$(SBT) $(SBT_FLAGS) clean publishLocal
7373
$(SBT) $(SBT_FLAGS) scalastyle coverage test
7474
$(SBT) $(SBT_FLAGS) coverageReport
7575

@@ -87,3 +87,8 @@ $(targetDir)/%.h: $(c_resources_dir)/%.h
8787

8888
$(targetDir)/%.out: $(targetDir)/%
8989
$(SBT) $(SBT_FLAGS) "test:runMain ChiselTests.MiniChisel $(notdir $(basename $<)) $(CHISEL_FLAGS) --test --targetDir $(targetDir)"
90+
91+
# The "last-resort" rule.
92+
# We assume the target is something like "+clean".
93+
%::
94+
$(SBT) $(SBT_FLAGS) $@

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Chisel3
2-
Chisel3 is a new Firrtl based chisel.
3-
It is currently in BETA VERSION, so some Chisel features may change in the coming months.
2+
3+
Chisel is a new hardware construction language to support advanced hardware design and circuit generation.
4+
The latest version of [Chisel](https://chisel.eecs.berkeley.edu/) is Chisel3,
5+
which uses Firrtl as an intermediate hardware representation language.
6+
7+
Chisel3 is currently in BETA VERSION, so some Chisel features may change in the coming months.
48

59
Please visit the [Wiki](https://github.com/ucb-bar/chisel3/wiki) for a more
610
detailed description.

build.sbt

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,47 @@
11
// See LICENSE for license details.
22

3-
site.settings
4-
5-
site.includeScaladoc()
6-
7-
ghpages.settings
8-
9-
import UnidocKeys._
10-
11-
lazy val customUnidocSettings = unidocSettings ++ Seq (
12-
doc in Compile := (doc in ScalaUnidoc).value,
13-
target in unidoc in ScalaUnidoc := crossTarget.value / "api"
14-
)
3+
enablePlugins(SiteScaladocPlugin)
4+
5+
enablePlugins(GhpagesPlugin)
6+
7+
def scalacOptionsVersion(scalaVersion: String): Seq[String] = {
8+
Seq() ++ {
9+
// If we're building with Scala > 2.11, enable the compile option
10+
// switch to support our anonymous Bundle definitions:
11+
// https://github.com/scala/bug/issues/10047
12+
CrossVersion.partialVersion(scalaVersion) match {
13+
case Some((2, scalaMajor: Int)) if scalaMajor < 12 => Seq()
14+
case _ => Seq("-Xsource:2.11")
15+
}
16+
}
17+
}
18+
19+
def javacOptionsVersion(scalaVersion: String): Seq[String] = {
20+
Seq() ++ {
21+
// Scala 2.12 requires Java 8. We continue to generate
22+
// Java 7 compatible code for Scala 2.11
23+
// for compatibility with old clients.
24+
CrossVersion.partialVersion(scalaVersion) match {
25+
case Some((2, scalaMajor: Int)) if scalaMajor < 12 =>
26+
Seq("-source", "1.7", "-target", "1.7")
27+
case _ =>
28+
Seq("-source", "1.8", "-target", "1.8")
29+
}
30+
}
31+
}
1532

1633
lazy val commonSettings = Seq (
1734
organization := "edu.berkeley.cs",
18-
version := "3.0-SNAPSHOT_2017-08-16",
19-
git.remoteRepo := "git@github.com:ucb-bar/chisel3.git",
35+
version := "3.0-SNAPSHOT_2017-09-14",
36+
git.remoteRepo := "git@github.com:freechipsproject/chisel3.git",
2037
autoAPIMappings := true,
2138
scalaVersion := "2.11.11",
39+
crossScalaVersions := Seq("2.11.11", "2.12.3"),
2240
resolvers ++= Seq(
2341
Resolver.sonatypeRepo("snapshots"),
2442
Resolver.sonatypeRepo("releases")
2543
),
26-
scalacOptions := Seq("-deprecation", "-feature"),
44+
scalacOptions := Seq("-deprecation", "-feature") ++ scalacOptionsVersion(scalaVersion.value),
2745
libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value,
2846
addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full),
2947
// Use the root project's unmanaged base for all sub-projects.
@@ -54,8 +72,8 @@ lazy val publishSettings = Seq (
5472
</license>
5573
</licenses>
5674
<scm>
57-
<url>https://github.com/ucb-bar/chisel3.git</url>
58-
<connection>scm:git:github.com/ucb-bar/chisel3.git</connection>
75+
<url>https://github.com/freechipsproject/chisel3.git</url>
76+
<connection>scm:git:github.com/freechipsproject/chisel3.git</connection>
5977
</scm>
6078
<developers>
6179
<developer>
@@ -77,7 +95,7 @@ lazy val publishSettings = Seq (
7795
}
7896
)
7997

80-
val defaultVersions = Map("firrtl" -> "1.0-SNAPSHOT_2017-08-16")
98+
val defaultVersions = Map("firrtl" -> "1.0-SNAPSHOT_2017-09-14")
8199

82100
lazy val chiselSettings = Seq (
83101
name := "chisel3",
@@ -89,13 +107,13 @@ lazy val chiselSettings = Seq (
89107
libraryDependencies ++= Seq(
90108
"org.scalatest" %% "scalatest" % "3.0.1" % "test",
91109
"org.scalacheck" %% "scalacheck" % "1.13.4" % "test",
92-
"com.github.scopt" %% "scopt" % "3.5.0"
110+
"com.github.scopt" %% "scopt" % "3.6.0"
93111
),
94112

95113
// Tests from other projects may still run concurrently.
96114
parallelExecution in Test := true,
97115

98-
javacOptions ++= Seq("-target", "1.7")
116+
javacOptions ++= javacOptionsVersion(scalaVersion.value)
99117
)
100118

101119
lazy val coreMacros = (project in file("coreMacros")).
@@ -112,14 +130,14 @@ lazy val root = RootProject(file("."))
112130

113131
lazy val chisel = (project in file(".")).
114132
enablePlugins(BuildInfoPlugin).
133+
enablePlugins(ScalaUnidocPlugin).
115134
settings(
116135
buildInfoPackage := name.value,
117136
buildInfoOptions += BuildInfoOption.BuildTime,
118137
buildInfoUsePackageAsPath := true,
119138
buildInfoKeys := Seq[BuildInfoKey](buildInfoPackage, version, scalaVersion, sbtVersion)
120139
).
121140
settings(commonSettings: _*).
122-
settings(customUnidocSettings: _*).
123141
settings(chiselSettings: _*).
124142
settings(publishSettings: _*).
125143
// Prevent separate JARs from being generated for coreMacros and chiselFrontend.

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

Lines changed: 77 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -76,104 +76,26 @@ sealed abstract class Aggregate extends Data {
7676
private[core] override def connectFromBits(that: Bits)(implicit sourceInfo: SourceInfo,
7777
compileOptions: CompileOptions): Unit = {
7878
var i = 0
79-
val bits = Wire(UInt(this.width), init=that) // handles width padding
79+
val bits = WireInit(UInt(this.width), that) // handles width padding
8080
for (x <- flatten) {
8181
x.connectFromBits(bits(i + x.getWidth - 1, i))
8282
i += x.getWidth
8383
}
8484
}
8585
}
8686

87-
object Vec {
87+
trait VecFactory {
8888
/** Creates a new [[Vec]] with `n` entries of the specified data type.
8989
*
9090
* @note elements are NOT assigned by default and have no value
9191
*/
92-
def apply[T <: Data](n: Int, gen: T)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Vec[T] = new Vec(gen.chiselCloneType, n)
93-
94-
@deprecated("Vec argument order should be size, t; this will be removed by the official release", "chisel3")
95-
def apply[T <: Data](gen: T, n: Int)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Vec[T] = new Vec(gen.chiselCloneType, n)
96-
97-
/** Creates a new [[Vec]] composed of elements of the input Seq of [[Data]]
98-
* nodes.
99-
*
100-
* @note input elements should be of the same type (this is checked at the
101-
* FIRRTL level, but not at the Scala / Chisel level)
102-
* @note the width of all output elements is the width of the largest input
103-
* element
104-
* @note output elements are connected from the input elements
105-
*/
106-
def apply[T <: Data](elts: Seq[T]): Vec[T] = macro VecTransform.apply_elts
107-
108-
def do_apply[T <: Data](elts: Seq[T])(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Vec[T] = {
109-
// REVIEW TODO: this should be removed in favor of the apply(elts: T*)
110-
// varargs constructor, which is more in line with the style of the Scala
111-
// collection API. However, a deprecation phase isn't possible, since
112-
// changing apply(elt0, elts*) to apply(elts*) causes a function collision
113-
// with apply(Seq) after type erasure. Workarounds by either introducing a
114-
// DummyImplicit or additional type parameter will break some code.
115-
116-
// Check that types are homogeneous. Width mismatch for Elements is safe.
117-
require(!elts.isEmpty)
118-
elts.foreach(requireIsHardware(_, "vec element"))
119-
120-
val vec = Wire(new Vec(cloneSupertype(elts, "Vec"), elts.length))
121-
122-
// TODO: try to remove the logic for this mess
123-
elts.head.direction match {
124-
case ActualDirection.Input | ActualDirection.Output | ActualDirection.Unspecified =>
125-
// When internal wires are involved, driver / sink must be specified explicitly, otherwise
126-
// the system is unable to infer which is driver / sink
127-
(vec zip elts).foreach(x => x._1 := x._2)
128-
case ActualDirection.Bidirectional(_) =>
129-
// For bidirectional, must issue a bulk connect so subelements are resolved correctly.
130-
// Bulk connecting two wires may not succeed because Chisel frontend does not infer
131-
// directions.
132-
(vec zip elts).foreach(x => x._1 <> x._2)
92+
def apply[T <: Data](n: Int, gen: T)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Vec[T] = {
93+
if (compileOptions.declaredTypeMustBeUnbound) {
94+
requireIsChiselType(gen, "vec type")
13395
}
134-
vec
96+
new Vec(gen.chiselCloneType, n)
13597
}
13698

137-
/** Creates a new [[Vec]] composed of the input [[Data]] nodes.
138-
*
139-
* @note input elements should be of the same type (this is checked at the
140-
* FIRRTL level, but not at the Scala / Chisel level)
141-
* @note the width of all output elements is the width of the largest input
142-
* element
143-
* @note output elements are connected from the input elements
144-
*/
145-
def apply[T <: Data](elt0: T, elts: T*): Vec[T] = macro VecTransform.apply_elt0
146-
147-
def do_apply[T <: Data](elt0: T, elts: T*)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Vec[T] =
148-
apply(elt0 +: elts.toSeq)
149-
150-
/** Creates a new [[Vec]] of length `n` composed of the results of the given
151-
* function applied over a range of integer values starting from 0.
152-
*
153-
* @param n number of elements in the vector (the function is applied from
154-
* 0 to `n-1`)
155-
* @param gen function that takes in an Int (the index) and returns a
156-
* [[Data]] that becomes the output element
157-
*/
158-
def tabulate[T <: Data](n: Int)(gen: (Int) => T): Vec[T] = macro VecTransform.tabulate
159-
160-
def do_tabulate[T <: Data](n: Int)(gen: (Int) => T)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Vec[T] =
161-
apply((0 until n).map(i => gen(i)))
162-
163-
/** Creates a new [[Vec]] of length `n` composed of the result of the given
164-
* function repeatedly applied.
165-
*
166-
* @param n number of elements (amd the number of times the function is
167-
* called)
168-
* @param gen function that generates the [[Data]] that becomes the output
169-
* element
170-
*/
171-
@deprecated("Vec.fill(n)(gen) is deprecated. Please use Vec(Seq.fill(n)(gen))", "chisel3")
172-
def fill[T <: Data](n: Int)(gen: => T): Vec[T] = macro VecTransform.fill
173-
174-
def do_fill[T <: Data](n: Int)(gen: => T)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Vec[T] =
175-
apply(Seq.fill(n)(gen))
176-
17799
/** Truncate an index to implement modulo-power-of-2 addressing. */
178100
private[core] def truncateIndex(idx: UInt, n: Int)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): UInt = {
179101
val w = BigInt(n-1).bitLength
@@ -184,6 +106,8 @@ object Vec {
184106
}
185107
}
186108

109+
object Vec extends VecFactory
110+
187111
/** A vector (array) of [[Data]] elements. Provides hardware versions of various
188112
* collection transformation functions found in software array implementations.
189113
*
@@ -208,7 +132,7 @@ object Vec {
208132
* - when multiple conflicting assignments are performed on a Vec element, the last one takes effect (unlike Mem, where the result is undefined)
209133
* - Vecs, unlike classes in Scala's collection library, are propagated intact to FIRRTL as a vector type, which may make debugging easier
210134
*/
211-
sealed class Vec[T <: Data] private (gen: => T, val length: Int)
135+
sealed class Vec[T <: Data] private[core] (gen: => T, val length: Int)
212136
extends Aggregate with VecLike[T] {
213137
private[core] override def typeEquivalent(that: Data): Boolean = that match {
214138
case that: Vec[T] =>
@@ -326,6 +250,74 @@ sealed class Vec[T <: Data] private (gen: => T, val length: Int)
326250
}
327251
}
328252

253+
object VecInit {
254+
/** Creates a new [[Vec]] composed of elements of the input Seq of [[Data]]
255+
* nodes.
256+
*
257+
* @note input elements should be of the same type (this is checked at the
258+
* FIRRTL level, but not at the Scala / Chisel level)
259+
* @note the width of all output elements is the width of the largest input
260+
* element
261+
* @note output elements are connected from the input elements
262+
*/
263+
def apply[T <: Data](elts: Seq[T]): Vec[T] = macro VecTransform.apply_elts
264+
265+
def do_apply[T <: Data](elts: Seq[T])(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Vec[T] = {
266+
// REVIEW TODO: this should be removed in favor of the apply(elts: T*)
267+
// varargs constructor, which is more in line with the style of the Scala
268+
// collection API. However, a deprecation phase isn't possible, since
269+
// changing apply(elt0, elts*) to apply(elts*) causes a function collision
270+
// with apply(Seq) after type erasure. Workarounds by either introducing a
271+
// DummyImplicit or additional type parameter will break some code.
272+
273+
// Check that types are homogeneous. Width mismatch for Elements is safe.
274+
require(!elts.isEmpty)
275+
elts.foreach(requireIsHardware(_, "vec element"))
276+
277+
val vec = Wire(new Vec(cloneSupertype(elts, "Vec"), elts.length))
278+
279+
// TODO: try to remove the logic for this mess
280+
elts.head.direction match {
281+
case ActualDirection.Input | ActualDirection.Output | ActualDirection.Unspecified =>
282+
// When internal wires are involved, driver / sink must be specified explicitly, otherwise
283+
// the system is unable to infer which is driver / sink
284+
(vec zip elts).foreach(x => x._1 := x._2)
285+
case ActualDirection.Bidirectional(_) =>
286+
// For bidirectional, must issue a bulk connect so subelements are resolved correctly.
287+
// Bulk connecting two wires may not succeed because Chisel frontend does not infer
288+
// directions.
289+
(vec zip elts).foreach(x => x._1 <> x._2)
290+
}
291+
vec
292+
}
293+
294+
/** Creates a new [[Vec]] composed of the input [[Data]] nodes.
295+
*
296+
* @note input elements should be of the same type (this is checked at the
297+
* FIRRTL level, but not at the Scala / Chisel level)
298+
* @note the width of all output elements is the width of the largest input
299+
* element
300+
* @note output elements are connected from the input elements
301+
*/
302+
def apply[T <: Data](elt0: T, elts: T*): Vec[T] = macro VecTransform.apply_elt0
303+
304+
def do_apply[T <: Data](elt0: T, elts: T*)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Vec[T] =
305+
apply(elt0 +: elts.toSeq)
306+
307+
/** Creates a new [[Vec]] of length `n` composed of the results of the given
308+
* function applied over a range of integer values starting from 0.
309+
*
310+
* @param n number of elements in the vector (the function is applied from
311+
* 0 to `n-1`)
312+
* @param gen function that takes in an Int (the index) and returns a
313+
* [[Data]] that becomes the output element
314+
*/
315+
def tabulate[T <: Data](n: Int)(gen: (Int) => T): Vec[T] = macro VecTransform.tabulate
316+
317+
def do_tabulate[T <: Data](n: Int)(gen: (Int) => T)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Vec[T] =
318+
apply((0 until n).map(i => gen(i)))
319+
}
320+
329321
/** A trait for [[Vec]]s containing common hardware generators for collection
330322
* operations.
331323
*/

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ object assert { // scalastyle:ignore object.name
5151
}
5252

5353
def apply_impl_do(cond: Bool, line: String, message: Option[String], data: Bits*)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions) {
54-
when (!(cond || Builder.forcedReset)) {
54+
when (!(cond || Module.reset.toBool)) {
5555
val fmt = message match {
5656
case Some(str) => s"Assertion failed: $str\n at $line\n"
5757
case None => s"Assertion failed\n at $line\n"
@@ -77,7 +77,7 @@ object assert { // scalastyle:ignore object.name
7777
object stop { // scalastyle:ignore object.name
7878
/** Terminate execution with a failure code. */
7979
def apply(code: Int)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Unit = {
80-
when (!Builder.forcedReset) {
80+
when (!Module.reset.toBool) {
8181
pushCommand(Stop(sourceInfo, Node(Builder.forcedClock), code))
8282
}
8383
}

0 commit comments

Comments
 (0)