1

I am using the preprocessor of gcc to remove the comments from a verilog (.v) file (since the comment syntax is same as C/C++). I am using perl and hence used a shell command from my perl script

gcc -E $dest > $commentsrem

where $dest is my verilog file renamed as a .c file. Since the preprocessor outputs data onto stdout, I redirected it to a file named $commentsrem . Now the problem I face is that I get messages on the terminal saying

try.c:577: unterminated character constant

I guess this is because although in C you need to use '\' to continue a statement on a new line, verilog has no such requirement. That is what it is reporting.

Now although in spite of these, it achieves what I want, it's making the terminal messy. Any way to keep it quiet?

2 Answers 2

1

Redirecting standard error to the null device would silence all error output from the preprocessor. Not generally recommended, as you will not see genuine errors either.

gcc -E $dest > $commentsrem 2> /dev/null

The better way would be to filter known messages from the stderr by use of grep -v, so you would still see other error messages. For this, you need to redirect stderr to stdout, because piping doesn't work on stderr:

gcc -E $dest 2>&1 > $commentsrem | grep -v "unterminated character constant"

The order of the redirections is important here. If you wrote > $commentsrem 2>&1, the error messages would end up in $commentsrem instead.

For details on the redirecting, ref. this Q/A.

2
  • Thanks for this !! A little more help, suppose I want to suppress some other error strings too , say "Cannot find keyboard type" along with this error, what options do I use for grep. -e doesnt work in my grep.
    – gururaj
    Jun 13, 2012 at 10:47
  • @gururaj: grep -v "unterminated character constant\|Cannot find keyboard type" If you found my answer helpful, consider upvoting / accepting it. That's how this website works, you know?
    – DevSolar
    Jun 13, 2012 at 11:15
1

Since you are using Perl, the vppreproc script can be used to remove Verilog comments.

vppreproc --nocomment in.v > out.v

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.