added while and repeat support to verilog parser
authorClifford Wolf <clifford@clifford.at>
Fri, 6 Jun 2014 15:40:04 +0000 (17:40 +0200)
committerClifford Wolf <clifford@clifford.at>
Fri, 6 Jun 2014 15:40:04 +0000 (17:40 +0200)
frontends/ast/ast.cc
frontends/ast/ast.h
frontends/verilog/lexer.l
frontends/verilog/parser.y

index f2f2d0e69fe466e146ead3986fc1d5bf5ca20866..105645f950eda5e84a0f48979f50e60bb85e70a6 100644 (file)
@@ -137,6 +137,7 @@ std::string AST::type2str(AstNodeType type)
        X(AST_DEFAULT)
        X(AST_FOR)
        X(AST_WHILE)
+       X(AST_REPEAT)
        X(AST_GENVAR)
        X(AST_GENFOR)
        X(AST_GENIF)
index 72a2a4600ded4198e4ac5d5250931361e153a8b2..8f9c353493f77d7b97d6e9a7ad475d7670b3316e 100644 (file)
@@ -117,6 +117,7 @@ namespace AST
                AST_DEFAULT,
                AST_FOR,
                AST_WHILE,
+               AST_REPEAT,
 
                AST_GENVAR,
                AST_GENFOR,
index 226a26709569cf89e8b3785bbca1027186f2ad6d..5300d1b263aa5fdbc1cbc161a77976d680b50ea9 100644 (file)
@@ -140,6 +140,8 @@ namespace VERILOG_FRONTEND {
 "default"      { return TOK_DEFAULT; }
 "generate"     { return TOK_GENERATE; }
 "endgenerate"  { return TOK_ENDGENERATE; }
+"while"        { return TOK_WHILE; }
+"repeat"       { return TOK_REPEAT; }
 
 "assert"([ \t\r\n]+"property")? { return TOK_ASSERT; }
 
index ed9be692b87c3e1f852cbd443c21fbb4177d1395..a12dcf142624c29bb12f5924a9d8ccacd7ab938a 100644 (file)
@@ -98,7 +98,7 @@ static void free_attr(std::map<std::string, AstNode*> *al)
 %token TOK_MODULE TOK_ENDMODULE TOK_PARAMETER TOK_LOCALPARAM TOK_DEFPARAM
 %token TOK_INPUT TOK_OUTPUT TOK_INOUT TOK_WIRE TOK_REG
 %token TOK_INTEGER TOK_SIGNED TOK_ASSIGN TOK_ALWAYS TOK_INITIAL
-%token TOK_BEGIN TOK_END TOK_IF TOK_ELSE TOK_FOR
+%token TOK_BEGIN TOK_END TOK_IF TOK_ELSE TOK_FOR TOK_WHILE TOK_REPEAT
 %token TOK_POSEDGE TOK_NEGEDGE TOK_OR
 %token TOK_CASE TOK_CASEX TOK_CASEZ TOK_ENDCASE TOK_DEFAULT
 %token TOK_FUNCTION TOK_ENDFUNCTION TOK_TASK TOK_ENDTASK
@@ -819,6 +819,32 @@ behavioral_stmt:
                ast_stack.pop_back();
                ast_stack.pop_back();
        } |
+       attr TOK_WHILE '(' expr ')' {
+               AstNode *node = new AstNode(AST_WHILE);
+               ast_stack.back()->children.push_back(node);
+               ast_stack.push_back(node);
+               append_attr(node, $1);
+               AstNode *block = new AstNode(AST_BLOCK);
+               ast_stack.back()->children.push_back($4);
+               ast_stack.back()->children.push_back(block);
+               ast_stack.push_back(block);
+       } behavioral_stmt {
+               ast_stack.pop_back();
+               ast_stack.pop_back();
+       } |
+       attr TOK_REPEAT '(' expr ')' {
+               AstNode *node = new AstNode(AST_REPEAT);
+               ast_stack.back()->children.push_back(node);
+               ast_stack.push_back(node);
+               append_attr(node, $1);
+               AstNode *block = new AstNode(AST_BLOCK);
+               ast_stack.back()->children.push_back($4);
+               ast_stack.back()->children.push_back(block);
+               ast_stack.push_back(block);
+       } behavioral_stmt {
+               ast_stack.pop_back();
+               ast_stack.pop_back();
+       } |
        attr TOK_IF '(' expr ')' {
                AstNode *node = new AstNode(AST_CASE);
                AstNode *block = new AstNode(AST_BLOCK);