Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preprocessor callback request #94

Closed
veripoolbot opened this issue May 27, 2009 · 12 comments
Closed

Preprocessor callback request #94

veripoolbot opened this issue May 27, 2009 · 12 comments
Assignees

Comments

@veripoolbot
Copy link
Collaborator


Author Name: David A
Original Redmine Issue: 94 from https://www.veripool.org
Original Date: 2009-05-27
Original Assignee: Wilson Snyder (@wsnyder)


Hi,

I might be wrong, but I haven't found a way (callback) to let the parser notify me when a (previously define) MACRO is being substituted.

Would it be possible to include such a callback? preferably if the callback could provide (argument list) the text to be substituted (once all MACRO arguments have been resolved).

Thanks,

David

@veripoolbot
Copy link
Collaborator Author


Original Redmine Comment
Author Name: Wilson Snyder (@wsnyder)
Original Date: 2009-05-28T00:32:01Z


The Verilog::Preproc::def_value callback handles this now; by default it calls Verilog::Getopt. You can change it to do whatever you like, or intercept the Getopt's version by subclassing Verilog::Getopt and passing a reference to that new class in the opt=> argument of the Verilog::SigParser->new call.

@veripoolbot
Copy link
Collaborator Author


Original Redmine Comment
Author Name: David A
Original Date: 2009-05-28T03:26:20Z


I'll give it a try, thanks!

@veripoolbot
Copy link
Collaborator Author


Original Redmine Comment
Author Name: David A
Original Date: 2009-05-29T00:30:53Z


Hi Wilson,

Does this work for macros with arguments? I haven't find the way to do what I need.

Ideally what I need is to know what is going to be substituted (before it actually is substituted) and a way modify it before it is substituted.

In other words this would be a callback (once the macro's actual argument have been inserted in the macro-value) once the macro-value is ready to substituted in the buffer (but before it is actually substituted), with an input argument providing the actual macro-value, and expecting a return value with the modified macro-value (a string which is what will be actually substituted).

Is there away to do this with the current capabilities of the Verilog::Preproc
(sorry to ask again, I couldn't find a way to do it), if not, could it be included in a future release?

Thanks in advance
David

@veripoolbot
Copy link
Collaborator Author


Original Redmine Comment
Author Name: Wilson Snyder (@wsnyder)
Original Date: 2009-05-29T00:51:38Z


I think you're looking for VPreprocImp::defineSubst, which is in c++ code to call a perl hook at the bottom?

IE calling `foo(bar) would insert result_of(CALLBACK(definition_with_foo_bar_expanded))?

@veripoolbot
Copy link
Collaborator Author


Original Redmine Comment
Author Name: David A
Original Date: 2009-05-29T19:07:52Z


Thats what I need. I'll take a look. Thanks

@veripoolbot
Copy link
Collaborator Author


Original Redmine Comment
Author Name: Saul Cuellar
Original Date: 2009-06-01T15:34:17Z


Hi guys,

David, I had the same problem recently and I modified the Verilog::Preproc to add a new callback. As Wilson said you need VPreprocImp::defineSubst. The new callback is "subsdef" and some of the features that it has are:

  • It's called when a macro substution is going to be executed.

  • It takes the substituted string as arguments. Then you can change it. ;)

  • The callback should return a string variable. If you don't want to modify the original process just return what you got as argument.

  • Any returned string is send to the parser.

I hope this callback can help you.

Thanks Wilson Verilog-Perl is an excelent open soure project, I would like to contribute with new features.

@veripoolbot
Copy link
Collaborator Author


Original Redmine Comment
Author Name: David A
Original Date: 2009-06-05T16:08:34Z


Thanks, that worked fine!.

@veripoolbot
Copy link
Collaborator Author


Original Redmine Comment
Author Name: Wilson Snyder (@wsnyder)
Original Date: 2009-06-05T20:41:35Z


Saul, Thanks for patching this, it's great to have contributions and I want to add it to the next release.

Sorry, perhaps I missed something, but the four files attached here seem to match the distribution version and don't have any changes in them. Can you attach the changes (best is a "git diff" off from the git version.) I'm also confused as to what David tried.

@veripoolbot
Copy link
Collaborator Author


Original Redmine Comment
Author Name: David A
Original Date: 2009-06-16T15:47:40Z


Hi Wilson,

I know Saul from school and we're working on similar projects. He sent me the extended parser code prior to the post, so I never really checked the code he uploaded with his post. :P

Anyhow, here is the code Saul sent me originally, which adds the aforementioned callback (changes made by Saul).

@veripoolbot
Copy link
Collaborator Author


Original Redmine Comment
Author Name: Wilson Snyder (@wsnyder)
Original Date: 2009-06-16T19:09:10Z


Thanks for the files. Unless you see a reason not to, I think the callback should also be called for non-parameterized defines. While defValue could be hacked to do the same thing for non-param defines only, it seems non-obvious that substDef wouldn't be called for both types.

@veripoolbot
Copy link
Collaborator Author


Original Redmine Comment
Author Name: Wilson Snyder (@wsnyder)
Original Date: 2009-06-16T19:24:00Z


I made two changes; I call the callback on non-parameterized defines, and I renamed it def_substitute to match the other def_* functions. And I added a test.

Thanks again for the patches. I've pushed this to git, and it will be in the next release.

@veripoolbot
Copy link
Collaborator Author


Original Redmine Comment
Author Name: Wilson Snyder (@wsnyder)
Original Date: 2009-06-17T12:01:50Z


In 3.211.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants