From b4fc5104d4ded3b82cacc1224f0030a07a49a992 Mon Sep 17 00:00:00 2001 From: Jacob Chang Date: Tue, 19 Sep 2017 19:26:54 -0700 Subject: [PATCH] Add cover property API that can be refined through Config PropertyLibrary (#998) --- src/main/scala/tilelink/ToAXI4.scala | 2 +- src/main/scala/util/Property.scala | 58 ++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/main/scala/util/Property.scala diff --git a/src/main/scala/tilelink/ToAXI4.scala b/src/main/scala/tilelink/ToAXI4.scala index 3d9d4784..a4588006 100644 --- a/src/main/scala/tilelink/ToAXI4.scala +++ b/src/main/scala/tilelink/ToAXI4.scala @@ -48,7 +48,7 @@ case class TLToAXI4Node(beatBytes: Int, stripBits: Int = 0) extends MixedAdapter minLatency = p.minLatency) }) -class TLToAXI4(beatBytes: Int, combinational: Boolean = true, adapterName: Option[String] = None, stripBits: Int = 0)(implicit p: Parameters) extends LazyModule +class TLToAXI4(val beatBytes: Int, val combinational: Boolean = true, val adapterName: Option[String] = None, val stripBits: Int = 0)(implicit p: Parameters) extends LazyModule { val node = TLToAXI4Node(beatBytes, stripBits) diff --git a/src/main/scala/util/Property.scala b/src/main/scala/util/Property.scala new file mode 100644 index 00000000..f3c81672 --- /dev/null +++ b/src/main/scala/util/Property.scala @@ -0,0 +1,58 @@ +// See LICENSE.SiFive for license details. + +package freechips.rocketchip.util.property + +import Chisel._ +import chisel3.internal.sourceinfo.{SourceInfo, SourceLine} +import freechips.rocketchip.config.{Field, Parameters} + +case object PropertyLibrary extends Field[BasePropertyLibrary](new DefaultPropertyLibrary) + + +sealed abstract class PropertyType(name: String) { + override def toString: String = name +} + +object PropertyType { + object Assert extends PropertyType("Assert") + object Assume extends PropertyType("Assume") + object Cover extends PropertyType("Cover") +} + +trait BasePropertyParameters { + val pType: PropertyType + val cond: Bool + val label: String + val message: String +} + +case class CoverPropertyParameters( + cond: Bool, + label: String = "", + message: String = "") extends BasePropertyParameters { + val pType = PropertyType.Cover +} + +abstract class BasePropertyLibrary { + def generateProperty(prop_param: BasePropertyParameters)(implicit sourceInfo: SourceInfo) +} + +class DefaultPropertyLibrary extends BasePropertyLibrary { + def generateProperty(prop_param: BasePropertyParameters)(implicit sourceInfo: SourceInfo) { + // default is to do nothing + Unit + } +} + +object cover { + def apply(cond: Bool)(implicit sourceInfo: SourceInfo, p: Parameters): Unit = { + p(PropertyLibrary).generateProperty(CoverPropertyParameters(cond)) + } + def apply(cond: Bool, label: String)(implicit sourceInfo: SourceInfo, p: Parameters): Unit = { + p(PropertyLibrary).generateProperty(CoverPropertyParameters(cond, label)) + } + def apply(cond: Bool, label: String, message: String)(implicit sourceInfo: SourceInfo, p: Parameters): Unit = { + p(PropertyLibrary).generateProperty(CoverPropertyParameters(cond, label, message)) + } +} +