[logo] 
 
Home
News
Activity
About/Contact
Major Tools
  Dinotrace
  Verilator
  Verilog-mode
  Verilog-Perl
Other Tools
  BugVise
  CovVise
  Force-Gate-Sim
  Gspice
  IPC::Locker
  Rsvn
  SVN::S4
  SystemPerl
  Voneline
  WFH
General Info
  Papers

Did anyone ever use the Parser as a stand-alone SV parser in a C++ project?

Added by Jan Seyler about 1 year ago

Hey there,

did anyone ever use the Parser of Verilog-Perl outside of Verilog-Perl in an autonomous C++ application? I'm trying to do this right now and I have some problems creating an instance of the Parser and using it.

It would be great if someone could help me!

Thanking you in anticipation


Replies (64)

RE: Did anyone ever use the Parser as a stand-alone SV parser in a C++ project? - Added by Jan Seyler about 1 year ago

Hey,

yeah now, after tinkering this morning it is working. THANK YOU!

Now to progress, why is there no moduleCb called? Are they depending on the keywordCb or operatorCb?

Regards

RE: Did anyone ever use the Parser as a stand-alone SV parser in a C++ project? - Added by Jan Seyler about 1 year ago

Hi,

I realized, that I didn't activate the sigparser... :( So now it is working for now, but parsing is terminated after every commentCb. Is that a bug or am I doing anything wrong?

And what I see is, that the parser does not see the declaration of classes within classes or modules. I do only get keywordCb here but nothing like a portCb. So how can I see what classes are declared within oder classes, like

class htax_bridge_scoreboard extends uvm_scoreboard;

    int unsigned count_cht32dut_p    = 0;

    htax_cfg cfg;
...
endclass
Here the parser does only see:
My_Parser::keywordCb called;class
My_Parser::symbolCb called;htax_bridge_scoreboard
My_Parser::classCb called kwd class name: htax_bridge_scoreboard virt: 
My_Parser::keywordCb called;extends
My_Parser::symbolCb called;uvm_scoreboard
My_Parser::operatorCb called;;
My_Parser::keywordCb called;int
My_Parser::keywordCb called;unsigned
My_Parser::symbolCb called;count_cht32dut_p
My_Parser::operatorCb called;=
My_Parser::numberCb called;0
My_Parser::operatorCb called;;
My_Parser::varCb called
name: count_cht32dut_p
object of: class
net: 
data_type: int unsigned
value: 0
My_Parser::symbolCb called;htax_cfg
My_Parser::symbolCb called;cfg
My_Parser::operatorCb called;;

RE: Did anyone ever use the Parser as a stand-alone SV parser in a C++ project? - Added by Wilson Snyder about 1 year ago

Perhaps you didn't declare htax_cfg as a data type? Data types must be predeclared according to the LRM, and otherwise the parser gets confused.

RE: Did anyone ever use the Parser as a stand-alone SV parser in a C++ project? - Added by Jan Seyler about 1 year ago

No, I didn't. So the parser is not capable of recognizing declaration of classes? Its obvious, because they have the form "symbol symbol" what is quite general but it would be so usefull. What would be needed here is a database where already defined classes are stored and declared as keywords or data types. Is there also no way to get the parents of derived classes? Like in my example "htax_bridge_scoreboard extends uvm_scoreboard;", is there a chance to get somethin like:

classCb:
kwd: class
name: htax_bridge_scoreboard
extends: uvm_scoreboard

Should be possible, because 'extends' is already a keyword, right?

Thank you!! Its great, that you are always responding and helping me that much!

RE: Did anyone ever use the Parser as a stand-alone SV parser in a C++ project? - Added by Wilson Snyder about 1 year ago

It recognizes classes. htax_cfg is being used as a data type, not being declared; cfg is what is being declared. The standard says you must declare data types before using them.

As for getting the extends, look at VParseBison.y and see what yEXTENDS does. Right now it imports the symbol table but doesn't do a call back, nor pass it up to the classCb (which is actually called before EXTENDS is even parsed). Change it to do whatever you want.

RE: Did anyone ever use the Parser as a stand-alone SV parser in a C++ project? - Added by Jan Seyler about 1 year ago

Yeah but what, if the class is declared in another file? Will ist recognize it as a datatype later on?

I'll see what I can do with the yEXTENDS part.

Is the error with the commentCb local for my program or is that supposed to be that way?

Thank you, regards

RE: Did anyone ever use the Parser as a stand-alone SV parser in a C++ project? - Added by Wilson Snyder about 1 year ago

