Add register initialization option to commandline
MODIFY
docs/cli.md
docs/cli.md
@@ -38,4 +38,6 @@ See `./Ripes --help` for further information.
| --pipeline | Report pipeline state |
| --regs | Report register values |
| --runinfo | Report simulation information in output (processor configuration, input file, ...) |
+| --reginit <[rid:v]>| Comma-separated list of register initialization values. The register value may be specified in signed, hex, or boolean notation. Format: `<register idx>=<value>,<register idx>=<value>` |
+

MODIFY
src/cli/clioptions.cpp
src/cli/clioptions.cpp
#include "clioptions.h"
#include "processorregistry.h"
+#include "radix.h"
#include "telemetry.h"
#include <QFile>
#include <QMetaEnum>
@@ -23,6 +24,12 @@ void addCLIOptions(QCommandLineParser &parser, Ripes::CLIModeOptions &options) {
"ISA extensions to enable (comma "
"separated)",
"extensions", ""));
+ parser.addOption(QCommandLineOption(
+ "reginit",
+ "Comma-separated list of register initialization values. The register "
+ "value may be specified in signed, hex, or boolean notation. Format:\n"
+ "<register idx>=<value>,<register idx>=<value>",
+ "[rid:v]"));
parser.addOption(QCommandLineOption(
"timeout",
"Simulation timeout in milliseconds. If simulation does not finish "
@@ -127,6 +134,49 @@ bool parseCLIOptions(QCommandLineParser &parser, QString &errorMessage,
options.outputFile = parser.value("output");
+ // Validate register initializations
+ if (parser.isSet("reginit")) {
+ QStringList regInitList = parser.value("reginit").split(",");
+ for (auto &regInit : regInitList) {
+ QStringList regInitParts = regInit.split("=");
+ if (regInitParts.size() != 2) {
+ errorMessage = "Invalid register initialization '" + regInit +
+ "' specified (--reginit).";
+ return false;
+ }
+ bool ok;
+ int regIdx = regInitParts[0].toInt(&ok);
+ if (!ok) {
+ errorMessage = "Invalid register index '" + regInitParts[0] +
+ "' specified (--reginit).";
+ return false;
+ }
+
+ auto &vstr = regInitParts[1];
+ VInt regVal;
+ if (vstr.startsWith("0x"))
+ regVal = decodeRadixValue(vstr, Radix::Hex, &ok);
+ else if (vstr.startsWith("0b"))
+ regVal = decodeRadixValue(vstr, Radix::Binary, &ok);
+ else
+ regVal = decodeRadixValue(vstr, Radix::Signed, &ok);
+
+ if (!ok) {
+ errorMessage =
+ "Invalid register value '" + vstr + "' specified (--reginit).";
+ return false;
+ }
+
+ if (options.regInit.count(regIdx) > 0) {
+ errorMessage = "Duplicate register initialization for register " +
+ QString::number(regIdx) + " specified (--reginit).";
+ return false;
+ }
+
+ options.regInit[regIdx] = regVal;
+ }
+ }
+
// Enable selected telemetry options.
for (auto &telemetry : options.telemetry)
if (parser.isSet("all") || parser.isSet(telemetry->key()))

MODIFY
src/cli/clioptions.h
src/cli/clioptions.h
@@ -17,6 +17,7 @@ struct CLIModeOptions {
QString outputFile = "";
bool jsonOutput = false;
int timeout = 0;
+ RegisterInitialization regInit;
// A list of enabled telemetry options.
std::vector<std::shared_ptr<Telemetry>> telemetry;

MODIFY
src/cli/clirunner.cpp
src/cli/clirunner.cpp
@@ -35,7 +35,8 @@ static QString qVariantToString(QVariant &v) {
CLIRunner::CLIRunner(const CLIModeOptions &options)
: QObject(), m_options(options) {
info("Ripes CLI mode", false, true);
- ProcessorHandler::selectProcessor(m_options.proc, m_options.isaExtensions);
+ ProcessorHandler::selectProcessor(m_options.proc, m_options.isaExtensions,
+ m_options.regInit);
// Connect systemIO output to stdout.
connect(&SystemIO::get(), &SystemIO::doPrint, this, [&](auto text) {

Add register initialization option to commandline