-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Scala3] Scala2 compatibility changes (#4483)
- Loading branch information
1 parent
eb31402
commit bbcc405
Showing
21 changed files
with
236 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
core/src/main/scala-2/chisel3/experimental/dataview/InvertibleDataView.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package chisel3.experimental.dataview | ||
|
||
import chisel3._ | ||
import scala.reflect.runtime.universe.WeakTypeTag | ||
|
||
private[chisel3] trait InvertibleDataView { | ||
def swapArgs[A, B, C, D](f: (A, B) => Iterable[(C, D)]): (B, A) => Iterable[(D, C)] = { | ||
case (b, a) => f(a, b).map(_.swap) | ||
} | ||
|
||
/** Provides `invert` for invertible [[DataView]]s | ||
* | ||
* This must be done as an extension method because it applies an addition constraint on the `Target` | ||
* type parameter, namely that it must be a subtype of [[Data]]. | ||
* | ||
* @note [[PartialDataView]]s are **not** invertible and will result in an elaboration time exception | ||
*/ | ||
implicit class InvertibleDataView[T <: Data: WeakTypeTag, V <: Data: WeakTypeTag](view: DataView[T, V]) { | ||
def invert(mkView: V => T): DataView[V, T] = { | ||
// It would've been nice to make this a compiler error, but it's unclear how to make that work. | ||
// We tried having separate TotalDataView and PartialDataView and only defining inversion for | ||
// TotalDataView. For some reason, implicit resolution wouldn't invert TotalDataViews. This is | ||
// probably because it was looking for the super-type DataView and since invertDataView was | ||
// only defined on TotalDataView, it wasn't included in implicit resolution. Thus we end up | ||
// with a runtime check. | ||
if (!view.total) { | ||
val tt = implicitly[WeakTypeTag[T]].tpe | ||
val vv = implicitly[WeakTypeTag[V]].tpe | ||
val msg = s"Cannot invert '$view' as it is non-total.\n Try providing a DataView[$vv, $tt]." + | ||
s"\n Please see https://www.chisel-lang.org/chisel3/docs/explanations/dataview." | ||
throw InvalidViewException(msg) | ||
} | ||
implicit val sourceInfo = view.sourceInfo | ||
new DataView[V, T](mkView, swapArgs(view.mapping), view.total) | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
core/src/main/scala-2/chisel3/experimental/hierarchy/HierarchyPackage.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package chisel3.experimental | ||
|
||
/** Classes or traits which will be used with the [[Definition]] + [[Instance]] api should be marked | ||
* with the [[instantiable]] annotation at the class/trait definition. | ||
* | ||
* @example {{{ | ||
* @instantiable | ||
* class MyModule extends Module { | ||
* ... | ||
* } | ||
* | ||
* val d = Definition(new MyModule) | ||
* val i0 = Instance(d) | ||
* val i1 = Instance(d) | ||
* }}} | ||
*/ | ||
class instantiable extends chisel3.internal.instantiable | ||
|
||
/** Classes marked with [[instantiable]] can have their vals marked with the [[public]] annotation to | ||
* enable accessing these values from a [[Definition]] or [[Instance]] of the class. | ||
* | ||
* Only vals of the the following types can be marked [[public]]: | ||
* 1. IsInstantiable | ||
* 2. IsLookupable | ||
* 3. Data | ||
* 4. BaseModule | ||
* 5. Iterable/Option containing a type that meets these requirements | ||
* 6. Basic type like String, Int, BigInt etc. | ||
* | ||
* @example {{{ | ||
* @instantiable | ||
* class MyModule extends Module { | ||
* @public val in = IO(Input(UInt(3.W))) | ||
* @public val out = IO(Output(UInt(3.W))) | ||
* .. | ||
* } | ||
* | ||
* val d = Definition(new MyModule) | ||
* val i0 = Instance(d) | ||
* val i1 = Instance(d) | ||
* | ||
* i1.in := i0.out | ||
* }}} | ||
*/ | ||
class public extends chisel3.internal.public |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package chisel3 | ||
|
||
private[chisel3] trait PrintfImpl { | ||
|
||
/** Helper for packing escape characters */ | ||
private[chisel3] def format(formatIn: String): String = { | ||
require(formatIn.forall(c => c.toInt > 0 && c.toInt < 128), "format strings must comprise non-null ASCII values") | ||
def escaped(x: Char) = { | ||
require(x.toInt >= 0, s"char ${x} to Int ${x.toInt} must be >= 0") | ||
if (x == '"' || x == '\\') { | ||
s"\\${x}" | ||
} else if (x == '\n') { | ||
"\\n" | ||
} else if (x == '\t') { | ||
"\\t" | ||
} else { | ||
require( | ||
x.toInt >= 32, | ||
s"char ${x} to Int ${x.toInt} must be >= 32" | ||
) // TODO \xNN once FIRRTL issue #59 is resolved | ||
x | ||
} | ||
} | ||
formatIn.map(escaped).mkString("") | ||
} | ||
} |
Oops, something went wrong.