summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authormergify[bot]2022-02-10 01:50:28 +0000
committerGitHub2022-02-10 01:50:28 +0000
commit556ce6398e2f23d1f796d4626b4010f00726f4cd (patch)
treec4ec9237b389f84b3b6144faba5d67cc2e53e486 /core/src
parent556ce39b2b33787407a3634f775b6a2a9da086c8 (diff)
Make Tuple2 Lookupable (#2372) (#2406)
(cherry picked from commit 024847d75079a125e5946e9dcf2ed9c14d2db730) Co-authored-by: Megan Wachs <megan@sifive.com>
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/scala/chisel3/experimental/hierarchy/Lookupable.scala24
1 files changed, 23 insertions, 1 deletions
diff --git a/core/src/main/scala/chisel3/experimental/hierarchy/Lookupable.scala b/core/src/main/scala/chisel3/experimental/hierarchy/Lookupable.scala
index 8552267a..a0c2209b 100644
--- a/core/src/main/scala/chisel3/experimental/hierarchy/Lookupable.scala
+++ b/core/src/main/scala/chisel3/experimental/hierarchy/Lookupable.scala
@@ -19,7 +19,7 @@ import chisel3.internal.{throwException, AggregateViewBinding, Builder, ChildBin
*/
@implicitNotFound(
"@public is only legal within a class or trait marked @instantiable, and only on vals of type" +
- " Data, BaseModule, IsInstantiable, IsLookupable, or Instance[_], or in an Iterable, Option, or Either"
+ " Data, BaseModule, IsInstantiable, IsLookupable, or Instance[_], or in an Iterable, Option, Either, or Tuple2"
)
trait Lookupable[-B] {
type C // Return type of the lookup
@@ -402,6 +402,28 @@ object Lookupable {
}
}
}
+
+ implicit def lookupTuple2[X, Y](
+ implicit sourceInfo: SourceInfo,
+ compileOptions: CompileOptions,
+ lookupableX: Lookupable[X],
+ lookupableY: Lookupable[Y]
+ ) = new Lookupable[(X, Y)] {
+ type C = (lookupableX.C, lookupableY.C)
+ def definitionLookup[A](that: A => (X, Y), definition: Definition[A]): C = {
+ val ret = that(definition.proto)
+ (
+ lookupableX.definitionLookup[A](_ => ret._1, definition),
+ lookupableY.definitionLookup[A](_ => ret._2, definition)
+ )
+ }
+ def instanceLookup[A](that: A => (X, Y), instance: Instance[A]): C = {
+ import instance._
+ val ret = that(proto)
+ (lookupableX.instanceLookup[A](_ => ret._1, instance), lookupableY.instanceLookup[A](_ => ret._2, instance))
+ }
+ }
+
implicit def lookupIsInstantiable[B <: IsInstantiable](
implicit sourceInfo: SourceInfo,
compileOptions: CompileOptions