Skip to content

Commit 565026f

Browse files
committed
Add register initialization option to commandline
1 parent 001df5a commit 565026f

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

docs/cli.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ See `./Ripes --help` for further information.
3838
| --pipeline | Report pipeline state |
3939
| --regs | Report register values |
4040
| --runinfo | Report simulation information in output (processor configuration, input file, ...) |
41+
| --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>` |
42+
4143

src/cli/clioptions.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "clioptions.h"
22
#include "processorregistry.h"
3+
#include "radix.h"
34
#include "telemetry.h"
45
#include <QFile>
56
#include <QMetaEnum>
@@ -23,6 +24,12 @@ void addCLIOptions(QCommandLineParser &parser, Ripes::CLIModeOptions &options) {
2324
"ISA extensions to enable (comma "
2425
"separated)",
2526
"extensions", ""));
27+
parser.addOption(QCommandLineOption(
28+
"reginit",
29+
"Comma-separated list of register initialization values. The register "
30+
"value may be specified in signed, hex, or boolean notation. Format:\n"
31+
"<register idx>=<value>,<register idx>=<value>",
32+
"[rid:v]"));
2633
parser.addOption(QCommandLineOption(
2734
"timeout",
2835
"Simulation timeout in milliseconds. If simulation does not finish "
@@ -127,6 +134,49 @@ bool parseCLIOptions(QCommandLineParser &parser, QString &errorMessage,
127134

128135
options.outputFile = parser.value("output");
129136

137+
// Validate register initializations
138+
if (parser.isSet("reginit")) {
139+
QStringList regInitList = parser.value("reginit").split(",");
140+
for (auto &regInit : regInitList) {
141+
QStringList regInitParts = regInit.split("=");
142+
if (regInitParts.size() != 2) {
143+
errorMessage = "Invalid register initialization '" + regInit +
144+
"' specified (--reginit).";
145+
return false;
146+
}
147+
bool ok;
148+
int regIdx = regInitParts[0].toInt(&ok);
149+
if (!ok) {
150+
errorMessage = "Invalid register index '" + regInitParts[0] +
151+
"' specified (--reginit).";
152+
return false;
153+
}
154+
155+
auto &vstr = regInitParts[1];
156+
VInt regVal;
157+
if (vstr.startsWith("0x"))
158+
regVal = decodeRadixValue(vstr, Radix::Hex, &ok);
159+
else if (vstr.startsWith("0b"))
160+
regVal = decodeRadixValue(vstr, Radix::Binary, &ok);
161+
else
162+
regVal = decodeRadixValue(vstr, Radix::Signed, &ok);
163+
164+
if (!ok) {
165+
errorMessage =
166+
"Invalid register value '" + vstr + "' specified (--reginit).";
167+
return false;
168+
}
169+
170+
if (options.regInit.count(regIdx) > 0) {
171+
errorMessage = "Duplicate register initialization for register " +
172+
QString::number(regIdx) + " specified (--reginit).";
173+
return false;
174+
}
175+
176+
options.regInit[regIdx] = regVal;
177+
}
178+
}
179+
130180
// Enable selected telemetry options.
131181
for (auto &telemetry : options.telemetry)
132182
if (parser.isSet("all") || parser.isSet(telemetry->key()))

src/cli/clioptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct CLIModeOptions {
1717
QString outputFile = "";
1818
bool jsonOutput = false;
1919
int timeout = 0;
20+
RegisterInitialization regInit;
2021

2122
// A list of enabled telemetry options.
2223
std::vector<std::shared_ptr<Telemetry>> telemetry;

src/cli/clirunner.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ static QString qVariantToString(QVariant &v) {
3535
CLIRunner::CLIRunner(const CLIModeOptions &options)
3636
: QObject(), m_options(options) {
3737
info("Ripes CLI mode", false, true);
38-
ProcessorHandler::selectProcessor(m_options.proc, m_options.isaExtensions);
38+
ProcessorHandler::selectProcessor(m_options.proc, m_options.isaExtensions,
39+
m_options.regInit);
3940

4041
// Connect systemIO output to stdout.
4142
connect(&SystemIO::get(), &SystemIO::doPrint, this, [&](auto text) {

0 commit comments

Comments
 (0)