Added Verilog parser support for asserts
authorClifford Wolf <clifford@clifford.at>
Sun, 19 Jan 2014 03:18:22 +0000 (04:18 +0100)
committerClifford Wolf <clifford@clifford.at>
Sun, 19 Jan 2014 03:18:22 +0000 (04:18 +0100)
frontends/ast/ast.cc
frontends/ast/ast.h
frontends/verilog/lexer.l
frontends/verilog/parser.y

index 2015848850c14738eea1b380907d704f09333584..ecc58cf63d658fee4c73ec0693d182feaafee8a5 100644 (file)
@@ -80,6 +80,7 @@ std::string AST::type2str(AstNodeType type)
        X(AST_CELLTYPE)
        X(AST_IDENTIFIER)
        X(AST_PREFIX)
+       X(AST_ASSERT)
        X(AST_FCALL)
        X(AST_TO_SIGNED)
        X(AST_TO_UNSIGNED)
index 22853d0f9b08f95d4bb0e21d30eb8f0a569a6808..6aaa90e86dd22eedf85fa99c05a1c01a05f9be99 100644 (file)
@@ -58,6 +58,7 @@ namespace AST
                AST_CELLTYPE,
                AST_IDENTIFIER,
                AST_PREFIX,
+               AST_ASSERT,
 
                AST_FCALL,
                AST_TO_SIGNED,
index 9e606d90f7714b0ecf93c6e3d9bb57a3b15b5394..81167cf4eccd3d6e3b5e0811750cd58717c0c120 100644 (file)
@@ -113,6 +113,8 @@ namespace VERILOG_FRONTEND {
 "generate"     { return TOK_GENERATE; }
 "endgenerate"  { return TOK_ENDGENERATE; }
 
+"assert"([ \t\r\n]+"property")? { return TOK_ASSERT; }
+
 "input"   { return TOK_INPUT; }
 "output"  { return TOK_OUTPUT; }
 "inout"   { return TOK_INOUT; }
index 874482d6ecb41753b56322e7c5b608de93d24a13..b0c4db8ae08bfed08e84ae9aaa40ceab72034b13 100644 (file)
@@ -104,7 +104,7 @@ static void free_attr(std::map<std::string, AstNode*> *al)
 %token TOK_GENERATE TOK_ENDGENERATE TOK_GENVAR
 %token TOK_SYNOPSYS_FULL_CASE TOK_SYNOPSYS_PARALLEL_CASE
 %token TOK_SUPPLY0 TOK_SUPPLY1 TOK_TO_SIGNED TOK_TO_UNSIGNED
-%token TOK_POS_INDEXED TOK_NEG_INDEXED
+%token TOK_POS_INDEXED TOK_NEG_INDEXED TOK_ASSERT
 
 %type <ast> wire_type range non_opt_range expr basic_expr concat_list rvalue lvalue lvalue_concat_list
 %type <string> opt_label tok_prim_wrapper hierarchical_id
@@ -366,7 +366,7 @@ module_body:
 
 module_body_stmt:
        task_func_decl | param_decl | localparam_decl | defparam_decl | wire_decl | assign_stmt | cell_stmt |
-       always_stmt | TOK_GENERATE module_gen_body TOK_ENDGENERATE | defattr;
+       always_stmt | TOK_GENERATE module_gen_body TOK_ENDGENERATE | defattr | assert;
 
 task_func_decl:
        TOK_TASK TOK_ID ';' {
@@ -748,6 +748,11 @@ opt_label:
                $$ = NULL;
        };
 
+assert:
+       TOK_ASSERT '(' expr ')' ';' {
+               ast_stack.back()->children.push_back(new AstNode(AST_ASSERT, $3));
+       };
+
 simple_behavioral_stmt:
        lvalue '=' expr {
                AstNode *node = new AstNode(AST_ASSIGN_EQ, $1, $3);
@@ -760,7 +765,7 @@ simple_behavioral_stmt:
 
 // this production creates the obligatory if-else shift/reduce conflict
 behavioral_stmt:
-       defattr | wire_decl |
+       defattr | assert | wire_decl |
        simple_behavioral_stmt ';' |
        hierarchical_id attr {
                AstNode *node = new AstNode(AST_TCALL);