1
- /** this package contains all the dfhdl hardware annotations
2
- */
3
- package dfhdl .hw
4
-
1
+ package dfhdl .compiler .ir
5
2
import dfhdl .compiler .printing .{Printer , HasCodeString }
6
- import scala .annotation .StaticAnnotation
7
3
import dfhdl .internals .*
8
- import scala .annotation .Annotation
9
4
import upickle .default .*
10
5
import dfhdl .internals .StableEnum
11
- import dfhdl .compiler .ir .ConfigN
12
- import dfhdl .compiler .ir .{RateNumber , FreqNumber , TimeNumber }
13
6
14
7
object annotation :
15
- sealed abstract class HWAnnotation extends StaticAnnotation , Product , Serializable , HasCodeString
16
- derives CanEqual :
17
- val isActive : Boolean
8
+ sealed abstract class HWAnnotation extends Product , Serializable , HasCodeString derives CanEqual
18
9
19
- extension (annotList : List [Annotation ])
20
- def getActiveHWAnnotations : List [HWAnnotation ] = annotList.collect {
21
- case annot : HWAnnotation if annot.isActive => annot
22
- }
23
10
object HWAnnotation :
24
11
given ReadWriter [HWAnnotation ] = ReadWriter .merge(
25
- summon[ReadWriter [unused ]],
26
- summon[ReadWriter [pure ]],
27
- summon[ReadWriter [flattenMode ]],
12
+ summon[ReadWriter [Unused ]],
13
+ summon[ReadWriter [Pure . type ]],
14
+ summon[ReadWriter [FlattenMode ]],
28
15
summon[ReadWriter [constraints.Constraint ]]
29
16
)
30
17
31
- sealed trait unused extends HWAnnotation derives ReadWriter
32
- object unused :
33
- /** `quiet` suppresses the unused warning for the tagged value.
34
- */
35
- final case class quiet (isActive : Boolean ) extends unused :
36
- def this () = this (true )
37
- def codeString (using Printer ): String = " @hw.annotation.unused.quiet"
38
-
39
- /** `keep` suppresses the unused warning, and also attempts to keep the tagged value.
40
- */
41
- final case class keep (isActive : Boolean ) extends unused :
42
- def this () = this (true )
43
- def codeString (using Printer ): String = " @hw.annotation.unused.keep"
44
-
45
- /** `prune` removes all the redundant paths until and including the tagged value.
46
- */
47
- final case class prune (isActive : Boolean ) extends unused :
48
- def this () = this (true )
49
- def codeString (using Printer ): String = " @hw.annotation.unused.prune"
50
- end unused
18
+ enum Unused extends HWAnnotation derives ReadWriter :
19
+ case Quiet , Keep , Prune
20
+ def codeString (using Printer ): String =
21
+ this match
22
+ case Quiet => " @hw.annotation.unused.quiet"
23
+ case Keep => " @hw.annotation.unused.keep"
24
+ case Prune => " @hw.annotation.unused.prune"
51
25
52
- final case class pure ( isActive : Boolean ) extends HWAnnotation derives ReadWriter :
53
- def this () = this ( true )
26
+ case object Pure extends HWAnnotation :
27
+ given ReadWriter [ Pure . type ] = macroRW
54
28
def codeString (using Printer ): String = " @hw.annotation.pure"
55
29
56
30
/** Flattening Mode:
57
31
* - transparent: $memberName
58
32
* - prefix: $ownerName$sep$memberName
59
33
* - suffix: $memberName$sep$ownerName
60
34
*/
61
- enum flattenMode extends HWAnnotation , StableEnum derives CanEqual , ReadWriter :
62
- case transparent()
63
- case prefix(sep : String )
64
- case suffix(sep : String )
65
- val isActive : Boolean = true
35
+ enum FlattenMode extends HWAnnotation , StableEnum derives ReadWriter :
36
+ case Transparent
37
+ case Prefix (sep : String )
38
+ case Suffix (sep : String )
66
39
def codeString (using Printer ): String =
67
40
" @hw.annotation.flattenMode." + (
68
41
this match
69
- case transparent() => " transparent()"
70
- case prefix (sep) => s """ prefix(" $sep") """
71
- case suffix (sep) => s """ suffix(" $sep") """
42
+ case Transparent => " transparent()"
43
+ case Prefix (sep) => s """ prefix(" $sep") """
44
+ case Suffix (sep) => s """ suffix(" $sep") """
72
45
)
73
- object flattenMode :
74
- val defaultPrefixUnderscore = flattenMode.prefix (" _" )
46
+ object FlattenMode :
47
+ val defaultPrefixUnderscore = FlattenMode . Prefix (" _" )
75
48
end annotation
76
49
77
50
object constraints :
78
- sealed abstract class Constraint extends annotation.HWAnnotation derives ReadWriter :
79
- val isActive : Boolean = true
51
+ sealed abstract class Constraint extends annotation.HWAnnotation derives ReadWriter
80
52
sealed abstract class SigConstraint extends Constraint derives ReadWriter :
81
53
val bitIdx : ConfigN [Int ]
82
- final case class device (name : String , properties : Map [String , String ])
83
- extends Constraint
54
+ final case class Device (name : String , properties : Map [String , String ]) extends Constraint
84
55
derives CanEqual , ReadWriter :
85
56
def this (name : String , properties : (String , String )* ) =
86
57
this (name, properties.toMap)
@@ -97,13 +68,13 @@ object constraints:
97
68
case num : TimeNumber => s " $name = ${printer.csDFTimeData(num)}"
98
69
case _ => s " $name = ${value}"
99
70
100
- final case class io (
71
+ final case class IO (
101
72
bitIdx : ConfigN [Int ] = None ,
102
73
loc : ConfigN [String ] = None ,
103
- standard : ConfigN [io .Standard ] = None ,
104
- slewRate : ConfigN [io .SlewRate ] = None ,
74
+ standard : ConfigN [IO .Standard ] = None ,
75
+ slewRate : ConfigN [IO .SlewRate ] = None ,
105
76
driveStrength : ConfigN [Int ] = None ,
106
- pullMode : ConfigN [io .PullMode ] = None
77
+ pullMode : ConfigN [IO .PullMode ] = None
107
78
) extends SigConstraint derives CanEqual , ReadWriter :
108
79
def codeString (using Printer ): String =
109
80
val params = List (
@@ -116,8 +87,8 @@ object constraints:
116
87
).filter(_.nonEmpty).mkString(" , " )
117
88
s """ @io( $params) """
118
89
end codeString
119
- end io
120
- object io :
90
+ end IO
91
+ object IO :
121
92
enum Standard extends StableEnum , HasCodeString derives CanEqual , ReadWriter :
122
93
case LVCMOS33 , LVCMOS25 , LVCMOS18
123
94
def codeString (using Printer ): String = " io.Standard." + this .toString
@@ -128,8 +99,8 @@ object constraints:
128
99
case UP , DOWN
129
100
def codeString (using Printer ): String = " io.PullMode." + this .toString
130
101
131
- object timing :
132
- final case class ignore (
102
+ object Timing :
103
+ final case class Ignore (
133
104
bitIdx : ConfigN [Int ] = None ,
134
105
maxFreqMinPeriod : ConfigN [RateNumber ] = None
135
106
) extends SigConstraint
@@ -141,10 +112,10 @@ object constraints:
141
112
).filter(_.nonEmpty).mkString(" , " )
142
113
s """ @timing.ignore( $params) """
143
114
144
- final case class clock (
115
+ final case class Clock (
145
116
rate : RateNumber
146
117
) extends Constraint derives CanEqual , ReadWriter :
147
118
def codeString (using Printer ): String =
148
119
s """ @timing.clock( ${csParam(" rate" , rate)}) """
149
- end timing
120
+ end Timing
150
121
end constraints
0 commit comments