Skip to content

Commit

Permalink
Add register initialization option to commandline
Browse files Browse the repository at this point in the history
  • Loading branch information
mortbopet committed Apr 3, 2022
1 parent 001df5a commit 565026f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>` |


50 changes: 50 additions & 0 deletions src/cli/clioptions.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "clioptions.h"
#include "processorregistry.h"
#include "radix.h"
#include "telemetry.h"
#include <QFile>
#include <QMetaEnum>
Expand All @@ -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 "
Expand Down Expand Up @@ -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()))
Expand Down
1 change: 1 addition & 0 deletions src/cli/clioptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/cli/clirunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 565026f

Please sign in to comment.