If it's in another file you'll need to `include it of course. Or equivalently have the parser parse that first.

If the Verilog is valid there shouldn't be errors. See if "vhier" takes the code. If it does and your program doesn't then there's something wrong in your program. It a simulator takes it (listing the exact same files) and vhier doesn't then maybe there's a vhier/parser bug.

RE: Did anyone ever use the Parser as a stand-alone SV parser in a C++ project? - Added by Jan Seyler about 1 year ago

Hi,

I tried this and it works just fine. Great! Now I do have another problem:

As the MakeMaker File is pretty confusing. What files are the basics and what do I need to compile to get everything done? I want to add a extendsCb to the yacc file. So I need to call bisonpre VParseBison.y bison VParseBison.y

You are doing some kind of renaming in your Makefile, right? How can I include that into my project?

Thanks

RE: Did anyone ever use the Parser as a stand-alone SV parser in a C++ project? - Added by Jan Seyler about 1 year ago

Hello again,

I just updated the GIT. I do still have a few questions, maybe you find some time to answer them :D

1) what's about the commentCb? Why does it terminate parsing and how? 2) I tried to implement a extendsCb(), but it is not called? Did I do anything wrong? I included it in VParseBison.y, VParse and My_Parser...

Thank you

RE: Did anyone ever use the Parser as a stand-alone SV parser in a C++ project? - Added by Jan Seyler about 1 year ago

Hey,

to fast. It is working perfectly fine. The parser just needs to know the classes before extending them... As it should be...

Now I try to face the commentCb problem.

Regards.

RE: Did anyone ever use the Parser as a stand-alone SV parser in a C++ project? - Added by Jan Seyler about 1 year ago

Hi,

I did trace the commentCb Problem. The according file is attached. Do you maybe see anything obviously wrong? What I think is interesting is the very first line one page 5. Or maybe the error on Page 6

22295 VParseBison.c: No such file or directory.

Do you know where the error is?

Thanks!!

commtentCb.pdf (35.3 kB)

RE: Did anyone ever use the Parser as a stand-alone SV parser in a C++ project? - Added by Wilson Snyder about 1 year ago

Certainly if it is running out of memory that's a problem, but it doesn't seem to be following that path. You should get an error message printed, but maybe your wrapper doesn't see them. I'd just add some printf()'s before each commentCb to see what the code is doing.

The file not found is just GCC saying it can't find the file to list. You probably need to point it to the proper subdirectory.

RE: Did anyone ever use the Parser as a stand-alone SV parser in a C++ project? - Added by Jan Seyler about 1 year ago

Hey,

thanks! The problem is, that it terminated after the first commentCb ever found. So there are no more Cb besides the endofparsing one. It is running out of memory, even if the comment is very short. I just don't know what the problem is.

How can I pass the error-messages through?

Regards, Jan

RE: Did anyone ever use the Parser as a stand-alone SV parser in a C++ project? - Added by Wilson Snyder about 1 year ago

The parser calls VFileLine::error. Note in Preproc.xs this is overridden to do something different for perl. However, when out of memory often there might not be enough space to make the error objects, so I don't know if this will work.

RE: Did anyone ever use the Parser as a stand-alone SV parser in a C++ project? - Added by Jan Seyler about 1 year ago

Hello again,

two more questions: 1) Do you have any idea about the comment problem? It is definitely a parser problem. I deleted all the whole callback and the parser still terminates after each comment.

2) Is there a chance to get a kind of dependency tree out of the parser or preproc? WHat I want to do is elaborate all files in a directory to see what files includes which one. So I can write a list or a tree back and parse the files in this order.

Best regards, Jan

RE: Did anyone ever use the Parser as a stand-alone SV parser in a C++ project? - Added by Wilson Snyder about 1 year ago

For commentCb, I suggest adding printf's before and after each call point and trace what's going on.

vhier has several options for making dependency trees, including listing all files needed for a design.

RE: Did anyone ever use the Parser as a stand-alone SV parser in a C++ project? - Added by Jan Seyler about 1 year ago

Hi,

I am trying to remove the comments in the ifstream before sending them to the parser. But I get a segfault after doing a trim_left to the filelines... Do you know how this may happen?

May the reason be, that I give strings to the parser and not the fileline handler given by Verilog-Perl?

Very weid problem...

Thanks

RE: Did anyone ever use the Parser as a stand-alone SV parser in a C++ project? - Added by Jan Seyler about 1 year ago

Hi,

it's me again :)

A new problem occured: I remove all linecomments befor passing them to the parser. Now everything works fine but the parser throws the endparseCb to early.

My last few lines are:
My_Parser::keywordCb called;endfunction
My_Parser::keywordCb called;endclass
My_Parser::commentCb called
My_Parser::endparseCb called
classes parsed: 2
1 classes still in working queue

The problem is that the "endclass" keyword is recognized but the endclassCb is never called because the endparseCb is thrown earlier.

Any suggestions for that?

Thanks, Jan

RE: Did anyone ever use the Parser as a stand-alone SV parser in a C++ project? - Added by Wilson Snyder about 1 year ago

Looks like endParse is sent when I set m_eof instead of when it is used. Try calling it instead on a <<EOF>> rule in VParseLex.l under "default rules". If it works I'll take the patch back.

RE: Did anyone ever use the Parser as a stand-alone SV parser in a C++ project? - Added by Jan Seyler about 1 year ago

Thanks, I'll try to do that. By the way, did you ever verify the rule
"//"[^\n]*        { FL; VALTEXT; CALLBACK(commentCb); }  /* throw away single line comments */

Maybe this is the cause for the weird commentCb behaviour.

RE: Did anyone ever use the Parser as a stand-alone SV parser in a C++ project? - Added by Jan Seyler about 1 year ago

So I tried to put it in the <<EOF>> rule like this:

<V95,V01,V05,S05,S09>{
  "`"[a-zA-Z_0-9]+    { FL; VALTEXT;
              if (LPARSEP->sigParser()) { yyerrorf("Define or directive not defined: %s",yytext); }
              else { CALLBACK(preprocCb); } }
  "//"[^\n]*        { FL; VALTEXT; CALLBACK(commentCb); }  /* throw away single line comments */
  "/*"                   { FL; yy_push_state(CMTMODE); yymore(); }  // FL; marks start for COMMENT callback
  .            { FL; VALTEXT; CALLBACK(operatorCb); return ygenOPERATOR; } /* return single char ops. */
  <<EOF>>        { CALLBACK(endparseCb); yyterminate(); }
}

