mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-06 17:44:09 +00:00
After reading the SV spec, using non-standard predict() instead of expect()
This commit is contained in:
parent
721f1f5ecf
commit
d7763634b6
4
README
4
README
|
@ -384,8 +384,8 @@ from SystemVerilog:
|
||||||
form. In module context: "assert property (<expression>);" and within an
|
form. In module context: "assert property (<expression>);" and within an
|
||||||
always block: "assert(<expression>);". It is transformed to a $assert cell.
|
always block: "assert(<expression>);". It is transformed to a $assert cell.
|
||||||
|
|
||||||
- The "assume" and "expect" statements from SystemVerilog are also
|
- The "assume" statements from SystemVerilog are also supported. The same
|
||||||
supported. The same limitations as with the "assert" statement apply.
|
limitations as with the "assert" statement apply.
|
||||||
|
|
||||||
- The keywords "always_comb", "always_ff" and "always_latch", "logic" and
|
- The keywords "always_comb", "always_ff" and "always_latch", "logic" and
|
||||||
"bit" are supported.
|
"bit" are supported.
|
||||||
|
|
|
@ -8,7 +8,7 @@ module demo1(input clk, input addtwo, output iseven);
|
||||||
cnt = (iseven ? cnt == 10 : cnt == 11) ? 0 : next_cnt;
|
cnt = (iseven ? cnt == 10 : cnt == 11) ? 0 : next_cnt;
|
||||||
|
|
||||||
assert property (cnt != 15);
|
assert property (cnt != 15);
|
||||||
// initial expect ((iseven && addtwo) || cnt == 9);
|
// initial predict ((iseven && addtwo) || cnt == 9);
|
||||||
endmodule
|
endmodule
|
||||||
|
|
||||||
module inc(input addtwo, output iseven, input [3:0] a, output [3:0] y);
|
module inc(input addtwo, output iseven, input [3:0] a, output [3:0] y);
|
||||||
|
|
|
@ -82,7 +82,7 @@ std::string AST::type2str(AstNodeType type)
|
||||||
X(AST_PREFIX)
|
X(AST_PREFIX)
|
||||||
X(AST_ASSERT)
|
X(AST_ASSERT)
|
||||||
X(AST_ASSUME)
|
X(AST_ASSUME)
|
||||||
X(AST_EXPECT)
|
X(AST_PREDICT)
|
||||||
X(AST_FCALL)
|
X(AST_FCALL)
|
||||||
X(AST_TO_BITS)
|
X(AST_TO_BITS)
|
||||||
X(AST_TO_SIGNED)
|
X(AST_TO_SIGNED)
|
||||||
|
|
|
@ -65,7 +65,7 @@ namespace AST
|
||||||
AST_PREFIX,
|
AST_PREFIX,
|
||||||
AST_ASSERT,
|
AST_ASSERT,
|
||||||
AST_ASSUME,
|
AST_ASSUME,
|
||||||
AST_EXPECT,
|
AST_PREDICT,
|
||||||
|
|
||||||
AST_FCALL,
|
AST_FCALL,
|
||||||
AST_TO_BITS,
|
AST_TO_BITS,
|
||||||
|
|
|
@ -1296,11 +1296,11 @@ RTLIL::SigSpec AstNode::genRTLIL(int width_hint, bool sign_hint)
|
||||||
// generate $assert cells
|
// generate $assert cells
|
||||||
case AST_ASSERT:
|
case AST_ASSERT:
|
||||||
case AST_ASSUME:
|
case AST_ASSUME:
|
||||||
case AST_EXPECT:
|
case AST_PREDICT:
|
||||||
{
|
{
|
||||||
const char *celltype = "$assert";
|
const char *celltype = "$assert";
|
||||||
if (type == AST_ASSUME) celltype = "$assume";
|
if (type == AST_ASSUME) celltype = "$assume";
|
||||||
if (type == AST_EXPECT) celltype = "$expect";
|
if (type == AST_PREDICT) celltype = "$predict";
|
||||||
|
|
||||||
log_assert(children.size() == 2);
|
log_assert(children.size() == 2);
|
||||||
|
|
||||||
|
|
|
@ -1348,7 +1348,7 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
|
||||||
}
|
}
|
||||||
skip_dynamic_range_lvalue_expansion:;
|
skip_dynamic_range_lvalue_expansion:;
|
||||||
|
|
||||||
if (stage > 1 && (type == AST_ASSERT || type == AST_ASSUME || type == AST_EXPECT) && current_block != NULL)
|
if (stage > 1 && (type == AST_ASSERT || type == AST_ASSUME || type == AST_PREDICT) && current_block != NULL)
|
||||||
{
|
{
|
||||||
std::stringstream sstr;
|
std::stringstream sstr;
|
||||||
sstr << "$formal$" << filename << ":" << linenum << "$" << (autoidx++);
|
sstr << "$formal$" << filename << ":" << linenum << "$" << (autoidx++);
|
||||||
|
@ -1405,7 +1405,7 @@ skip_dynamic_range_lvalue_expansion:;
|
||||||
goto apply_newNode;
|
goto apply_newNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stage > 1 && (type == AST_ASSERT || type == AST_ASSUME || type == AST_EXPECT) && children.size() == 1)
|
if (stage > 1 && (type == AST_ASSERT || type == AST_ASSUME || type == AST_PREDICT) && children.size() == 1)
|
||||||
{
|
{
|
||||||
children.push_back(mkconst_int(1, false, 1));
|
children.push_back(mkconst_int(1, false, 1));
|
||||||
did_something = true;
|
did_something = true;
|
||||||
|
|
|
@ -63,6 +63,10 @@ YOSYS_NAMESPACE_END
|
||||||
frontend_verilog_yylval.string = new std::string(std::string("\\") + yytext); \
|
frontend_verilog_yylval.string = new std::string(std::string("\\") + yytext); \
|
||||||
return TOK_ID;
|
return TOK_ID;
|
||||||
|
|
||||||
|
#define NON_KEYWORD() \
|
||||||
|
frontend_verilog_yylval.string = new std::string(std::string("\\") + yytext); \
|
||||||
|
return TOK_ID;
|
||||||
|
|
||||||
#define YY_INPUT(buf,result,max_size) \
|
#define YY_INPUT(buf,result,max_size) \
|
||||||
result = readsome(*VERILOG_FRONTEND::lexin, buf, max_size)
|
result = readsome(*VERILOG_FRONTEND::lexin, buf, max_size)
|
||||||
|
|
||||||
|
@ -173,7 +177,7 @@ YOSYS_NAMESPACE_END
|
||||||
|
|
||||||
"assert" { if (formal_mode) return TOK_ASSERT; SV_KEYWORD(TOK_ASSERT); }
|
"assert" { if (formal_mode) return TOK_ASSERT; SV_KEYWORD(TOK_ASSERT); }
|
||||||
"assume" { if (formal_mode) return TOK_ASSUME; SV_KEYWORD(TOK_ASSUME); }
|
"assume" { if (formal_mode) return TOK_ASSUME; SV_KEYWORD(TOK_ASSUME); }
|
||||||
"expect" { if (formal_mode) return TOK_EXPECT; SV_KEYWORD(TOK_EXPECT); }
|
"predict" { if (formal_mode) return TOK_PREDICT; NON_KEYWORD(); }
|
||||||
"property" { if (formal_mode) return TOK_PROPERTY; SV_KEYWORD(TOK_PROPERTY); }
|
"property" { if (formal_mode) return TOK_PROPERTY; SV_KEYWORD(TOK_PROPERTY); }
|
||||||
"logic" { SV_KEYWORD(TOK_REG); }
|
"logic" { SV_KEYWORD(TOK_REG); }
|
||||||
"bit" { SV_KEYWORD(TOK_REG); }
|
"bit" { SV_KEYWORD(TOK_REG); }
|
||||||
|
|
|
@ -113,7 +113,7 @@ static void free_attr(std::map<std::string, AstNode*> *al)
|
||||||
%token TOK_SYNOPSYS_FULL_CASE TOK_SYNOPSYS_PARALLEL_CASE
|
%token TOK_SYNOPSYS_FULL_CASE TOK_SYNOPSYS_PARALLEL_CASE
|
||||||
%token TOK_SUPPLY0 TOK_SUPPLY1 TOK_TO_SIGNED TOK_TO_UNSIGNED
|
%token TOK_SUPPLY0 TOK_SUPPLY1 TOK_TO_SIGNED TOK_TO_UNSIGNED
|
||||||
%token TOK_POS_INDEXED TOK_NEG_INDEXED TOK_ASSERT TOK_ASSUME
|
%token TOK_POS_INDEXED TOK_NEG_INDEXED TOK_ASSERT TOK_ASSUME
|
||||||
%token TOK_EXPECT TOK_PROPERTY
|
%token TOK_PREDICT TOK_PROPERTY
|
||||||
|
|
||||||
%type <ast> range range_or_multirange non_opt_range non_opt_multirange range_or_signed_int
|
%type <ast> range range_or_multirange non_opt_range non_opt_multirange range_or_signed_int
|
||||||
%type <ast> wire_type expr basic_expr concat_list rvalue lvalue lvalue_concat_list
|
%type <ast> wire_type expr basic_expr concat_list rvalue lvalue lvalue_concat_list
|
||||||
|
@ -967,8 +967,8 @@ assert:
|
||||||
TOK_ASSUME '(' expr ')' ';' {
|
TOK_ASSUME '(' expr ')' ';' {
|
||||||
ast_stack.back()->children.push_back(new AstNode(AST_ASSUME, $3));
|
ast_stack.back()->children.push_back(new AstNode(AST_ASSUME, $3));
|
||||||
} |
|
} |
|
||||||
TOK_EXPECT '(' expr ')' ';' {
|
TOK_PREDICT '(' expr ')' ';' {
|
||||||
ast_stack.back()->children.push_back(new AstNode(AST_EXPECT, $3));
|
ast_stack.back()->children.push_back(new AstNode(AST_PREDICT, $3));
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_property:
|
assert_property:
|
||||||
|
@ -978,8 +978,8 @@ assert_property:
|
||||||
TOK_ASSUME TOK_PROPERTY '(' expr ')' ';' {
|
TOK_ASSUME TOK_PROPERTY '(' expr ')' ';' {
|
||||||
ast_stack.back()->children.push_back(new AstNode(AST_ASSUME, $4));
|
ast_stack.back()->children.push_back(new AstNode(AST_ASSUME, $4));
|
||||||
} |
|
} |
|
||||||
TOK_EXPECT TOK_PROPERTY '(' expr ')' ';' {
|
TOK_PREDICT TOK_PROPERTY '(' expr ')' ';' {
|
||||||
ast_stack.back()->children.push_back(new AstNode(AST_EXPECT, $4));
|
ast_stack.back()->children.push_back(new AstNode(AST_PREDICT, $4));
|
||||||
};
|
};
|
||||||
|
|
||||||
simple_behavioral_stmt:
|
simple_behavioral_stmt:
|
||||||
|
|
|
@ -116,7 +116,7 @@ struct CellTypes
|
||||||
|
|
||||||
setup_type("$assert", {A, EN}, pool<RTLIL::IdString>(), true);
|
setup_type("$assert", {A, EN}, pool<RTLIL::IdString>(), true);
|
||||||
setup_type("$assume", {A, EN}, pool<RTLIL::IdString>(), true);
|
setup_type("$assume", {A, EN}, pool<RTLIL::IdString>(), true);
|
||||||
setup_type("$expect", {A, EN}, pool<RTLIL::IdString>(), true);
|
setup_type("$predict", {A, EN}, pool<RTLIL::IdString>(), true);
|
||||||
setup_type("$equiv", {A, B}, {Y}, true);
|
setup_type("$equiv", {A, B}, {Y}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1017,7 +1017,7 @@ namespace {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cell->type.in("$assert", "$assume", "$expect")) {
|
if (cell->type.in("$assert", "$assume", "$predict")) {
|
||||||
port("\\A", 1);
|
port("\\A", 1);
|
||||||
port("\\EN", 1);
|
port("\\EN", 1);
|
||||||
check_expected();
|
check_expected();
|
||||||
|
@ -1798,7 +1798,7 @@ RTLIL::Cell* RTLIL::Module::addAssume(RTLIL::IdString name, RTLIL::SigSpec sig_a
|
||||||
|
|
||||||
RTLIL::Cell* RTLIL::Module::addExpect(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_en)
|
RTLIL::Cell* RTLIL::Module::addExpect(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_en)
|
||||||
{
|
{
|
||||||
RTLIL::Cell *cell = addCell(name, "$expect");
|
RTLIL::Cell *cell = addCell(name, "$predict");
|
||||||
cell->setPort("\\A", sig_a);
|
cell->setPort("\\A", sig_a);
|
||||||
cell->setPort("\\EN", sig_en);
|
cell->setPort("\\EN", sig_en);
|
||||||
return cell;
|
return cell;
|
||||||
|
|
|
@ -1347,7 +1347,7 @@ struct SatGen
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cell->type == "$expect")
|
if (cell->type == "$predict")
|
||||||
{
|
{
|
||||||
std::string pf = prefix + (timestep == -1 ? "" : stringf("@%d:", timestep));
|
std::string pf = prefix + (timestep == -1 ? "" : stringf("@%d:", timestep));
|
||||||
expects_a[pf].append((*sigmap)(cell->getPort("\\A")));
|
expects_a[pf].append((*sigmap)(cell->getPort("\\A")));
|
||||||
|
|
|
@ -421,7 +421,7 @@ pass. The combinatorial logic cells can be mapped to physical cells from a Liber
|
||||||
using the {\tt abc} pass.
|
using the {\tt abc} pass.
|
||||||
|
|
||||||
\begin{fixme}
|
\begin{fixme}
|
||||||
Add information about {\tt \$assert}, {\tt \$assume}, {\tt \$expect}, and {\tt \$equiv} cells.
|
Add information about {\tt \$assert}, {\tt \$assume}, {\tt \$predict}, and {\tt \$equiv} cells.
|
||||||
\end{fixme}
|
\end{fixme}
|
||||||
|
|
||||||
\begin{fixme}
|
\begin{fixme}
|
||||||
|
|
|
@ -313,7 +313,7 @@ bool set_keep_assert(std::map<RTLIL::Module*, bool> &cache, RTLIL::Module *mod)
|
||||||
if (cache.count(mod) == 0)
|
if (cache.count(mod) == 0)
|
||||||
for (auto c : mod->cells()) {
|
for (auto c : mod->cells()) {
|
||||||
RTLIL::Module *m = mod->design->module(c->type);
|
RTLIL::Module *m = mod->design->module(c->type);
|
||||||
if ((m != nullptr && set_keep_assert(cache, m)) || c->type.in("$assert", "$assume", "$expect"))
|
if ((m != nullptr && set_keep_assert(cache, m)) || c->type.in("$assert", "$assume", "$predict"))
|
||||||
return cache[mod] = true;
|
return cache[mod] = true;
|
||||||
}
|
}
|
||||||
return cache[mod];
|
return cache[mod];
|
||||||
|
|
|
@ -64,7 +64,7 @@ struct keep_cache_t
|
||||||
|
|
||||||
bool query(Cell *cell)
|
bool query(Cell *cell)
|
||||||
{
|
{
|
||||||
if (cell->type.in("$memwr", "$meminit", "$assert", "$assume", "$expect"))
|
if (cell->type.in("$memwr", "$meminit", "$assert", "$assume", "$predict"))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (cell->has_keep_attr())
|
if (cell->has_keep_attr())
|
||||||
|
|
|
@ -731,7 +731,7 @@ struct TestCellPass : public Pass {
|
||||||
// cell_types["$concat"] = "A";
|
// cell_types["$concat"] = "A";
|
||||||
// cell_types["$assert"] = "A";
|
// cell_types["$assert"] = "A";
|
||||||
// cell_types["$assume"] = "A";
|
// cell_types["$assume"] = "A";
|
||||||
// cell_types["$expect"] = "A";
|
// cell_types["$predict"] = "A";
|
||||||
|
|
||||||
cell_types["$lut"] = "*";
|
cell_types["$lut"] = "*";
|
||||||
cell_types["$sop"] = "*";
|
cell_types["$sop"] = "*";
|
||||||
|
|
|
@ -1305,18 +1305,10 @@ endmodule
|
||||||
|
|
||||||
// --------------------------------------------------------
|
// --------------------------------------------------------
|
||||||
|
|
||||||
module \$expect (A, EN);
|
module \$predict (A, EN);
|
||||||
|
|
||||||
input A, EN;
|
input A, EN;
|
||||||
|
|
||||||
`ifndef SIMLIB_NOCHECKS
|
|
||||||
always @* begin
|
|
||||||
if (A === 1'b1 && EN === 1'b1) begin
|
|
||||||
$display("Expectation %m passed.");
|
|
||||||
end
|
|
||||||
end
|
|
||||||
`endif
|
|
||||||
|
|
||||||
endmodule
|
endmodule
|
||||||
|
|
||||||
// --------------------------------------------------------
|
// --------------------------------------------------------
|
||||||
|
|
Loading…
Reference in a new issue