2019-12-12 09:14:20 -06:00
|
|
|
/*
|
|
|
|
* yosys -- Yosys Open SYnthesis Suite
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
|
2019-12-12 13:51:59 -06:00
|
|
|
* 2019 Nina Engelhardt <nak@symbioticeda.com>
|
2019-12-12 09:14:20 -06:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "kernel/register.h"
|
|
|
|
#include "kernel/rtlil.h"
|
|
|
|
#include "kernel/log.h"
|
|
|
|
|
|
|
|
USING_YOSYS_NAMESPACE
|
|
|
|
PRIVATE_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
struct ScratchpadPass : public Pass {
|
|
|
|
ScratchpadPass() : Pass("scratchpad", "get/set values in the scratchpad") { }
|
|
|
|
void help() YS_OVERRIDE
|
|
|
|
{
|
|
|
|
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
|
|
|
log("\n");
|
2019-12-12 13:51:59 -06:00
|
|
|
log(" scratchpad [options]\n");
|
2019-12-12 09:14:20 -06:00
|
|
|
log("\n");
|
|
|
|
log("This pass allows to read and modify values from the scratchpad of the current\n");
|
2019-12-16 06:09:31 -06:00
|
|
|
log("design. Options:\n");
|
|
|
|
log("\n");
|
2019-12-12 09:14:20 -06:00
|
|
|
log(" -get <identifier>\n");
|
2019-12-16 06:09:31 -06:00
|
|
|
log(" print the value saved in the scratchpad under the given identifier.\n");
|
|
|
|
log("\n");
|
2019-12-12 09:14:20 -06:00
|
|
|
log(" -set <identifier> <value>\n");
|
2019-12-16 06:09:31 -06:00
|
|
|
log(" save the given value in the scratchpad under the given identifier.\n");
|
|
|
|
log("\n");
|
2019-12-12 09:14:20 -06:00
|
|
|
log(" -unset <identifier>\n");
|
2019-12-16 06:09:31 -06:00
|
|
|
log(" remove the entry for the given identifier from the scratchpad.\n");
|
|
|
|
log("\n");
|
2019-12-12 09:14:20 -06:00
|
|
|
log(" -copy <identifier_from> <identifier_to>\n");
|
2019-12-16 06:09:31 -06:00
|
|
|
log(" copy the value of the first identifier to the second identifier.\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -assert <identifier> <value>\n");
|
|
|
|
log(" assert that the entry for the given identifier is set to the given value.\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -assert-set <identifier>\n");
|
|
|
|
log(" assert that the entry for the given identifier exists.\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -assert-unset <identifier>\n");
|
|
|
|
log(" assert that the entry for the given identifier does not exist.\n");
|
|
|
|
log("\n");
|
2019-12-12 09:14:20 -06:00
|
|
|
log("The identifier may not contain whitespace. By convention, it is usually prefixed\n");
|
|
|
|
log("by the name of the pass that uses it, e.g. 'opt.did_something'. If the value\n");
|
|
|
|
log("contains whitespace, it must be enclosed in double quotes.\n");
|
|
|
|
log("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
|
|
|
|
{
|
|
|
|
size_t argidx;
|
|
|
|
for (argidx = 1; argidx < args.size(); argidx++)
|
|
|
|
{
|
|
|
|
if (args[argidx] == "-get" && argidx+1 < args.size()) {
|
|
|
|
string identifier = args[++argidx];
|
|
|
|
if (design->scratchpad.count(identifier)){
|
|
|
|
log("%s\n", design->scratchpad_get_string(identifier).c_str());
|
|
|
|
} else {
|
|
|
|
log("\"%s\" not set\n", identifier.c_str());
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (args[argidx] == "-set" && argidx+2 < args.size()) {
|
|
|
|
string identifier = args[++argidx];
|
|
|
|
string value = args[++argidx];
|
|
|
|
if (value.front() == '\"' && value.back() == '\"') value = value.substr(1, value.size() - 2);
|
|
|
|
design->scratchpad_set_string(identifier, value);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (args[argidx] == "-unset" && argidx+1 < args.size()) {
|
|
|
|
string identifier = args[++argidx];
|
|
|
|
design->scratchpad_unset(identifier);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (args[argidx] == "-copy" && argidx+2 < args.size()) {
|
|
|
|
string identifier_from = args[++argidx];
|
|
|
|
string identifier_to = args[++argidx];
|
|
|
|
if (design->scratchpad.count(identifier_from) == 0) log_error("\"%s\" not set\n", identifier_from.c_str());
|
|
|
|
string value = design->scratchpad_get_string(identifier_from);
|
|
|
|
design->scratchpad_set_string(identifier_to, value);
|
|
|
|
continue;
|
|
|
|
}
|
2019-12-16 06:09:31 -06:00
|
|
|
if (args[argidx] == "-assert" && argidx+2 < args.size()) {
|
|
|
|
string identifier = args[++argidx];
|
|
|
|
string expected = args[++argidx];
|
|
|
|
if (expected.front() == '\"' && expected.back() == '\"') expected = expected.substr(1, expected.size() - 2);
|
|
|
|
if (design->scratchpad.count(identifier) == 0)
|
|
|
|
log_error("Assertion failed: scratchpad entry '%s' is not defined\n", identifier.c_str());
|
|
|
|
string value = design->scratchpad_get_string(identifier);
|
|
|
|
if (value != expected) {
|
|
|
|
log_error("Assertion failed: scratchpad entry '%s' is set to '%s' instead of the asserted '%s'\n",
|
|
|
|
identifier.c_str(), value.c_str(), expected.c_str());
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (args[argidx] == "-assert-set" && argidx+1 < args.size()) {
|
|
|
|
string identifier = args[++argidx];
|
|
|
|
if (design->scratchpad.count(identifier) == 0)
|
|
|
|
log_error("Assertion failed: scratchpad entry '%s' is not defined\n", identifier.c_str());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (args[argidx] == "-assert-unset" && argidx+1 < args.size()) {
|
|
|
|
string identifier = args[++argidx];
|
|
|
|
if (design->scratchpad.count(identifier) > 0)
|
|
|
|
log_error("Assertion failed: scratchpad entry '%s' is defined\n", identifier.c_str());
|
|
|
|
continue;
|
|
|
|
}
|
2019-12-12 09:14:20 -06:00
|
|
|
break;
|
|
|
|
}
|
2019-12-18 05:30:30 -06:00
|
|
|
extra_args(args, argidx, design, false);
|
2019-12-12 09:14:20 -06:00
|
|
|
}
|
|
|
|
} ScratchpadPass;
|
|
|
|
PRIVATE_NAMESPACE_END
|