Added support for DPI function with different names in C and Verilog
authorClifford Wolf <clifford@clifford.at>
Thu, 21 Aug 2014 15:22:04 +0000 (17:22 +0200)
committerClifford Wolf <clifford@clifford.at>
Thu, 21 Aug 2014 15:22:04 +0000 (17:22 +0200)
frontends/ast/simplify.cc
frontends/verilog/lexer.l
frontends/verilog/parser.y

index 5cf64310b5d19783d170fe58adb06daf76329c9c..859058cb981d31d5167ef9b00dbc94c2d3ab7e64 100644 (file)
@@ -1451,15 +1451,15 @@ skip_dynamic_range_lvalue_expansion:;
                                std::vector<AstNode*> args;
 
                                rtype = RTLIL::unescape_id(dpi_decl->children.at(0)->str);
-                               fname = RTLIL::unescape_id(dpi_decl->str);
+                               fname = RTLIL::unescape_id(dpi_decl->children.at(1)->str);
 
-                               for (int i = 1; i < SIZE(dpi_decl->children); i++)
+                               for (int i = 2; i < SIZE(dpi_decl->children); i++)
                                {
-                                       if (i-1 >= SIZE(children))
+                                       if (i-2 >= SIZE(children))
                                                log_error("Insufficient number of arguments in DPI function call at %s:%d.\n", filename.c_str(), linenum);
 
                                        argtypes.push_back(RTLIL::unescape_id(dpi_decl->children.at(i)->str));
-                                       args.push_back(children.at(i-1)->clone());
+                                       args.push_back(children.at(i-2)->clone());
                                        while (args.back()->simplify(true, false, false, stage, -1, false, true)) { }
 
                                        if (args.back()->type != AST_CONSTANT && args.back()->type != AST_REALVALUE)
index cf51aac82c3c33434ccf4ad7d67fdcb995d26e0b..f79f81a9c21690cf506cdeb3fd0859934f626804 100644 (file)
@@ -280,10 +280,6 @@ import[ \t\r\n]+\"(DPI|DPI-C)\"[ \t\r\n]+function[ \t\r\n]+ {
        return TOK_DPI_FUNCTION;
 }
 
-<IMPORT_DPI>[(),] {
-       return *yytext;
-}
-
 <IMPORT_DPI>[a-zA-Z_$][a-zA-Z0-9_$]* {
        frontend_verilog_yylval.string = new std::string(std::string("\\") + yytext);
        return TOK_ID;
@@ -296,6 +292,10 @@ import[ \t\r\n]+\"(DPI|DPI-C)\"[ \t\r\n]+function[ \t\r\n]+ {
        return *yytext;
 }
 
+<IMPORT_DPI>. {
+       return *yytext;
+}
+
 "\\"[^ \t\r\n]+ {
        frontend_verilog_yylval.string = new std::string(yytext);
        return TOK_ID;
index 1d62bc3bed8dff03d973c41736b3efd44df90d94..22312c6d1e01d963d411375700af1d277fcf539b 100644 (file)
@@ -416,7 +416,7 @@ module_body_stmt:
 
 task_func_decl:
        attr TOK_DPI_FUNCTION TOK_ID TOK_ID {
-               current_function_or_task = new AstNode(AST_DPI_FUNCTION, AstNode::mkconst_str(*$3));
+               current_function_or_task = new AstNode(AST_DPI_FUNCTION, AstNode::mkconst_str(*$3), AstNode::mkconst_str(*$4));
                current_function_or_task->str = *$4;
                append_attr(current_function_or_task, $1);
                ast_stack.back()->children.push_back(current_function_or_task);
@@ -425,6 +425,17 @@ task_func_decl:
        } opt_dpi_function_args ';' {
                current_function_or_task = NULL;
        } |
+       attr TOK_DPI_FUNCTION TOK_ID '=' TOK_ID TOK_ID {
+               current_function_or_task = new AstNode(AST_DPI_FUNCTION, AstNode::mkconst_str(*$5), AstNode::mkconst_str(*$3));
+               current_function_or_task->str = *$6;
+               append_attr(current_function_or_task, $1);
+               ast_stack.back()->children.push_back(current_function_or_task);
+               delete $3;
+               delete $5;
+               delete $6;
+       } opt_dpi_function_args ';' {
+               current_function_or_task = NULL;
+       } |
        attr TOK_TASK TOK_ID ';' {
                current_function_or_task = new AstNode(AST_TASK);
                current_function_or_task->str = *$3;