summaryrefslogtreecommitdiff
path: root/core/src/main/scala/chisel3/experimental/hierarchy/LibraryHooks.scala
blob: d4818f6391686348158097862f8c255e89e62b61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// SPDX-License-Identifier: Apache-2.0

package chisel3.experimental.hierarchy

import scala.annotation.implicitNotFound

@implicitNotFound("These functions are only for building hierarchy-compatible Chisel libraries! Users beware!")
// DO NOT extend unless you know what you are doing!!!!!! Not for the casual user!
trait InsideHierarchyLibraryExtension

// Collection of public functions to give non-core-Chisel libraries the ability to build integrations with
// the experimental hierarchy package
object LibraryHooks {

  /** Builds a new instance given a definition and function to create a new instance-specific Underlying, from the
    * definition's Underlying
    * @note Implicitly requires being inside a Hierarchy Library Extension
    */
  def buildInstance[A](
    definition:       Definition[A],
    createUnderlying: Underlying[A] => Underlying[A]
  )(
    implicit inside: InsideHierarchyLibraryExtension
  ): Instance[A] = {
    new Instance(createUnderlying(definition.underlying))
  }

  /** Builds a new definition given an Underlying implementation
    * @note Implicitly requires being inside a Hierarchy Library Extension
    */
  def buildDefinition[A](underlying: Underlying[A])(implicit inside: InsideHierarchyLibraryExtension): Definition[A] = {
    new Definition(underlying)
  }
}