• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
      • Gl
      • Esim
      • Vl2014
        • Warnings
        • Primitives
        • Use-set
        • Syntax
        • Getting-started
        • Utilities
        • Loader
          • Preprocessor
            • Vl-iframe-p
            • Preprocessor-ifdef-minutia
            • Vl-preprocess-loop
            • Vl-read-until-end-of-define
            • Vl-expand-define
            • Vl-read-include
            • Vl-process-ifdef
            • Vl-substitute-into-macro-text
            • Vl-preprocess
            • Vl-define
            • Vl-process-define
            • Vl-process-undef
            • Preprocessor-include-minutia
              • Vl-split-define-text
              • Vl-read-timescale
              • Vl-line-up-define-formals-and-actuals
              • Vl-process-else
              • Vl-process-endif
              • Vl-istack-p
              • Vl-is-compiler-directive-p
              • Vl-check-remaining-formals-all-have-defaults
              • Vl-safe-previous-n
              • Vl-safe-next-n
              • Vl-defines
              • *vl-preprocess-clock*
            • Vl-loadconfig
            • Lexer
            • Vl-loadstate
            • Parser
            • Vl-load-merge-descriptions
            • Scope-of-defines
            • Vl-load-file
            • Vl-flush-out-descriptions
            • Vl-description
            • Vl-loadresult
            • Vl-read-file
            • Vl-find-basename/extension
            • Vl-find-file
            • Vl-read-files
            • Extended-characters
            • Vl-load
            • Vl-load-main
            • Vl-load-description
            • Vl-descriptions-left-to-load
            • Inject-warnings
            • Vl-load-descriptions
            • Vl-load-files
            • Vl-load-summary
            • Vl-collect-modules-from-descriptions
            • Vl-descriptionlist
          • Transforms
          • Lint
          • Mlib
          • Server
          • Kit
          • Printer
          • Esim-vl
          • Well-formedness
        • Sv
        • Fgl
        • Vwsim
        • Vl
        • X86isa
        • Svl
        • Rtl
      • Software-verification
      • Math
      • Testing-utilities
    • Preprocessor

    Preprocessor-include-minutia

    Subtle notes about `include handling.

    The Verilog spec is very vague about how include directives are to be processed.

    It does nicely explain that we are to simply replace the `include "foo.v" directive with the entire contents of foo.b, and explains some things related to the syntax of the directive. It also says that the included file can itself contain include directives, which of course seems perfectly reasonable.

    The spec explicitly says the filename can be an absolute or relative pathname. In the case of an absolute pathname, the intention seems pretty clear.

    Unfortunately, the spec does not explain anything about what a relative path is relative to. Upon reading the spec, I thought, "well, obviously it means relative to whatever file is currently being processed." But it turns out that this is not at all how Verilog-XL and NCVerilog handle things.

    Instead, both of these tools include a notion of include directories. These directories are similar to, but distinct from, the library directories which are used to load "missing" modules. These directories are configured with command-line options like:

    +incdir+/home/jared/dir1 +incdir+/home/jared/dir2 ...

    When these tools see `include "foo.v", they seem to search for foo.v in these include directories, and include the first file that is found.

    Because of this, it does not work to just try to write includes relative to whatever file is being loaded, you just always write them relative to whatever the include path is going to be.