@@ -2,20 +2,32 @@ package dfhdl.platforms.resources
2
2
import dfhdl .internals .*
3
3
import dfhdl .core .*
4
4
import scala .annotation .Annotation
5
- import dfhdl .compiler .ir .constraints .Constraint
5
+ import dfhdl .compiler .ir .constraints .{ Constraint , SigConstraint }
6
6
import scala .collection .mutable .ListBuffer
7
7
8
8
trait ResourceContext extends OnCreateEvents , HasDFC , HasClsMetaArgs :
9
9
final lazy val dfc : DFC = __dfc
10
10
final lazy val id : String = dfc.nameOpt.get
11
- private var resourceConstraints = ListBuffer [Constraint ]()
12
- def getResourceConstraints : List [Constraint ] =
13
- resourceConstraints.toList ++ dfc.annotations.collect {
14
- case constraint : Constraint => constraint
15
- }
11
+ // the top-level resource owner is set to be itself
12
+ private [resources] val owner : ResourceOwner =
13
+ dfc.mutableDB.ResourceOwnershipContext .ownerOpt.getOrElse(this .asInstanceOf [ResourceOwner ])
14
+ private [resources] val isTopResource : Boolean =
15
+ dfc.mutableDB.ResourceOwnershipContext .ownerOpt.isEmpty
16
+ private var resourceConstraints = ListBuffer .from(dfc.annotations.collect {
17
+ case constraint : Constraint => constraint
18
+ })
19
+ def getResourceConstraints : List [Constraint ] = resourceConstraints.toList
20
+ // the constraints that are directly applied to this resource and its owners
21
+ private [resources] lazy val directAndOwnerSigConstraints : List [SigConstraint ] =
22
+ val ownerConstraints = if (isTopResource) Nil else owner.directAndOwnerSigConstraints
23
+ (ownerConstraints ++ getResourceConstraints.collect {
24
+ case constraint : SigConstraint => constraint
25
+ }).distinct
16
26
protected def __dfc : DFC =
17
27
println(" Severe error: missing DFHDL context!\n Make sure you enable the DFHDL compiler plugin." )
18
28
sys.exit(1 )
29
+ protected def injectConstraint (constraint : Constraint ): Unit =
30
+ resourceConstraints += constraint
19
31
protected def setClsNamePos (
20
32
name : String ,
21
33
position : Position ,
0 commit comments