Skip to content

Compiler directives cause downstream errors #32

@MatchlessJoyride

Description

@MatchlessJoyride

ast_error.py.txt
error.sv.txt
no_error.sv.txt

I have attached three files to help recreate this issue. You'll have to remove the .txt extension to run them locally.

When a compiler directive is inserted in the codebase, it has a potential to "break" the syntax. In error.sv I have made a contrived example that breaks the begin/end of an always_comb block:

    always_comb begin
        `ifndef MYDEFINE
            if (a) begin
        `else
            if (b) begin
        `endif
                c = a ^ b;
            end
    end

This has the downstream effect of breaking the ability of tree-sitter to properly parse the module instantiation.

In ast_error.py you will see this query:

MODULE_INST_QUERY = '''
(module_instantiation
  (simple_identifier) @module_name (#eq? @module_name "my_module")
  (hierarchical_instance
    (name_of_instance
      (simple_identifier) @instance_name
    )
  )
)
'''

When ast_error.py is run against no_error.sv, it properly returns the module instantiation. But it does not when you run it against error.sv.

Command lines:

python ast_error.py error.sv

python ast_error.py no_error.sv

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions