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
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
def LeftStar[T](body: Parameters => T)(implicit p: Parameters) = body(p.alterPartial {
|
|
|
|
case CardinalityInferenceDirectionKey => CardinalityInferenceDirection.SINK_TO_SOURCE
|
|
|
|
})
|
|
|
|
def RightStar[T](body: Parameters => T)(implicit p: Parameters) = body(p.alterPartial {
|
|
|
|
case CardinalityInferenceDirectionKey => CardinalityInferenceDirection.SOURCE_TO_SINK
|
|
|
|
})
|
|
|
|
def NoStar[T](body: Parameters => T)(implicit p: Parameters) = body(p.alterPartial {
|
|
|
|
case CardinalityInferenceDirectionKey => CardinalityInferenceDirection.NO_INFERENCE
|
|
|
|
})
|
|
|
|
def FlipStar[T](body: Parameters => T)(implicit p: Parameters) = body(p.alterPartial {
|
2017-09-07 22:33:07 +02:00
|
|
|
case CardinalityInferenceDirectionKey => p(CardinalityInferenceDirectionKey).flip
|
2017-09-07 00:30:25 +02:00
|
|
|
})
|
2016-10-04 00:17:36 +02:00
|
|
|
}
|