2016-11-28 01:16:37 +01:00
|
|
|
// See LICENSE.SiFive for license details.
|
|
|
|
|
2017-07-07 19:48:16 +02:00
|
|
|
package freechips.rocketchip
|
|
|
|
|
2016-10-04 00:17:36 +02:00
|
|
|
import chisel3.internal.sourceinfo.{SourceInfo, SourceLine, UnlocatableSourceInfo}
|
2017-09-07 00:30:25 +02:00
|
|
|
import freechips.rocketchip.config.Parameters
|
2016-10-04 00:17:36 +02:00
|
|
|
|
|
|
|
package object diplomacy
|
|
|
|
{
|
2017-11-02 01:03:01 +01:00
|
|
|
type SimpleNodeHandle[D, U, E, B <: Chisel.Data] = NodeHandle[D, U, E, B, D, U, E, B]
|
2017-10-27 09:26:35 +02:00
|
|
|
|
2016-10-04 00:17:36 +02:00
|
|
|
def sourceLine(sourceInfo: SourceInfo, prefix: String = " (", suffix: String = ")") = sourceInfo match {
|
|
|
|
case SourceLine(filename, line, col) => s"$prefix$filename:$line:$col$suffix"
|
|
|
|
case _ => ""
|
|
|
|
}
|
2017-03-01 02:50:54 +01:00
|
|
|
|
|
|
|
def bitIndexes(x: BigInt, tail: Seq[Int] = Nil): Seq[Int] = {
|
|
|
|
require (x >= 0)
|
|
|
|
if (x == 0) {
|
|
|
|
tail.reverse
|
|
|
|
} else {
|
|
|
|
val lowest = x.lowestSetBit
|
|
|
|
bitIndexes(x.clearBit(lowest), lowest +: tail)
|
|
|
|
}
|
|
|
|
}
|
2017-09-07 00:30:25 +02:00
|
|
|
|
2017-09-09 01:17:45 +02:00
|
|
|
implicit class BigIntHexContext(val sc: StringContext) extends AnyVal {
|
|
|
|
def x(args: Any*): BigInt = {
|
|
|
|
val orig = sc.s(args: _*)
|
|
|
|
BigInt(orig.replace("_", ""), 16)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-21 02:18:38 +01:00
|
|
|
type PropertyOption = Option[(String, Seq[ResourceValue])]
|
|
|
|
type PropertyMap = Iterable[(String, Seq[ResourceValue])]
|
|
|
|
|
|
|
|
implicit class IntToProperty(x: Int) {
|
|
|
|
def asProperty: Seq[ResourceValue] = Seq(ResourceInt(BigInt(x)))
|
|
|
|
}
|
|
|
|
|
|
|
|
implicit class BigIntToProperty(x: BigInt) {
|
|
|
|
def asProperty: Seq[ResourceValue] = Seq(ResourceInt(x))
|
|
|
|
}
|
|
|
|
|
|
|
|
implicit class StringToProperty(x: String) {
|
|
|
|
def asProperty: Seq[ResourceValue] = Seq(ResourceString(x))
|
|
|
|
}
|
|
|
|
|
|
|
|
implicit class DeviceToPeroperty(x: Device) {
|
|
|
|
def asProperty: Seq[ResourceValue] = Seq(ResourceReference(x.label))
|
|
|
|
}
|
|
|
|
|
2017-09-07 23:25:33 +02:00
|
|
|
def EnableMonitors[T](body: Parameters => T)(implicit p: Parameters) = body(p.alterPartial {
|
|
|
|
case MonitorsEnabled => true
|
|
|
|
})
|
|
|
|
def DisableMonitors[T](body: Parameters => T)(implicit p: Parameters) = body(p.alterPartial {
|
|
|
|
case MonitorsEnabled => false
|
|
|
|
})
|
2017-09-26 22:23:54 +02:00
|
|
|
def FlipRendering[T](body: Parameters => T)(implicit p: Parameters) = body(p.alterPartial {
|
|
|
|
case RenderFlipped => !p(RenderFlipped)
|
|
|
|
})
|
2016-10-04 00:17:36 +02:00
|
|
|
}
|