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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
// See LICENSE for license details.
package object chisel3 { // scalastyle:ignore package.object.name
import scala.language.experimental.macros
import internal.firrtl.{Width, NumericBound}
import internal.sourceinfo.{SourceInfo, SourceInfoTransform}
import util.BitPat
import chisel3.core.{Binding, FlippedBinder}
import chisel3.util._
import chisel3.internal.firrtl.Port
type Direction = chisel3.core.Direction
val Input = chisel3.core.Input
val Output = chisel3.core.Output
val Flipped = chisel3.core.Flipped
type Data = chisel3.core.Data
val Wire = chisel3.core.Wire
val Clock = chisel3.core.Clock
type Clock = chisel3.core.Clock
type Aggregate = chisel3.core.Aggregate
val Vec = chisel3.core.Vec
type Vec[T <: Data] = chisel3.core.Vec[T]
type VecLike[T <: Data] = chisel3.core.VecLike[T]
type Bundle = chisel3.core.Bundle
val assert = chisel3.core.assert
type Element = chisel3.core.Element
type Bits = chisel3.core.Bits
/** This contains literal constructor factory methods that are deprecated as of Chisel3.
* These will be removed very soon. It's recommended you move your code soon.
*
* Some recommended regex replacements:
* (note: these are not guaranteed to handle all edge cases! check all replacements!)
* Bool((true|false)) => $1.B
* UInt\(width\s*=\s*(\d+|[_a-zA-Z][_0-9a-zA-Z]*)\) => UInt($1.W)
* (UInt|SInt|Bits).width\((\d+|[_a-zA-Z][_0-9a-zA-Z]*)\) => $1($2.W)
* (U|S)Int\((-?\d+|0[xX][0-9a-fA-F]+)\) => $2.$1
* UInt\((\d+|0[xX][0-9a-fA-F]+),\s*(?:width)?\s*=\s*(\d+)\) => $1.U($2.W)
* (UInt|SInt)\(([_a-zA-Z][_0-9a-zA-Z]*)\) => $2.as$1
*/
trait UIntFactory extends chisel3.core.UIntFactory {
/** Create a UInt literal with inferred width. */
@deprecated("use n.U", "chisel3, will be removed by end of 2016")
def apply(n: String): UInt = Lit(chisel3.core.fromStringToLiteral.parse(n),
chisel3.core.fromStringToLiteral.parsedWidth(n))
/** Create a UInt literal with fixed width. */
@deprecated("use n.U(width.W)", "chisel3, will be removed by end of 2016")
def apply(n: String, width: Int): UInt = Lit(chisel3.core.fromStringToLiteral.parse(n),
Width(width))
/** Create a UInt literal with specified width. */
@deprecated("use value.U(width)", "chisel3, will be removed by end of 2016")
def apply(value: BigInt, width: Width): UInt = Lit(value, width)
/** Create a UInt literal with fixed width. */
@deprecated("use value.U(width.W)", "chisel3, will be removed by end of 2016")
def apply(value: BigInt, width: Int): UInt = Lit(value, Width(width))
/** Create a UInt with a specified width - compatibility with Chisel2. */
@deprecated("use UInt(width.W)", "chisel3, will be removed by end of 2016")
def apply(dir: Option[Direction] = None, width: Int): UInt = apply(Width(width))
/** Create a UInt literal with inferred width.- compatibility with Chisel2. */
@deprecated("use value.U", "chisel3, will be removed by end of 2016")
def apply(value: BigInt): UInt = apply(value, Width())
/** Create a UInt with a specified width */
@deprecated("use UInt(width.W)", "chisel3, will be removed by end of 2016")
def width(width: Int): UInt = apply(Width(width))
/** Create a UInt port with specified width. */
@deprecated("use UInt(width)", "chisel3, will be removed by end of 2016")
def width(width: Width): UInt = apply(width)
}
/** This contains literal constructor factory methods that are deprecated as of Chisel3.
* These will be removed very soon. It's recommended you move your code soon.
*/
trait SIntFactory extends chisel3.core.SIntFactory {
/** Create a SInt type or port with fixed width. */
@deprecated("use SInt(width.W)", "chisel3, will be removed by end of 2016")
def width(width: Int): SInt = apply(Width(width))
/** Create an SInt type with specified width. */
@deprecated("use SInt(width)", "chisel3, will be removed by end of 2016")
def width(width: Width): SInt = apply(width)
/** Create an SInt literal with inferred width. */
@deprecated("use value.S", "chisel3, will be removed by end of 2016")
def apply(value: BigInt): SInt = Lit(value)
/** Create an SInt literal with fixed width. */
@deprecated("use value.S(width.W)", "chisel3, will be removed by end of 2016")
def apply(value: BigInt, width: Int): SInt = Lit(value, width)
/** Create an SInt literal with specified width. */
@deprecated("use value.S(width)", "chisel3, will be removed by end of 2016")
def apply(value: BigInt, width: Width): SInt = Lit(value, width)
@deprecated("use value.S", "chisel3, will be removed by end of 2016")
def Lit(value: BigInt): SInt = Lit(value, Width())
@deprecated("use value.S(width)", "chisel3, will be removed by end of 2016")
def Lit(value: BigInt, width: Int): SInt = Lit(value, Width(width))
}
/** This contains literal constructor factory methods that are deprecated as of Chisel3.
* These will be removed very soon. It's recommended you move your code soon.
*/
trait BoolFactory extends chisel3.core.BoolFactory {
/** Creates Bool literal.
*/
@deprecated("use x.B", "chisel3, will be removed by end of 2016")
def apply(x: Boolean): Bool = Lit(x)
}
object Bits extends UIntFactory
type Num[T <: Data] = chisel3.core.Num[T]
type UInt = chisel3.core.UInt
object UInt extends UIntFactory
type SInt = chisel3.core.SInt
object SInt extends SIntFactory
type FixedPoint = chisel3.core.FixedPoint
val FixedPoint = chisel3.core.FixedPoint
type Bool = chisel3.core.Bool
object Bool extends BoolFactory
val Mux = chisel3.core.Mux
type BlackBox = chisel3.core.BlackBox
val Mem = chisel3.core.Mem
type MemBase[T <: Data] = chisel3.core.MemBase[T]
type Mem[T <: Data] = chisel3.core.Mem[T]
val SeqMem = chisel3.core.SeqMem
type SeqMem[T <: Data] = chisel3.core.SeqMem[T]
val Module = chisel3.core.Module
type Module = chisel3.core.Module
val printf = chisel3.core.printf
val Reg = chisel3.core.Reg
val when = chisel3.core.when
type WhenContext = chisel3.core.WhenContext
type Printable = chisel3.core.Printable
val Printable = chisel3.core.Printable
type Printables = chisel3.core.Printables
val Printables = chisel3.core.Printables
type PString = chisel3.core.PString
val PString = chisel3.core.PString
type FirrtlFormat = chisel3.core.FirrtlFormat
val FirrtlFormat = chisel3.core.FirrtlFormat
type Decimal = chisel3.core.Decimal
val Decimal = chisel3.core.Decimal
type Hexadecimal = chisel3.core.Hexadecimal
val Hexadecimal = chisel3.core.Hexadecimal
type Binary = chisel3.core.Binary
val Binary = chisel3.core.Binary
type Character = chisel3.core.Character
val Character = chisel3.core.Character
type Name = chisel3.core.Name
val Name = chisel3.core.Name
type FullName = chisel3.core.FullName
val FullName = chisel3.core.FullName
val Percent = chisel3.core.Percent
/** Implicit for custom Printable string interpolator */
implicit class PrintableHelper(val sc: StringContext) extends AnyVal {
/** Custom string interpolator for generating Printables: p"..."
* Will call .toString on any non-Printable arguments (mimicking s"...")
*/
def p(args: Any*): Printable = {
sc.checkLengths(args) // Enforce sc.parts.size == pargs.size + 1
val pargs: Seq[Option[Printable]] = args map {
case p: Printable => Some(p)
case d: Data => Some(d.toPrintable)
case any => for {
v <- Option(any) // Handle null inputs
str = v.toString
if !str.isEmpty // Handle empty Strings
} yield PString(str)
}
val parts = sc.parts map StringContext.treatEscapes
// Zip sc.parts and pargs together ito flat Seq
// eg. Seq(sc.parts(0), pargs(0), sc.parts(1), pargs(1), ...)
val seq = for { // append None because sc.parts.size == pargs.size + 1
(literal, arg) <- parts zip (pargs :+ None)
optPable <- Seq(Some(PString(literal)), arg)
pable <- optPable // Remove Option[_]
} yield pable
Printables(seq)
}
}
implicit def string2Printable(str: String): Printable = PString(str)
implicit class fromtIntToLiteral(override val x: Int) extends chisel3.core.fromIntToLiteral(x)
implicit class fromBigIntToLiteral(override val x: BigInt) extends chisel3.core.fromBigIntToLiteral(x)
implicit class fromStringToLiteral(override val x: String) extends chisel3.core.fromStringToLiteral(x)
implicit class fromBooleanToLiteral(override val x: Boolean) extends chisel3.core.fromBooleanToLiteral(x)
implicit class fromDoubleToLiteral(override val x: Double) extends chisel3.core.fromDoubleToLiteral(x)
implicit class fromIntToWidth(override val x: Int) extends chisel3.core.fromIntToWidth(x)
implicit class fromUIntToBitPatComparable(val x: UInt) extends AnyVal {
final def === (that: BitPat): Bool = macro SourceInfoTransform.thatArg
@deprecated("Use '=/=', which avoids potential precedence problems", "chisel3")
final def != (that: BitPat): Bool = macro SourceInfoTransform.thatArg
final def =/= (that: BitPat): Bool = macro SourceInfoTransform.thatArg
def do_=== (that: BitPat)(implicit sourceInfo: SourceInfo): Bool = that === x // scalastyle:ignore method.name
def do_!= (that: BitPat)(implicit sourceInfo: SourceInfo): Bool = that != x // scalastyle:ignore method.name
def do_=/= (that: BitPat)(implicit sourceInfo: SourceInfo): Bool = that =/= x // scalastyle:ignore method.name
}
// Compatibility with existing code.
val INPUT = chisel3.core.Direction.Input
val OUTPUT = chisel3.core.Direction.Output
val NODIR = chisel3.core.Direction.Unspecified
type ChiselException = chisel3.internal.ChiselException
// Debugger/Tester access to internal Chisel data structures and methods.
def getDataElements(a: Aggregate): Seq[Element] = {
a.allElements
}
def getModulePorts(m: Module): Seq[Port] = m.getPorts
def getFirrtlDirection(d: Data): Direction = chisel3.core.Data.getFirrtlDirection(d)
/** Package for experimental features, which may have their API changed, be removed, etc.
*
* Because its contents won't necessarily have the same level of stability and support as
* non-experimental, you must explicitly import this package to use its contents.
*/
object experimental {
type Param = chisel3.core.Param
type IntParam = chisel3.core.IntParam
val IntParam = chisel3.core.IntParam
type DoubleParam = chisel3.core.DoubleParam
val DoubleParam = chisel3.core.DoubleParam
type StringParam = chisel3.core.StringParam
val StringParam = chisel3.core.StringParam
type RawParam = chisel3.core.RawParam
val RawParam = chisel3.core.RawParam
// Implicit conversions for BlackBox Parameters
implicit def fromIntToIntParam(x: Int): IntParam = IntParam(BigInt(x))
implicit def fromLongToIntParam(x: Long): IntParam = IntParam(BigInt(x))
implicit def fromBigIntToIntParam(x: BigInt): IntParam = IntParam(x)
implicit def fromDoubleToDoubleParam(x: Double): DoubleParam = DoubleParam(x)
implicit def fromStringToStringParam(x: String): StringParam = StringParam(x)
implicit class ChiselRange(val sc: StringContext) extends AnyVal {
/** Specifies a range using mathematical range notation. Variables can be interpolated using
* standard string interpolation syntax.
* @example {{{
* UInt(range"[0, 2)")
* UInt(range"[0, $myInt)")
* UInt(range"[0, ${myInt + 2})")
* }}}
*/
def range(args: Any*): (NumericBound[Int], NumericBound[Int]) = macro chisel3.internal.RangeTransform.apply
}
}
}
|