Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for emitting string-valued plusargs and plusargs with no default #2453

Merged
merged 5 commits into from
May 11, 2020
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions src/main/scala/util/PlusArg.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@ import chisel3._
import chisel3.experimental._
import chisel3.util.HasBlackBoxResource

@deprecated("This will be removed in Rocket Chip 2020.08", "Rocket Chip 2020.05")
case class PlusArgInfo(default: BigInt, docstring: String)

/** Case class for PlusArg information
*
* @tparam A scala type of the PlusArg value
* @param default optional default value
* @param docstring text to include in the help
* @param doctype description of the Verilog type of the PlusArg value (e.g. STRING, INT)
*/
private case class PlusArgContainer[A](default: Option[A], docstring: String, doctype: String)

class plusarg_reader(val format: String, val default: BigInt, val docstring: String, val width: Int) extends BlackBox(Map(
"FORMAT" -> StringParam(format),
"DEFAULT" -> IntParam(default),
Expand Down Expand Up @@ -40,7 +50,7 @@ object PlusArg
* pass.
*/
def apply(name: String, default: BigInt = 0, docstring: String = "", width: Int = 32): UInt = {
PlusArgArtefacts.append(name, default, docstring)
PlusArgArtefacts.append(name, Some(default), docstring)
Module(new plusarg_reader(name + "=%d", default, docstring, width)).io.out
}

Expand All @@ -49,25 +59,41 @@ object PlusArg
* Default 0 will never assert.
*/
def timeout(name: String, default: BigInt = 0, docstring: String = "", width: Int = 32)(count: UInt) {
PlusArgArtefacts.append(name, default, docstring)
PlusArgArtefacts.append(name, Some(default), docstring)
Module(new PlusArgTimeout(name + "=%d", default, docstring, width)).io.count := count
}
}

object PlusArgArtefacts {
private var artefacts: Map[String, PlusArgInfo] = Map.empty
private var artefacts: Map[String, PlusArgContainer[_]] = Map.empty

/* Add a new PlusArg */
@deprecated(
"Use `Some(BigInt)` to specify a `default` value. This will be removed in Rocket Chip 2020.08",
"Rocket Chip 2020.05"
)
def append(name: String, default: BigInt, docstring: String): Unit =
artefacts = artefacts ++ Map(name -> PlusArgInfo(default, docstring))
append(name, Some(default), docstring)

/** Add a new PlusArg
*
* @tparam A scala type of the PlusArg value
* @param name name for the PlusArg
* @param default optional default value
* @param docstring text to include in the help
* @param doctype description of the Verilog type of the PlusArg value (e.g. STRING, INT)
*/
def append[A](name: String, default: Option[A], docstring: String, doctype: String = "INT"): Unit =
jwright6323 marked this conversation as resolved.
Show resolved Hide resolved
artefacts = artefacts ++ Map(name -> PlusArgContainer[A](default, docstring, doctype))

/* From plus args, generate help text */
private def serializeHelp_cHeader(tab: String = ""): String = artefacts
.map{ case(arg, PlusArgInfo(default, docstring)) =>
s"""|$tab+$arg=INT\\n\\
|$tab${" "*20}$docstring\\n\\
|$tab${" "*22}(default=$default)""".stripMargin }.toSeq
.mkString("\\n\\\n") ++ "\""
.map{ case(arg, info) =>
s"""|$tab+$arg=${info.doctype}\\n\\
|$tab${" "*20}${info.docstring}\\n\\
|""".stripMargin ++ info.default.map{ case default =>
s"$tab${" "*22}(default=${default})\\n\\\n"}.getOrElse("")
}.toSeq.mkString("\\n\\\n") ++ "\""

/* From plus args, generate a char array of their names */
private def serializeArray_cHeader(tab: String = ""): String = {
Expand Down