Link PlusArg to emulator command line options
- adds a mutable singleton (PlusArgArtefacts) to store information about Rocket PlusArgs - adds methods to PlusArgArtefacts to emit C snippets that are consumed by emulator.cc for correct argument parsing and help text generation - emits snippets in $(CONFIG).plusArgs via BaseCoreplex-set ElaborationArtefacts - modify emulator/Makefrag-verilator to include $(CONFIG).plusArgs - cleanup help text (docstring) for existing PlusArgs Signed-off-by: Schuyler Eldridge <schuyler.eldridge@gmail.com>
This commit is contained in:
@ -4,6 +4,8 @@ package freechips.rocketchip.util
|
||||
|
||||
import Chisel._
|
||||
|
||||
case class PlusArgInfo(default: Int, docstring: String)
|
||||
|
||||
class plusarg_reader(val format: String, val default: Int, val docstring: String) extends BlackBox(Map(
|
||||
"FORMAT" -> chisel3.core.StringParam(format),
|
||||
"DEFAULT" -> chisel3.core.IntParam(default))) {
|
||||
@ -20,6 +22,42 @@ object PlusArg
|
||||
// Add a docstring to document the arg, which can be dumped in an elaboration
|
||||
// pass.
|
||||
|
||||
def apply(name: String, default: Int = 0, docstring: String = ""): UInt =
|
||||
def apply(name: String, default: Int = 0, docstring: String = ""): UInt = {
|
||||
PlusArgArtefacts.append(name, default, docstring)
|
||||
Module(new plusarg_reader(name + "=%d", default, docstring)).io.out
|
||||
}
|
||||
}
|
||||
|
||||
object PlusArgArtefacts {
|
||||
private var artefacts: Map[String, PlusArgInfo] = Map.empty
|
||||
|
||||
/* Add a new PlusArg */
|
||||
def append(name: String, default: Int, docstring: String): Unit =
|
||||
artefacts = artefacts ++ Map(name -> PlusArgInfo(default, docstring))
|
||||
|
||||
/* From plus args, generate help text */
|
||||
private def serializeHelp(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") ++ "\""
|
||||
|
||||
/* From plus args, generate a char array of their names */
|
||||
private def serializeArray(tab: String = ""): String = {
|
||||
val prettyTab = tab + " " * 44 // Length of 'static const ...'
|
||||
s"${tab}static const char * verilog_plusargs [] = {\\\n" ++
|
||||
artefacts
|
||||
.map{ case(arg, _) => s"""$prettyTab"$arg",\\\n""" }
|
||||
.mkString("")++
|
||||
s"${prettyTab}0};"
|
||||
}
|
||||
|
||||
/* Generate C code to be included in emulator.cc that helps with
|
||||
* argument parsing based on available Verilog PlusArgs */
|
||||
def serialize(): String =
|
||||
s"""|#define PLUSARG_USAGE_OPTIONS \"EMULATOR VERILOG PLUSARGS\\n\\
|
||||
|${serializeHelp(" "*7)}
|
||||
|${serializeArray()}
|
||||
|""".stripMargin
|
||||
}
|
||||
|
Reference in New Issue
Block a user