VSCode-SystemVerilog icon indicating copy to clipboard operation
VSCode-SystemVerilog copied to clipboard

`include directive should be allowed anywhere

Open DanChianucci opened this issue 4 years ago • 8 comments

Currently I get an extraneous input error if the `include is anywhere except file scope.

ie) With UVM, it is common for the uvc package to simple contain includes for individual classes

package my_uvc_pkg;
  `include "transaction_class.svh"   //<-- Error seen here because parser is not expecting `include
  `include "monitor_class.svh"
  // etc...
endpackage

DanChianucci avatar Aug 23 '21 15:08 DanChianucci

It looks like this same issue extends to all compiler directives. ie `uvm_component_utils(my_component)

DanChianucci avatar Aug 23 '21 15:08 DanChianucci

@DanChianucci do you know what is generating the error? Are you using Verilator? If so, it is known to crash hard on most UVM syntaxes. Please see #31.

joecrop avatar Nov 01 '21 16:11 joecrop

The bundled antlr parser is generating the error

DanChianucci avatar Nov 16 '21 15:11 DanChianucci

Hi @DanChianucci, I finally got around to this. I don't think the problem is the include inside a package. When I rename the file to be transaction_class.sv (removed the h in the extension) the parser is happy. Can you confirm this? If so, this is an easy fix. This file compiles with no errors for me:

package my_uvc_pkg;
    `include "transaction_class.sv"
    `include "monitor_class.sv"
    // etc...
endpackage

class joe extends uvm_object;

    `uvm_object_utils(joe);

    function new(string name = "joe");
        super.new(name);
    endfunction: new
    
enclass joe 

joecrop avatar Mar 09 '22 17:03 joecrop

Changing from .svh to .sv fixes Issue #127
ie. "missing FILENAME at '"transaction_class.svh"'

but not the error I am talking about in this issue ie. extraneous input "`include"

DanChianucci avatar Mar 14 '22 14:03 DanChianucci

Thanks @DanChianucci, I am able to reproduce this now. There are quite a few places that are missing allowance of includes. I'll try and capture as many as I can find.

joecrop avatar Mar 14 '22 20:03 joecrop

always @( * ) begin
  if ( cond1 ) begin
    case ( sig_key )
      `DEF_CASE1 : sig_name <= 8'b0;
      `DEF_CASE2 : sig_name <= 8'b1;
      default : sig_name <= 8'b1;
    endcase
  end
end

Gives "no viable alternative at input" for: `DEF_CASE1, `DEF_CASE2 and default

It seems that ` sign and default are problems here.

niciki-niciki avatar Nov 07 '22 12:11 niciki-niciki

When instantiating module and using some

...
  .port_name ( `DEF_VAL ),
...

for constant port value - I also get "no viable alternative at input" for ` sign

niciki-niciki avatar Nov 07 '22 13:11 niciki-niciki