From 4c7cda1c8b8a782da90f6bbd00e0a98aa1817f6e Mon Sep 17 00:00:00 2001 From: "N. Engelhardt" Date: Thu, 12 Dec 2019 16:14:20 +0100 Subject: add a command to read/modify scratchpad contents --- passes/cmds/scratchpad.cc | 86 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 passes/cmds/scratchpad.cc (limited to 'passes/cmds/scratchpad.cc') diff --git a/passes/cmds/scratchpad.cc b/passes/cmds/scratchpad.cc new file mode 100644 index 000000000..7d53c8a4f --- /dev/null +++ b/passes/cmds/scratchpad.cc @@ -0,0 +1,86 @@ +/* + * yosys -- Yosys Open SYnthesis Suite + * + * Copyright (C) 2012 Clifford Wolf + * + * 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"); + log(" scratchpad [ -get id | -set id val | -unset id | -copy id1 id2 ]\n"); + log("\n"); + log("This pass allows to read and modify values from the scratchpad of the current\n"); + log("design. Options:\n"); + log(" -get \n"); + log(" -set \n"); + log(" -unset \n"); + log(" -copy \n"); + 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 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; + } + log("Unrecognized argument: %s\n", args[argidx].c_str()); + break; + } + } +} ScratchpadPass; +PRIVATE_NAMESPACE_END -- cgit v1.2.3 From 1187e91c2f2684cb204c555cb3d53b68c7381c40 Mon Sep 17 00:00:00 2001 From: "N. Engelhardt" Date: Thu, 12 Dec 2019 20:51:59 +0100 Subject: add test and make help message more verbose --- passes/cmds/scratchpad.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'passes/cmds/scratchpad.cc') diff --git a/passes/cmds/scratchpad.cc b/passes/cmds/scratchpad.cc index 7d53c8a4f..c11c41caf 100644 --- a/passes/cmds/scratchpad.cc +++ b/passes/cmds/scratchpad.cc @@ -2,6 +2,7 @@ * yosys -- Yosys Open SYnthesis Suite * * Copyright (C) 2012 Clifford Wolf + * 2019 Nina Engelhardt * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -30,14 +31,18 @@ struct ScratchpadPass : public Pass { { // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---| log("\n"); - log(" scratchpad [ -get id | -set id val | -unset id | -copy id1 id2 ]\n"); + log(" scratchpad [options]\n"); log("\n"); log("This pass allows to read and modify values from the scratchpad of the current\n"); log("design. Options:\n"); log(" -get \n"); + log(" print the value saved in the scratchpad under the given identifier\n"); log(" -set \n"); + log(" save the given value in the scratchpad under the given identifier\n"); log(" -unset \n"); + log(" remove the entry for the given identifier from the scratchpad\n"); log(" -copy \n"); + log(" copy the value of the first identifier to the second identifier\n"); 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"); -- cgit v1.2.3 From ce3615b3670b942ae281db425b290023b1395b69 Mon Sep 17 00:00:00 2001 From: "N. Engelhardt" Date: Fri, 13 Dec 2019 10:28:34 +0100 Subject: add periods and newlines to help message --- passes/cmds/scratchpad.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'passes/cmds/scratchpad.cc') diff --git a/passes/cmds/scratchpad.cc b/passes/cmds/scratchpad.cc index c11c41caf..6bf14a6bd 100644 --- a/passes/cmds/scratchpad.cc +++ b/passes/cmds/scratchpad.cc @@ -34,15 +34,15 @@ struct ScratchpadPass : public Pass { log(" scratchpad [options]\n"); log("\n"); log("This pass allows to read and modify values from the scratchpad of the current\n"); - log("design. Options:\n"); + log("design. Options:\n\n"); log(" -get \n"); - log(" print the value saved in the scratchpad under the given identifier\n"); + log(" print the value saved in the scratchpad under the given identifier.\n\n"); log(" -set \n"); - log(" save the given value in the scratchpad under the given identifier\n"); + log(" save the given value in the scratchpad under the given identifier.\n\n"); log(" -unset \n"); - log(" remove the entry for the given identifier from the scratchpad\n"); + log(" remove the entry for the given identifier from the scratchpad.\n\n"); log(" -copy \n"); - log(" copy the value of the first identifier to the second identifier\n"); + log(" copy the value of the first identifier to the second identifier.\n\n"); 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"); -- cgit v1.2.3 From abcd82dacadc8b5af6b2b7f6d7cbdb635d276440 Mon Sep 17 00:00:00 2001 From: "N. Engelhardt" Date: Mon, 16 Dec 2019 13:09:31 +0100 Subject: add assert option to scratchpad command --- passes/cmds/scratchpad.cc | 49 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) (limited to 'passes/cmds/scratchpad.cc') diff --git a/passes/cmds/scratchpad.cc b/passes/cmds/scratchpad.cc index 6bf14a6bd..805badc7e 100644 --- a/passes/cmds/scratchpad.cc +++ b/passes/cmds/scratchpad.cc @@ -34,15 +34,29 @@ struct ScratchpadPass : public Pass { log(" scratchpad [options]\n"); log("\n"); log("This pass allows to read and modify values from the scratchpad of the current\n"); - log("design. Options:\n\n"); + log("design. Options:\n"); + log("\n"); log(" -get \n"); - log(" print the value saved in the scratchpad under the given identifier.\n\n"); + log(" print the value saved in the scratchpad under the given identifier.\n"); + log("\n"); log(" -set \n"); - log(" save the given value in the scratchpad under the given identifier.\n\n"); + log(" save the given value in the scratchpad under the given identifier.\n"); + log("\n"); log(" -unset \n"); - log(" remove the entry for the given identifier from the scratchpad.\n\n"); + log(" remove the entry for the given identifier from the scratchpad.\n"); + log("\n"); log(" -copy \n"); - log(" copy the value of the first identifier to the second identifier.\n\n"); + log(" copy the value of the first identifier to the second identifier.\n"); + log("\n"); + log(" -assert \n"); + log(" assert that the entry for the given identifier is set to the given value.\n"); + log("\n"); + log(" -assert-set \n"); + log(" assert that the entry for the given identifier exists.\n"); + log("\n"); + log(" -assert-unset \n"); + log(" assert that the entry for the given identifier does not exist.\n"); + log("\n"); 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"); @@ -83,6 +97,31 @@ struct ScratchpadPass : public Pass { design->scratchpad_set_string(identifier_to, value); continue; } + 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; + } log("Unrecognized argument: %s\n", args[argidx].c_str()); break; } -- cgit v1.2.3 From 3671ecc7d0b3792c61ceee858435b3b75ad4739c Mon Sep 17 00:00:00 2001 From: "N. Engelhardt" Date: Wed, 18 Dec 2019 12:30:30 +0100 Subject: use extra_args --- passes/cmds/scratchpad.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'passes/cmds/scratchpad.cc') diff --git a/passes/cmds/scratchpad.cc b/passes/cmds/scratchpad.cc index 805badc7e..7ec55b78e 100644 --- a/passes/cmds/scratchpad.cc +++ b/passes/cmds/scratchpad.cc @@ -122,9 +122,9 @@ struct ScratchpadPass : public Pass { log_error("Assertion failed: scratchpad entry '%s' is defined\n", identifier.c_str()); continue; } - log("Unrecognized argument: %s\n", args[argidx].c_str()); break; } + extra_args(args, argidx, design, false); } } ScratchpadPass; PRIVATE_NAMESPACE_END -- cgit v1.2.3 From a63e2508fcca395e795029d5c57c59acc63a9959 Mon Sep 17 00:00:00 2001 From: Eddie Hung Date: Tue, 7 Jan 2020 12:52:03 -0800 Subject: Add RTLIL::constpad, init by yosys_setup(); use for abc9 --- passes/cmds/scratchpad.cc | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'passes/cmds/scratchpad.cc') diff --git a/passes/cmds/scratchpad.cc b/passes/cmds/scratchpad.cc index 7ec55b78e..34ec0863a 100644 --- a/passes/cmds/scratchpad.cc +++ b/passes/cmds/scratchpad.cc @@ -70,8 +70,10 @@ struct ScratchpadPass : public Pass { { if (args[argidx] == "-get" && argidx+1 < args.size()) { string identifier = args[++argidx]; - if (design->scratchpad.count(identifier)){ + if (design->scratchpad.count(identifier)) { log("%s\n", design->scratchpad_get_string(identifier).c_str()); + } else if (RTLIL::constpad.count(identifier)) { + log("%s\n", RTLIL::constpad.at(identifier).c_str()); } else { log("\"%s\" not set\n", identifier.c_str()); } @@ -79,6 +81,8 @@ struct ScratchpadPass : public Pass { } if (args[argidx] == "-set" && argidx+2 < args.size()) { string identifier = args[++argidx]; + if (RTLIL::constpad.count(identifier)) + log_error("scratchpad entry \"%s\" is a global constant\n", identifier.c_str()); string value = args[++argidx]; if (value.front() == '\"' && value.back() == '\"') value = value.substr(1, value.size() - 2); design->scratchpad_set_string(identifier, value); @@ -92,8 +96,15 @@ struct ScratchpadPass : public Pass { 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); + string value; + if (design->scratchpad.count(identifier_from)) + value = design->scratchpad_get_string(identifier_from); + else if (RTLIL::constpad.count(identifier_from)) + value = RTLIL::constpad.at(identifier_from); + else + log_error("\"%s\" not set\n", identifier_from.c_str()); + if (RTLIL::constpad.count(identifier_to)) + log_error("scratchpad entry \"%s\" is a global constant\n", identifier_to.c_str()); design->scratchpad_set_string(identifier_to, value); continue; } @@ -102,10 +113,10 @@ struct ScratchpadPass : public Pass { 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()); + log_error("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", + log_error("scratchpad entry '%s' is set to '%s' instead of the asserted '%s'\n", identifier.c_str(), value.c_str(), expected.c_str()); } continue; @@ -113,13 +124,13 @@ struct ScratchpadPass : public Pass { 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()); + log_error("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()); + log_error("scratchpad entry '%s' is defined\n", identifier.c_str()); continue; } break; -- cgit v1.2.3