drom / circt-fuzzer

Generator of random circuits
MIT License
4 stars 1 forks source link

Generate Context Sensitive Keywords #12

Open seldridge opened 3 years ago

seldridge commented 3 years ago

The FIRRTL grammar is context sensitive. While not insanely critical, it could help catch parsing bugs if there's an option to generate identifiers that use known FIRRTL keywords.

E.g., the following circuit is tricky for a parser (see: input intput, output UInt, or inst of of inst):

circuit Tricky:
  module inst:
    input input: UInt<1>
    output UInt: UInt<1>
    UInt <= input
  module Tricky:
    input input: UInt<1>
    output UInt: UInt<1>

    inst of of inst

    of.input <= input
    UInt <= of.UInt

The CIRCT FIRRTL parser currently falls down with this:

firtool Tricky.fir
# Tricky.fir:5:10: error: expected '(' in integer expression
#     UInt <= input

While the Scala FIRRTL Compiler parser doesn't care (because it's using an ANLTR specification of the grammar).

Support for this would help unearth things like: https://github.com/llvm/circt/issues/550.

However, this type of problem is likely pretty rare and this issue is likely lower priority.

drom commented 3 years ago

Good idea. Do you think that set of focused tests could cover these corner cases?

seldridge commented 3 years ago

Do you think that set of focused tests could cover these corner cases?

Probably. The test cases included in fixes to llvm/circt#550 and llvm/circt#559 are effectively this.

I had thought that this problem would be more widespread, but I wasn't able to uncover issues other than those two. It's not high priority to add this feature to the fuzzer.