But as there are more than one file in the buffer, I am afraid this will raise more problems than it solves.

Another idea would be using yyin or yy_switch_to_buffer() directly. How is the buffer structure in your parser organized. I'm not sure <<EOF>> will work with this.

Regards

RE: Did anyone ever use the Parser as a stand-alone SV parser in a C++ project? - Added by Wilson Snyder about 1 year ago

I believe moving endParse as described will fix the problem of it being called before the endclass. If you have different requirements, the solution will obviously be different :)

I didn't understand your comment about commentCb, but if you think it might solve your easier issue please try it and just let me know if it helps.

RE: Did anyone ever use the Parser as a stand-alone SV parser in a C++ project? - Added by Jan Seyler 11 months ago

Hi,

I just realized a problem. When I parse a function like
function int blub(uvm_component parent);
        return 0;
    endfunction : blub
where uvm_component is not known, the parser starts a functionCb but the endtastfunctionCb is never called. I guess the function does not match the grammar, because the function
function int blub();
        return 0;
    endfunction : blub

is parsed correctly. So I guess it can be traced back to the portlist.

At the moment, I am trying to understand every match for the function_declaration in the Yacc file, but this is kind of deep. So maybe you can just say me, what is not conform to IEEE with the first function.

As I don't want to mess the grammar, I am thinking about adding the endtaskfunctionCb to the token within the lex-file.

I see the very same problem with the endclassCb.

Interestingly, if uvm_component is declared as a class in front of the function, the functionCb is not working at all.

Thank you, regards

RE: Did anyone ever use the Parser as a stand-alone SV parser in a C++ project? - Added by Wilson Snyder 11 months ago

The parser requires all types to be predefined. This is required by the language standard. However I've debated fixing that, this requires a major parsing change. The bigger problem is the parser can't currently handle UVM, because it breaks a number of assumptions about how things work. I intend to fix this at some point, but they are probably 6 months away as I do not need them at present. If you'd like to start on either I can provide pointers.

RE: Did anyone ever use the Parser as a stand-alone SV parser in a C++ project? - Added by Jan Seyler 11 months ago

Hey, I actually would love to see UVM working with this parser! As I need this now, Can you please give me some pointers?

And I think, I will actually do the quick fix, by adding the callback in the Lexer.

Regards

« Previous 1 2 3 Next » (26-50/64)