diff options
Diffstat (limited to 'frontends')
| -rw-r--r-- | frontends/aiger/aigerparse.cc | 33 | ||||
| -rw-r--r-- | frontends/ast/ast.cc | 18 | ||||
| -rw-r--r-- | frontends/ast/genrtlil.cc | 2 | ||||
| -rw-r--r-- | frontends/ast/simplify.cc | 8 | ||||
| -rw-r--r-- | frontends/verific/verific.cc | 67 | ||||
| -rw-r--r-- | frontends/verific/verific.h | 4 | ||||
| -rw-r--r-- | frontends/verific/verificsva.cc | 2 | ||||
| -rw-r--r-- | frontends/verilog/const2ast.cc | 24 | ||||
| -rw-r--r-- | frontends/verilog/verilog_parser.y | 8 | 
9 files changed, 110 insertions, 56 deletions
diff --git a/frontends/aiger/aigerparse.cc b/frontends/aiger/aigerparse.cc index 85ee34e2d..bd0596cc0 100644 --- a/frontends/aiger/aigerparse.cc +++ b/frontends/aiger/aigerparse.cc @@ -30,6 +30,7 @@  #include <libkern/OSByteOrder.h>  #define __builtin_bswap32 OSSwapInt32  #endif +#define __STDC_FORMAT_MACROS  #include <inttypes.h>  #include "kernel/yosys.h" @@ -151,12 +152,12 @@ struct ConstEvalAig  		RTLIL::State eval_ret = RTLIL::Sx;  		if (cell->type == "$_NOT_") { -			if (sig_a == RTLIL::S0) eval_ret = RTLIL::S1; -			else if (sig_a == RTLIL::S1) eval_ret = RTLIL::S0; +			if (sig_a == State::S0) eval_ret = State::S1; +			else if (sig_a == State::S1) eval_ret = State::S0;  		}  		else if (cell->type == "$_AND_") { -			if (sig_a == RTLIL::S0) { -				eval_ret = RTLIL::S0; +			if (sig_a == State::S0) { +				eval_ret = State::S0;  				goto eval_end;  			} @@ -164,15 +165,15 @@ struct ConstEvalAig  				RTLIL::SigBit sig_b = cell->getPort("\\B");  				if (!eval(sig_b))  					return false; -				if (sig_b == RTLIL::S0) { -					eval_ret = RTLIL::S0; +				if (sig_b == State::S0) { +					eval_ret = State::S0;  					goto eval_end;  				} -				if (sig_a != RTLIL::S1 || sig_b != RTLIL::S1) +				if (sig_a != State::S1 || sig_b != State::S1)  					goto eval_end; -				eval_ret = RTLIL::S1; +				eval_ret = State::S1;  			}  		}  		else log_abort(); @@ -256,7 +257,7 @@ end_of_header:  	RTLIL::Wire* n0 = module->wire("\\__0__");  	if (n0) -		module->connect(n0, RTLIL::S0); +		module->connect(n0, State::S0);  	// Parse footer (symbol table, comments, etc.)  	unsigned l1; @@ -371,7 +372,7 @@ void AigerReader::parse_xaiger(const dict<int,IdString> &box_lookup)  	RTLIL::Wire* n0 = module->wire("\\__0__");  	if (n0) -		module->connect(n0, RTLIL::S0); +		module->connect(n0, State::S0);  	// Parse footer (symbol table, comments, etc.)  	std::string s; @@ -520,9 +521,9 @@ void AigerReader::parse_aiger_ascii()  				log_error("Line %u cannot be interpreted as a latch!\n", line_count);  			if (l3 == 0) -				q_wire->attributes["\\init"] = RTLIL::S0; +				q_wire->attributes["\\init"] = State::S0;  			else if (l3 == 1) -				q_wire->attributes["\\init"] = RTLIL::S1; +				q_wire->attributes["\\init"] = State::S1;  			else if (l3 == l1) {  				//q_wire->attributes["\\init"] = RTLIL::Sx;  			} @@ -531,7 +532,7 @@ void AigerReader::parse_aiger_ascii()  		}  		else {  			// AIGER latches are assumed to be initialized to zero -			q_wire->attributes["\\init"] = RTLIL::S0; +			q_wire->attributes["\\init"] = State::S0;  		}  		latches.push_back(q_wire);  	} @@ -645,9 +646,9 @@ void AigerReader::parse_aiger_binary()  				log_error("Line %u cannot be interpreted as a latch!\n", line_count);  			if (l3 == 0) -				q_wire->attributes["\\init"] = RTLIL::S0; +				q_wire->attributes["\\init"] = State::S0;  			else if (l3 == 1) -				q_wire->attributes["\\init"] = RTLIL::S1; +				q_wire->attributes["\\init"] = State::S1;  			else if (l3 == l1) {  				//q_wire->attributes["\\init"] = RTLIL::Sx;  			} @@ -656,7 +657,7 @@ void AigerReader::parse_aiger_binary()  		}  		else {  			// AIGER latches are assumed to be initialized to zero -			q_wire->attributes["\\init"] = RTLIL::S0; +			q_wire->attributes["\\init"] = State::S0;  		}  		latches.push_back(q_wire);  	} diff --git a/frontends/ast/ast.cc b/frontends/ast/ast.cc index 943466ee3..07ef0a86e 100644 --- a/frontends/ast/ast.cc +++ b/frontends/ast/ast.cc @@ -283,8 +283,8 @@ void AstNode::dumpAst(FILE *f, std::string indent) const  	if (!bits.empty()) {  		fprintf(f, " bits='");  		for (size_t i = bits.size(); i > 0; i--) -			fprintf(f, "%c", bits[i-1] == RTLIL::S0 ? '0' : -					bits[i-1] == RTLIL::S1 ? '1' : +			fprintf(f, "%c", bits[i-1] == State::S0 ? '0' : +					bits[i-1] == State::S1 ? '1' :  					bits[i-1] == RTLIL::Sx ? 'x' :  					bits[i-1] == RTLIL::Sz ? 'z' : '?');  		fprintf(f, "'(%d)", GetSize(bits)); @@ -716,7 +716,7 @@ AstNode *AstNode::mkconst_int(uint32_t v, bool is_signed, int width)  	node->integer = v;  	node->is_signed = is_signed;  	for (int i = 0; i < width; i++) { -		node->bits.push_back((v & 1) ? RTLIL::S1 : RTLIL::S0); +		node->bits.push_back((v & 1) ? State::S1 : State::S0);  		v = v >> 1;  	}  	node->range_valid = true; @@ -733,9 +733,9 @@ AstNode *AstNode::mkconst_bits(const std::vector<RTLIL::State> &v, bool is_signe  	node->bits = v;  	for (size_t i = 0; i < 32; i++) {  		if (i < node->bits.size()) -			node->integer |= (node->bits[i] == RTLIL::S1) << i; +			node->integer |= (node->bits[i] == State::S1) << i;  		else if (is_signed && !node->bits.empty()) -			node->integer |= (node->bits.back() == RTLIL::S1) << i; +			node->integer |= (node->bits.back() == State::S1) << i;  	}  	node->range_valid = true;  	node->range_left = node->bits.size()-1; @@ -767,7 +767,7 @@ AstNode *AstNode::mkconst_str(const std::string &str)  	for (size_t i = 0; i < str.size(); i++) {  		unsigned char ch = str[str.size() - i - 1];  		for (int j = 0; j < 8; j++) { -			data.push_back((ch & 1) ? RTLIL::S1 : RTLIL::S0); +			data.push_back((ch & 1) ? State::S1 : State::S0);  			ch = ch >> 1;  		}  	} @@ -780,7 +780,7 @@ AstNode *AstNode::mkconst_str(const std::string &str)  bool AstNode::bits_only_01() const  {  	for (auto bit : bits) -		if (bit != RTLIL::S0 && bit != RTLIL::S1) +		if (bit != State::S0 && bit != State::S1)  			return false;  	return true;  } @@ -1164,7 +1164,7 @@ void AST::process(RTLIL::Design *design, AstNode *ast, bool dump_ast1, bool dump  				}  			} -			if (flag_icells && (*it)->str.substr(0, 2) == "\\$") +			if (flag_icells && (*it)->str.compare(0, 2, "\\$") == 0)  				(*it)->str = (*it)->str.substr(1);  			if (defer) @@ -1463,7 +1463,7 @@ std::string AstModule::derive_common(RTLIL::Design *design, dict<RTLIL::IdString  {  	std::string stripped_name = name.str(); -	if (stripped_name.substr(0, 9) == "$abstract") +	if (stripped_name.compare(0, 9, "$abstract") == 0)  		stripped_name = stripped_name.substr(9);  	log_header(design, "Executing AST frontend in derive mode using pre-parsed AST for module `%s'.\n", stripped_name.c_str()); diff --git a/frontends/ast/genrtlil.cc b/frontends/ast/genrtlil.cc index 571ddd988..407a34472 100644 --- a/frontends/ast/genrtlil.cc +++ b/frontends/ast/genrtlil.cc @@ -1516,7 +1516,7 @@ RTLIL::SigSpec AstNode::genRTLIL(int width_hint, bool sign_hint)  				AstNode *child = *it;  				if (child->type == AST_CELLTYPE) {  					cell->type = child->str; -					if (flag_icells && cell->type.substr(0, 2) == "\\$") +					if (flag_icells && cell->type.begins_with("\\$"))  						cell->type = cell->type.substr(1);  					continue;  				} diff --git a/frontends/ast/simplify.cc b/frontends/ast/simplify.cc index 6fb94d80b..54b9efaad 100644 --- a/frontends/ast/simplify.cc +++ b/frontends/ast/simplify.cc @@ -2319,7 +2319,7 @@ skip_dynamic_range_lvalue_expansion:;  				if (attr.first.str().rfind("\\via_celltype_defparam_", 0) == 0)  				{  					AstNode *cell_arg = new AstNode(AST_PARASET, attr.second->clone()); -					cell_arg->str = RTLIL::escape_id(attr.first.str().substr(strlen("\\via_celltype_defparam_"))); +					cell_arg->str = RTLIL::escape_id(attr.first.substr(strlen("\\via_celltype_defparam_")));  					cell->children.push_back(cell_arg);  				} @@ -2793,13 +2793,13 @@ AstNode *AstNode::readmem(bool is_readmemh, std::string mem_filename, AstNode *m  		std::getline(f, line);  		for (int i = 0; i < GetSize(line); i++) { -			if (in_comment && line.substr(i, 2) == "*/") { +			if (in_comment && line.compare(i, 2, "*/") == 0) {  				line[i] = ' ';  				line[i+1] = ' ';  				in_comment = false;  				continue;  			} -			if (!in_comment && line.substr(i, 2) == "/*") +			if (!in_comment && line.compare(i, 2, "/*") == 0)  				in_comment = true;  			if (in_comment)  				line[i] = ' '; @@ -2808,7 +2808,7 @@ AstNode *AstNode::readmem(bool is_readmemh, std::string mem_filename, AstNode *m  		while (1)  		{  			token = next_token(line, " \t\r\n"); -			if (token.empty() || token.substr(0, 2) == "//") +			if (token.empty() || token.compare(0, 2, "//") == 0)  				break;  			if (token[0] == '@') { diff --git a/frontends/verific/verific.cc b/frontends/verific/verific.cc index 06d58a44a..17c4a1e5b 100644 --- a/frontends/verific/verific.cc +++ b/frontends/verific/verific.cc @@ -19,6 +19,7 @@  #include "kernel/yosys.h"  #include "kernel/sigtools.h" +#include "kernel/celltypes.h"  #include "kernel/log.h"  #include <stdlib.h>  #include <stdio.h> @@ -111,9 +112,10 @@ string get_full_netlist_name(Netlist *nl)  // ================================================================== -VerificImporter::VerificImporter(bool mode_gates, bool mode_keep, bool mode_nosva, bool mode_names, bool mode_verific, bool mode_autocover) : +VerificImporter::VerificImporter(bool mode_gates, bool mode_keep, bool mode_nosva, bool mode_names, bool mode_verific, bool mode_autocover, bool mode_fullinit) :  		mode_gates(mode_gates), mode_keep(mode_keep), mode_nosva(mode_nosva), -		mode_names(mode_names), mode_verific(mode_verific), mode_autocover(mode_autocover) +		mode_names(mode_names), mode_verific(mode_verific), mode_autocover(mode_autocover), +		mode_fullinit(mode_fullinit)  {  } @@ -1454,6 +1456,50 @@ void VerificImporter::import_netlist(RTLIL::Design *design, Netlist *nl, std::se  		merge_past_ffs(past_ffs);  	} + +	if (!mode_fullinit) +	{ +		pool<SigBit> non_ff_bits; +		CellTypes ff_types; + +		ff_types.setup_internals_ff(); +		ff_types.setup_stdcells_mem(); + +		for (auto cell : module->cells()) +		{ +			if (ff_types.cell_known(cell->type)) +				continue; + +			for (auto conn : cell->connections()) +			{ +				if (!cell->output(conn.first)) +					continue; + +				for (auto bit : conn.second) +					if (bit.wire != nullptr) +						non_ff_bits.insert(bit); +			} +		} + +		for (auto wire : module->wires()) +		{ +			if (!wire->attributes.count("\\init")) +				continue; + +			Const &initval = wire->attributes.at("\\init"); +			for (int i = 0; i < GetSize(initval); i++) +			{ +				if (initval[i] != State::S0 && initval[i] != State::S1) +					continue; + +				if (non_ff_bits.count(SigBit(wire, i))) +					initval[i] = State::Sx; +			} + +			if (initval.is_fully_undef()) +				wire->attributes.erase("\\init"); +		} +	}  }  // ================================================================== @@ -1829,7 +1875,7 @@ void verific_import(Design *design, const std::map<std::string,std::string> &par  	while (!nl_todo.empty()) {  		Netlist *nl = *nl_todo.begin();  		if (nl_done.count(nl) == 0) { -			VerificImporter importer(false, false, false, false, false, false); +			VerificImporter importer(false, false, false, false, false, false, false);  			importer.import_netlist(design, nl, nl_todo);  		}  		nl_todo.erase(nl); @@ -1952,6 +1998,9 @@ struct VerificPass : public Pass {  		log("  -autocover\n");  		log("    Generate automatic cover statements for all asserts\n");  		log("\n"); +		log("  -fullinit\n"); +		log("    Keep all register initializations, even those for non-FF registers.\n"); +		log("\n");  		log("  -chparam name value \n");  		log("    Elaborate the specified top modules (all modules when -all given) using\n");  		log("    this parameter value. Modules on which this parameter does not exist will\n"); @@ -2140,7 +2189,7 @@ struct VerificPass : public Pass {  			veri_file::DefineMacro("VERIFIC");  			veri_file::DefineMacro(args[argidx] == "-formal" ? "FORMAL" : "SYNTHESIS"); -			for (argidx++; argidx < GetSize(args) && GetSize(args[argidx]) >= 2 && args[argidx].substr(0, 2) == "-D"; argidx++) { +			for (argidx++; argidx < GetSize(args) && GetSize(args[argidx]) >= 2 && args[argidx].compare(0, 2, "-D") == 0; argidx++) {  				std::string name = args[argidx].substr(2);  				if (args[argidx] == "-D") {  					if (++argidx >= GetSize(args)) @@ -2213,7 +2262,7 @@ struct VerificPass : public Pass {  			std::set<Netlist*> nl_todo, nl_done;  			bool mode_all = false, mode_gates = false, mode_keep = false;  			bool mode_nosva = false, mode_names = false, mode_verific = false; -			bool mode_autocover = false; +			bool mode_autocover = false, mode_fullinit = false;  			bool flatten = false, extnets = false;  			string dumpfile;  			Map parameters(STRING_HASH); @@ -2255,6 +2304,10 @@ struct VerificPass : public Pass {  					mode_autocover = true;  					continue;  				} +				if (args[argidx] == "-fullinit") { +					mode_fullinit = true; +					continue; +				}  				if (args[argidx] == "-chparam"  && argidx+2 < GetSize(args)) {  					const std::string &key = args[++argidx];  					const std::string &value = args[++argidx]; @@ -2283,7 +2336,7 @@ struct VerificPass : public Pass {  				break;  			} -			if (argidx > GetSize(args) && args[argidx].substr(0, 1) == "-") +			if (argidx > GetSize(args) && args[argidx].compare(0, 1, "-") == 0)  				cmd_error(args, argidx, "unknown option");  			if (mode_all) @@ -2378,7 +2431,7 @@ struct VerificPass : public Pass {  				Netlist *nl = *nl_todo.begin();  				if (nl_done.count(nl) == 0) {  					VerificImporter importer(mode_gates, mode_keep, mode_nosva, -							mode_names, mode_verific, mode_autocover); +							mode_names, mode_verific, mode_autocover, mode_fullinit);  					importer.import_netlist(design, nl, nl_todo);  				}  				nl_todo.erase(nl); diff --git a/frontends/verific/verific.h b/frontends/verific/verific.h index 88a6cc0ba..5cbd78f7b 100644 --- a/frontends/verific/verific.h +++ b/frontends/verific/verific.h @@ -72,9 +72,9 @@ struct VerificImporter  	pool<Verific::Net*, hash_ptr_ops> any_all_nets;  	bool mode_gates, mode_keep, mode_nosva, mode_names, mode_verific; -	bool mode_autocover; +	bool mode_autocover, mode_fullinit; -	VerificImporter(bool mode_gates, bool mode_keep, bool mode_nosva, bool mode_names, bool mode_verific, bool mode_autocover); +	VerificImporter(bool mode_gates, bool mode_keep, bool mode_nosva, bool mode_names, bool mode_verific, bool mode_autocover, bool mode_fullinit);  	RTLIL::SigBit net_map_at(Verific::Net *net); diff --git a/frontends/verific/verificsva.cc b/frontends/verific/verificsva.cc index 8ea8372d3..909e9b4f1 100644 --- a/frontends/verific/verificsva.cc +++ b/frontends/verific/verificsva.cc @@ -357,7 +357,7 @@ struct SvaFsm  		for (int i = 0; i < GetSize(nodes); i++)  		{  			if (next_state_sig[i] != State::S0) { -				clocking.addDff(NEW_ID, next_state_sig[i], state_wire[i], Const(0, 1)); +				clocking.addDff(NEW_ID, next_state_sig[i], state_wire[i], State::S0);  			} else {  				module->connect(state_wire[i], State::S0);  			} diff --git a/frontends/verilog/const2ast.cc b/frontends/verilog/const2ast.cc index f6a17b242..4bf5b1cf5 100644 --- a/frontends/verilog/const2ast.cc +++ b/frontends/verilog/const2ast.cc @@ -99,7 +99,7 @@ static void my_strtobin(std::vector<RTLIL::State> &data, const char *str, int le  	if (base == 10) {  		while (!digits.empty()) -			data.push_back(my_decimal_div_by_two(digits) ? RTLIL::S1 : RTLIL::S0); +			data.push_back(my_decimal_div_by_two(digits) ? State::S1 : State::S0);  	} else {  		int bits_per_digit = my_ilog2(base-1);  		for (auto it = digits.rbegin(), e = digits.rend(); it != e; it++) { @@ -115,17 +115,17 @@ static void my_strtobin(std::vector<RTLIL::State> &data, const char *str, int le  				else if (*it == 0xf2)  					data.push_back(RTLIL::Sa);  				else -					data.push_back((*it & bitmask) ? RTLIL::S1 : RTLIL::S0); +					data.push_back((*it & bitmask) ? State::S1 : State::S0);  			}  		}  	}  	int len = GetSize(data); -	RTLIL::State msb = data.empty() ? RTLIL::S0 : data.back(); +	RTLIL::State msb = data.empty() ? State::S0 : data.back();  	if (len_in_bits < 0) {  		if (len < 32) -			data.resize(32, msb == RTLIL::S0 || msb == RTLIL::S1 ? RTLIL::S0 : msb); +			data.resize(32, msb == State::S0 || msb == State::S1 ? RTLIL::S0 : msb);  		return;  	} @@ -133,11 +133,11 @@ static void my_strtobin(std::vector<RTLIL::State> &data, const char *str, int le  		log_file_error(current_filename, get_line_num(), "Unsized constant must have width of 1 bit, but have %d bits!\n", len);  	for (len = len - 1; len >= 0; len--) -		if (data[len] == RTLIL::S1) +		if (data[len] == State::S1)  			break; -	if (msb == RTLIL::S0 || msb == RTLIL::S1) { +	if (msb == State::S0 || msb == State::S1) {  		len += 1; -		data.resize(len_in_bits, RTLIL::S0); +		data.resize(len_in_bits, State::S0);  	} else {  		len += 2;  		data.resize(len_in_bits, msb); @@ -169,7 +169,7 @@ AstNode *VERILOG_FRONTEND::const2ast(std::string code, char case_type, bool warn  		for (int i = 0; i < len; i++) {  			unsigned char ch = str[len - i];  			for (int j = 0; j < 8; j++) { -				data.push_back((ch & 1) ? RTLIL::S1 : RTLIL::S0); +				data.push_back((ch & 1) ? State::S1 : State::S0);  				ch = ch >> 1;  			}  		} @@ -190,8 +190,8 @@ AstNode *VERILOG_FRONTEND::const2ast(std::string code, char case_type, bool warn  	if (*endptr == 0) {  		std::vector<RTLIL::State> data;  		my_strtobin(data, str, -1, 10, case_type, false); -		if (data.back() == RTLIL::S1) -			data.push_back(RTLIL::S0); +		if (data.back() == State::S1) +			data.push_back(State::S0);  		return AstNode::mkconst_bits(data, true);  	} @@ -237,8 +237,8 @@ AstNode *VERILOG_FRONTEND::const2ast(std::string code, char case_type, bool warn  			}  		}  		if (len_in_bits < 0) { -			if (is_signed && data.back() == RTLIL::S1) -				data.push_back(RTLIL::S0); +			if (is_signed && data.back() == State::S1) +				data.push_back(State::S0);  		}  		return AstNode::mkconst_bits(data, is_signed, is_unsized);  	} diff --git a/frontends/verilog/verilog_parser.y b/frontends/verilog/verilog_parser.y index 0fec445fa..4afd72b73 100644 --- a/frontends/verilog/verilog_parser.y +++ b/frontends/verilog/verilog_parser.y @@ -274,7 +274,7 @@ hierarchical_id:  		$$ = $1;  	} |  	hierarchical_id TOK_PACKAGESEP TOK_ID { -		if ($3->substr(0, 1) == "\\") +		if ($3->compare(0, 1, "\\") == 0)  			*$1 += "::" + $3->substr(1);  		else  			*$1 += "::" + *$3; @@ -282,7 +282,7 @@ hierarchical_id:  		$$ = $1;  	} |  	hierarchical_id '.' TOK_ID { -		if ($3->substr(0, 1) == "\\") +		if ($3->compare(0, 1, "\\") == 0)  			*$1 += "." + $3->substr(1);  		else  			*$1 += "." + *$3; @@ -2184,7 +2184,7 @@ basic_expr:  		$$ = $1;  	} |  	'(' expr ')' TOK_CONSTVAL { -		if ($4->substr(0, 1) != "'") +		if ($4->compare(0, 1, "'") != 0)  			frontend_verilog_yyerror("Cast operation must be applied on sized constants e.g. (<expr>)<constval> , while %s is not a sized constant.", $4->c_str());  		AstNode *bits = $2;  		AstNode *val = const2ast(*$4, case_type_stack.size() == 0 ? 0 : case_type_stack.back(), !lib_mode); @@ -2194,7 +2194,7 @@ basic_expr:  		delete $4;  	} |  	hierarchical_id TOK_CONSTVAL { -		if ($2->substr(0, 1) != "'") +		if ($2->compare(0, 1, "'") != 0)  			frontend_verilog_yyerror("Cast operation must be applied on sized constants, e.g. <ID>\'d0, while %s is not a sized constant.", $2->c_str());  		AstNode *bits = new AstNode(AST_IDENTIFIER);  		bits->str = *$1;  | 
