diff options
Diffstat (limited to 'passes/cmds')
| -rw-r--r-- | passes/cmds/Makefile.inc | 1 | ||||
| -rw-r--r-- | passes/cmds/autoname.cc | 2 | ||||
| -rw-r--r-- | passes/cmds/scc.cc | 51 | ||||
| -rw-r--r-- | passes/cmds/scratchpad.cc | 141 | ||||
| -rw-r--r-- | passes/cmds/show.cc | 2 | 
5 files changed, 169 insertions, 28 deletions
| diff --git a/passes/cmds/Makefile.inc b/passes/cmds/Makefile.inc index c7edc30fb..07a5d3ddc 100644 --- a/passes/cmds/Makefile.inc +++ b/passes/cmds/Makefile.inc @@ -32,3 +32,4 @@ OBJS += passes/cmds/chtype.o  OBJS += passes/cmds/blackbox.o  OBJS += passes/cmds/ltp.o  OBJS += passes/cmds/bugpoint.o +OBJS += passes/cmds/scratchpad.o diff --git a/passes/cmds/autoname.cc b/passes/cmds/autoname.cc index 4614a8153..50632201e 100644 --- a/passes/cmds/autoname.cc +++ b/passes/cmds/autoname.cc @@ -56,7 +56,7 @@ int autoname_worker(Module *module)  			for (auto &conn : cell->connections()) {  				string suffix = stringf("_%s", log_id(conn.first));  				for (auto bit : conn.second) -					if (bit.wire != nullptr && bit.wire->name[0] == '$') { +					if (bit.wire != nullptr && bit.wire->name[0] == '$' && !bit.wire->port_id) {  						IdString new_name(cell->name.str() + suffix);  						int score = wire_score.at(bit.wire);  						if (cell->output(conn.first)) score = 0; diff --git a/passes/cmds/scc.cc b/passes/cmds/scc.cc index 99f4fbae8..ad0554bae 100644 --- a/passes/cmds/scc.cc +++ b/passes/cmds/scc.cc @@ -301,42 +301,41 @@ struct SccPass : public Pass {  		RTLIL::Selection newSelection(false);  		int scc_counter = 0; -		for (auto &mod_it : design->modules_) -			if (design->selected(mod_it.second)) -			{ -				SccWorker worker(design, mod_it.second, nofeedbackMode, allCellTypes, maxDepth); +		for (auto mod : design->selected_modules()) +		{ +			SccWorker worker(design, mod, nofeedbackMode, allCellTypes, maxDepth); -				if (!setAttr.empty()) +			if (!setAttr.empty()) +			{ +				for (const auto &cells : worker.sccList)  				{ -					for (const auto &cells : worker.sccList) +					for (auto attr : setAttr)  					{ -						for (auto attr : setAttr) -						{ -							IdString attr_name(RTLIL::escape_id(attr.first)); -							string attr_valstr = attr.second; -							string index = stringf("%d", scc_counter); - -							for (size_t pos = 0; (pos = attr_valstr.find("{}", pos)) != string::npos; pos += index.size()) -								attr_valstr.replace(pos, 2, index); +						IdString attr_name(RTLIL::escape_id(attr.first)); +						string attr_valstr = attr.second; +						string index = stringf("%d", scc_counter); -							Const attr_value(attr_valstr); +						for (size_t pos = 0; (pos = attr_valstr.find("{}", pos)) != string::npos; pos += index.size()) +							attr_valstr.replace(pos, 2, index); -							for (auto cell : cells) -								cell->attributes[attr_name] = attr_value; -						} +						Const attr_value(attr_valstr); -						scc_counter++; +						for (auto cell : cells) +							cell->attributes[attr_name] = attr_value;  					} -				} -				else -				{ -					scc_counter += GetSize(worker.sccList); -				} -				if (selectMode) -					worker.select(newSelection); +					scc_counter++; +				} +			} +			else +			{ +				scc_counter += GetSize(worker.sccList);  			} +			if (selectMode) +				worker.select(newSelection); +		} +  		if (expect >= 0) {  			if (scc_counter == expect)  				log("Found and expected %d SCCs.\n", scc_counter); diff --git a/passes/cmds/scratchpad.cc b/passes/cmds/scratchpad.cc new file mode 100644 index 000000000..34ec0863a --- /dev/null +++ b/passes/cmds/scratchpad.cc @@ -0,0 +1,141 @@ +/* + *  yosys -- Yosys Open SYnthesis Suite + * + *  Copyright (C) 2012  Clifford Wolf <clifford@clifford.at> + *                2019  Nina Engelhardt <nak@symbioticeda.com> + * + *  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 [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("\n"); +		log("    -get <identifier>\n"); +		log("        print the value saved in the scratchpad under the given identifier.\n"); +		log("\n"); +		log("    -set <identifier> <value>\n"); +		log("        save the given value in the scratchpad under the given identifier.\n"); +		log("\n"); +		log("    -unset <identifier>\n"); +		log("        remove the entry for the given identifier from the scratchpad.\n"); +		log("\n"); +		log("    -copy <identifier_from> <identifier_to>\n"); +		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"); +		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 if (RTLIL::constpad.count(identifier)) { +					log("%s\n", RTLIL::constpad.at(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]; +				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); +				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]; +				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; +			} +			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("scratchpad entry '%s' is not defined\n", identifier.c_str()); +				string value = design->scratchpad_get_string(identifier); +				if (value != expected) { +					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; +			} +			if (args[argidx] == "-assert-set" && argidx+1 < args.size()) { +				string identifier = args[++argidx]; +				if (design->scratchpad.count(identifier) == 0) +					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("scratchpad entry '%s' is defined\n", identifier.c_str()); +				continue; +			} +			break; +		} +		extra_args(args, argidx, design, false); +	} +} ScratchpadPass; +PRIVATE_NAMESPACE_END diff --git a/passes/cmds/show.cc b/passes/cmds/show.cc index a3e969ef1..eeef24bde 100644 --- a/passes/cmds/show.cc +++ b/passes/cmds/show.cc @@ -873,7 +873,7 @@ struct ShowPass : public Pass {  			#ifdef __APPLE__  			std::string cmd = stringf("ps -fu %d | grep -q '[ ]%s' || xdot '%s' &", getuid(), dot_file.c_str(), dot_file.c_str());  			#else -			std::string cmd = stringf("{ test -f '%s.pid' && fuser -s '%s.pid'; } || ( echo $$ >&3; exec xdot '%s'; ) 3> '%s.pid' &", dot_file.c_str(), dot_file.c_str(), dot_file.c_str(), dot_file.c_str()); +			std::string cmd = stringf("{ test -f '%s.pid' && fuser -s '%s.pid' 2> /dev/null; } || ( echo $$ >&3; exec xdot '%s'; ) 3> '%s.pid' &", dot_file.c_str(), dot_file.c_str(), dot_file.c_str(), dot_file.c_str());  			#endif  			log("Exec: %s\n", cmd.c_str());  			if (run_command(cmd) != 0) | 
