├── .bazelrc ├── .clang-format ├── .clang-tidy ├── .editorconfig ├── .github ├── ISSUE_TEMPLATE │ ├── formatter-issue.md │ ├── kythe-issues.md │ ├── language-server-issue.md │ ├── lexer-parser-issue.md │ ├── style-linter-bug.md │ └── style-linter-feature-request.md ├── bin │ ├── before-submit.sh │ ├── build-and-test.sh │ ├── check-potential-problems.sh │ ├── error-log-analyzer.py │ ├── generate-coverage-html.sh │ ├── get-bant-path.sh │ ├── github-pages-setup.sh │ ├── install-bazel.sh │ ├── install-kythe-tools.sh │ ├── install-kythe.sh │ ├── make-compilation-db.sh │ ├── run-build-cleaner.sh │ ├── run-clang-tidy-cached.cc │ ├── run-format.sh │ ├── run-kythe.sh │ ├── set-compiler.sh │ ├── simple-install.sh │ ├── smoke-test.sh │ └── verify-kythe-extraction.sh ├── settings.sh └── workflows │ └── verible-ci.yml ├── .gitignore ├── .pylintrc ├── .readthedocs.yaml ├── AUTHORS ├── BUILD ├── CONTRIBUTING.md ├── LICENSE ├── MODULE.bazel ├── README.md ├── bazel ├── BUILD ├── bison.bzl ├── build-version.sh ├── flex.bzl ├── installer.patch ├── jsonhpp.BUILD ├── proto-fix-uninitialized-value.patch ├── sh_test_with_runfiles_lib.bzl ├── sh_test_with_runfiles_lib.sh └── variables.bzl ├── doc ├── conf.py ├── development.md ├── formatter.md ├── formatter_simplified_class_diagram.graphml ├── formatter_simplified_class_diagram.png ├── index.rst ├── indexing.md ├── parser_design.md ├── requirements.txt └── style_lint.md ├── external_libs ├── BUILD ├── README.md ├── editscript.h └── editscript_test.cc ├── img ├── Makefile ├── example-github-integration.png ├── language-server-demo-vscode.png ├── verible-logo-headline.png └── verible-logo.svg ├── kythe-browse.sh ├── shell.nix ├── third_party ├── portable_endian │ ├── BUILD │ └── portable_endian.h └── proto │ └── kythe │ ├── BUILD │ ├── LICENSE │ ├── README.md │ ├── analysis.proto │ └── storage.proto ├── verible ├── common │ ├── README.md │ ├── analysis │ │ ├── BUILD │ │ ├── README.md │ │ ├── citation.cc │ │ ├── citation.h │ │ ├── command-file-lexer.cc │ │ ├── command-file-lexer.h │ │ ├── command-file-lexer_test.cc │ │ ├── command_file.lex │ │ ├── file-analyzer.cc │ │ ├── file-analyzer.h │ │ ├── file-analyzer_test.cc │ │ ├── line-lint-rule.h │ │ ├── line-linter-test-utils.h │ │ ├── line-linter.cc │ │ ├── line-linter.h │ │ ├── line-linter_test.cc │ │ ├── lint-rule-status.cc │ │ ├── lint-rule-status.h │ │ ├── lint-rule-status_test.cc │ │ ├── lint-rule.h │ │ ├── lint-waiver.cc │ │ ├── lint-waiver.h │ │ ├── lint-waiver_test.cc │ │ ├── linter-test-utils.cc │ │ ├── linter-test-utils.h │ │ ├── linter-test-utils_test.cc │ │ ├── matcher │ │ │ ├── BUILD │ │ │ ├── README.md │ │ │ ├── bound-symbol-manager.cc │ │ │ ├── bound-symbol-manager.h │ │ │ ├── core-matchers.h │ │ │ ├── core-matchers_test.cc │ │ │ ├── descent-path.cc │ │ │ ├── descent-path.h │ │ │ ├── descent-path_test.cc │ │ │ ├── inner-match-handlers.cc │ │ │ ├── inner-match-handlers.h │ │ │ ├── matcher-builders.h │ │ │ ├── matcher-builders_test.cc │ │ │ ├── matcher-test-utils.cc │ │ │ ├── matcher-test-utils.h │ │ │ ├── matcher.cc │ │ │ ├── matcher.h │ │ │ └── matcher_test.cc │ │ ├── syntax-tree-lint-rule.h │ │ ├── syntax-tree-linter-test-utils.h │ │ ├── syntax-tree-linter.cc │ │ ├── syntax-tree-linter.h │ │ ├── syntax-tree-linter_test.cc │ │ ├── syntax-tree-search-test-utils.cc │ │ ├── syntax-tree-search-test-utils.h │ │ ├── syntax-tree-search-test-utils_test.cc │ │ ├── syntax-tree-search.cc │ │ ├── syntax-tree-search.h │ │ ├── syntax-tree-search_test.cc │ │ ├── text-structure-lint-rule.h │ │ ├── text-structure-linter-test-utils.h │ │ ├── text-structure-linter.cc │ │ ├── text-structure-linter.h │ │ ├── text-structure-linter_test.cc │ │ ├── token-stream-lint-rule.h │ │ ├── token-stream-linter-test-utils.h │ │ ├── token-stream-linter.cc │ │ ├── token-stream-linter.h │ │ ├── token-stream-linter_test.cc │ │ ├── violation-handler.cc │ │ └── violation-handler.h │ ├── formatting │ │ ├── BUILD │ │ ├── README.md │ │ ├── align.cc │ │ ├── align.h │ │ ├── align_test.cc │ │ ├── basic-format-style-init.cc │ │ ├── basic-format-style-init.h │ │ ├── basic-format-style.cc │ │ ├── basic-format-style.h │ │ ├── basic-format-style_test.cc │ │ ├── format-token.cc │ │ ├── format-token.h │ │ ├── format-token_test.cc │ │ ├── layout-optimizer-internal.h │ │ ├── layout-optimizer.cc │ │ ├── layout-optimizer.h │ │ ├── layout-optimizer_test.cc │ │ ├── line-wrap-searcher.cc │ │ ├── line-wrap-searcher.h │ │ ├── line-wrap-searcher_test.cc │ │ ├── state-node.cc │ │ ├── state-node.h │ │ ├── state-node_test.cc │ │ ├── token-partition-tree-test-utils.cc │ │ ├── token-partition-tree-test-utils.h │ │ ├── token-partition-tree.cc │ │ ├── token-partition-tree.h │ │ ├── token-partition-tree_test.cc │ │ ├── tree-annotator.cc │ │ ├── tree-annotator.h │ │ ├── tree-annotator_test.cc │ │ ├── tree-unwrapper.cc │ │ ├── tree-unwrapper.h │ │ ├── tree-unwrapper_test.cc │ │ ├── unwrapped-line-test-utils.cc │ │ ├── unwrapped-line-test-utils.h │ │ ├── unwrapped-line.cc │ │ ├── unwrapped-line.h │ │ ├── unwrapped-line_test.cc │ │ ├── verification.cc │ │ ├── verification.h │ │ └── verification_test.cc │ ├── lexer │ │ ├── BUILD │ │ ├── README.md │ │ ├── flex-lexer-adapter.h │ │ ├── lexer-test-util.cc │ │ ├── lexer-test-util.h │ │ ├── lexer-test-util_test.cc │ │ ├── lexer.h │ │ ├── token-generator.h │ │ ├── token-stream-adapter.cc │ │ ├── token-stream-adapter.h │ │ └── token-stream-adapter_test.cc │ ├── lsp │ │ ├── BUILD │ │ ├── dummy-ls.cc │ │ ├── dummy-ls_test.sh │ │ ├── jcxxgen-testfile.yaml │ │ ├── jcxxgen.cc │ │ ├── jcxxgen_test.cc │ │ ├── json-rpc-dispatcher.cc │ │ ├── json-rpc-dispatcher.h │ │ ├── json-rpc-dispatcher_test.cc │ │ ├── json-rpc-expect.cc │ │ ├── lsp-file-utils.cc │ │ ├── lsp-file-utils.h │ │ ├── lsp-file-utils_test.cc │ │ ├── lsp-protocol-enums.h │ │ ├── lsp-protocol-operators.h │ │ ├── lsp-protocol-operators_test.cc │ │ ├── lsp-protocol.yaml │ │ ├── lsp-text-buffer.cc │ │ ├── lsp-text-buffer.h │ │ ├── lsp-text-buffer_test.cc │ │ ├── message-stream-splitter.cc │ │ ├── message-stream-splitter.h │ │ └── message-stream-splitter_test.cc │ ├── parser │ │ ├── BUILD │ │ ├── README.md │ │ ├── bison-parser-adapter.h │ │ ├── bison-parser-common.cc │ │ ├── bison-parser-common.h │ │ ├── bison-parser-common_test.cc │ │ ├── parse.h │ │ ├── parser-param.cc │ │ ├── parser-param.h │ │ ├── parser-test-util.h │ │ └── yacc.bzl │ ├── strings │ │ ├── BUILD │ │ ├── README.md │ │ ├── comment-utils.cc │ │ ├── comment-utils.h │ │ ├── comment-utils_test.cc │ │ ├── compare.h │ │ ├── compare_test.cc │ │ ├── diff.cc │ │ ├── diff.h │ │ ├── diff_test.cc │ │ ├── display-utils.cc │ │ ├── display-utils.h │ │ ├── display-utils_test.cc │ │ ├── line-column-map.cc │ │ ├── line-column-map.h │ │ ├── line-column-map_test.cc │ │ ├── mem-block.h │ │ ├── naming-utils.cc │ │ ├── naming-utils.h │ │ ├── naming-utils_test.cc │ │ ├── obfuscator.cc │ │ ├── obfuscator.h │ │ ├── obfuscator_test.cc │ │ ├── patch.cc │ │ ├── patch.h │ │ ├── patch_test.cc │ │ ├── position.cc │ │ ├── position.h │ │ ├── position_test.cc │ │ ├── random.cc │ │ ├── random.h │ │ ├── random_test.cc │ │ ├── range.cc │ │ ├── range.h │ │ ├── range_test.cc │ │ ├── rebase.cc │ │ ├── rebase.h │ │ ├── rebase_test.cc │ │ ├── split.cc │ │ ├── split.h │ │ ├── split_test.cc │ │ ├── string-memory-map.h │ │ ├── string-memory-map_test.cc │ │ ├── utf8.h │ │ └── utf8_test.cc │ ├── text │ │ ├── BUILD │ │ ├── README.md │ │ ├── concrete-syntax-leaf.cc │ │ ├── concrete-syntax-leaf.h │ │ ├── concrete-syntax-leaf_test.cc │ │ ├── concrete-syntax-tree.cc │ │ ├── concrete-syntax-tree.h │ │ ├── concrete-syntax-tree_test.cc │ │ ├── config-utils.cc │ │ ├── config-utils.h │ │ ├── config-utils_test.cc │ │ ├── constants.h │ │ ├── macro-definition.cc │ │ ├── macro-definition.h │ │ ├── macro-definition_test.cc │ │ ├── parser-verifier.cc │ │ ├── parser-verifier.h │ │ ├── parser-verifier_test.cc │ │ ├── symbol-ptr.h │ │ ├── symbol.cc │ │ ├── symbol.h │ │ ├── syntax-tree-context.h │ │ ├── syntax-tree-context_test.cc │ │ ├── text-structure-test-utils.cc │ │ ├── text-structure-test-utils.h │ │ ├── text-structure.cc │ │ ├── text-structure.h │ │ ├── text-structure_test.cc │ │ ├── token-info-json.cc │ │ ├── token-info-json.h │ │ ├── token-info-json_test.cc │ │ ├── token-info-test-util.cc │ │ ├── token-info-test-util.h │ │ ├── token-info-test-util_test.cc │ │ ├── token-info.cc │ │ ├── token-info.h │ │ ├── token-info_test.cc │ │ ├── token-stream-view.cc │ │ ├── token-stream-view.h │ │ ├── token-stream-view_test.cc │ │ ├── tree-builder-test-util.cc │ │ ├── tree-builder-test-util.h │ │ ├── tree-builder-test-util_test.cc │ │ ├── tree-compare.cc │ │ ├── tree-compare.h │ │ ├── tree-compare_test.cc │ │ ├── tree-context-visitor.cc │ │ ├── tree-context-visitor.h │ │ ├── tree-context-visitor_test.cc │ │ ├── tree-utils.cc │ │ ├── tree-utils.h │ │ ├── tree-utils_test.cc │ │ └── visitors.h │ ├── tools │ │ ├── BUILD │ │ ├── README.md │ │ ├── patch-tool.cc │ │ ├── patch_tool_test.sh │ │ ├── verible-transform-interactive.sh │ │ └── verible-transform-interactive_test.sh │ └── util │ │ ├── BUILD │ │ ├── README.md │ │ ├── algorithm.h │ │ ├── algorithm_test.cc │ │ ├── auto-iterator.h │ │ ├── auto-iterator_test.cc │ │ ├── auto-pop-stack.h │ │ ├── auto-pop-stack_test.cc │ │ ├── bijective-map.h │ │ ├── bijective-map_test.cc │ │ ├── casts.h │ │ ├── container-iterator-range.h │ │ ├── container-iterator-range_test.cc │ │ ├── container-proxy.h │ │ ├── container-proxy_test.cc │ │ ├── container-util.h │ │ ├── enum-flags.h │ │ ├── enum-flags_test.cc │ │ ├── expandable-tree-view.h │ │ ├── expandable-tree-view_test.cc │ │ ├── file-util.cc │ │ ├── file-util.h │ │ ├── file-util_test.cc │ │ ├── forward.h │ │ ├── forward_test.cc │ │ ├── init-command-line.cc │ │ ├── init-command-line.h │ │ ├── interval-map.h │ │ ├── interval-map_test.cc │ │ ├── interval-set.h │ │ ├── interval-set_test.cc │ │ ├── interval.h │ │ ├── interval_test.cc │ │ ├── iterator-adaptors.h │ │ ├── iterator-adaptors_test.cc │ │ ├── iterator-range.h │ │ ├── iterator-range_test.cc │ │ ├── logging.h │ │ ├── map-tree.h │ │ ├── map-tree_test.cc │ │ ├── module-version.bzl │ │ ├── range.h │ │ ├── range_test.cc │ │ ├── sha256.cc │ │ ├── sha256.h │ │ ├── sha256_test.cc │ │ ├── simple-zip.cc │ │ ├── simple-zip.h │ │ ├── simple-zip_test.cc │ │ ├── spacer.cc │ │ ├── spacer.h │ │ ├── spacer_test.cc │ │ ├── status-macros.h │ │ ├── subcommand.cc │ │ ├── subcommand.h │ │ ├── subcommand_test.cc │ │ ├── thread-pool.cc │ │ ├── thread-pool.h │ │ ├── thread-pool_test.cc │ │ ├── top-n.h │ │ ├── top-n_test.cc │ │ ├── tree-operations.cc │ │ ├── tree-operations.h │ │ ├── tree-operations_test.cc │ │ ├── type-traits.h │ │ ├── type-traits_test.cc │ │ ├── user-interaction.cc │ │ ├── user-interaction.h │ │ ├── user-interaction_test.cc │ │ ├── value-saver.h │ │ ├── value-saver_test.cc │ │ ├── vector-tree-iterators.h │ │ ├── vector-tree-iterators_test.cc │ │ ├── vector-tree-test-util.cc │ │ ├── vector-tree-test-util.h │ │ ├── vector-tree.h │ │ ├── vector-tree_test.cc │ │ ├── with-reason.h │ │ └── with-reason_test.cc └── verilog │ ├── CST │ ├── BUILD │ ├── DPI.cc │ ├── DPI.h │ ├── DPI_test.cc │ ├── README.md │ ├── class.cc │ ├── class.h │ ├── class_test.cc │ ├── constraints.cc │ ├── constraints.h │ ├── constraints_test.cc │ ├── context-functions.h │ ├── context-functions_test.cc │ ├── data.cc │ ├── data.h │ ├── data_test.cc │ ├── declaration.cc │ ├── declaration.h │ ├── declaration_test.cc │ ├── dimensions.cc │ ├── dimensions.h │ ├── dimensions_test.cc │ ├── expression.cc │ ├── expression.h │ ├── expression_test.cc │ ├── functions.cc │ ├── functions.h │ ├── functions_test.cc │ ├── identifier.cc │ ├── identifier.h │ ├── identifier_test.cc │ ├── macro.cc │ ├── macro.h │ ├── macro_test.cc │ ├── match-test-utils.cc │ ├── match-test-utils.h │ ├── module.cc │ ├── module.h │ ├── module_test.cc │ ├── net.cc │ ├── net.h │ ├── net_test.cc │ ├── numbers.cc │ ├── numbers.h │ ├── numbers_test.cc │ ├── package.cc │ ├── package.h │ ├── package_test.cc │ ├── parameters.cc │ ├── parameters.h │ ├── parameters_test.cc │ ├── port.cc │ ├── port.h │ ├── port_test.cc │ ├── seq-block.cc │ ├── seq-block.h │ ├── seq-block_test.cc │ ├── statement.cc │ ├── statement.h │ ├── statement_test.cc │ ├── tasks.cc │ ├── tasks.h │ ├── tasks_test.cc │ ├── type.cc │ ├── type.h │ ├── type_test.cc │ ├── verilog-matchers.cc │ ├── verilog-matchers.h │ ├── verilog-matchers_test.cc │ ├── verilog-nonterminals.cc │ ├── verilog-nonterminals.h │ ├── verilog-nonterminals_test.cc │ ├── verilog-tree-json.cc │ ├── verilog-tree-json.h │ ├── verilog-tree-json_test.cc │ ├── verilog-tree-print.cc │ ├── verilog-tree-print.h │ ├── verilog-tree-print_test.cc │ ├── verilog-treebuilder-utils.cc │ ├── verilog-treebuilder-utils.h │ ├── verilog-treebuilder-utils_test.cc │ └── verilog_nonterminals_foreach.inc │ ├── README.md │ ├── analysis │ ├── BUILD │ ├── README.md │ ├── checkers │ │ ├── BUILD │ │ ├── README.md │ │ ├── always-comb-blocking-rule.cc │ │ ├── always-comb-blocking-rule.h │ │ ├── always-comb-blocking-rule_test.cc │ │ ├── always-comb-rule.cc │ │ ├── always-comb-rule.h │ │ ├── always-comb-rule_test.cc │ │ ├── always-ff-non-blocking-rule.cc │ │ ├── always-ff-non-blocking-rule.h │ │ ├── always-ff-non-blocking-rule_test.cc │ │ ├── banned-declared-name-patterns-rule.cc │ │ ├── banned-declared-name-patterns-rule.h │ │ ├── banned-declared-name-patterns-rule_test.cc │ │ ├── case-missing-default-rule.cc │ │ ├── case-missing-default-rule.h │ │ ├── case-missing-default-rule_test.cc │ │ ├── constraint-name-style-rule.cc │ │ ├── constraint-name-style-rule.h │ │ ├── constraint-name-style-rule_test.cc │ │ ├── create-object-name-match-rule.cc │ │ ├── create-object-name-match-rule.h │ │ ├── create-object-name-match-rule_test.cc │ │ ├── dff-name-style-rule.cc │ │ ├── dff-name-style-rule.h │ │ ├── dff-name-style-rule_test.cc │ │ ├── disable-statement-rule.cc │ │ ├── disable-statement-rule.h │ │ ├── disable-statement-rule_test.cc │ │ ├── endif-comment-rule.cc │ │ ├── endif-comment-rule.h │ │ ├── endif-comment-rule_test.cc │ │ ├── enum-name-style-rule.cc │ │ ├── enum-name-style-rule.h │ │ ├── enum-name-style-rule_test.cc │ │ ├── explicit-begin-rule.cc │ │ ├── explicit-begin-rule.h │ │ ├── explicit-begin-rule_test.cc │ │ ├── explicit-function-lifetime-rule.cc │ │ ├── explicit-function-lifetime-rule.h │ │ ├── explicit-function-lifetime-rule_test.cc │ │ ├── explicit-function-task-parameter-type-rule.cc │ │ ├── explicit-function-task-parameter-type-rule.h │ │ ├── explicit-function-task-parameter-type-rule_test.cc │ │ ├── explicit-parameter-storage-type-rule.cc │ │ ├── explicit-parameter-storage-type-rule.h │ │ ├── explicit-parameter-storage-type-rule_test.cc │ │ ├── explicit-task-lifetime-rule.cc │ │ ├── explicit-task-lifetime-rule.h │ │ ├── explicit-task-lifetime-rule_test.cc │ │ ├── forbid-consecutive-null-statements-rule.cc │ │ ├── forbid-consecutive-null-statements-rule.h │ │ ├── forbid-consecutive-null-statements-rule_test.cc │ │ ├── forbid-defparam-rule.cc │ │ ├── forbid-defparam-rule.h │ │ ├── forbid-defparam-rule_test.cc │ │ ├── forbid-line-continuations-rule.cc │ │ ├── forbid-line-continuations-rule.h │ │ ├── forbid-line-continuations-rule_test.cc │ │ ├── forbid-negative-array-dim.cc │ │ ├── forbid-negative-array-dim.h │ │ ├── forbid-negative-array-dim_test.cc │ │ ├── forbidden-anonymous-enums-rule.cc │ │ ├── forbidden-anonymous-enums-rule.h │ │ ├── forbidden-anonymous-enums-rule_test.cc │ │ ├── forbidden-anonymous-structs-unions-rule.cc │ │ ├── forbidden-anonymous-structs-unions-rule.h │ │ ├── forbidden-anonymous-structs-unions-rule_test.cc │ │ ├── forbidden-macro-rule.cc │ │ ├── forbidden-macro-rule.h │ │ ├── forbidden-macro-rule_test.cc │ │ ├── forbidden-symbol-rule.cc │ │ ├── forbidden-symbol-rule.h │ │ ├── forbidden-symbol-rule_test.cc │ │ ├── generate-label-prefix-rule.cc │ │ ├── generate-label-prefix-rule.h │ │ ├── generate-label-prefix-rule_test.cc │ │ ├── generate-label-rule.cc │ │ ├── generate-label-rule.h │ │ ├── generate-label-rule_test.cc │ │ ├── instance-shadow-rule.cc │ │ ├── instance-shadow-rule.h │ │ ├── instance-shadow-rule_test.cc │ │ ├── interface-name-style-rule.cc │ │ ├── interface-name-style-rule.h │ │ ├── interface-name-style-rule_test.cc │ │ ├── legacy-generate-region-rule.cc │ │ ├── legacy-generate-region-rule.h │ │ ├── legacy-generate-region-rule_test.cc │ │ ├── legacy-genvar-declaration-rule.cc │ │ ├── legacy-genvar-declaration-rule.h │ │ ├── legacy-genvar-declaration-rule_test.cc │ │ ├── line-length-rule.cc │ │ ├── line-length-rule.h │ │ ├── line-length-rule_test.cc │ │ ├── macro-name-style-rule.cc │ │ ├── macro-name-style-rule.h │ │ ├── macro-name-style-rule_test.cc │ │ ├── macro-string-concatenation-rule.cc │ │ ├── macro-string-concatenation-rule.h │ │ ├── macro-string-concatenation-rule_test.cc │ │ ├── mismatched-labels-rule.cc │ │ ├── mismatched-labels-rule.h │ │ ├── mismatched-labels-rule_test.cc │ │ ├── module-begin-block-rule.cc │ │ ├── module-begin-block-rule.h │ │ ├── module-begin-block-rule_test.cc │ │ ├── module-filename-rule.cc │ │ ├── module-filename-rule.h │ │ ├── module-filename-rule_test.cc │ │ ├── module-instantiation-rules.cc │ │ ├── module-instantiation-rules.h │ │ ├── module-instantiation-rules_test.cc │ │ ├── no-tabs-rule.cc │ │ ├── no-tabs-rule.h │ │ ├── no-tabs-rule_test.cc │ │ ├── no-trailing-spaces-rule.cc │ │ ├── no-trailing-spaces-rule.h │ │ ├── no-trailing-spaces-rule_test.cc │ │ ├── numeric-format-string-style-rule.cc │ │ ├── numeric-format-string-style-rule.h │ │ ├── numeric-format-string-style-rule_test.cc │ │ ├── one-module-per-file-rule.cc │ │ ├── one-module-per-file-rule.h │ │ ├── one-module-per-file-rule_test.cc │ │ ├── package-filename-rule.cc │ │ ├── package-filename-rule.h │ │ ├── package-filename-rule_test.cc │ │ ├── packed-dimensions-rule.cc │ │ ├── packed-dimensions-rule.h │ │ ├── packed-dimensions-rule_test.cc │ │ ├── parameter-name-style-rule.cc │ │ ├── parameter-name-style-rule.h │ │ ├── parameter-name-style-rule_test.cc │ │ ├── parameter-type-name-style-rule.cc │ │ ├── parameter-type-name-style-rule.h │ │ ├── parameter-type-name-style-rule_test.cc │ │ ├── plusarg-assignment-rule.cc │ │ ├── plusarg-assignment-rule.h │ │ ├── plusarg-assignment-rule_test.cc │ │ ├── port-name-suffix-rule.cc │ │ ├── port-name-suffix-rule.h │ │ ├── port-name-suffix-rule_test.cc │ │ ├── positive-meaning-parameter-name-rule.cc │ │ ├── positive-meaning-parameter-name-rule.h │ │ ├── positive-meaning-parameter-name-rule_test.cc │ │ ├── posix-eof-rule.cc │ │ ├── posix-eof-rule.h │ │ ├── posix-eof-rule_test.cc │ │ ├── proper-parameter-declaration-rule.cc │ │ ├── proper-parameter-declaration-rule.h │ │ ├── proper-parameter-declaration-rule_test.cc │ │ ├── signal-name-style-rule.cc │ │ ├── signal-name-style-rule.h │ │ ├── signal-name-style-rule_test.cc │ │ ├── struct-union-name-style-rule.cc │ │ ├── struct-union-name-style-rule.h │ │ ├── struct-union-name-style-rule_test.cc │ │ ├── suggest-parentheses-rule.cc │ │ ├── suggest-parentheses-rule.h │ │ ├── suggest-parentheses-rule_test.cc │ │ ├── suspicious-semicolon-rule.cc │ │ ├── suspicious-semicolon-rule.h │ │ ├── suspicious-semicolon-rule_test.cc │ │ ├── truncated-numeric-literal-rule.cc │ │ ├── truncated-numeric-literal-rule.h │ │ ├── truncated-numeric-literal-rule_test.cc │ │ ├── undersized-binary-literal-rule.cc │ │ ├── undersized-binary-literal-rule.h │ │ ├── undersized-binary-literal-rule_test.cc │ │ ├── unpacked-dimensions-rule.cc │ │ ├── unpacked-dimensions-rule.h │ │ ├── unpacked-dimensions-rule_test.cc │ │ ├── uvm-macro-semicolon-rule.cc │ │ ├── uvm-macro-semicolon-rule.h │ │ ├── uvm-macro-semicolon-rule_test.cc │ │ ├── v2001-generate-begin-rule.cc │ │ ├── v2001-generate-begin-rule.h │ │ ├── v2001-generate-begin-rule_test.cc │ │ ├── void-cast-rule.cc │ │ ├── void-cast-rule.h │ │ └── void-cast-rule_test.cc │ ├── default-rules.h │ ├── default-rules_test.cc │ ├── dependencies.cc │ ├── dependencies.h │ ├── dependencies_test.cc │ ├── descriptions.h │ ├── extractors.cc │ ├── extractors.h │ ├── extractors_test.cc │ ├── flow-tree.cc │ ├── flow-tree.h │ ├── flow-tree_test.cc │ ├── json-diagnostics.cc │ ├── json-diagnostics.h │ ├── json-diagnostics_test.cc │ ├── lint-rule-registry.cc │ ├── lint-rule-registry.h │ ├── lint-rule-registry_test.cc │ ├── symbol-table.cc │ ├── symbol-table.h │ ├── symbol-table_test.cc │ ├── verilog-analyzer.cc │ ├── verilog-analyzer.h │ ├── verilog-analyzer_test.cc │ ├── verilog-equivalence.cc │ ├── verilog-equivalence.h │ ├── verilog-equivalence_test.cc │ ├── verilog-excerpt-parse.cc │ ├── verilog-excerpt-parse.h │ ├── verilog-filelist.cc │ ├── verilog-filelist.h │ ├── verilog-filelist_test.cc │ ├── verilog-linter-configuration.cc │ ├── verilog-linter-configuration.h │ ├── verilog-linter-configuration_test.cc │ ├── verilog-linter-constants.h │ ├── verilog-linter.cc │ ├── verilog-linter.h │ ├── verilog-linter_test.cc │ ├── verilog-project.cc │ ├── verilog-project.h │ └── verilog-project_test.cc │ ├── formatting │ ├── BUILD │ ├── README.md │ ├── align.cc │ ├── align.h │ ├── comment-controls.cc │ ├── comment-controls.h │ ├── comment-controls_test.cc │ ├── format-style-init.cc │ ├── format-style-init.h │ ├── format-style.h │ ├── formatter-tuning_test.cc │ ├── formatter.cc │ ├── formatter.h │ ├── formatter_test.cc │ ├── token-annotator.cc │ ├── token-annotator.h │ ├── token-annotator_test.cc │ ├── tree-unwrapper.cc │ ├── tree-unwrapper.h │ ├── tree-unwrapper_test.cc │ ├── verilog-token.cc │ ├── verilog-token.h │ └── verilog-token_test.cc │ ├── parser │ ├── BUILD │ ├── README.md │ ├── verilog-lexer.cc │ ├── verilog-lexer.h │ ├── verilog-lexer_test.cc │ ├── verilog-lexical-context.cc │ ├── verilog-lexical-context.h │ ├── verilog-lexical-context_test.cc │ ├── verilog-parser.cc │ ├── verilog-parser.h │ ├── verilog-parser_test.cc │ ├── verilog-token-classifications.cc │ ├── verilog-token-classifications.h │ ├── verilog-token-classifications_test.cc │ ├── verilog-token.cc │ ├── verilog-token.h │ ├── verilog.lex │ └── verilog.y │ ├── preprocessor │ ├── BUILD │ ├── README.md │ ├── verilog-preprocess.cc │ ├── verilog-preprocess.h │ └── verilog-preprocess_test.cc │ ├── tools │ ├── README.md │ ├── diff │ │ ├── BUILD │ │ ├── README.md │ │ ├── diff_format_lex_error_test.sh │ │ ├── diff_format_match_test.sh │ │ ├── diff_format_mismatch_test.sh │ │ ├── diff_obfuscate_match_test.sh │ │ ├── diff_obfuscate_mismatch_test.sh │ │ ├── diff_user_errors_test.sh │ │ └── verilog-diff.cc │ ├── formatter │ │ ├── BUILD │ │ ├── README.md │ │ ├── diff-to-changed-lines.awk │ │ ├── diff_formatter.sh │ │ ├── format_file_badlines_test.sh │ │ ├── format_file_check_test.sh │ │ ├── format_file_lex_error_test.sh │ │ ├── format_file_lines_test.sh │ │ ├── format_file_syntax_error_test.sh │ │ ├── format_file_test.sh │ │ ├── format_inplace_test.sh │ │ ├── format_line_terminator_test.sh │ │ ├── format_stdin_inplace_test.sh │ │ ├── format_stdin_test.sh │ │ ├── git-verible-verilog-format.sh │ │ ├── triage_formatter.sh │ │ ├── verible-verilog-format-changed-lines-interactive.sh │ │ └── verilog-format.cc │ ├── kythe │ │ ├── BUILD │ │ ├── README.md │ │ ├── indexing-facts-tree-context.h │ │ ├── indexing-facts-tree-extractor.cc │ │ ├── indexing-facts-tree-extractor.h │ │ ├── indexing-facts-tree-extractor_test.cc │ │ ├── indexing-facts-tree.cc │ │ ├── indexing-facts-tree.h │ │ ├── indexing-facts-tree_test.cc │ │ ├── kythe-facts-extractor.cc │ │ ├── kythe-facts-extractor.h │ │ ├── kythe-facts.cc │ │ ├── kythe-facts.h │ │ ├── kythe-facts_test.cc │ │ ├── kythe-proto-output.cc │ │ ├── kythe-proto-output.h │ │ ├── kythe-schema-constants.h │ │ ├── kzip-creator.cc │ │ ├── kzip-creator.h │ │ ├── scope-resolver.cc │ │ ├── scope-resolver.h │ │ ├── scope-resolver_test.cc │ │ ├── testdata │ │ │ ├── array.sv │ │ │ ├── case.sv │ │ │ ├── class.sv │ │ │ ├── class_constructor.sv │ │ │ ├── class_extends.sv │ │ │ ├── class_extends_with_package.sv │ │ │ ├── class_member.sv │ │ │ ├── class_parameter.sv │ │ │ ├── conditional_generate.sv │ │ │ ├── declarations.sv │ │ │ ├── different_primitive_types.sv │ │ │ ├── do_while_loop.sv │ │ │ ├── enum.sv │ │ │ ├── event_control.sv │ │ │ ├── final.sv │ │ │ ├── for_loop.sv │ │ │ ├── for_loop_uint.sv │ │ │ ├── foreach.sv │ │ │ ├── forever.sv │ │ │ ├── function_and_task.sv │ │ │ ├── function_call_hierarchy.sv │ │ │ ├── function_call_inside_loop.sv │ │ │ ├── function_named_args.sv │ │ │ ├── function_overrides.sv │ │ │ ├── function_port_dimensions.sv │ │ │ ├── function_scoping.sv │ │ │ ├── function_user_defined_port.sv │ │ │ ├── if_condition.sv │ │ │ ├── include_file_test │ │ │ │ ├── A.svh │ │ │ │ ├── B.svh │ │ │ │ ├── C.sv │ │ │ │ ├── file_list.txt │ │ │ │ ├── included-file-1.svh │ │ │ │ ├── included-file-2.svh │ │ │ │ ├── module.sv │ │ │ │ ├── module2.sv │ │ │ │ ├── package_with_include.sv │ │ │ │ └── package_with_include_class.svh │ │ │ ├── include_with_dir_test │ │ │ │ ├── E.sv │ │ │ │ ├── file_list.txt │ │ │ │ ├── include_dir │ │ │ │ │ └── D.svh │ │ │ │ ├── module3.sv │ │ │ │ └── module4.sv │ │ │ ├── initial_block.sv │ │ │ ├── interface.sv │ │ │ ├── interface_with_module.sv │ │ │ ├── interface_with_parameter.sv │ │ │ ├── macro.sv │ │ │ ├── macro_call_test.sv │ │ │ ├── macro_with_function.sv │ │ │ ├── module.sv │ │ │ ├── module_actual_and_implicit_port.sv │ │ │ ├── module_extra_test.sv │ │ │ ├── module_instance_in_conditional_generate.sv │ │ │ ├── module_parameter.sv │ │ │ ├── module_port_type_forwarding.sv │ │ │ ├── module_with_same_prefix.sv │ │ │ ├── multi_file_test │ │ │ │ ├── file_list.txt │ │ │ │ ├── multi-file-1.sv │ │ │ │ ├── multi-file-2.sv │ │ │ │ ├── multi-file-3.sv │ │ │ │ └── multi-file-4.sv │ │ │ ├── nested_member_access.sv │ │ │ ├── package.sv │ │ │ ├── package_with_primitive.sv │ │ │ ├── primitive_type_with_dimensions.sv │ │ │ ├── primitive_types.sv │ │ │ ├── program.sv │ │ │ ├── propagate_data_type_module_port.sv │ │ │ ├── pure_virtual_function.sv │ │ │ ├── pure_virtual_task.sv │ │ │ ├── qualified_variable_type.sv │ │ │ ├── repeat.sv │ │ │ ├── reversed_definition.sv │ │ │ ├── struct.sv │ │ │ ├── struct_declaration_function_argument.sv │ │ │ ├── struct_inside_union.sv │ │ │ ├── task_scoping.sv │ │ │ ├── type_declaration.sv │ │ │ ├── union.sv │ │ │ ├── union_inside_struct.sv │ │ │ └── while_loop.sv │ │ ├── verification_test.sh │ │ ├── verilog-extractor-indexing-fact-type.cc │ │ ├── verilog-extractor-indexing-fact-type.h │ │ ├── verilog-kythe-extractor.cc │ │ ├── verilog-kythe-kzip-writer.cc │ │ ├── verilog_extractor_indexing_fact_type_foreach.inc │ │ └── verilog_kythe_extractor_test.sh │ ├── lint │ │ ├── BUILD │ │ ├── README.md │ │ ├── lint_tool_test.sh │ │ ├── show_line_col.sh │ │ ├── testdata │ │ │ ├── always_comb_blocking.sv │ │ │ ├── always_comb_module.sv │ │ │ ├── always_ff_non_blocking.sv │ │ │ ├── bad-id-lex.sv │ │ │ ├── banned_declared_name_patterns.sv │ │ │ ├── case_missing_default.sv │ │ │ ├── constraint_name_style.sv │ │ │ ├── defparam_usage.sv │ │ │ ├── dff_name_style.sv │ │ │ ├── disable_statement.sv │ │ │ ├── endif_comment.sv │ │ │ ├── enum_name_style.sv │ │ │ ├── explicit_begin.sv │ │ │ ├── explicit_function_lifetime.sv │ │ │ ├── explicit_function_parameter_type.sv │ │ │ ├── explicit_parameter_storage_type.sv │ │ │ ├── explicit_task_lifetime.sv │ │ │ ├── explicit_task_parameter_type.sv │ │ │ ├── forbid_consecutive_null_statements.sv │ │ │ ├── forbid_line_continuations.sv │ │ │ ├── forbid_negative_array_dim.sv │ │ │ ├── generate-label-module-body.sv │ │ │ ├── generate_begin_module.sv │ │ │ ├── generate_label_module.sv │ │ │ ├── generate_label_prefix.sv │ │ │ ├── instance-ports-module-body.sv │ │ │ ├── instance_parameters.sv │ │ │ ├── instance_ports.sv │ │ │ ├── interface_type_name_style.sv │ │ │ ├── legacy_generate_region.sv │ │ │ ├── legacy_genvar_declaration.sv │ │ │ ├── line-length-in-module-body.sv │ │ │ ├── localparam_name_style.sv │ │ │ ├── localparam_name_style_all_caps.sv │ │ │ ├── localparam_name_style_camel_case.sv │ │ │ ├── localparam_type_name_style.sv │ │ │ ├── long_line.sv │ │ │ ├── macro_name_style.sv │ │ │ ├── macro_string_concatenation.sv │ │ │ ├── mismatched_labels.sv │ │ │ ├── module_begin_block.sv │ │ │ ├── module_filename.sv │ │ │ ├── numeric_format_string_style.sv │ │ │ ├── object_creation_name.sv │ │ │ ├── one_module_per_file.sv │ │ │ ├── package_filename_pkg.sv │ │ │ ├── packed_dimensions.sv │ │ │ ├── parameter_name_style.sv │ │ │ ├── parameter_type_name_style.sv │ │ │ ├── plusarg_assignment.sv │ │ │ ├── port_name_suffix.sv │ │ │ ├── positive_meaning_parameter_name.sv │ │ │ ├── posix_eof.sv │ │ │ ├── proper_localparam_declaration.sv │ │ │ ├── proper_parameter_declaration.sv │ │ │ ├── psprintf.sv │ │ │ ├── shadow_parameter.sv │ │ │ ├── signal_name_style.sv │ │ │ ├── struct_name_style.sv │ │ │ ├── suggest_parentheses_example.sv │ │ │ ├── suspicious_semicolon.sv │ │ │ ├── tabs.sv │ │ │ ├── trailing_spaces.sv │ │ │ ├── truncated_numeric_literal.sv │ │ │ ├── typedef_enums.sv │ │ │ ├── typedef_structs.sv │ │ │ ├── typedef_unions.sv │ │ │ ├── undersized_binary_literal.sv │ │ │ ├── union_name_style.sv │ │ │ ├── unpacked_dimensions.sv │ │ │ ├── uvm_macro_semicolon.sv │ │ │ ├── uvm_warning.sv │ │ │ └── void-cast.sv │ │ ├── verilog-lint.cc │ │ └── verilog_style_lint.bzl │ ├── ls │ │ ├── BUILD │ │ ├── README.md │ │ ├── autoexpand.cc │ │ ├── autoexpand.h │ │ ├── autoexpand_test.cc │ │ ├── document-symbol-filler.cc │ │ ├── document-symbol-filler.h │ │ ├── hover.cc │ │ ├── hover.h │ │ ├── lsp-conversion.h │ │ ├── lsp-parse-buffer.cc │ │ ├── lsp-parse-buffer.h │ │ ├── lsp-parse-buffer_test.cc │ │ ├── symbol-table-handler.cc │ │ ├── symbol-table-handler.h │ │ ├── symbol-table-handler_test.cc │ │ ├── verible-lsp-adapter.cc │ │ ├── verible-lsp-adapter.h │ │ ├── verible-verilog-ls.cc │ │ ├── verible-verilog-ls_test.sh │ │ ├── verilog-language-server.cc │ │ ├── verilog-language-server.h │ │ ├── verilog-language-server_test.cc │ │ └── vscode │ │ │ ├── .gitignore │ │ │ ├── LICENSE │ │ │ ├── README.md │ │ │ ├── images │ │ │ └── icon.png │ │ │ ├── package.json │ │ │ ├── src │ │ │ ├── download-ls.ts │ │ │ └── extension.ts │ │ │ ├── tsconfig.json │ │ │ └── webpack.config.js │ ├── obfuscator │ │ ├── BUILD │ │ ├── README.md │ │ ├── obfuscate_test.sh │ │ └── verilog-obfuscate.cc │ ├── preprocessor │ │ ├── BUILD │ │ ├── README.md │ │ ├── verilog-preprocessor.cc │ │ └── verilog_preprocessor_test.sh │ ├── project │ │ ├── BUILD │ │ ├── README.md │ │ ├── project-tool.cc │ │ └── project_tool_test.sh │ └── syntax │ │ ├── BUILD │ │ ├── README.md │ │ ├── export_json_examples │ │ ├── BUILD.example │ │ ├── README.md │ │ ├── print_modules.py │ │ ├── print_tree.py │ │ ├── verible_verilog_syntax.py │ │ └── verible_verilog_syntax_test.py │ │ ├── triage_parser.sh │ │ ├── verilog-syntax.cc │ │ └── verilog_syntax_test.sh │ └── transform │ ├── BUILD │ ├── obfuscate.cc │ ├── obfuscate.h │ ├── obfuscate_test.cc │ ├── strip-comments.cc │ ├── strip-comments.h │ └── strip-comments_test.cc └── vnames.json /.clang-format: -------------------------------------------------------------------------------- 1 | # Use the Google style in this project. 2 | # https://google.github.io/styleguide/cppguide.html 3 | BasedOnStyle: Google 4 | 5 | # ...but switch off determining pointer alignment from 6 | # prevalence in file but always make it align right 7 | # to match the semantics of the C/C++ language. 8 | DerivePointerAlignment: false 9 | PointerAlignment: Right 10 | ReferenceAlignment: Right 11 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor config file, see http://editorconfig.org/ 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.{h,cc,sv,sh,yml,py}] 12 | indent_size = 2 13 | 14 | [BUILD] 15 | indent_size = 4 16 | 17 | [Makefile] 18 | indent_style = tab 19 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/formatter-issue.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: formatter issue 3 | about: formatter bugs and feature requests 4 | title: '' 5 | labels: formatter 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Test case** 11 | 12 | ```systemverilog 13 | // Input to the formatter, preferably a reduced test case. 14 | ``` 15 | 16 | Include any options or configuration used. 17 | 18 | **Actual output** 19 | 20 | ```systemverilog 21 | // This doesn't look right. 22 | ``` 23 | 24 | Include any possible diagnostic messages from the formatter. 25 | 26 | **Expected or suggested output** 27 | 28 | ```systemverilog 29 | // This result would look better from the formatter. 30 | ``` 31 | 32 | Citations to published style guides would help. 33 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/kythe-issues.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Kythe issues 3 | about: For kythe index extraction issues and feature requests 4 | title: "[kythe] bug title" 5 | labels: kythe 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Input test case 11 | 12 | Try to reduce the test down to a single demonstrative file. 13 | 14 | ```systemverilog 15 | // test code here 16 | ``` 17 | 18 | ## Describe what is wrong or missing 19 | 20 | e.g. is a fact missing? or is a reference link incorrect? 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/language-server-issue.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Language Server 3 | about: Language Server (LSP) issues 4 | title: '' 5 | labels: language-server 6 | assignees: '' 7 | 8 | --- 9 | 10 | A couple of questions first 11 | 12 | - Your IDE/editor (e.g. vscode, emacs,...) you use with verible LSP ? 13 | - IDE version: 14 | - What other SystemVerilog plugins are active alongside ? 15 | ----- 16 | 17 | **What activity failed** 18 | _(what functionality did not work as expected (e.g. Linting, Formatting, AUTO-expansion, go-to-definition, outline, hover,...)_ 19 | 20 | **Expectation** 21 | 22 | **What actually happened** 23 | 24 | **Test case** 25 | 26 | If needed, include SystemVerilog sample file(s) that show the code you want to do an operation on 27 | ```systemverilog 28 | // Sample SystemVerilog file in case 29 | ``` 30 | 31 | **Logfiles** 32 | 33 | If you invoke your editor with the environment variable `VERIBLE_LOGTHRESHOLD` set to 0, then useful log information will 34 | be generated that you can include here 35 | 36 | ```bash 37 | export VERIBLE_LOGTHRESHOLD=0 38 | code foo.sv 39 | ``` 40 | 41 | ***How to see the log output*** 42 | - _vscode_: go to `View -> Output`, then choose `Verible Language Server` in the dropdown 43 | - _emacs_: there is a buffer `*verible-ls::stderr*` that contains the log output 44 | - _kate_: output is printed on the terminal 45 | 46 | ```txt 47 | (paste log output here) 48 | ``` 49 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/lexer-parser-issue.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: lexer/parser issue 3 | about: Lexer and parser bugs 4 | title: '' 5 | labels: rejects-valid syntax 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | 12 | Short summary. 13 | 14 | **To Reproduce** 15 | 16 | ```systemverilog 17 | // Test case (preferably reduced) that illustrates the problem. 18 | ``` 19 | 20 | Include any options used. 21 | 22 | **Actual behavior:** 23 | 24 | Did it reject valid code? or crash? 25 | 26 | **Expected behavior** 27 | 28 | A clear and concise description of what you expected to happen. Citations to the 29 | [SystemVerilog-2017 Standard (LRM)](https://ieeexplore.ieee.org/document/8299595) 30 | would help. 31 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/style-linter-bug.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: style-linter bug 3 | about: style-linter bugs 4 | title: '' 5 | labels: style-linter 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | 12 | A clear and concise description of what the bug is. Include the 13 | `[style-lint-rule-name]` seen in diagnostics and configuration. 14 | 15 | **Test case (preferably reduced)** 16 | 17 | ```systemverilog 18 | // Ran the style linter on this code. 19 | ``` 20 | 21 | Include the filename if it was relevant to the diagnostic. 22 | 23 | **Actual vs. expected behavior** 24 | 25 | If the diagnostic is a lexer/syntax error, use the **lexer/parser bug template** 26 | instead. 27 | 28 | False-positive? False-negative? Crash? Wrong diagnostic location? 29 | 30 | What should have happened? 31 | 32 | Citations to published style guides would greatly help. 33 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/style-linter-feature-request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: style-linter feature request 3 | about: Suggest new style lint rules, or improvements for existing ones 4 | title: '' 5 | labels: enhancement, style-linter 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Summary** 11 | 12 | Brief description of request. Reference `[style-lint-rule-name]` if this is 13 | about an existing rule, or suggest new lint rule name. 14 | 15 | **Test cases and examples** 16 | 17 | The more examples you provide, the easier it will be for someone to come along 18 | and implement it. 19 | 20 | ```systemverilog 21 | // This example should be diagnosed. 22 | ``` 23 | 24 | ```systemverilog 25 | // This variant should NOT be diagnosed (negative test case) 26 | ``` 27 | 28 | **Proposal** 29 | 30 | [optional] Suggest approach or include pseudo code for how one might implement 31 | the rule. 32 | 33 | **Additional context** 34 | 35 | List citations to published style guides, or include relevant excerpts. 36 | -------------------------------------------------------------------------------- /.github/bin/get-bant-path.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2025 The Verible Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # Print path to a bant binary. Can be provided by an environment variable 17 | # or built from our dependency. 18 | 19 | BAZEL=${BAZEL:-bazel} 20 | BANT=${BANT:-needs-to-be-compiled-locally} 21 | 22 | # Bant not given, compile from bzlmod dep. 23 | if [ "${BANT}" = "needs-to-be-compiled-locally" ]; then 24 | "${BAZEL}" build -c opt --cxxopt=-std=c++20 @bant//bant:bant 2>/dev/null 25 | BANT=$(realpath bazel-bin/external/bant*/bant/bant | tail -1) 26 | fi 27 | 28 | echo $BANT 29 | -------------------------------------------------------------------------------- /.github/bin/install-bazel.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2020 The Verible Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | set -x 17 | 18 | if [ -z "${BAZEL_VERSION}" ]; then 19 | echo "Please set \$BAZEL_VERSION" 20 | exit 1 21 | fi 22 | 23 | if [[ "${ARCH}" != "arm64" ]]; then 24 | ARCH="x86_64" 25 | fi 26 | 27 | BAZEL_EXEC="/usr/bin/bazel" 28 | wget --no-verbose "https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-linux-"${ARCH} -O ${BAZEL_EXEC} 29 | chmod +x ${BAZEL_EXEC} 30 | bazel --version 31 | -------------------------------------------------------------------------------- /.github/bin/install-kythe-tools.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2020 The Verible Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | if [ -z "${KYTHE_TOOLS_VERSION}" ]; then 17 | echo "Please set \$KYTHE_TOOLS_VERSION" 18 | exit 1 19 | fi 20 | 21 | set -e 22 | 23 | echo "Fetching Kythe tools" 24 | 25 | mkdir kythe-tools-bin 26 | cd kythe-tools-bin 27 | # Use release, which comes with pre-built binaries 28 | wget --no-verbose -O kythe.tar.gz \ 29 | "https://github.com/kythe/kythe/releases/download/$KYTHE_TOOLS_VERSION/kythe-$KYTHE_TOOLS_VERSION.tar.gz" 30 | tar -xzf kythe.tar.gz "kythe-${KYTHE_TOOLS_VERSION}/tools/verifier" 31 | -------------------------------------------------------------------------------- /.github/bin/run-build-cleaner.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2024-2025 The Verible Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | set -u 17 | set -e 18 | 19 | BANT=$($(dirname $0)/get-bant-path.sh) 20 | 21 | if "${BANT}" -q dwyu ... ; then 22 | echo "Dependencies ok." >&2 23 | else 24 | cat >&2 <" 12 | exit 1 13 | fi 14 | 15 | TARGET_DIR=$1 16 | mkdir -p "${TARGET_DIR}" 17 | 18 | # Requires to have built before with 19 | # bazel build :install-binaries 20 | 21 | # Could we get the list of source from bazel query somehow ? 22 | 23 | TOOLS_DIR=bazel-bin/verible/verilog/tools 24 | for f in diff/verible-verilog-diff \ 25 | formatter/verible-verilog-format \ 26 | kythe/verible-verilog-kythe-extractor \ 27 | kythe/verible-verilog-kythe-kzip-writer \ 28 | lint/verible-verilog-lint \ 29 | ls/verible-verilog-ls \ 30 | obfuscator/verible-verilog-obfuscate \ 31 | preprocessor/verible-verilog-preprocessor \ 32 | project/verible-verilog-project \ 33 | syntax/verible-verilog-syntax 34 | do 35 | install "${TOOLS_DIR}/$f" "${TARGET_DIR}" 36 | done 37 | 38 | COMMON_TOOLS_DIR=bazel-bin/verible/common/tools 39 | for f in verible-patch-tool 40 | do 41 | install "${COMMON_TOOLS_DIR}/$f" "${TARGET_DIR}" 42 | done 43 | -------------------------------------------------------------------------------- /.github/bin/verify-kythe-extraction.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2020 The Verible Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | set -e 17 | 18 | # Verify that Verilog Kythe indexer produces the expected Kythe indexing facts. 19 | # Note: verifier tool path assumes it came with the release pre-built. 20 | KYTHE_DIRNAME="kythe-${KYTHE_TOOLS_VERSION}" 21 | KYTHE_DIR_ABS="$(readlink -f "kythe-tools-bin/${KYTHE_DIRNAME}")" 22 | bazel test --test_output=errors --test_arg="$KYTHE_DIR_ABS/tools/verifier" verilog/tools/kythe:verification_test 23 | -------------------------------------------------------------------------------- /.github/settings.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2020 The Verible Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # WARNING: All values set in this file need to be plain strings as they have to 17 | # pass through things like Docker files which don't support bash arrays and 18 | # similar functionality. 19 | 20 | set -e 21 | set -x 22 | 23 | [[ "${BASH_SOURCE[0]}" != "${0}" ]] && SOURCED=1 || SOURCED=0 24 | 25 | if [ $SOURCED -ne 1 ]; then 26 | echo "settings.sh should be sourced, not run." 27 | exit 1 28 | fi 29 | 30 | export GIT_VERSION=${GIT_VERSION:-$(git describe --match='v*')} 31 | 32 | export BAZEL_CXXOPTS="-std=c++17" 33 | 34 | # Progress output is just noisy in CI outputs. 35 | export BAZEL_OPTS="-c opt --noshow_progress" 36 | 37 | # Used to fetch the BAZEL version where needed. 38 | export BAZEL_VERSION=7.6.1 39 | 40 | # Kythe version for extracting xRefs 41 | export KYTHE_VERSION=v0.0.68 42 | # Kythe version for fetching tools (verification tools, etc.) 43 | export KYTHE_TOOLS_VERSION=${KYTHE_VERSION} 44 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | /bazel-* 3 | MODULE.bazel.lock 4 | tags 5 | releasing/out 6 | coverage-html/ 7 | __pycache__/ 8 | 9 | compile_flags.txt 10 | run-clang-tidy-cached 11 | verible_clang-tidy.* 12 | 13 | # Local user config 14 | .envrc 15 | .direnv 16 | user.bazelrc 17 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # Read the Docs configuration file for Sphinx projects 2 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 3 | 4 | # Required 5 | version: 2 6 | 7 | # Set the OS, Python version and other tools you might need 8 | build: 9 | os: ubuntu-22.04 10 | tools: 11 | python: "3.12" 12 | 13 | # Build documentation in the "docs/" directory with Sphinx 14 | sphinx: 15 | configuration: doc/conf.py 16 | 17 | python: 18 | install: 19 | - requirements: doc/requirements.txt 20 | 21 | formats: 22 | - pdf 23 | - epub 24 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # This is the list of Verible authors for copyright purposes. 2 | # 3 | # This does not necessarily list everyone who has contributed code, since in 4 | # some cases, their employer may be the copyright holder. To see the full list 5 | # of contributors, see the revision history in source control. 6 | Google LLC 7 | David Fang 8 | Sergey Sokolov 9 | Jonathan Mayer 10 | Jeremy Colebrook-Soucie 11 | Cameron Korzecke 12 | Carissa Kathuria 13 | Henner Zeller 14 | -------------------------------------------------------------------------------- /MODULE.bazel: -------------------------------------------------------------------------------- 1 | module( 2 | name = "verible", 3 | version = "head", 4 | ) 5 | 6 | bazel_dep(name = "abseil-cpp", version = "20250127.0") 7 | bazel_dep(name = "bazel_skylib", version = "1.7.1") 8 | bazel_dep(name = "nlohmann_json", version = "3.11.3.bcr.1") 9 | bazel_dep(name = "platforms", version = "0.0.11") 10 | bazel_dep(name = "protobuf", version = "31.0-rc2") 11 | bazel_dep(name = "re2", version = "2024-07-02.bcr.1") 12 | bazel_dep(name = "rules_bison", version = "0.3") 13 | bazel_dep(name = "rules_flex", version = "0.3") 14 | bazel_dep(name = "rules_license", version = "1.0.0") 15 | bazel_dep(name = "rules_m4", version = "0.2.3") 16 | bazel_dep(name = "zlib", version = "1.3.1.bcr.5") 17 | 18 | bazel_dep(name = "googletest", version = "1.15.2", dev_dependency = True) 19 | 20 | # To build compilation DB and run build-cleaning 21 | bazel_dep(name = "bant", version = "0.2.0", dev_dependency = True) 22 | -------------------------------------------------------------------------------- /bazel/BUILD: -------------------------------------------------------------------------------- 1 | """ 2 | Rules for adding './configure && make' style dependencies. 3 | """ 4 | 5 | load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") 6 | 7 | package( 8 | default_applicable_licenses = ["//:license"], 9 | default_visibility = [ 10 | "//:__subpackages__", 11 | ], 12 | features = ["layering_check"], 13 | ) 14 | 15 | cc_library( 16 | name = "flex", 17 | deps = [ 18 | "@rules_flex//flex:current_flex_toolchain", # For FlexLexer.h 19 | ], 20 | ) 21 | 22 | exports_files([ 23 | "bison.bzl", 24 | "flex.bzl", 25 | "sh_test_with_runfiles_lib.bzl", 26 | "sh_test_with_runfiles_lib.sh", 27 | ]) 28 | 29 | bool_flag( 30 | name = "use_local_flex_bison", 31 | build_setting_default = False, 32 | ) 33 | 34 | config_setting( 35 | name = "use_local_flex_bison_enabled", 36 | flag_values = {":use_local_flex_bison": "true"}, 37 | ) 38 | 39 | bool_flag( 40 | name = "create_static_linked_executables", 41 | build_setting_default = False, 42 | ) 43 | 44 | config_setting( 45 | name = "static_linked_executables", 46 | flag_values = {":create_static_linked_executables": "true"}, 47 | ) 48 | -------------------------------------------------------------------------------- /bazel/flex.bzl: -------------------------------------------------------------------------------- 1 | # -*- Python -*- 2 | # Copyright 2017-2021 The Verible Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Bazel rule to run flex toolchain 17 | """ 18 | 19 | # Adapter rule around the @rules_flex toolchain. 20 | def genlex(name, src, out): 21 | """Generate C/C++ language source from lex file using Flex 22 | """ 23 | native.genrule( 24 | name = name, 25 | srcs = [src], 26 | outs = [out], 27 | cmd = select({ 28 | "//bazel:use_local_flex_bison_enabled": "flex --outfile=$@ $<", 29 | "@platforms//os:windows": "win_flex.exe --outfile=$@ $<", 30 | "//conditions:default": "M4=$(M4) $(FLEX) --outfile=$@ $<", 31 | }), 32 | toolchains = select({ 33 | "//bazel:use_local_flex_bison_enabled": [], 34 | "@platforms//os:windows": [], 35 | "//conditions:default": [ 36 | "@rules_flex//flex:current_flex_toolchain", 37 | "@rules_m4//m4:current_m4_toolchain", 38 | ], 39 | }), 40 | ) 41 | -------------------------------------------------------------------------------- /bazel/installer.patch: -------------------------------------------------------------------------------- 1 | --- ./installer/installer.bash.template.orig 2023-02-01 13:10:18.224882680 -0800 2 | +++ ./installer/installer.bash.template 2023-02-01 13:10:30.952848590 -0800 3 | @@ -104,7 +104,7 @@ 4 | $sudo mkdir --parents -- "${target_dir}" 5 | 6 | $sudo install -m "${target_mode}" \ 7 | - -T -- "${source}" "${target_dir}/${target_name}" 8 | + -- "${source}" "${target_dir}/${target_name}" 9 | } 10 | 11 | function main() { 12 | -------------------------------------------------------------------------------- /bazel/jsonhpp.BUILD: -------------------------------------------------------------------------------- 1 | # JSON for Modern C++ https://github.com/nlohmann/json 2 | # 3 | # This file is not directly needed anymore, but left 4 | # here for now for projects still using a WORKSPACE 5 | # reference. 6 | # 7 | # Should probably be removed around mid 2025. 8 | 9 | licenses(["unencumbered"]) # Public Domain or MIT 10 | 11 | exports_files(["LICENSE"]) 12 | 13 | cc_library( 14 | name = "singleheader-json", 15 | hdrs = [ 16 | "single_include/nlohmann/json.hpp", 17 | ], 18 | includes = ["single_include"], 19 | visibility = ["//visibility:public"], 20 | copts = select({ 21 | "@platforms//os:windows": [], 22 | "//conditions:default": ["-fexceptions"], 23 | }), 24 | features = ["-use_header_modules"], # precompiled headers incompatible with -fexceptions. 25 | ) 26 | -------------------------------------------------------------------------------- /bazel/proto-fix-uninitialized-value.patch: -------------------------------------------------------------------------------- 1 | diff --git a/src/google/protobuf/io/coded_stream.cc b/src/google/protobuf/io/coded_stream.cc 2 | index 61f639308..6de9ea833 100644 3 | --- a/src/google/protobuf/io/coded_stream.cc 4 | +++ b/src/google/protobuf/io/coded_stream.cc 5 | @@ -522,7 +522,7 @@ int CodedInputStream::ReadVarintSizeAsIntFallback() { 6 | // Optimization: We're also safe if the buffer is non-empty and it ends 7 | // with a byte that would terminate a varint. 8 | (buffer_end_ > buffer_ && !(buffer_end_[-1] & 0x80))) { 9 | - uint64_t temp; 10 | + uint64_t temp = 0; 11 | ::std::pair p = ReadVarint64FromArray(buffer_, &temp); 12 | if (!p.first || temp > static_cast(INT_MAX)) return -1; 13 | buffer_ = p.second; 14 | @@ -632,7 +632,7 @@ std::pair CodedInputStream::ReadVarint64Fallback() { 15 | // Optimization: We're also safe if the buffer is non-empty and it ends 16 | // with a byte that would terminate a varint. 17 | (buffer_end_ > buffer_ && !(buffer_end_[-1] & 0x80))) { 18 | - uint64_t temp; 19 | + uint64_t temp = 0; 20 | ::std::pair p = ReadVarint64FromArray(buffer_, &temp); 21 | if (!p.first) { 22 | return std::make_pair(0, false); 23 | -------------------------------------------------------------------------------- /bazel/sh_test_with_runfiles_lib.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2017-2020 The Verible Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # Test wrapper to load bazel runfiles library before running script 17 | 18 | # --- begin runfiles.bash initialization v2 --- 19 | # Copy-pasted from the Bazel Bash runfiles library v2. 20 | set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash 21 | source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ 22 | source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ 23 | source "$0.runfiles/$f" 2>/dev/null || \ 24 | source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ 25 | source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ 26 | { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e 27 | # --- end runfiles.bash initialization v2 --- 28 | 29 | # Remove exit on failure set by runfiles.bash... 30 | set +e 31 | 32 | source "$(rlocation ${TEST_WORKSPACE}/${1})" "${@:2}" -------------------------------------------------------------------------------- /bazel/variables.bzl: -------------------------------------------------------------------------------- 1 | STATIC_EXECUTABLES_FEATURE = select({ 2 | "//bazel:static_linked_executables": ["fully_static_link"], 3 | "//conditions:default": [], 4 | }) 5 | -------------------------------------------------------------------------------- /doc/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from datetime import datetime 4 | 5 | extensions = ['myst_parser'] 6 | templates_path = ['templates', '_templates', '.templates'] 7 | source_suffix = ['.rst', '.md'] 8 | source_parsers = { 9 | '.rst': 'restructuredtext', 10 | '.md': 'markdown', 11 | } 12 | master_doc = 'index' 13 | project = u'verible' 14 | copyright = str(datetime.now().year) 15 | version = 'latest' 16 | release = 'latest' 17 | exclude_patterns = ['_build'] 18 | pygments_style = 'sphinx' 19 | htmlhelp_basename = 'verible' 20 | html_theme = 'sphinx_rtd_theme' 21 | file_insertion_enabled = False 22 | latex_documents = [ 23 | ('index', 'verible.tex', u'verible Documentation', u'', 'manual'), 24 | ] 25 | -------------------------------------------------------------------------------- /doc/formatter_simplified_class_diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chipsalliance/verible/d42da6b978d480222da00fb45ea5f84ec1158ab5/doc/formatter_simplified_class_diagram.png -------------------------------------------------------------------------------- /doc/index.rst: -------------------------------------------------------------------------------- 1 | Using Verible 2 | ============= 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | style_lint.md 8 | formatter.md 9 | indexing.md 10 | 11 | Developing Verible 12 | ================== 13 | 14 | .. toctree:: 15 | :maxdepth: 2 16 | 17 | development.md 18 | parser_design.md 19 | -------------------------------------------------------------------------------- /doc/requirements.txt: -------------------------------------------------------------------------------- 1 | sphinx 2 | sphinx-rtd-theme 3 | pillow 4 | mock 5 | myst-parser 6 | -------------------------------------------------------------------------------- /external_libs/BUILD: -------------------------------------------------------------------------------- 1 | # This package contains externally owned libraries. 2 | # 3 | # editscript - is a template-generic sequence diff algorithm based on 4 | # diff-match-patch. 5 | 6 | package( 7 | default_applicable_licenses = ["//:license"], 8 | default_visibility = [ 9 | "//:__subpackages__", 10 | ], 11 | features = ["layering_check"], 12 | ) 13 | 14 | cc_library( 15 | name = "editscript", 16 | hdrs = ["editscript.h"], 17 | ) 18 | 19 | cc_test( 20 | name = "editscript_test", 21 | srcs = ["editscript_test.cc"], 22 | deps = [ 23 | ":editscript", 24 | "@abseil-cpp//absl/strings", 25 | "@googletest//:gtest", 26 | "@googletest//:gtest_main", 27 | ], 28 | ) 29 | -------------------------------------------------------------------------------- /external_libs/README.md: -------------------------------------------------------------------------------- 1 | # External Libraries 2 | 3 | The preferred method to using external dependencies is the 4 | [Bazel](http://bazel.io) [WORKSPACE](../WORKSPACE) file. For situations where 5 | that workflow is not well supported, this directory contains copies of libraries 6 | that belong to external sources. 7 | -------------------------------------------------------------------------------- /img/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile in case PNGs need to be regenerated. 2 | 3 | all: verible-logo-headline.png 4 | 5 | verible-logo-headline.png: verible-logo.svg 6 | inkscape -w 128 $^ --export-filename $@ 7 | -------------------------------------------------------------------------------- /img/example-github-integration.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chipsalliance/verible/d42da6b978d480222da00fb45ea5f84ec1158ab5/img/example-github-integration.png -------------------------------------------------------------------------------- /img/language-server-demo-vscode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chipsalliance/verible/d42da6b978d480222da00fb45ea5f84ec1158ab5/img/language-server-demo-vscode.png -------------------------------------------------------------------------------- /img/verible-logo-headline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chipsalliance/verible/d42da6b978d480222da00fb45ea5f84ec1158ab5/img/verible-logo-headline.png -------------------------------------------------------------------------------- /shell.nix: -------------------------------------------------------------------------------- 1 | # This is a nix-shell for use with the nix package manager. 2 | # If you have nix installed, you may simply run `nix-shell` 3 | # in this repo, and have all dependencies ready in the new shell. 4 | 5 | { pkgs ? import {} }: 6 | let 7 | verible_used_stdenv = pkgs.stdenv; 8 | #verible_used_stdenv = pkgs.gcc13Stdenv; 9 | #verible_used_stdenv = pkgs.clang17Stdenv; 10 | in 11 | verible_used_stdenv.mkDerivation { 12 | name = "verible-build-environment"; 13 | buildInputs = with pkgs; 14 | [ 15 | bazel_7 16 | git 17 | 18 | # For scripts used inside bzl rules and tests 19 | gnused 20 | 21 | # To run error-log-analyzer 22 | python3 23 | python3Packages.mdutils 24 | ripgrep 25 | 26 | # To manually run export_json_examples 27 | python3Packages.anytree 28 | 29 | # For using --//bazel:use_local_flex_bison if desired 30 | flex 31 | bison 32 | 33 | # To build vscode vsix package 34 | nodejs 35 | 36 | # Ease development 37 | lcov # coverage html generation. 38 | bazel-buildtools # buildifier 39 | 40 | llvmPackages_19.clang-tools # for clang-tidy 41 | llvmPackages_17.clang-tools # for clang-format 42 | ]; 43 | shellHook = '' 44 | # clang tidy: use latest. 45 | export CLANG_TIDY=${pkgs.llvmPackages_19.clang-tools}/bin/clang-tidy 46 | 47 | # There is too much volatility between even micro-versions of 48 | # later clang-format. Let's use stable 17 for now. 49 | export CLANG_FORMAT=${pkgs.llvmPackages_17.clang-tools}/bin/clang-format 50 | ''; 51 | } 52 | -------------------------------------------------------------------------------- /third_party/portable_endian/BUILD: -------------------------------------------------------------------------------- 1 | licenses(["unencumbered"]) 2 | 3 | cc_library( 4 | name = "portable_endian", 5 | hdrs = ["portable_endian.h"], 6 | visibility = ["//verible/common/util:__pkg__"], 7 | ) 8 | -------------------------------------------------------------------------------- /third_party/proto/kythe/BUILD: -------------------------------------------------------------------------------- 1 | load("@protobuf//bazel:cc_proto_library.bzl", "cc_proto_library") 2 | 3 | package( 4 | default_visibility = ["//visibility:public"], 5 | features = ["layering_check"], 6 | ) 7 | 8 | proto_library( 9 | name = "storage_proto", 10 | srcs = ["storage.proto"], 11 | ) 12 | 13 | cc_proto_library( 14 | name = "storage_cc_proto", 15 | deps = [":storage_proto"], 16 | ) 17 | 18 | proto_library( 19 | name = "analysis_proto", 20 | srcs = ["analysis.proto"], 21 | deps = [ 22 | ":storage_proto", 23 | "@protobuf//:any_proto", 24 | "@protobuf//:timestamp_proto", 25 | ], 26 | ) 27 | 28 | cc_proto_library( 29 | name = "analysis_cc_proto", 30 | deps = [":analysis_proto"], 31 | ) 32 | -------------------------------------------------------------------------------- /third_party/proto/kythe/README.md: -------------------------------------------------------------------------------- 1 | # Kythe proto schema 2 | 3 | Proto schemas imported from https://github.com/kythe/kythe 4 | 5 | * https://github.com/kythe/kythe/blob/5c07b3bb2823cf29bb4ef7a9243f504ff55b84a9/kythe/proto/analysis.proto 6 | * https://github.com/kythe/kythe/blob/5c07b3bb2823cf29bb4ef7a9243f504ff55b84a9/kythe/proto/storage.proto 7 | -------------------------------------------------------------------------------- /verible/common/README.md: -------------------------------------------------------------------------------- 1 | # Verible's Language-Agnostic Core Library 2 | 3 | 6 | 7 | The libraries provided herein are _language-agnostic_ and have nothing to do 8 | with Verilog or SystemVerilog. 9 | 10 | ## Subdirectory Summary 11 | 12 | * [util](./util): generic algorithms, data structures, patterns 13 | * [strings](./strings): functions that operate purely on strings 14 | * [lexer](./lexer): lexer interfaces and adaptors that produce token streams 15 | * [parser](./parser): parser interfaces and adaptors that build syntax trees 16 | out of tokens 17 | * [text](./text): structural representations of source code (tokens, lines, 18 | trees, etc.) 19 | * [analysis](./analysis): various analysis and query facilities on text 20 | structures 21 | * [formatting](./formatting): reusable source code formatting operations 22 | -------------------------------------------------------------------------------- /verible/common/analysis/README.md: -------------------------------------------------------------------------------- 1 | # Analysis Library 2 | 3 | 6 | 7 | This directory contains libraries for analyzing (read-only) 8 | [structural representations of text](../text), such as lines, token streams, and 9 | syntax trees. You can find classes for building lint rules and linters here. 10 | 11 | See the [matcher](matcher) subdirectory for a syntax-tree matching library. 12 | -------------------------------------------------------------------------------- /verible/common/analysis/citation.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "verible/common/analysis/citation.h" 16 | 17 | #include 18 | #include 19 | 20 | #include "absl/strings/str_cat.h" 21 | 22 | namespace verible { 23 | std::string GetStyleGuideCitation(std::string_view topic) { 24 | return absl::StrCat("[Style: ", topic, "]"); 25 | } 26 | } // namespace verible 27 | -------------------------------------------------------------------------------- /verible/common/analysis/citation.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef VERIBLE_COMMON_ANALYSIS_CITATION_H_ 16 | #define VERIBLE_COMMON_ANALYSIS_CITATION_H_ 17 | 18 | #include 19 | #include 20 | 21 | namespace verible { 22 | // Given a styleguide topic, return a reference to some styleguide 23 | // citation for the given topic (e.g. just the topic-name or an URL). 24 | std::string GetStyleGuideCitation(std::string_view topic); 25 | } // namespace verible 26 | 27 | #endif // VERIBLE_COMMON_ANALYSIS_CITATION_H_ 28 | -------------------------------------------------------------------------------- /verible/common/analysis/line-lint-rule.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // LineLintRule represents a line-based scanner for detecting lint 16 | // violations. It scans one line at a time, and may update internal state 17 | // held by any subclasses. 18 | 19 | #ifndef VERIBLE_COMMON_ANALYSIS_LINE_LINT_RULE_H_ 20 | #define VERIBLE_COMMON_ANALYSIS_LINE_LINT_RULE_H_ 21 | 22 | #include 23 | 24 | #include "verible/common/analysis/lint-rule.h" 25 | 26 | namespace verible { 27 | 28 | class LineLintRule : public LintRule { 29 | public: 30 | ~LineLintRule() override = default; // not yet final 31 | 32 | // Scans a single line during analysis. 33 | virtual void HandleLine(std::string_view line) = 0; 34 | 35 | // Analyze the final state of the rule, after the last line has been read. 36 | virtual void Finalize() {} 37 | }; 38 | 39 | } // namespace verible 40 | 41 | #endif // VERIBLE_COMMON_ANALYSIS_LINE_LINT_RULE_H_ 42 | -------------------------------------------------------------------------------- /verible/common/analysis/matcher/README.md: -------------------------------------------------------------------------------- 1 | # Matcher Library 2 | 3 | 6 | 7 | This library provides means of matching prescribed syntax-tree patterns. 8 | 9 | 10 | -------------------------------------------------------------------------------- /verible/common/analysis/matcher/bound-symbol-manager.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "verible/common/analysis/matcher/bound-symbol-manager.h" 16 | 17 | #include 18 | #include 19 | 20 | #include "verible/common/text/symbol.h" 21 | #include "verible/common/util/container-util.h" 22 | #include "verible/common/util/logging.h" 23 | 24 | using verible::container::FindOrNull; 25 | 26 | namespace verible { 27 | namespace matcher { 28 | 29 | bool BoundSymbolManager::ContainsSymbol(const std::string &id) const { 30 | return bound_symbols_.find(id) != bound_symbols_.end(); 31 | } 32 | 33 | const Symbol *BoundSymbolManager::FindSymbol(const std::string &id) const { 34 | auto *result = FindOrNull(bound_symbols_, id); 35 | return result ? *result : nullptr; 36 | } 37 | 38 | void BoundSymbolManager::BindSymbol(const std::string &id, 39 | const Symbol *symbol) { 40 | bound_symbols_[id] = ABSL_DIE_IF_NULL(symbol); 41 | } 42 | 43 | } // namespace matcher 44 | } // namespace verible 45 | -------------------------------------------------------------------------------- /verible/common/analysis/token-stream-lint-rule.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // TokenStreamLintRule represents a token-based scanner for detecing lint 16 | // violations. It scans one token at a time, and may update internal state 17 | // held by any subclasses. 18 | 19 | #ifndef VERIBLE_COMMON_ANALYSIS_TOKEN_STREAM_LINT_RULE_H_ 20 | #define VERIBLE_COMMON_ANALYSIS_TOKEN_STREAM_LINT_RULE_H_ 21 | 22 | #include "verible/common/analysis/lint-rule.h" 23 | #include "verible/common/text/token-info.h" 24 | 25 | namespace verible { 26 | 27 | class TokenStreamLintRule : public LintRule { 28 | public: 29 | ~TokenStreamLintRule() override = default; // not yet final 30 | 31 | // Scans a single token during analysis. 32 | virtual void HandleToken(const TokenInfo &token) = 0; 33 | }; 34 | 35 | } // namespace verible 36 | 37 | #endif // VERIBLE_COMMON_ANALYSIS_TOKEN_STREAM_LINT_RULE_H_ 38 | -------------------------------------------------------------------------------- /verible/common/formatting/basic-format-style-init.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2021 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef VERIBLE_COMMON_FORMATTING_BASIC_FORMAT_STYLE_INIT_H_ 16 | #define VERIBLE_COMMON_FORMATTING_BASIC_FORMAT_STYLE_INIT_H_ 17 | 18 | #include "verible/common/formatting/basic-format-style.h" 19 | 20 | namespace verible { 21 | 22 | // Initialize format style from flags. 23 | void InitializeFromFlags(BasicFormatStyle *style); 24 | 25 | // TODO: initialize from configuration file. 26 | // https://github.com/chipsalliance/verible/issues/898 27 | // Possibly using common/text/config_utils.h 28 | } // namespace verible 29 | #endif // VERIBLE_COMMON_FORMATTING_BASIC_FORMAT_STYLE_INIT_H_ 30 | -------------------------------------------------------------------------------- /verible/common/formatting/basic-format-style_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "verible/common/formatting/basic-format-style.h" 16 | 17 | #include 18 | 19 | #include "gtest/gtest.h" 20 | 21 | namespace verible { 22 | namespace { 23 | 24 | TEST(IndentationStyleParseFlagTest, Parse) { 25 | std::string error; 26 | IndentationStyle istyle; 27 | // Test valid values. 28 | EXPECT_TRUE(AbslParseFlag("indent", &istyle, &error)); 29 | EXPECT_EQ(istyle, IndentationStyle::kIndent); 30 | EXPECT_TRUE(AbslParseFlag("wrap", &istyle, &error)); 31 | EXPECT_EQ(istyle, IndentationStyle::kWrap); 32 | // Test for invalid string. 33 | EXPECT_FALSE(AbslParseFlag("invalid", &istyle, &error)); 34 | } 35 | 36 | TEST(IndentationStyleUnparseFlagTest, Unparse) { 37 | EXPECT_EQ(AbslUnparseFlag(IndentationStyle::kIndent), "indent"); 38 | EXPECT_EQ(AbslUnparseFlag(IndentationStyle::kWrap), "wrap"); 39 | } 40 | 41 | } // namespace 42 | } // namespace verible 43 | -------------------------------------------------------------------------------- /verible/common/formatting/layout-optimizer.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2021 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Implementation of a code layout optimizer described by 16 | // Phillip Yelland in "A New Approach to Optimal Code Formatting" 17 | // (https://research.google/pubs/pub44667/) and originally implemented 18 | // in rfmt (https://github.com/google/rfmt). 19 | 20 | #ifndef VERIBLE_VERILOG_FORMATTING_LAYOUT_OPTIMIZER_H_ 21 | #define VERIBLE_VERILOG_FORMATTING_LAYOUT_OPTIMIZER_H_ 22 | 23 | #include "verible/common/formatting/basic-format-style.h" 24 | #include "verible/common/formatting/token-partition-tree.h" 25 | 26 | namespace verible { 27 | 28 | // Handles formatting of `node` using LayoutOptimizer. 29 | void OptimizeTokenPartitionTree(const BasicFormatStyle &style, 30 | TokenPartitionTree *node); 31 | 32 | } // namespace verible 33 | 34 | #endif // VERIBLE_VERILOG_FORMATTING_LAYOUT_OPTIMIZER_H_ 35 | -------------------------------------------------------------------------------- /verible/common/formatting/verification.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef VERIBLE_COMMON_FORMATTING_VERIFICATION_H_ 16 | #define VERIBLE_COMMON_FORMATTING_VERIFICATION_H_ 17 | 18 | #include 19 | 20 | #include "absl/status/status.h" 21 | #include "verible/common/strings/position.h" 22 | 23 | namespace verible { 24 | 25 | // Verifies that 'formatted_text' == 'reformatted_text', and return a status 26 | // indicating the success of that comparison. 27 | // The following parameters are only used for diagnostics: 28 | // 'original_text' is the text before any formatting was done. 29 | // 'lines' is the set of lines requested if incrementally formatting. 30 | absl::Status ReformatMustMatch(std::string_view original_text, 31 | const LineNumberSet &lines, 32 | std::string_view formatted_text, 33 | std::string_view reformatted_text); 34 | 35 | } // namespace verible 36 | 37 | #endif // VERIBLE_COMMON_FORMATTING_VERIFICATION_H_ 38 | -------------------------------------------------------------------------------- /verible/common/lexer/README.md: -------------------------------------------------------------------------------- 1 | # Lexer Library 2 | 3 | 6 | 7 | This directory contains language-agnostic support libraries for working with 8 | (Flex-generated) lexers. This library provides alternative interfaces for 9 | working with lexer data, such as adapting them into generator functions, or 10 | producing token streams. These adapters extend the use of lexers beyond direct 11 | integrating into parsers. 12 | 13 | See the [text](../text) library for token data structures. 14 | -------------------------------------------------------------------------------- /verible/common/lexer/lexer-test-util.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "verible/common/lexer/lexer-test-util.h" 16 | 17 | #include 18 | #include 19 | 20 | #include "verible/common/text/token-info.h" 21 | #include "verible/common/util/logging.h" 22 | 23 | namespace verible { 24 | 25 | void FakeLexer::SetTokensData(const std::vector &tokens) { 26 | tokens_ = tokens; 27 | tokens_iter_ = tokens_.begin(); 28 | } 29 | 30 | const TokenInfo &FakeLexer::DoNextToken() { 31 | CHECK(tokens_iter_ != tokens_.cend()); 32 | return *tokens_iter_++; 33 | } 34 | 35 | std::ostream &operator<<(std::ostream &stream, const ShowCode &code) { 36 | return stream << " from code:\n" << code.text << "<>"; 37 | } 38 | 39 | } // namespace verible 40 | -------------------------------------------------------------------------------- /verible/common/lexer/token-generator.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // TokenGenerator is a type alias to a TokenInfo generator function. 16 | 17 | #ifndef VERIBLE_COMMON_LEXER_TOKEN_GENERATOR_H_ 18 | #define VERIBLE_COMMON_LEXER_TOKEN_GENERATOR_H_ 19 | 20 | #include 21 | 22 | #include "verible/common/text/token-info.h" 23 | 24 | namespace verible { 25 | 26 | // TokenGenerator is any callable that returns one TokenInfo at a time. 27 | // TODO(fangism): can we return const-reference? 28 | using TokenGenerator = std::function; 29 | 30 | } // namespace verible 31 | 32 | #endif // VERIBLE_COMMON_LEXER_TOKEN_GENERATOR_H_ 33 | -------------------------------------------------------------------------------- /verible/common/lsp/jcxxgen-testfile.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Verible Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | SomeObject: 16 | a: integer = 123 17 | b: string = "foo" 18 | 19 | BaseObject: 20 | string_value: string 21 | string_value_with_default: string = "Hello World" 22 | string_value_optional?: string 23 | string_value_optional_with_default?: string = "Optional World" 24 | 25 | integer_value: integer 26 | integer_value_with_default: integer = 42 27 | integer_value_optional?: integer 28 | 29 | bool_value: boolean 30 | struct_value: SomeObject 31 | generic_object?: object 32 | 33 | DerivedObject: 34 | <: BaseObject 35 | additional_integer_value: integer 36 | -------------------------------------------------------------------------------- /verible/common/lsp/lsp-file-utils.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef VERIBLE_COMMON_LSP_LSP_FILE_UTILS_H 17 | #define VERIBLE_COMMON_LSP_LSP_FILE_UTILS_H 18 | 19 | #include 20 | #include 21 | 22 | namespace verible::lsp { 23 | // Converts file:// scheme entries to actual system paths. 24 | // If other scheme is provided, method returns empty string_view. 25 | // TODO (glatosinski) current resolving of LSP URIs is very naive 26 | // and supports only narrow use cases of file:// specifier. 27 | std::string LSPUriToPath(std::string_view uri); 28 | 29 | // Converts filesystem paths to file:// scheme entries. 30 | std::string PathToLSPUri(std::string_view path); 31 | } // namespace verible::lsp 32 | 33 | #endif // VERIBLE_COMMON_LSP_LSP_FILE_UTILS_H 34 | -------------------------------------------------------------------------------- /verible/common/parser/README.md: -------------------------------------------------------------------------------- 1 | # Parser Library 2 | 3 | 6 | 7 | This language-agnostic library contains adapters and helpers for working with 8 | Yacc/Bison-generated parsers. Such adapters includes being able to accept tokens 9 | from sources that are not directly coming from a lexer function. Such 10 | flexibility enables intermediate processing on token streams before parsing 11 | them. 12 | 13 | See the [text](../text) library for syntax tree data structures. 14 | -------------------------------------------------------------------------------- /verible/common/strings/README.md: -------------------------------------------------------------------------------- 1 | # String Libraries 2 | 3 | 6 | 7 | This directory is a home to functions that work with text-as-strings. The 8 | interface to most functions in here are `std::string` and `absl::string_view` 9 | (eventually `std::string_view` once minimum library requirements move beyond 10 | C++11), and `std::istream` and `std::ostream`. 11 | 12 | If there's a pure string operation that is not already covered by 13 | [absl's string library](https://github.com/abseil/abseil-cpp/tree/master/absl/strings), 14 | it should go here. 15 | -------------------------------------------------------------------------------- /verible/common/strings/comment-utils.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef VERIBLE_COMMON_STRINGS_COMMENT_UTILS_H_ 16 | #define VERIBLE_COMMON_STRINGS_COMMENT_UTILS_H_ 17 | 18 | #include 19 | 20 | namespace verible { 21 | 22 | // Removes /* and */ from block comments and // from end-line comments. 23 | // Removes excess wrapping characters such as /**** and ****/ and /////. 24 | // If text is not a comment, it is returned unmodified, but in general, do not 25 | // rely on any specific behavior for non-comments. 26 | // Result is always a substring of the original (bounds may be equal). 27 | std::string_view StripComment(std::string_view); 28 | 29 | // Same as StripComment, but also removes leading and trailing whitespace. 30 | std::string_view StripCommentAndSpacePadding(std::string_view); 31 | 32 | } // namespace verible 33 | 34 | #endif // VERIBLE_COMMON_STRINGS_COMMENT_UTILS_H_ 35 | -------------------------------------------------------------------------------- /verible/common/strings/compare.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef VERIBLE_COMMON_STRINGS_COMPARE_H_ 16 | #define VERIBLE_COMMON_STRINGS_COMPARE_H_ 17 | 18 | #include 19 | 20 | namespace verible { 21 | 22 | // This comparator enables heteregeneous lookup on a string-keyed associative 23 | // array (using string_view). 24 | // 25 | // See https://abseil.io/tips/144 for further explanation. 26 | // 27 | // Example: std::map 28 | struct StringViewCompare { 29 | using is_transparent = void; 30 | 31 | // Works on anything that is implicitly convertible to string_view. 32 | bool operator()(std::string_view a, std::string_view b) const { 33 | return a < b; 34 | } 35 | }; 36 | 37 | } // namespace verible 38 | 39 | #endif // VERIBLE_COMMON_STRINGS_COMPARE_H_ 40 | -------------------------------------------------------------------------------- /verible/common/strings/naming-utils.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef VERIBLE_COMMON_STRINGS_NAMING_UTILS_H_ 16 | #define VERIBLE_COMMON_STRINGS_NAMING_UTILS_H_ 17 | 18 | #include 19 | 20 | namespace verible { 21 | 22 | // Returns true if the string contains only capital letters, digits, and 23 | // underscores. 24 | bool IsNameAllCapsUnderscoresDigits(std::string_view); 25 | 26 | // Returns true if the all the underscores in the string are followed by digits. 27 | bool AllUnderscoresFollowedByDigits(std::string_view); 28 | 29 | // Returns true if the string follows UpperCamelCase naming convention, where 30 | // underscores are allowed when separating a digit. 31 | bool IsUpperCamelCaseWithDigits(std::string_view); 32 | 33 | // Returns true if the string follows lower_snake_case naming convention. 34 | bool IsLowerSnakeCaseWithDigits(std::string_view); 35 | 36 | } // namespace verible 37 | 38 | #endif // VERIBLE_COMMON_STRINGS_NAMING_UTILS_H_ 39 | -------------------------------------------------------------------------------- /verible/common/strings/position.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "verible/common/strings/position.h" 16 | 17 | #include 18 | 19 | namespace verible { 20 | 21 | int AdvancingTextNewColumnPosition(int old_column_position, 22 | std::string_view advancing_text) { 23 | const auto last_newline = advancing_text.find_last_of('\n'); 24 | if (last_newline == std::string_view::npos) { 25 | // No newlines, so treat every character as one column position, 26 | // even tabs. 27 | return old_column_position + advancing_text.length(); 28 | } 29 | // Count characters after the last newline. 30 | return advancing_text.length() - last_newline - 1; 31 | } 32 | 33 | } // namespace verible 34 | -------------------------------------------------------------------------------- /verible/common/strings/random.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef VERIBLE_COMMON_STRINGS_RANDOM_H_ 16 | #define VERIBLE_COMMON_STRINGS_RANDOM_H_ 17 | 18 | #include 19 | #include 20 | 21 | namespace verible { 22 | 23 | // Returns a random character in [a-zA-Z]. 24 | char RandomAlphaChar(); 25 | 26 | // Returns a random character in [a-zA-Z0-9]. 27 | char RandomAlphaNumChar(); 28 | 29 | // Returns an identifier ([alpha][alnum]*) of equal length to input. 30 | std::string RandomEqualLengthIdentifier(std::string_view input); 31 | 32 | } // namespace verible 33 | 34 | #endif // VERIBLE_COMMON_STRINGS_RANDOM_H_ 35 | -------------------------------------------------------------------------------- /verible/common/strings/range.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "verible/common/strings/range.h" 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | #include "verible/common/util/logging.h" 22 | #include "verible/common/util/range.h" 23 | 24 | namespace verible { 25 | 26 | std::string_view make_string_view_range(std::string_view::const_iterator begin, 27 | std::string_view::const_iterator end) { 28 | const int length = std::distance(begin, end); 29 | CHECK_GE(length, 0) << "Malformed string bounds."; 30 | return std::string_view(&*begin, length); 31 | } 32 | 33 | std::pair SubstringOffsets(std::string_view substring, 34 | std::string_view superstring) { 35 | return SubRangeIndices(substring, superstring); 36 | } 37 | 38 | } // namespace verible 39 | -------------------------------------------------------------------------------- /verible/common/strings/range.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef VERIBLE_COMMON_STRINGS_RANGE_H_ 16 | #define VERIBLE_COMMON_STRINGS_RANGE_H_ 17 | 18 | #include 19 | #include 20 | 21 | namespace verible { 22 | 23 | // Construct a string_view from two end-points. 24 | // string_view lacks the two-iterator constructor that (iterator) ranges and 25 | // containers do. 26 | // Note, this can go with c++20 built-in string_view constructor. 27 | std::string_view make_string_view_range(std::string_view::const_iterator begin, 28 | std::string_view::const_iterator end); 29 | 30 | // Returns [x,y] where superstring.substr(x, y-x) == substring. 31 | // Precondition: substring must be a sub-range of superstring. 32 | std::pair SubstringOffsets(std::string_view substring, 33 | std::string_view superstring); 34 | 35 | } // namespace verible 36 | 37 | #endif // VERIBLE_COMMON_STRINGS_RANGE_H_ 38 | -------------------------------------------------------------------------------- /verible/common/strings/rebase.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "verible/common/strings/rebase.h" 16 | 17 | #include 18 | 19 | #include "verible/common/util/logging.h" 20 | 21 | namespace verible { 22 | 23 | void RebaseStringView(std::string_view *src, std::string_view dest) { 24 | CHECK_EQ(*src, dest) << "RebaseStringView() is only valid when the " 25 | "new text referenced matches the old text."; 26 | *src = dest; 27 | } 28 | 29 | void RebaseStringView(std::string_view *src, const char *dest) { 30 | RebaseStringView(src, std::string_view(dest, src->length())); 31 | } 32 | 33 | } // namespace verible 34 | -------------------------------------------------------------------------------- /verible/common/text/README.md: -------------------------------------------------------------------------------- 1 | # Text Structural Representation Libraries 2 | 3 | 6 | 7 | At the heart of language-tooling libraries and applications lie various 8 | structural representations of text, and the functions that operate on them. This 9 | directory contains _language-agnostic_ data structures like: 10 | 11 | * Tokens: annotated substrings of a body of text, often what a lexer produces. 12 | * Token streams: iterable representations of lexer output, including 13 | filtered views thereof. 14 | * Syntax trees: represent how parsers understand and organize code 15 | hierarchically. 16 | 17 | ## Key Concepts 18 | 19 | `absl::string_view`s do not just represent text, but they represent **position** 20 | within a larger body of text, by virtue of comparing their `begin` and `end` 21 | bounds. This concept is leveraged heavily to avoid unnecessary string copying. A 22 | base `string_view` that represents a body of text and serve as the basis for 23 | interchanging between substring-views and byte-offsets relative to the start of 24 | the base. 25 | -------------------------------------------------------------------------------- /verible/common/text/constants.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // This header defines constants common to all lexers and parsers. 16 | 17 | #ifndef VERIBLE_COMMON_TEXT_CONSTANTS_H_ 18 | #define VERIBLE_COMMON_TEXT_CONSTANTS_H_ 19 | 20 | namespace verible { 21 | 22 | // This is the value of EOF token from all Flex-generated lexers. 23 | // This is also the value expected by Bison-generated parsers for $end. 24 | inline constexpr int TK_EOF = 0; 25 | 26 | // Language-specific tags for various nonterminals should be nonzero. 27 | enum NodeEnum { 28 | kUntagged = 0, 29 | }; 30 | 31 | } // namespace verible 32 | 33 | #endif // VERIBLE_COMMON_TEXT_CONSTANTS_H_ 34 | -------------------------------------------------------------------------------- /verible/common/text/symbol-ptr.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2023 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef VERIBLE_COMMON_TEXT_SYMBOLPTR_H_ 16 | #define VERIBLE_COMMON_TEXT_SYMBOLPTR_H_ 17 | 18 | #include 19 | 20 | namespace verible { 21 | class Symbol; 22 | using SymbolPtr = std::unique_ptr; 23 | } // namespace verible 24 | #endif // VERIBLE_COMMON_TEXT_SYMBOLPTR_H_ 25 | -------------------------------------------------------------------------------- /verible/common/text/symbol.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "verible/common/text/symbol.h" 16 | 17 | #include 18 | 19 | namespace verible { 20 | 21 | std::ostream &operator<<(std::ostream &stream, SymbolKind kind) { 22 | switch (kind) { 23 | case SymbolKind::kLeaf: 24 | return stream << "SymbolKind::kLeaf"; 25 | case SymbolKind::kNode: 26 | return stream << "SymbolKind::kNode"; 27 | } 28 | return stream << "SymbolKind::UNKNOWN"; 29 | } 30 | 31 | } // namespace verible 32 | -------------------------------------------------------------------------------- /verible/common/text/token-info-json.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "verible/common/text/token-info-json.h" 16 | 17 | #include 18 | #include 19 | 20 | #include "nlohmann/json.hpp" 21 | #include "verible/common/text/token-info.h" 22 | 23 | namespace verible { 24 | 25 | nlohmann::json ToJson(const TokenInfo &token_info, 26 | const TokenInfo::Context &context, bool include_text) { 27 | nlohmann::json json(nlohmann::json::object()); 28 | std::ostringstream stream; 29 | context.token_enum_translator(stream, token_info.token_enum()); 30 | json["start"] = token_info.left(context.base); 31 | json["end"] = token_info.right(context.base); 32 | json["tag"] = stream.str(); 33 | 34 | if (include_text) { 35 | json["text"] = std::string(token_info.text()); 36 | } 37 | 38 | return json; 39 | } 40 | 41 | } // namespace verible 42 | -------------------------------------------------------------------------------- /verible/common/text/token-info-json.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef VERIBLE_COMMON_TEXT_TOKEN_INFO_JSON_H_ 16 | #define VERIBLE_COMMON_TEXT_TOKEN_INFO_JSON_H_ 17 | 18 | #include "nlohmann/json.hpp" 19 | #include "verible/common/text/token-info.h" 20 | 21 | namespace verible { 22 | 23 | // Returns JSON representation of TokenInfo 24 | nlohmann::json ToJson(const TokenInfo &token_info, 25 | const TokenInfo::Context &context, 26 | bool include_text = false); 27 | 28 | } // namespace verible 29 | 30 | #endif // VERIBLE_COMMON_TEXT_TOKEN_INFO_JSON_H_ 31 | -------------------------------------------------------------------------------- /verible/common/text/tree-builder-test-util.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "verible/common/text/tree-builder-test-util.h" 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | #include "verible/common/text/symbol.h" 22 | #include "verible/common/text/tree-utils.h" 23 | #include "verible/common/util/logging.h" 24 | 25 | namespace verible { 26 | 27 | constexpr std::string_view kDontCareText; 28 | 29 | SymbolPtr XLeaf(int token_enum) { return Leaf(token_enum, kDontCareText); } 30 | 31 | const Symbol *DescendPath(const Symbol &symbol, 32 | std::initializer_list path) { 33 | const Symbol *node_symbol = &symbol; 34 | for (const auto &index : path) { 35 | const auto &node = SymbolCastToNode(*ABSL_DIE_IF_NULL(node_symbol)); 36 | CHECK_LT(index, node.size()); // bounds check, like ::at() 37 | node_symbol = node[index].get(); 38 | } 39 | return node_symbol; 40 | } 41 | 42 | } // namespace verible 43 | -------------------------------------------------------------------------------- /verible/common/tools/README.md: -------------------------------------------------------------------------------- 1 | # Generic Programs 2 | 3 | 6 | 7 | This directory contains application-agnostic tools that support the Verible 8 | project. 9 | 10 | * `verible-patch-tool`: a multi-tool for working with diffs/patches. 11 | -------------------------------------------------------------------------------- /verible/common/util/README.md: -------------------------------------------------------------------------------- 1 | # Generic Libraries 2 | 3 | 6 | 7 | This directory contains libraries that are general-purpose, and not tied to any 8 | particular application or domain. This includes (but is not limited to) data 9 | structures, algorithms, interface adapters, file and I/O libraries, and debug 10 | utilities. 11 | -------------------------------------------------------------------------------- /verible/common/util/logging.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef VERIBLE_COMMON_UTIL_LOGGING_H_ 16 | #define VERIBLE_COMMON_UTIL_LOGGING_H_ 17 | 18 | #ifdef __GNUC__ 19 | // b/246413374 20 | #pragma GCC diagnostic push 21 | #pragma GCC diagnostic ignored "-Wsign-compare" 22 | #endif 23 | #include "absl/log/check.h" // IWYU pragma: export 24 | #ifdef __GNUC__ 25 | #pragma GCC diagnostic pop 26 | #endif 27 | 28 | #include "absl/log/die_if_null.h" // IWYU pragma: export 29 | #include "absl/log/log.h" // IWYU pragma: export 30 | 31 | #define CHECK_NOTNULL(p) (void)ABSL_DIE_IF_NULL(p) 32 | 33 | #endif // VERIBLE_COMMON_UTIL_LOGGING_H_ 34 | -------------------------------------------------------------------------------- /verible/common/util/module-version.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2025 The Verible Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Provide a helper function to extract version number from MODULE.bazel""" 16 | 17 | def get_version_define_from_module(name = ""): 18 | module_version = native.module_version() 19 | if module_version: 20 | return ['-DVERIBLE_MODULE_VERSION=\\"{0}\\"'.format(module_version)] 21 | else: 22 | return [] 23 | -------------------------------------------------------------------------------- /verible/common/util/spacer.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "verible/common/util/spacer.h" 16 | 17 | #include 18 | #include 19 | 20 | namespace verible { 21 | 22 | std::ostream &operator<<(std::ostream &stream, const Spacer &spacer) { 23 | for (size_t i = 0; i < spacer.repeat; ++i) { 24 | stream << spacer.repeated_char; 25 | } 26 | return stream; 27 | } 28 | 29 | } // namespace verible 30 | -------------------------------------------------------------------------------- /verible/common/util/spacer.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef VERIBLE_COMMON_UTIL_SPACER_H_ 16 | #define VERIBLE_COMMON_UTIL_SPACER_H_ 17 | 18 | #include 19 | #include 20 | 21 | namespace verible { 22 | 23 | // Streamable print adapter that prints a number of spaces without allocating 24 | // any temporary string. 25 | struct Spacer { 26 | explicit Spacer(size_t n, char c = ' ') : repeat(n), repeated_char(c) {} 27 | size_t repeat; 28 | char repeated_char; 29 | }; 30 | 31 | std::ostream &operator<<(std::ostream &, const Spacer &); 32 | 33 | } // namespace verible 34 | 35 | #endif // VERIBLE_COMMON_UTIL_SPACER_H_ 36 | -------------------------------------------------------------------------------- /verible/common/util/spacer_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "verible/common/util/spacer.h" 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | #include "gtest/gtest.h" 22 | 23 | namespace verible { 24 | namespace { 25 | 26 | TEST(SpacerTest, DefaultSpaces) { 27 | for (size_t i = 0; i < 10; ++i) { 28 | const Spacer s(i); // default to ' ' 29 | std::ostringstream stream; 30 | stream << s; 31 | EXPECT_EQ(stream.str(), std::string(i, ' ')); 32 | } 33 | } 34 | 35 | TEST(SpacerTest, CustomSpaces) { 36 | constexpr char test_char = '.'; 37 | for (size_t i = 0; i < 10; ++i) { 38 | const Spacer s(i, test_char); 39 | std::ostringstream stream; 40 | stream << s; 41 | EXPECT_EQ(stream.str(), std::string(i, test_char)); 42 | } 43 | } 44 | 45 | } // namespace 46 | } // namespace verible 47 | -------------------------------------------------------------------------------- /verible/common/util/status-macros.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef VERIBLE_COMMON_UTIL_STATUS_MACROS_H_ 16 | #define VERIBLE_COMMON_UTIL_STATUS_MACROS_H_ 17 | 18 | #include "absl/base/optimization.h" 19 | 20 | namespace verible { 21 | namespace util { 22 | 23 | // Run a command that returns a absl::Status. If the called code returns an 24 | // error status, return that status up out of this method too. 25 | // 26 | // Example: 27 | // RETURN_IF_ERROR(DoThings(4)); 28 | #define RETURN_IF_ERROR(expr) \ 29 | do { \ 30 | /* Using _status below to avoid capture problems if expr is "status". */ \ 31 | absl::Status _status = (expr); \ 32 | if (ABSL_PREDICT_FALSE(!_status.ok())) return _status; \ 33 | } while (0) 34 | 35 | } // namespace util 36 | } // namespace verible 37 | 38 | #endif // VERIBLE_COMMON_UTIL_STATUS_MACROS_H_ 39 | -------------------------------------------------------------------------------- /verible/common/util/tree-operations.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2022 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "verible/common/util/tree-operations.h" 16 | 17 | #include 18 | #include 19 | 20 | #include "absl/strings/str_cat.h" 21 | #include "absl/strings/str_join.h" 22 | 23 | namespace verible { 24 | 25 | std::ostream &operator<<(std::ostream &stream, const NodePath &p) { 26 | return stream << absl::StrCat( 27 | "{", absl::StrJoin(p.path.begin(), p.path.end(), ","), "}"); 28 | } 29 | 30 | } // namespace verible 31 | -------------------------------------------------------------------------------- /verible/common/util/type-traits_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "verible/common/util/type-traits.h" 16 | 17 | #include 18 | 19 | #include "gtest/gtest.h" 20 | 21 | namespace verible { 22 | namespace { 23 | 24 | TEST(MatchConst, NonConst) { 25 | static_assert(std::is_same_v, int>); 26 | static_assert(std::is_same_v, int>); 27 | } 28 | 29 | TEST(MatchConst, Const) { 30 | static_assert(std::is_same_v, const int>); 31 | static_assert( 32 | std::is_same_v, const int>); 33 | } 34 | 35 | } // namespace 36 | } // namespace verible 37 | -------------------------------------------------------------------------------- /verible/common/util/value-saver.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef VERIBLE_COMMON_UTIL_VALUE_SAVER_H_ 16 | #define VERIBLE_COMMON_UTIL_VALUE_SAVER_H_ 17 | 18 | namespace verible { 19 | 20 | // An object of this type modifies a given variable in the constructor 21 | // and restores its original value in the destructor. 22 | template 23 | class ValueSaver { 24 | public: 25 | ValueSaver(T *p, const T &newval) : ptr_(p), oldval_(*ptr_) { 26 | *ptr_ = newval; 27 | } 28 | // The one-arg version just uses the current value as newval. 29 | explicit ValueSaver(T *p) : ptr_(p), oldval_(*ptr_) {} 30 | 31 | ~ValueSaver() { *ptr_ = oldval_; } 32 | 33 | ValueSaver(ValueSaver &&) = delete; 34 | ValueSaver(const ValueSaver &) = delete; 35 | ValueSaver &operator=(const ValueSaver &) = delete; 36 | 37 | private: 38 | T *const ptr_; 39 | const T oldval_; 40 | }; 41 | 42 | } // namespace verible 43 | 44 | #endif // VERIBLE_COMMON_UTIL_VALUE_SAVER_H_ 45 | -------------------------------------------------------------------------------- /verible/common/util/value-saver_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "verible/common/util/value-saver.h" 16 | 17 | #include "gtest/gtest.h" 18 | 19 | namespace verible { 20 | namespace { 21 | 22 | TEST(ValueSaverTest, NoChange) { 23 | int x = 1; 24 | const ValueSaver temp(&x); 25 | EXPECT_EQ(x, 1); 26 | } 27 | 28 | TEST(ValueSaverTest, ChangeAndRestore) { 29 | int x = 1; 30 | { 31 | const ValueSaver temp(&x); 32 | x = 0; 33 | } 34 | EXPECT_EQ(x, 1); 35 | } 36 | 37 | TEST(ValueSaverTest, ChangeInConstructor) { 38 | int x = 1; 39 | { 40 | const ValueSaver temp(&x, 2); 41 | EXPECT_EQ(x, 2); 42 | } 43 | EXPECT_EQ(x, 1); 44 | } 45 | 46 | TEST(ValueSaverTest, NestedScopes) { 47 | int x = 1; 48 | { 49 | const ValueSaver temp(&x, 2); 50 | EXPECT_EQ(x, 2); 51 | { 52 | const ValueSaver temp(&x, 5); 53 | EXPECT_EQ(x, 5); 54 | } 55 | EXPECT_EQ(x, 2); 56 | } 57 | EXPECT_EQ(x, 1); 58 | } 59 | 60 | } // namespace 61 | } // namespace verible 62 | -------------------------------------------------------------------------------- /verible/common/util/with-reason.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef VERIBLE_COMMON_UTIL_WITH_REASON_H_ 16 | #define VERIBLE_COMMON_UTIL_WITH_REASON_H_ 17 | 18 | namespace verible { 19 | 20 | // In functions with priority-ordered return statements, this helps with 21 | // identifying the statement that took effect. 22 | // 23 | // Instead of writing: 24 | // int f() { 25 | // ... 26 | // return value1; // explanation1 27 | // ... 28 | // return value2; // explanation2 29 | // } 30 | // 31 | // Write: 32 | // WithReason f() { 33 | // ... 34 | // return {value1; "explanation1..."}; 35 | // ... 36 | // return {value2; "explanation2..."}; 37 | // } 38 | // 39 | // The caller should unpack the struct, and can print the reason string 40 | // when desired. 41 | template 42 | struct WithReason { 43 | T value; 44 | const char *reason; // A simple string literal shall suffice. 45 | }; 46 | 47 | } // namespace verible 48 | 49 | #endif // VERIBLE_COMMON_UTIL_WITH_REASON_H_ 50 | -------------------------------------------------------------------------------- /verible/verilog/CST/DPI.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "verible/verilog/CST/DPI.h" 16 | 17 | #include 18 | 19 | #include "verible/common/analysis/syntax-tree-search.h" 20 | #include "verible/common/text/concrete-syntax-tree.h" 21 | #include "verible/common/text/tree-utils.h" 22 | #include "verible/verilog/CST/verilog-matchers.h" 23 | #include "verible/verilog/CST/verilog-nonterminals.h" 24 | 25 | namespace verilog { 26 | 27 | using verible::Symbol; 28 | using verible::SyntaxTreeNode; 29 | 30 | std::vector FindAllDPIImports(const Symbol &root) { 31 | return SearchSyntaxTree(root, NodekDPIImportItem()); 32 | } 33 | 34 | const SyntaxTreeNode *GetDPIImportPrototype(const Symbol &symbol) { 35 | return GetSubtreeAsNode(symbol, NodeEnum::kDPIImportItem, 5); 36 | } 37 | 38 | } // namespace verilog 39 | -------------------------------------------------------------------------------- /verible/verilog/CST/constraints.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef VERIBLE_VERILOG_CST_CONSTRAINTS_H_ 16 | #define VERIBLE_VERILOG_CST_CONSTRAINTS_H_ 17 | 18 | #include 19 | 20 | #include "verible/common/analysis/syntax-tree-search.h" 21 | #include "verible/common/text/concrete-syntax-tree.h" 22 | #include "verible/common/text/symbol.h" 23 | #include "verible/common/text/token-info.h" 24 | #include "verible/verilog/CST/verilog-matchers.h" // IWYU pragma: keep 25 | 26 | namespace verilog { 27 | 28 | std::vector FindAllConstraintDeclarations( 29 | const verible::Symbol &root); 30 | 31 | bool IsOutOfLineConstraintDefinition(const verible::Symbol &symbol); 32 | 33 | const verible::TokenInfo *GetSymbolIdentifierFromConstraintDeclaration( 34 | const verible::Symbol &symbol); 35 | 36 | } // namespace verilog 37 | 38 | #endif // VERIBLE_VERILOG_CST_CONSTRAINTS_H_ 39 | -------------------------------------------------------------------------------- /verible/verilog/CST/data.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // This unit provides helper functions that pertain to SystemVerilog 16 | // net declaration nodes in the parser-generated concrete syntax tree. 17 | 18 | #ifndef VERIBLE_VERILOG_CST_DATA_H_ 19 | #define VERIBLE_VERILOG_CST_DATA_H_ 20 | 21 | #include 22 | 23 | #include "verible/common/text/concrete-syntax-tree.h" 24 | #include "verible/common/text/symbol.h" 25 | #include "verible/common/text/token-info.h" 26 | 27 | namespace verilog { 28 | 29 | // Returns tokens that correspond to declared names in data declarations 30 | std::vector GetIdentifiersFromDataDeclaration( 31 | const verible::Symbol &symbol); 32 | 33 | } // namespace verilog 34 | 35 | #endif // VERIBLE_VERILOG_CST_DATA_H_ 36 | -------------------------------------------------------------------------------- /verible/verilog/CST/verilog-matchers.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Nothing in here: Just a c++ file place-holder used in the cc_library() so 16 | // that bazel knows that the header-implementation in that libray is C++. 17 | // Otherwise the compilation DB will emit it as C and clang-tidy/clangd would 18 | // have trouble with the header (e.g. complains that is not found 19 | // as it would read it as C file). 20 | 21 | // TL;DR 22 | // Don't remove. Work around bazel's assumptions of C++-ness. 23 | -------------------------------------------------------------------------------- /verible/verilog/CST/verilog-tree-json.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef VERIBLE_VERILOG_CST_VERILOG_TREE_JSON_H_ 16 | #define VERIBLE_VERILOG_CST_VERILOG_TREE_JSON_H_ 17 | 18 | #include 19 | 20 | #include "nlohmann/json.hpp" 21 | #include "verible/common/text/symbol.h" 22 | 23 | namespace verilog { 24 | 25 | // Returns a JSON representation of tree contained at root. 26 | nlohmann::json ConvertVerilogTreeToJson(const verible::Symbol &root, 27 | std::string_view base); 28 | 29 | } // namespace verilog 30 | 31 | #endif // VERIBLE_VERILOG_CST_VERILOG_TREE_JSON_H_ 32 | -------------------------------------------------------------------------------- /verible/verilog/CST/verilog_nonterminals_foreach.inc: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // This files is used to generate repetitive code for every enumeration 16 | // value in "verilog/CST/verilog_nonterminals.h". 17 | // To use this #define a CONSIDER() macro before including this file, 18 | // and #undef it after including this file. 19 | 20 | #ifndef CONSIDER 21 | #error \ 22 | "Define the CONSIDER macro before including this file " \ 23 | "(and undefine it after)." 24 | #endif // CONSIDER 25 | 26 | // CONSIDER(...) cases are auto-generated from verilog_nonterminals.h' enum. 27 | #include "verible/verilog/CST/verilog_nonterminals_foreach-gen.inc" 28 | -------------------------------------------------------------------------------- /verible/verilog/README.md: -------------------------------------------------------------------------------- 1 | # SystemVerilog Libraries and Tools 2 | 3 | 6 | 7 | This subtree contains SystemVerilog-specific libraries and tools. 8 | 9 | Standalone installable tools are organized under [tools](./tools). 10 | 11 | All other directories contain only supporting libraries. 12 | -------------------------------------------------------------------------------- /verible/verilog/analysis/checkers/README.md: -------------------------------------------------------------------------------- 1 | # Lint Rules 2 | 3 | 6 | 7 | This directory provides implementations of all lint rules. Lint rules make 8 | themselves available by registering themselves (upon library loading), so they 9 | can be referenced and selected by name. 10 | 11 | User documentation for the lint rules is generated dynamically, and can be found 12 | at https://chipsalliance.github.io/verible/verilog_lint.html, or by running 13 | `verible-verilog-lint --help_rules` for text or `--generate_markdown`. 14 | 15 | [Linter user documentation can be found here](../../tools/lint). 16 | -------------------------------------------------------------------------------- /verible/verilog/analysis/default-rules_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "verible/verilog/analysis/default-rules.h" 16 | 17 | #include "gtest/gtest.h" 18 | #include "verible/verilog/analysis/lint-rule-registry.h" 19 | 20 | namespace verilog { 21 | namespace analysis { 22 | namespace { 23 | 24 | // Test that rules in the default set are all registered. 25 | TEST(DefaultRuleTest, AllDefaultValid) { 26 | for (const auto &rule_id : kDefaultRuleSet) { 27 | EXPECT_TRUE(IsRegisteredLintRule(rule_id)) 28 | << "Registry is missing rule_id: " << rule_id; 29 | } 30 | } 31 | 32 | } // namespace 33 | } // namespace analysis 34 | } // namespace verilog 35 | -------------------------------------------------------------------------------- /verible/verilog/analysis/json-diagnostics.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef VERIBLE_VERILOG_ANALYSIS_JSON_DIAGNOSTICS_H_ 16 | #define VERIBLE_VERILOG_ANALYSIS_JSON_DIAGNOSTICS_H_ 17 | 18 | #include 19 | 20 | #include "nlohmann/json.hpp" 21 | #include "verible/verilog/analysis/verilog-analyzer.h" 22 | 23 | namespace verilog { 24 | 25 | // Returns JSON list with information about errors. At most "limit" errors 26 | // are returned (zero means unlimited). 27 | nlohmann::json GetLinterTokenErrorsAsJson( 28 | const verilog::VerilogAnalyzer *analyzer, size_t limit); 29 | 30 | } // namespace verilog 31 | 32 | #endif // VERIBLE_VERILOG_ANALYSIS_JSON_DIAGNOSTICS_H_ 33 | -------------------------------------------------------------------------------- /verible/verilog/analysis/verilog-linter-constants.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef VERIBLE_VERILOG_ANALYSIS_VERILOG_LINTER_CONSTANTS_H_ 16 | #define VERIBLE_VERILOG_ANALYSIS_VERILOG_LINTER_CONSTANTS_H_ 17 | 18 | #include 19 | 20 | namespace verilog { 21 | 22 | // This is the leading string that makes a comment a lint waiver. 23 | inline constexpr std::string_view kLinterTrigger = "verilog_lint:"; 24 | 25 | // This command says to waive one line (this or next applicable). 26 | inline constexpr std::string_view kLinterWaiveLineCommand = "waive"; 27 | 28 | // This command says to start waiving a rule from this line... 29 | inline constexpr std::string_view kLinterWaiveStartCommand = "waive-start"; 30 | 31 | // ... and stop waiving at this line. 32 | inline constexpr std::string_view kLinterWaiveStopCommand = "waive-stop"; 33 | 34 | } // namespace verilog 35 | 36 | #endif // VERIBLE_VERILOG_ANALYSIS_VERILOG_LINTER_CONSTANTS_H_ 37 | -------------------------------------------------------------------------------- /verible/verilog/formatting/README.md: -------------------------------------------------------------------------------- 1 | # SystemVerilog Formatting 2 | 3 | 6 | 7 | This directory contains all of the SystemVerilog-specific formatter 8 | implementation. 9 | 10 | [Tool user documentation can be found here](../tools/formatter). 11 | 12 | ## Formatter Subsystems 13 | 14 | [Full developer documentation can be found here](../../doc/formatter.md). 15 | 16 | Below is a quick summary of the major components. 17 | 18 | [formatter.h](formatter.h) contains the top-level entry point into the 19 | formatter. Text-in-text-out tests are in [formatter_test.cc](formatter_test.cc). 20 | 21 | [FormatStyle](format_style.h) defines ways in which formatting can be 22 | configured. 23 | 24 | [token_annotator.h](token_annotator.h) marks up a token stream with formatting 25 | constraints such as minimum spacing, and always/never-wrap. 26 | 27 | [TreeUnwrapper](tree_unwrapper.h) converts a SV syntax tree into a 28 | language-agnostic TokenPartitionTree representation for doing formatting 29 | operations. 30 | 31 | [align.h](align.h) implements everything related to tabular alignment of 32 | specific sections of code. 33 | 34 | [comment_controls.h](comment_controls.h) implements comment directives thet 35 | disable formatting on ranges of text. 36 | -------------------------------------------------------------------------------- /verible/verilog/formatting/align.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef VERIBLE_VERILOG_FORMATTING_ALIGN_H_ 16 | #define VERIBLE_VERILOG_FORMATTING_ALIGN_H_ 17 | 18 | #include 19 | 20 | #include "verible/common/formatting/token-partition-tree.h" 21 | #include "verible/common/strings/position.h" // for ByteOffsetSet 22 | #include "verible/verilog/formatting/format-style.h" 23 | 24 | namespace verilog { 25 | namespace formatter { 26 | 27 | // For certain Verilog language construct groups, vertically align some 28 | // tokens by inserting padding-spaces. 29 | // TODO(fangism): pass in disabled formatting ranges 30 | void TabularAlignTokenPartitions( 31 | const FormatStyle &style, std::string_view full_text, 32 | const verible::ByteOffsetSet &disabled_byte_ranges, 33 | verible::TokenPartitionTree *partition_ptr); 34 | 35 | } // namespace formatter 36 | } // namespace verilog 37 | 38 | #endif // VERIBLE_VERILOG_FORMATTING_ALIGN_H_ 39 | -------------------------------------------------------------------------------- /verible/verilog/formatting/format-style-init.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2021 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef VERIBLE_VERILOG_FORMATTING_FORMAT_STYLE_INIT_H_ 16 | #define VERIBLE_VERILOG_FORMATTING_FORMAT_STYLE_INIT_H_ 17 | 18 | #include "verible/verilog/formatting/format-style.h" 19 | 20 | namespace verilog { 21 | namespace formatter { 22 | 23 | // Initialize format style from flags. 24 | void InitializeFromFlags(FormatStyle *style); 25 | 26 | // TODO: initialize from configuration file. 27 | // https://github.com/chipsalliance/verible/issues/898 28 | // Possibly using common/text/config_utils.h 29 | } // namespace formatter 30 | } // namespace verilog 31 | #endif // VERIBLE_VERILOG_FORMATTING_FORMAT_STYLE_INIT_H_ 32 | -------------------------------------------------------------------------------- /verible/verilog/parser/verilog-token.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef VERIBLE_VERILOG_TOKEN_VERILOG_TOKEN_H_ 16 | #define VERIBLE_VERILOG_TOKEN_VERILOG_TOKEN_H_ 17 | 18 | #include 19 | #include 20 | 21 | namespace verilog { 22 | 23 | // Returns token identifier suitable for use in string-based APIs (such as JSON 24 | // export in verible-verilog-syntax). The identifiers are easy to type in 25 | // programming languages and are mostly self-explanatory. They use: 26 | // - Token text for string and character literal tokens. Examples: 27 | // "module", "==", ";", "'" 28 | // - Token name used in verilog/parser/verilog.y. This uses the original token 29 | // names, not their (optional) display names. Examples: 30 | // "SymbolIdentifier", "TK_DecNumber", "TK_EOL_COMMENT", "TK_NEWLINE" 31 | // 32 | // See also: verilog_symbol_name() in verilog_parser.h 33 | std::string_view TokenTypeToString(size_t tokentype); 34 | 35 | } // namespace verilog 36 | 37 | #endif // VERIBLE_VERILOG_TOKEN_VERILOG_TOKEN_H_ 38 | -------------------------------------------------------------------------------- /verible/verilog/preprocessor/README.md: -------------------------------------------------------------------------------- 1 | # SystemVerilog Preprocessor 2 | 3 | 6 | 7 | Since early applications such as the style linter and formatter operate on 8 | _unpreprocessed_ source code, preprocessing constructs were incorporated 9 | directly into the [grammar](../parser/verilog.y) with limitations. 10 | 11 | ## Pseudo Preprocessing 12 | 13 | Pseudo-preprocessing refers to any number of strategies that perform partial or 14 | approximate preprocessing, by making assumptions, such as whether conditional 15 | branches are taken or not taken, or expanding macros to the extent where local 16 | definitions are available. The outcome of these "transformations" is a modified 17 | view of the original text that could result in covering different preprocessing 18 | code paths (blanking out not-taken branches), which could result in different 19 | lexing and parsing results. Any number of strategies could be used to overcome 20 | the limitations of preprocessing support in the parser, which in turn improves 21 | the outreach of tools like the linter and formatter. 22 | 23 | Most of these are not yet implemented, but 24 | [help is wanted](https://github.com/chipsalliance/verible/issues/183). 25 | 26 | ## Standard-Compliant SV Preprocessor 27 | 28 | ... does not exist in this codebase yet. See 29 | https://github.com/chipsalliance/verible/issues/183. 30 | 31 | SystemVerilog preprocessing is in many ways 32 | [more complicated than C/C++ preprocessing](https://www.veripool.org/papers/Preproc_Good_Evil_SNUGBos10_paper.pdf). 33 | -------------------------------------------------------------------------------- /verible/verilog/tools/README.md: -------------------------------------------------------------------------------- 1 | # SystemVerilog Tools 2 | 3 | 6 | 7 | This directory is the root of installable SystemVerilog tools. 8 | -------------------------------------------------------------------------------- /verible/verilog/tools/diff/README.md: -------------------------------------------------------------------------------- 1 | # SystemVerilog Lexical Diff Tool 2 | 3 | 6 | 7 | `verible-verilog-diff` compares two SystemVerilog source files and reports the 8 | first lexical difference. Equivalence is determined by the comparison `--mode`. 9 | 10 | * `--mode=format` Checks for equivalence of text ignoring whitespaces. 11 | * `--mode=obfuscate` Checks for equivalence including spaces, and verifies 12 | lengths of identifiers. 13 | 14 | Equivalence analysis also looks inside macro definition bodies and macro call 15 | arguments, recursively. 16 | 17 | Exit codes: 18 | 19 | * 0: files are equivalent 20 | * 1: files differ, or contain lexical errors 21 | * 2: error reading file 22 | -------------------------------------------------------------------------------- /verible/verilog/tools/diff/diff_format_lex_error_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2017-2020 The Verible Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # Tests verible-verilog-diff --mode=format 17 | 18 | declare -r MY_INPUT_FILE1="${TEST_TMPDIR}/myinput1.txt" 19 | declare -r MY_INPUT_FILE2="${TEST_TMPDIR}/myinput2.txt" 20 | 21 | # Get tool from argument 22 | [[ "$#" == 1 ]] || { 23 | echo "Expecting 1 positional argument, verible-verilog-diff path." 24 | exit 1 25 | } 26 | difftool="$(rlocation ${TEST_WORKSPACE}/${1})" 27 | 28 | # contains lexical error token "1mm" 29 | cat >${MY_INPUT_FILE1} <${MY_INPUT_FILE2} <${MY_INPUT_FILE1} <${MY_INPUT_FILE2} <${MY_INPUT_FILE1} <${MY_INPUT_FILE2} <${MY_INPUT_FILE1} <${MY_INPUT_FILE2} <${MY_INPUT_FILE1} <${MY_INPUT_FILE} < ${MY_OUTPUT_FILE} 34 | [[ "$?" -eq 1 ]] || exit 1 35 | 36 | echo "PASS" 37 | -------------------------------------------------------------------------------- /verible/verilog/tools/formatter/format_file_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2017-2020 The Verible Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # Tests verible-verilog-format reading from a file, printing to stdout. 17 | 18 | declare -r MY_INPUT_FILE="${TEST_TMPDIR}/myinput.txt" 19 | declare -r MY_OUTPUT_FILE="${TEST_TMPDIR}/myoutput.txt" 20 | declare -r MY_EXPECT_FILE="${TEST_TMPDIR}/myexpect.txt" 21 | 22 | # Get tool from argument 23 | [[ "$#" == 1 ]] || { 24 | echo "Expecting 1 positional argument, verible-verilog-format path." 25 | exit 1 26 | } 27 | formatter="$(rlocation ${TEST_WORKSPACE}/${1})" 28 | 29 | cat >${MY_INPUT_FILE} <${MY_EXPECT_FILE} < ${MY_OUTPUT_FILE} || exit 1 40 | diff --strip-trailing-cr "${MY_OUTPUT_FILE}" "${MY_EXPECT_FILE}" || exit 2 41 | 42 | echo "PASS" 43 | -------------------------------------------------------------------------------- /verible/verilog/tools/formatter/format_inplace_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2017-2020 The Verible Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # Tests the --inplace flag of verible-verilog-format. 17 | 18 | declare -r MY_OUTPUT_FILE="${TEST_TMPDIR}/myoutput.txt" 19 | declare -r MY_EXPECT_FILE="${TEST_TMPDIR}/myexpect.txt" 20 | 21 | # Get tool from argument 22 | [[ "$#" == 1 ]] || { 23 | echo "Expecting 1 positional argument, verible-verilog-format path." 24 | exit 1 25 | } 26 | formatter="$(rlocation ${TEST_WORKSPACE}/$1)" 27 | 28 | # Will overwrite this file in-place. 29 | cat >${MY_OUTPUT_FILE} <${MY_EXPECT_FILE} <${MY_INPUT_FILE} <${MY_EXPECT_FILE} < ${MY_OUTPUT_FILE} || exit 1 41 | diff --strip-trailing-cr "${MY_OUTPUT_FILE}" "${MY_EXPECT_FILE}" || exit 2 42 | 43 | echo "PASS" 44 | -------------------------------------------------------------------------------- /verible/verilog/tools/formatter/format_stdin_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2017-2020 The Verible Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # Tests - as stdin for verible-verilog-format. 17 | 18 | declare -r MY_INPUT_FILE="${TEST_TMPDIR}/myinput.txt" 19 | declare -r MY_OUTPUT_FILE="${TEST_TMPDIR}/myoutput.txt" 20 | declare -r MY_EXPECT_FILE="${TEST_TMPDIR}/myexpect.txt" 21 | 22 | # Get tool from argument 23 | [[ "$#" == 1 ]] || { 24 | echo "Expecting 1 positional argument, verible-verilog-format path." 25 | exit 1 26 | } 27 | formatter="$(rlocation ${TEST_WORKSPACE}/${1})" 28 | 29 | # Will overwrite this file in-place. 30 | cat >${MY_INPUT_FILE} <${MY_EXPECT_FILE} < ${MY_OUTPUT_FILE} || exit 1 41 | diff --strip-trailing-cr "${MY_OUTPUT_FILE}" "${MY_EXPECT_FILE}" || exit 2 42 | 43 | echo "PASS" 44 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/kythe-proto-output.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef VERIBLE_VERILOG_TOOLS_KYTHE_KYTHE_PROTO_OUTPUT_H_ 16 | #define VERIBLE_VERILOG_TOOLS_KYTHE_KYTHE_PROTO_OUTPUT_H_ 17 | 18 | #include "google/protobuf/io/zero_copy_stream_impl.h" 19 | #include "verible/verilog/tools/kythe/kythe-facts-extractor.h" 20 | #include "verible/verilog/tools/kythe/kythe-facts.h" 21 | 22 | namespace verilog { 23 | namespace kythe { 24 | 25 | class KytheProtoOutput final : public KytheOutput { 26 | public: 27 | explicit KytheProtoOutput(int output_fd); 28 | ~KytheProtoOutput() final; 29 | 30 | // Output Kythe facts from the indexing data in proto format. 31 | void Emit(const Fact &fact) final; 32 | void Emit(const Edge &edge) final; 33 | 34 | private: 35 | ::google::protobuf::io::FileOutputStream out_; 36 | }; 37 | 38 | } // namespace kythe 39 | } // namespace verilog 40 | 41 | #endif // VERIBLE_VERILOG_TOOLS_KYTHE_KYTHE_PROTO_OUTPUT_H_ 42 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/case.sv: -------------------------------------------------------------------------------- 1 | //- @m1 defines/binding _ 2 | module m1; 3 | //- @temp defines/binding Temp0 4 | //- @x defines/binding X 5 | //- @y defines/binding Y 6 | int temp, x, y; 7 | 8 | //- @temp ref Temp0 9 | case (temp) 10 | //- @x ref X 11 | x: begin 12 | //- @temp defines/binding Temp7 13 | int temp; 14 | //- @temp ref Temp7 15 | assign temp = 1; 16 | end 17 | //- @y ref Y 18 | y: begin 19 | //- @temp defines/binding Temp8 20 | int temp; 21 | //- @temp ref Temp8 22 | assign temp = 1; 23 | end 24 | endcase 25 | 26 | //- @temp ref Temp0 27 | assign temp = 1; 28 | 29 | endmodule 30 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/class_extends_with_package.sv: -------------------------------------------------------------------------------- 1 | //- @p_pkg defines/binding PPkg 2 | package p_pkg; 3 | //- @A defines/binding A 4 | class A; 5 | //- @var1 defines/binding Var1 6 | int var1; 7 | endclass 8 | 9 | //- @X defines/binding X 10 | class X; 11 | //- @Y defines/binding Y 12 | class Y; 13 | //- @var2 defines/binding Var2 14 | int var2; 15 | endclass 16 | endclass 17 | endpackage 18 | 19 | //- @C defines/binding C 20 | //- @p_pkg ref PPkg 21 | //- @A ref A 22 | //- C extends A 23 | class C extends p_pkg::A; 24 | //- @f1 defines/binding _ 25 | function int f1(); 26 | //- @var1 ref Var1 27 | return var1; 28 | endfunction 29 | endclass 30 | 31 | //- @H defines/binding H 32 | //- @p_pkg ref PPkg 33 | //- @X ref X 34 | //- @Y ref Y 35 | //- H extends Y 36 | class H extends p_pkg::X::Y; 37 | //- @f2 defines/binding _ 38 | function int f2(); 39 | //- @var2 ref Var2 40 | return var2; 41 | endfunction 42 | endclass 43 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/conditional_generate.sv: -------------------------------------------------------------------------------- 1 | //- @m1 defines/binding _ 2 | module m1; 3 | //- @temp defines/binding Temp0 4 | //- @x defines/binding X 5 | int temp, x; 6 | 7 | //- @x ref X 8 | if (x) begin 9 | //- @temp defines/binding Temp7 10 | int temp; 11 | //- @temp ref Temp7 12 | assign temp = 1; 13 | //- @x ref X 14 | end else if(x) begin 15 | //- @temp defines/binding Temp8 16 | int temp; 17 | //- @temp ref Temp8 18 | assign temp = 1; 19 | end else begin 20 | //- @temp defines/binding Temp9 21 | int temp; 22 | //- @temp ref Temp9 23 | assign temp = 1; 24 | end 25 | 26 | //- @#0 x ref X 27 | if (x) begin 28 | //- @temp defines/binding Temp1 29 | int temp; 30 | //- @temp ref Temp1 31 | assign temp = 1; 32 | //- @x ref X 33 | end else if(x) begin 34 | //- @temp defines/binding Temp3 35 | int temp; 36 | //- @temp ref Temp3 37 | assign temp = 1; 38 | end else begin 39 | //- @temp defines/binding Temp4 40 | int temp; 41 | //- @temp ref Temp4 42 | assign temp = 1; 43 | end 44 | 45 | //- @temp ref Temp0 46 | assign temp = 1; 47 | 48 | endmodule 49 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/declarations.sv: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //- _FileNode.node/kind file 5 | //- @my_pkg defines/binding _ 6 | package my_pkg; 7 | 8 | //- @my_class defines/binding _ 9 | class my_class; 10 | endclass 11 | 12 | //- @my_integer defines/binding _ 13 | integer my_integer = 10; 14 | 15 | //- @my_enum1 defines/binding _ 16 | //- @my_enum2 defines/binding _ 17 | //- @my_var1 defines/binding _ 18 | //- @my_var2 defines/binding _ 19 | enum {my_enum1, my_enum2} my_var1, my_var2; 20 | 21 | //- @my_function defines/binding _ 22 | //- @my_arg1 defines/binding _ 23 | function void my_function(int my_arg1); 24 | endfunction 25 | 26 | //- @my_task defines/binding _ 27 | //- @my_arg2 defines/binding _ 28 | task my_task(int my_arg2); 29 | endtask 30 | 31 | endpackage 32 | 33 | //- @my_module defines/binding _ 34 | module my_module; endmodule 35 | 36 | //- @my_program defines/binding _ 37 | program my_program; endprogram 38 | 39 | //- @my_interface defines/binding _ 40 | interface my_interface; endinterface 41 | 42 | 43 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/different_primitive_types.sv: -------------------------------------------------------------------------------- 1 | //- @c1 defines/binding _ 2 | class c1; 3 | 4 | //- @var1 defines/binding _ 5 | shortreal var1; 6 | 7 | //- @var2 defines/binding _ 8 | event var2; 9 | 10 | //- @var3 defines/binding _ 11 | chandle var3; 12 | 13 | //- @var4 defines/binding _ 14 | realtime var4; 15 | 16 | //- @var5 defines/binding _ 17 | real var5; 18 | 19 | //- @var6 defines/binding _ 20 | int var6; 21 | 22 | //- @var7 defines/binding _ 23 | logic var7; 24 | 25 | //- @var8 defines/binding _ 26 | bit var8; 27 | 28 | //- @var9 defines/binding _ 29 | string var9; 30 | 31 | endclass 32 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/do_while_loop.sv: -------------------------------------------------------------------------------- 1 | //- @m1 defines/binding _ 2 | module m1; 3 | //- @temp defines/binding Temp0 4 | //- @y defines/binding Y 5 | int temp, y; 6 | 7 | initial begin 8 | do begin 9 | //- @temp defines/binding Temp8 10 | int temp; 11 | //- @temp ref Temp8 12 | assign temp = 1; 13 | //- @y ref Y 14 | end while(y < 5); 15 | end 16 | 17 | //- @temp ref Temp0 18 | assign temp = 1; 19 | 20 | endmodule 21 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/enum.sv: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //- _FileNode.node/kind file 5 | package my_pkg; 6 | //- @AA defines/binding _AA 7 | //- @BB defines/binding BB 8 | //- @my_enum_var1 defines/binding MyEnumVar1 9 | enum {AA, BB} my_enum_var1; 10 | 11 | //- @idx defines/binding Idx 12 | int idx = 0; 13 | 14 | //- @var5 defines/binding Var5 15 | int var5[5]; 16 | 17 | //- @AA2 defines/binding _ 18 | //- @BB2 defines/binding _ 19 | //- @my_enum_var2 defines/binding _ 20 | //- @idx ref Idx 21 | //- @var5 ref Var5 22 | enum {AA2, BB2 = var5[idx]} my_enum_var2; 23 | 24 | //- @AA2 defines/binding _ 25 | //- @BB2 defines/binding _ 26 | //- @my_enum_var3 defines/binding _ 27 | //- @idx ref Idx 28 | //- @var5 ref Var5 29 | typedef enum {AA2, BB2 = var5[idx]} my_enum_var3; 30 | 31 | //- @CC defines/binding _CC 32 | //- @DD defines/binding DD 33 | //- @my_enum2 defines/binding MyEnum2 34 | typedef enum {CC, DD} my_enum2; 35 | endpackage 36 | 37 | module my_module; 38 | initial begin 39 | //- @my_enum2 ref MyEnum2 40 | //- @my_enum_var2 defines/binding _ 41 | //- @DD ref DD 42 | automatic my_pkg::my_enum2 my_enum_var2 = my_pkg::DD; 43 | 44 | //- @my_enum_var1 ref MyEnumVar1 45 | //- @BB ref BB 46 | my_pkg::my_enum_var1 = my_pkg::BB; 47 | end 48 | endmodule 49 | 50 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/event_control.sv: -------------------------------------------------------------------------------- 1 | //- @t1 defines/binding _ 2 | //- @y defines/binding Y 3 | task t1(int y); 4 | //- @x defines/binding X 5 | int x[10]; 6 | //- @x ref X 7 | //- @y ref Y 8 | @x[y]; 9 | endtask 10 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/final.sv: -------------------------------------------------------------------------------- 1 | //- @m1 defines/binding _ 2 | module m1; 3 | //- @temp defines/binding Temp0 4 | int temp; 5 | 6 | final begin 7 | //- @temp defines/binding Temp8 8 | int temp; 9 | //- @temp ref Temp8 10 | assign temp = 1; 11 | end 12 | 13 | //- @temp ref Temp0 14 | assign temp = 1; 15 | 16 | endmodule 17 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/for_loop.sv: -------------------------------------------------------------------------------- 1 | //- @m1 defines/binding _ 2 | module m1; 3 | //- @y defines/binding Y 4 | //- @x defines/binding X 5 | //- @#1i defines/binding I0 6 | int y[10], x[10], i; 7 | 8 | //- @#0i defines/binding I 9 | //- @#1i ref I 10 | //- @#2i ref I 11 | for (genvar i=0; i<32; i++) begin 12 | //- @#1i ref I 13 | //- @#2i ref I 14 | //- @y ref Y 15 | //- @x ref X 16 | assign y[i] = x[i]; 17 | 18 | //- @temp defines/binding Temp0 19 | int temp; 20 | //- @temp ref Temp0 21 | assign temp = 1; 22 | end 23 | 24 | //- @#0i defines/binding I2 25 | //- @#1i ref I2 26 | //- @#2i ref I2 27 | for (genvar i=0; i<32; i++) begin 28 | //- @#1i ref I2 29 | //- @#2i ref I2 30 | //- @y ref Y 31 | //- @x ref X 32 | assign y[i] = x[i]; 33 | 34 | //- @temp defines/binding Temp2 35 | int temp; 36 | //- @temp ref Temp2 37 | assign temp = 1; 38 | end 39 | 40 | initial begin 41 | //- @#1i defines/binding I1 42 | //- @#2i ref I1 43 | //- @#3i ref I1 44 | for (int i = 0; i < 50; i++) begin 45 | //- @temp defines/binding Temp1 46 | int temp; 47 | //- @temp ref Temp1 48 | assign temp = 1; 49 | end 50 | end 51 | 52 | //- @#1i ref I0 53 | assign i = 1; 54 | 55 | endmodule 56 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/for_loop_uint.sv: -------------------------------------------------------------------------------- 1 | //- @uint defines/binding Uint 2 | typedef int uint; 3 | 4 | //- @my_module defines/binding _ 5 | module my_module(); 6 | //- @y defines/binding Y 7 | int y = 0; 8 | initial begin 9 | //- @uint ref Uint 10 | //- @#0x defines/binding X 11 | //- @#1x ref X 12 | //- @#2x ref X 13 | for (uint x = 1; x < 5; x++) begin 14 | //- @y ref Y 15 | y++; 16 | end 17 | end 18 | endmodule 19 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/foreach.sv: -------------------------------------------------------------------------------- 1 | //- @m1 defines/binding _ 2 | module m1; 3 | //- @y defines/binding Y 4 | //- @temp defines/binding Temp0 5 | int y[10], temp; 6 | 7 | initial begin 8 | //- @y ref Y 9 | foreach (y) begin 10 | //- @temp defines/binding Temp8 11 | int temp; 12 | //- @temp ref Temp8 13 | assign temp = 1; 14 | end 15 | end 16 | 17 | //- @temp ref Temp0 18 | assign temp = 1; 19 | 20 | endmodule 21 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/forever.sv: -------------------------------------------------------------------------------- 1 | //- @m1 defines/binding _ 2 | module m1; 3 | //- @temp defines/binding Temp0 4 | int temp; 5 | 6 | initial begin 7 | forever begin 8 | //- @temp defines/binding Temp8 9 | int temp; 10 | //- @temp ref Temp8 11 | assign temp = 1; 12 | end 13 | end 14 | 15 | //- @temp ref Temp0 16 | assign temp = 1; 17 | 18 | endmodule 19 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/function_and_task.sv: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //- _FileNode.node/kind file 5 | 6 | //- @my_function defines/binding MyFunction 7 | //- MyFunction.node/kind function 8 | //- MyFunction.complete definition 9 | //- @my_arg1 defines/binding MyArg1 10 | //- MyArg1.node/kind variable 11 | //- MyArg1.complete definition 12 | //- MyArg1 childof MyFunction 13 | //- @my_arg2 defines/binding MyArg2 14 | //- MyArg2.node/kind variable 15 | //- MyArg2.complete definition 16 | //- MyArg2 childof MyFunction 17 | function int my_function(int my_arg1, int my_arg2); 18 | //- @my_arg1 ref MyArg1 19 | //- @my_arg2 ref MyArg2 20 | return my_arg1 + my_arg2; 21 | endfunction 22 | 23 | //- @my_task defines/binding MyTask 24 | //- MyTask.node/kind function 25 | //- MyTask.complete definition 26 | //- @my_arg3 defines/binding MyArg3 27 | //- MyArg3.node/kind variable 28 | //- MyArg3.complete definition 29 | //- MyArg3 childof MyTask 30 | //- @my_arg4 defines/binding MyArg4 31 | //- MyArg4.node/kind variable 32 | //- MyArg4.complete definition 33 | //- MyArg4 childof MyTask 34 | task my_task(int my_arg3, int my_arg4); 35 | //- @my_arg3 ref MyArg3 36 | //- @my_arg4 ref MyArg4 37 | $display(my_arg3 + my_arg4); 38 | endtask : my_task 39 | 40 | module my_module; 41 | initial begin 42 | //- @my_function ref MyFunction 43 | //- @my_function ref/call MyFunction 44 | //- @ii defines/binding VarI 45 | automatic integer ii = my_function(2, 6); 46 | //- @my_task ref MyTask 47 | //- @my_task ref/call MyTask 48 | //- @ii ref VarI 49 | my_task(ii, 6); 50 | end 51 | endmodule 52 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/function_call_hierarchy.sv: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //- _FileNode.node/kind file 5 | 6 | //- @top_pkg defines/binding TopPkg 7 | package top_pkg; 8 | //- @f1 defines/binding F1 9 | //- F1.node/kind function 10 | //- F1 childof TopPkg 11 | function automatic int f1(int arg1); 12 | int temp1 = f2(arg1); 13 | int temp2 = f2(arg1); 14 | //- @f3 ref/call F3 15 | //- @f3 ref F3 16 | return f3(arg1); 17 | endfunction 18 | 19 | //- @f2 defines/binding F2 20 | //- F2.node/kind function 21 | //- F2 childof TopPkg 22 | function automatic int f2(int arg1); 23 | //- @f3 ref F3 24 | //- @f3 ref/call F3 25 | return f3(arg1); 26 | endfunction 27 | 28 | //- @f3 defines/binding F3 29 | //- F3.node/kind function 30 | //- F3 childof TopPkg 31 | function automatic int f3(int arg1); 32 | return arg1; 33 | endfunction 34 | endpackage 35 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/function_call_inside_loop.sv: -------------------------------------------------------------------------------- 1 | //- @f1 defines/binding F1 2 | //- @k defines/binding K 3 | function int f1(int k); 4 | //- @k ref K 5 | return k; 6 | endfunction 7 | 8 | //- @m1 defines/binding _ 9 | module m1; 10 | //- @y defines/binding Y 11 | //- @x defines/binding X 12 | int y[10], x[10]; 13 | 14 | //- @#0i defines/binding I 15 | //- @#1i ref I 16 | //- @#2i ref I 17 | for (genvar i=0; i<32; i++) begin 18 | //- @#1i ref I 19 | //- @#2i ref I 20 | //- @y ref Y 21 | //- @x ref X 22 | //- @f1 ref F1 23 | assign y[i] = f1(x[i]); 24 | end 25 | 26 | initial begin 27 | //- @#1i defines/binding I1 28 | //- @#2i ref I1 29 | //- @#3i ref I1 30 | for (int i = 0; i < 50; i++) begin 31 | //- @#1i ref I1 32 | //- @#2i ref I1 33 | //- @y ref Y 34 | //- @x ref X 35 | //- @f1 ref F1 36 | assign y[i] = f1(x[i]); 37 | end 38 | end 39 | 40 | endmodule 41 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/function_named_args.sv: -------------------------------------------------------------------------------- 1 | //- @f1 defines/binding F1 2 | //- @A defines/binding A 3 | //- @B defines/binding B 4 | function void f1(int A, int B); 5 | endfunction 6 | 7 | //- @g1 defines/binding _ 8 | //- @C defines/binding C 9 | //- @D defines/binding D 10 | function void g1(int C, int D); 11 | //- @f1 ref F1 12 | //- @A ref A 13 | //- @B ref B 14 | //- @C ref C 15 | //- @D ref D 16 | f1(.A(C), .B(D)); 17 | endfunction 18 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/function_port_dimensions.sv: -------------------------------------------------------------------------------- 1 | //- @var1 defines/binding Var1 2 | //- @var2 defines/binding Var2 3 | //- @var3 defines/binding Var3 4 | //- @var4 defines/binding Var4 5 | int var1, var2, var3, var4; // TODO(#604): Technically, this should be a localparam. 6 | 7 | //- @f4 defines/binding _ 8 | //- @var1 ref Var1 9 | //- @var2 ref Var2 10 | //- @var3 ref Var3 11 | //- @var4 ref Var4 12 | //- @t1 defines/binding T1 13 | function f4(int [var1:var2] t1 [var3:var4]); 14 | //- @x defines/binding X 15 | //- @y defines/binding Y 16 | //- @data defines/binding Data 17 | struct { int x; int y; } data; 18 | //- @sum defines/binding _ 19 | //- @#0data ref Data 20 | //- @#1data ref Data 21 | //- @x ref X 22 | //- @y ref Y 23 | //- @t1 ref T1 24 | int sum = data.x + data.y + t1; 25 | endfunction 26 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/function_scoping.sv: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //- @top_pkg defines/binding TopPkg 5 | package top_pkg; 6 | //- @my_function defines/binding PkgFunction 7 | //- PkgFunction.node/kind function 8 | //- @my_arg1 defines/binding PkgArg 9 | function automatic int my_function(int my_arg1); 10 | //- @my_arg1 ref PkgArg 11 | return my_arg1; 12 | endfunction 13 | 14 | //- @your_function defines/binding _ 15 | function automatic int your_function(int your_arg1); 16 | //- @my_function ref PkgFunction 17 | //- @my_function ref/call PkgFunction 18 | //- @top_pkg ref TopPkg 19 | return top_pkg::my_function(your_arg1); 20 | endfunction 21 | endpackage 22 | 23 | class nested_class; 24 | //- @my_function defines/binding ClassFunction 25 | //- ClassFunction.node/kind function 26 | //- @my_arg1 defines/binding ClassArg 27 | function int my_function(int my_arg1); 28 | //- @my_arg1 ref ClassArg 29 | return my_arg1; 30 | endfunction 31 | endclass 32 | 33 | module function_scoping; 34 | import top_pkg::*; 35 | 36 | initial begin 37 | //- @my_function ref PkgFunction 38 | //- @my_function ref/call PkgFunction 39 | automatic int i = my_function(2); 40 | 41 | //- @nc_instance defines/binding ClassInstance 42 | automatic nested_class nc_instance = new(); 43 | 44 | //- @nc_instance ref ClassInstance 45 | //- @my_function ref ClassFunction 46 | //- @my_function ref/call ClassFunction 47 | automatic int j = nc_instance.my_function(2); 48 | end 49 | endmodule 50 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/function_user_defined_port.sv: -------------------------------------------------------------------------------- 1 | //- @X defines/binding X 2 | class X; 3 | //- @var1 defines/binding Var1 4 | int var1; 5 | endclass 6 | 7 | //- @f1 defines/binding _ 8 | //- @X ref X 9 | //- @x1 defines/binding X1 10 | function int f1(X x1); 11 | //- @x1 ref X1 12 | //- @var1 ref Var1 13 | return x1.var1; 14 | endfunction 15 | 16 | //- @f2 defines/binding _ 17 | //- @X ref X 18 | //- @x1 defines/binding X2 19 | task f2(X x1); 20 | //- @x1 ref X2 21 | //- @var1 ref Var1 22 | $display(x1.var1); 23 | endtask 24 | 25 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/include_file_test/A.svh: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //- @A defines/binding A 5 | localparam A = 1; 6 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/include_file_test/B.svh: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //- @B defines/binding B 5 | //- @A ref A 6 | localparam B = A + 1; 7 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/include_file_test/C.sv: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //- @"\"A.svh\"" ref/includes Asvh 5 | //- Asvh.node/kind file 6 | `include "A.svh" 7 | //- @"\"B.svh\"" ref/includes Bsvh 8 | //- Bsvh.node/kind file 9 | `include "B.svh" 10 | 11 | //- @C defines/binding _ 12 | //- @A ref A 13 | //- @B ref B 14 | localparam C = A + B; 15 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/include_file_test/file_list.txt: -------------------------------------------------------------------------------- 1 | C.sv 2 | module.sv 3 | module2.sv 4 | package_with_include.sv 5 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/include_file_test/included-file-1.svh: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //- @MyClassIncludedFile1 defines/binding MyClassIncludedFile1 5 | class MyClassIncludedFile1; 6 | //- @var6 defines/binding Var6 7 | static int var6; 8 | 9 | //- @my_fun1 defines/binding MyFun1 10 | static function int my_fun1(); 11 | return 1; 12 | endfunction 13 | endclass 14 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/include_file_test/included-file-2.svh: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //- @"\"included-file-1.svh\"" ref/includes IncludedFile1Svh 5 | //- IncludedFile1Svh.node/kind file 6 | `include "included-file-1.svh" 7 | 8 | //- @MyClassIncludedFile2 defines/binding MyClassIncludedFile2 9 | class MyClassIncludedFile2; 10 | //- @var5 defines/binding Var5 11 | static int var5; 12 | 13 | //- @my_fun3 defines/binding _ 14 | function int my_fun3(); 15 | //- @var6 ref Var6 16 | //- @MyClassIncludedFile1 ref MyClassIncludedFile1 17 | return MyClassIncludedFile1::var6; 18 | endfunction 19 | endclass 20 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/include_file_test/module.sv: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //- @"\"included-file-2.svh\"" ref/includes IncludedFile2Svh 5 | //- IncludedFile2Svh.node/kind file 6 | `include "included-file-2.svh" 7 | 8 | //- @my_module defines/binding _ 9 | module my_module(); 10 | 11 | initial begin 12 | //- @MyClassIncludedFile1 ref MyClassIncludedFile1 13 | //- @instance2 defines/binding Instance2 14 | static MyClassIncludedFile1 instance2 = new(); 15 | 16 | //- @MyClassIncludedFile2 ref MyClassIncludedFile2 17 | //- @MyClassIncludedFile1 ref MyClassIncludedFile1 18 | //- @var5 ref Var5 19 | //- @var6 ref Var6 20 | MyClassIncludedFile2::var5 = MyClassIncludedFile1::var6; 21 | 22 | //- @instance2 ref Instance2 23 | //- @my_fun1 ref MyFun1 24 | //- @my_fun1 ref/call MyFun1 25 | $display(instance2.my_fun1()); 26 | 27 | //- @MyClassIncludedFile1 ref MyClassIncludedFile1 28 | //- @my_fun1 ref MyFun1 29 | //- @my_fun1 ref/call MyFun1 30 | $display(MyClassIncludedFile1.my_fun1()); 31 | end 32 | 33 | endmodule 34 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/include_file_test/module2.sv: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //- @"\"included-file-2.svh\"" ref/includes IncludedFile2Svh 5 | //- IncludedFile2Svh.node/kind file 6 | `include "included-file-2.svh" 7 | 8 | //- @my_module2 defines/binding _ 9 | module my_module2(); 10 | 11 | initial begin 12 | //- @MyClassIncludedFile1 ref MyClassIncludedFile1 13 | //- @instance1 defines/binding Instance1 14 | static MyClassIncludedFile1 instance1 = new(); 15 | 16 | //- @MyClassIncludedFile2 ref MyClassIncludedFile2 17 | //- @MyClassIncludedFile1 ref MyClassIncludedFile1 18 | //- @var5 ref Var5 19 | //- @var6 ref Var6 20 | MyClassIncludedFile2::var5 = MyClassIncludedFile1::var6; 21 | 22 | //- @instance1 ref Instance1 23 | //- @my_fun1 ref MyFun1 24 | //- @my_fun1 ref/call MyFun1 25 | $display(instance1.my_fun1()); 26 | 27 | //- @MyClassIncludedFile1 ref MyClassIncludedFile1 28 | //- @my_fun1 ref MyFun1 29 | //- @my_fun1 ref/call MyFun1 30 | $display(MyClassIncludedFile1.my_fun1()); 31 | end 32 | 33 | endmodule 34 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/include_file_test/package_with_include.sv: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //- _FileNode.node/kind file 5 | //- @package_with_include defines/binding MyPkg 6 | package package_with_include; 7 | //- @"\"package_with_include_class.svh\"" ref/includes PackageWithIncludeClassSvh 8 | //- PackageWithIncludeClassSvh.node/kind file 9 | `include "package_with_include_class.svh" 10 | endpackage 11 | 12 | module my_module; 13 | import package_with_include::*; 14 | initial begin 15 | //- @my_class1 ref MyClass1 16 | static my_class1 handle1 = new(); 17 | 18 | //- @my_var ref MyVar 19 | handle1::my_var = 10; 20 | 21 | //- @my_function ref MyFunction 22 | $display(handle1.my_function()); 23 | 24 | //- @my_task ref/call MyTask 25 | handle1.my_task(2); 26 | 27 | //- @my_class2 ref MyClass2 28 | //- @my_static_var ref MyStaticVar 29 | $display(my_class2::my_static_var); 30 | 31 | end 32 | endmodule 33 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/include_file_test/package_with_include_class.svh: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //- _FileNode.node/kind file 5 | //- @my_class1 defines/binding MyClass1 6 | //- MyClass1 childof MyPkg 7 | class my_class1; 8 | //- @my_var defines/binding MyVar 9 | int my_var; 10 | 11 | //- @my_function defines/binding MyFunction 12 | virtual function int my_function(); 13 | return my_var; 14 | endfunction 15 | 16 | //- @my_task defines/binding MyTask 17 | task my_task(int my_arg2); 18 | $display(my_arg2); 19 | endtask 20 | 21 | endclass 22 | 23 | //- @my_class2 defines/binding MyClass2 24 | //- MyClass2 childof MyPkg 25 | class my_class2; 26 | 27 | //- @my_static_var defines/binding MyStaticVar 28 | static int my_static_var; 29 | 30 | //- @my_function defines/binding _ 31 | function int my_function(); 32 | //- @my_static_var ref MyStaticVar 33 | return my_static_var; 34 | endfunction 35 | endclass 36 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/include_with_dir_test/E.sv: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //- @"\"D.svh\"" ref/includes Dsvh 5 | //- Dsvh.node/kind file 6 | `include "D.svh" 7 | 8 | //- @"\"A.svh\"" ref/includes Asvh1 9 | //- Asvh1.node/kind file 10 | `include "A.svh" 11 | 12 | //- @"\"B.svh\"" ref/includes Bsvh2 13 | //- Bsvh2.node/kind file 14 | `include "B.svh" 15 | 16 | //- @E defines/binding _ 17 | //- @D ref D 18 | localparam E = D; 19 | 20 | //- @F defines/binding _ 21 | //- @A ref A 22 | //- @B ref B 23 | localparam F = A + B; 24 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/include_with_dir_test/file_list.txt: -------------------------------------------------------------------------------- 1 | E.sv 2 | module3.sv 3 | module4.sv 4 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/include_with_dir_test/include_dir/D.svh: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //- @D defines/binding D 5 | localparam D = 1; 6 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/include_with_dir_test/module3.sv: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //- @"\"included-file-2.svh\"" ref/includes IncludedFile2Svh 5 | //- IncludedFile2Svh.node/kind file 6 | `include "included-file-2.svh" 7 | 8 | //- @my_module defines/binding _ 9 | module my_module(); 10 | 11 | initial begin 12 | //- @MyClassIncludedFile1 ref MyClassIncludedFile1 13 | //- @instance2 defines/binding Instance2 14 | static MyClassIncludedFile1 instance2 = new(); 15 | 16 | //- @MyClassIncludedFile2 ref MyClassIncludedFile2 17 | //- @MyClassIncludedFile1 ref MyClassIncludedFile1 18 | //- @var5 ref Var5 19 | //- @var6 ref Var6 20 | MyClassIncludedFile2::var5 = MyClassIncludedFile1::var6; 21 | 22 | //- @instance2 ref Instance2 23 | //- @my_fun1 ref MyFun1 24 | //- @my_fun1 ref/call MyFun1 25 | $display(instance2.my_fun1()); 26 | 27 | //- @MyClassIncludedFile1 ref MyClassIncludedFile1 28 | //- @my_fun1 ref MyFun1 29 | //- @my_fun1 ref/call MyFun1 30 | $display(MyClassIncludedFile1.my_fun1()); 31 | end 32 | 33 | endmodule 34 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/include_with_dir_test/module4.sv: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //- @"\"included-file-2.svh\"" ref/includes IncludedFile2Svh 5 | //- IncludedFile2Svh.node/kind file 6 | `include "included-file-2.svh" 7 | 8 | //- @my_module2 defines/binding _ 9 | module my_module2(); 10 | 11 | initial begin 12 | //- @MyClassIncludedFile1 ref MyClassIncludedFile1 13 | //- @instance1 defines/binding Instance1 14 | static MyClassIncludedFile1 instance1 = new(); 15 | 16 | //- @MyClassIncludedFile2 ref MyClassIncludedFile2 17 | //- @MyClassIncludedFile1 ref MyClassIncludedFile1 18 | //- @var5 ref Var5 19 | //- @var6 ref Var6 20 | MyClassIncludedFile2::var5 = MyClassIncludedFile1::var6; 21 | 22 | //- @instance1 ref Instance1 23 | //- @my_fun1 ref MyFun1 24 | //- @my_fun1 ref/call MyFun1 25 | $display(instance1.my_fun1()); 26 | 27 | //- @MyClassIncludedFile1 ref MyClassIncludedFile1 28 | //- @my_fun1 ref MyFun1 29 | //- @my_fun1 ref/call MyFun1 30 | $display(MyClassIncludedFile1.my_fun1()); 31 | end 32 | 33 | endmodule 34 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/initial_block.sv: -------------------------------------------------------------------------------- 1 | //- @m1 defines/binding _ 2 | module m1; 3 | //- @temp defines/binding Temp0 4 | int temp; 5 | 6 | initial begin 7 | //- @temp defines/binding Temp8 8 | int temp; 9 | //- @temp ref Temp8 10 | assign temp = 1; 11 | end 12 | 13 | //- @temp ref Temp0 14 | assign temp = 1; 15 | 16 | endmodule 17 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/interface.sv: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //- @MyInterface defines/binding MyInterface 5 | //- MyInterface.node/kind interface 6 | interface MyInterface(); 7 | //- @reset defines/binding _ 8 | wire reset; 9 | //- @clk defines/binding _ 10 | wire clk; 11 | //- @in defines/binding _ 12 | logic [7:0] in; 13 | 14 | //- @MyNestedInterface defines/binding MyNestedInterface 15 | //- MyNestedInterface childof MyInterface 16 | //- MyNestedInterface.node/kind interface 17 | interface MyNestedInterface(); 18 | 19 | //- @MyNestedInterface ref MyNestedInterface 20 | endinterface: MyNestedInterface 21 | //- @MyInterface ref MyInterface 22 | endinterface: MyInterface 23 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/interface_with_parameter.sv: -------------------------------------------------------------------------------- 1 | 2 | //- @A defines/binding _ 3 | interface A #( 4 | //- @DATA_WIDTH defines/binding DATA_WIDTH2 5 | parameter DATA_WIDTH = 32 6 | ) (); 7 | 8 | //- @instr_id defines/binding _ 9 | //- @DATA_WIDTH ref DATA_WIDTH2 10 | logic [DATA_WIDTH-1:0] instr_id; 11 | endinterface 12 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/macro_call_test.sv: -------------------------------------------------------------------------------- 1 | //- @c defines/binding C 2 | //- @x defines/binding _ 3 | `define c(x) 4 | 5 | //- @f1 defines/binding _ 6 | //- @j defines/binding J 7 | function int f1(int j); 8 | 9 | //- @#0"c" ref/expands C 10 | //- @#1"c" ref/call C 11 | //- @#2"c" ref/expands C 12 | //- @#0j ref J 13 | //- @#1j ref J 14 | return `c(`c(j)(`c(j))); 15 | endfunction 16 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/macro_with_function.sv: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //- @PRINT_STRING defines/binding _ 5 | `define PRINT_STRING(str1) $display("%s\n", str1) 6 | 7 | //- @PRINT_3_STRINGS defines/binding Print3Strings 8 | `define PRINT_3_STRINGS(str1, str2, str3) \ 9 | `PRINT_STRING(str1); \ 10 | `PRINT_STRING(str2); \ 11 | `PRINT_STRING(str3); 12 | 13 | //- @TEN defines/binding Ten 14 | `define TEN 10 15 | 16 | package my_pkg; 17 | //- @my_function defines/binding MyFunction 18 | function automatic my_function(int arg1, int arg2); 19 | return arg1 + arg2; 20 | endfunction 21 | endpackage 22 | 23 | //- @macro defines/binding _ 24 | module macro; 25 | initial begin 26 | //- @arg2 defines/binding Arg2 27 | automatic integer arg2 = 2; 28 | 29 | //- @ii defines/binding _ 30 | //- @my_function ref/call MyFunction 31 | //- @"TEN" ref/expands Ten 32 | //- @arg2 ref Arg2 33 | automatic integer ii = my_pkg::my_function(`TEN, arg2); 34 | 35 | //- @"PRINT_3_STRINGS" ref/expands Print3Strings 36 | `PRINT_3_STRINGS("Grand", "Tour", "S4"); 37 | end 38 | endmodule 39 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/module_extra_test.sv: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //- _FileNode.node/kind file 5 | 6 | //- @my_module defines/binding MyModule 7 | module my_module ( 8 | //- @in1 defines/binding In1 9 | input bit in1, 10 | //- @in2 defines/binding In2 11 | input bit in2, 12 | //- @out1 defines/binding Out1 13 | output bit out1 14 | ); 15 | 16 | //- @in1 ref In1 17 | //- @in2 ref In2 18 | //- @out1 ref Out1 19 | assign out1 = in1 & in2; 20 | endmodule 21 | 22 | //- @top defines/binding Top 23 | module top; 24 | //- @aa defines/binding AA 25 | //- @bb defines/binding BB 26 | //- @cc defines/binding CC 27 | bit aa, bb, cc; 28 | 29 | //- @my_module ref MyModule 30 | //- @dut defines/binding _ 31 | //- @aa ref AA 32 | //- @bb ref BB 33 | //- @cc ref CC 34 | my_module dut(.in1(aa), .in2(bb), .out1(cc)); 35 | 36 | endmodule 37 | 38 | //- @top_top defines/binding TopTop 39 | module top_top; 40 | //- @#0top ref Top 41 | //- @top_module defines/binding TopInstance 42 | //- TopInstance childof TopTop 43 | top top_module(); 44 | endmodule 45 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/module_port_type_forwarding.sv: -------------------------------------------------------------------------------- 1 | //- _FileNode.node/kind file 2 | 3 | //- @my_module defines/binding MyModule 4 | //- MyModule.node/kind record 5 | //- MyModule.subkind module 6 | //- MyModule.complete definition 7 | module my_module ( 8 | //- @n1 ref NDef 9 | n1, 10 | //- @b1 defines/binding B1Def 11 | //- B1Def.node/kind variable 12 | //- B1Def.complete definition 13 | //- B1Def childof MyModule 14 | bit b1, 15 | //- @b2 defines/binding B2Def 16 | //- B2Def.node/kind variable 17 | //- B2Def.complete definition 18 | //- B2Def childof MyModule 19 | b2, 20 | //- @x defines/binding XDef 21 | //- XDef.node/kind variable 22 | //- XDef.complete definition 23 | //- XDef childof MyModule 24 | input x, 25 | //- @x2 defines/binding X2Def 26 | //- X2Def.node/kind variable 27 | //- X2Def.complete definition 28 | //- X2Def childof MyModule 29 | x2, 30 | //- @y defines/binding YDef 31 | //- YDef.node/kind variable 32 | //- YDef.complete definition 33 | //- YDef childof MyModule 34 | output wire y, 35 | //- @z defines/binding ZDef 36 | //- ZDef.node/kind variable 37 | //- ZDef.complete definition 38 | //- ZDef childof MyModule 39 | z 40 | ); 41 | 42 | //- @n1 defines/binding NDef 43 | //- NDef.node/kind variable 44 | //- NDef.complete definition 45 | //- NDef childof MyModule 46 | input n1; 47 | 48 | endmodule 49 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/module_with_same_prefix.sv: -------------------------------------------------------------------------------- 1 | //- _FileNode.node/kind file 2 | 3 | //- @top defines/binding TopModule 4 | //- TopModule.node/kind record 5 | //- TopModule.subkind module 6 | //- TopModule.complete definition 7 | module top; 8 | endmodule 9 | 10 | //- @top_top defines/binding TopTopModule 11 | //- TopTopModule.node/kind record 12 | //- TopTopModule.subkind module 13 | //- TopTopModule.complete definition 14 | module top_top; 15 | 16 | //- @#0top ref TopModule 17 | //- @top_instance defines/binding TopInstanceDef 18 | //- TopInstanceDef.node/kind variable 19 | //- TopInstanceDef.complete definition 20 | //- TopInstanceDef childof TopTopModule 21 | top top_instance (); 22 | endmodule 23 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/multi_file_test/file_list.txt: -------------------------------------------------------------------------------- 1 | multi-file-1.sv 2 | multi-file-2.sv 3 | multi-file-3.sv 4 | multi-file-4.sv 5 | 6 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/multi_file_test/multi-file-1.sv: -------------------------------------------------------------------------------- 1 | //- _FileNode.node/kind file 2 | 3 | //- @pkg1 defines/binding Pkg1 4 | package pkg1; 5 | //- @PARAM defines/binding Param 6 | parameter int PARAM = 1; 7 | 8 | //- @my_class defines/binding MyClass 9 | class my_class; 10 | //- @instance1 defines/binding Instance1 11 | my_class instance1 = new(); 12 | 13 | //- @var1 defines/binding Var1 14 | static int var1; 15 | 16 | //- @my_fun defines/binding MyFun 17 | static function int my_fun(); 18 | //- @var1 ref Var1 19 | return var1; 20 | endfunction 21 | endclass 22 | endpackage 23 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/multi_file_test/multi-file-2.sv: -------------------------------------------------------------------------------- 1 | //- @my_class defines/binding MyClass1 2 | class my_class; 3 | endclass 4 | 5 | //- @pkg2 defines/binding _ 6 | package pkg2; 7 | //- @my_class2 defines/binding _ 8 | class my_class2; 9 | 10 | //- @my_class ref MyClass1 11 | //- @instance1 defines/binding _ 12 | my_class instance1 = new(); 13 | 14 | //- @var2 defines/binding Var2 15 | static int var2; 16 | 17 | //- @my_fun defines/binding _ 18 | static function int my_fun(); 19 | //- @var2 ref Var2 20 | return var2; 21 | endfunction 22 | endclass 23 | endpackage 24 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/multi_file_test/multi-file-3.sv: -------------------------------------------------------------------------------- 1 | //- @my_module defines/binding MyModule 2 | module my_module#( 3 | //- @ADDR_WIDTH defines/binding ADDR_WIDTH 4 | parameter ADDR_WIDTH=8 5 | ) 6 | //-@in1 defines/binding _ 7 | (input in1); 8 | 9 | //- @pkg1 ref/imports Pkg1 10 | import pkg1::*; 11 | 12 | //- @my_class ref MyClass 13 | //- @instance2 defines/binding Instance2 14 | my_class instance2 = new(); 15 | 16 | //- @PARAM ref Param 17 | initial $display(PARAM); 18 | 19 | //- @instance2 ref Instance2 20 | //- @var1 ref Var1 21 | initial $display(instance2::var1); 22 | 23 | //- @instance2 ref Instance2 24 | //- @my_fun ref MyFun 25 | //- @my_fun ref/call MyFun 26 | initial $display(instance2.my_fun()); 27 | 28 | //- @instance2 ref Instance2 29 | //- @instance1 ref Instance1 30 | //- @var1 ref Var1 31 | initial $display(instance2::instance1::var1); 32 | endmodule 33 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/multi_file_test/multi-file-4.sv: -------------------------------------------------------------------------------- 1 | //- @my_module2 defines/binding _ 2 | module my_module2( 3 | //- @in2 defines/binding In2 4 | input in2); 5 | 6 | //- @my_module ref MyModule 7 | my_module #( 8 | //- @ADDR_WIDTH ref ADDR_WIDTH 9 | //- @pkg1 ref Pkg1 10 | //- @PARAM ref Param 11 | .ADDR_WIDTH(pkg1::PARAM)) 12 | //- @m defines/binding _ 13 | //- @in2 ref In2 14 | m(in2); 15 | endmodule 16 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/package_with_primitive.sv: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | //- _FileNode.node/kind file 5 | //- @my_pkg1 defines/binding MyPkg1 6 | package my_pkg1; 7 | //- @my_integer defines/binding MyInteger 8 | integer my_integer = 10; 9 | endpackage 10 | 11 | // Second package also defines my_integer. 12 | //- @my_pkg2 defines/binding MyPkg2 13 | package my_pkg2; 14 | //- @my_integer defines/binding MyInteger2 15 | integer my_integer = 10; 16 | endpackage 17 | 18 | // First imported reference to the first package. 19 | module my_module1; 20 | //- @my_pkg1 ref/imports MyPkg1 21 | import my_pkg1::*; 22 | //- @my_integer ref MyInteger 23 | initial $display(my_integer); 24 | endmodule 25 | 26 | // Second reference to the second package. 27 | module my_module2; 28 | //- @my_pkg2 ref MyPkg2 29 | //- @my_integer ref MyInteger2 30 | initial $display(my_pkg2::my_integer); 31 | endmodule 32 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/primitive_type_with_dimensions.sv: -------------------------------------------------------------------------------- 1 | //- _FileNode.node/kind file 2 | 3 | //- @foo_pkg defines/binding FooPkg 4 | package foo_pkg; 5 | //- @DATA_WIDTH defines/binding DATA_WIDTH 6 | parameter int DATA_WIDTH = 1; 7 | //- @DATA_LENGTH defines/binding DATA_LENGTH 8 | parameter int DATA_LENGTH = 1; 9 | endpackage 10 | 11 | //- @baz_pkg defines/binding _ 12 | package baz_pkg; 13 | // //- @var5 defines/binding _ 14 | // //- @#0foo_pkg ref FooPkg 15 | // //- @#1foo_pkg ref FooPkg 16 | // //- @#2foo_pkg ref FooPkg 17 | // //- @#3foo_pkg ref FooPkg 18 | // //- @#0DATA_WIDTH ref DATA_WIDTH 19 | // //- @#1DATA_WIDTH ref DATA_WIDTH 20 | // //- @#0DATA_LENGTH ref DATA_LENGTH 21 | // //- @#1DATA_LENGTH ref DATA_LENGTH 22 | int [foo_pkg::DATA_WIDTH-1:foo_pkg::DATA_LENGTH] var5 [foo_pkg::DATA_WIDTH-1:foo_pkg::DATA_LENGTH]; 23 | 24 | //- @bar_c defines/binding _ 25 | class bar_c; 26 | //- @var2 defines/binding _ 27 | //- @#0foo_pkg ref FooPkg 28 | //- @#1foo_pkg ref FooPkg 29 | //- @#2foo_pkg ref FooPkg 30 | //- @#3foo_pkg ref FooPkg 31 | //- @#0DATA_WIDTH ref DATA_WIDTH 32 | //- @#1DATA_WIDTH ref DATA_WIDTH 33 | //- @#0DATA_LENGTH ref DATA_LENGTH 34 | //- @#1DATA_LENGTH ref DATA_LENGTH 35 | bit [foo_pkg::DATA_WIDTH-1:foo_pkg::DATA_LENGTH] var2 [foo_pkg::DATA_WIDTH-1:foo_pkg::DATA_LENGTH]; 36 | endclass 37 | endpackage 38 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/program.sv: -------------------------------------------------------------------------------- 1 | //- @mem_intf defines/binding MemIntf 2 | interface mem_intf; 3 | //- @clk defines/binding CLK 4 | logic clk; 5 | endinterface 6 | 7 | //- @testcase defines/binding TestCase 8 | //- TestCase.node/kind record 9 | //- TestCase.subkind program 10 | program testcase ( 11 | //- @intf defines/binding Intf 12 | interface intf 13 | ); 14 | //- @#1env defines/binding Env 15 | environment env; 16 | initial begin 17 | //- @env ref Env 18 | //- @intf ref Intf 19 | env = new(intf); 20 | end 21 | //- @testcase ref TestCase 22 | endprogram: testcase 23 | 24 | //- @tbench_top defines/binding _ 25 | module tbench_top; 26 | //- @mem_intf ref MemIntf 27 | //- @#1intf defines/binding Intf1 28 | mem_intf intf(); 29 | 30 | //- @memory ref Memory 31 | //- @dut defines/binding _ 32 | memory dut( 33 | //- @#0clk ref Clk2 34 | //- @intf ref Intf1 35 | //- @#1clk ref CLK 36 | .clk(intf.clk), 37 | ); 38 | 39 | //- @testcase ref TestCase 40 | //- @#1test defines/binding _ 41 | //- @intf ref Intf1 42 | testcase test(intf); 43 | endmodule 44 | 45 | //- @memory defines/binding Memory 46 | module memory ( 47 | //- @clk ref Clk2 48 | clk 49 | ); 50 | //- @clk defines/binding Clk2 51 | input clk; 52 | endmodule 53 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/qualified_variable_type.sv: -------------------------------------------------------------------------------- 1 | //- @pkg defines/binding Pkg 2 | package pkg; 3 | //- @my_class defines/binding MyClass 4 | //- @P1 defines/binding P1 5 | class my_class#(parameter P1 = 1); 6 | //- @var3 defines/binding Var3 7 | int var3; 8 | endclass 9 | endpackage 10 | 11 | //- @my_module defines/binding _ 12 | module my_module(); 13 | //- @var4 defines/binding Var4 14 | int var4; 15 | //- @pkg ref Pkg 16 | //- @my_class ref MyClass 17 | //- @var1 defines/binding Var1 18 | //- @P1 ref P1 19 | //- @var4 ref Var4 20 | pkg::my_class#(.P1(var4)) var1; 21 | //- @pkg ref Pkg 22 | //- @my_class ref MyClass 23 | //- @var2 defines/binding Var2 24 | //- @P1 ref P1 25 | //- @var4 ref Var4 26 | pkg::my_class#(.P1(var4)) var2 = new(); 27 | 28 | initial begin 29 | //- @var1 ref Var1 30 | var1 = new(); 31 | 32 | //- @var1 ref Var1 33 | //- @var3 ref Var3 34 | $display(var1.var3); 35 | //- @var2 ref Var2 36 | //- @var3 ref Var3 37 | $display(var2.var3); 38 | end 39 | endmodule 40 | 41 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/repeat.sv: -------------------------------------------------------------------------------- 1 | //- @m1 defines/binding _ 2 | module m1; 3 | //- @temp defines/binding Temp0 4 | int temp; 5 | 6 | initial begin 7 | //- @temp ref Temp0 8 | repeat (temp) begin 9 | //- @temp defines/binding Temp8 10 | int temp; 11 | //- @temp ref Temp8 12 | assign temp = 1; 13 | end 14 | end 15 | 16 | //- @temp ref Temp0 17 | assign temp = 1; 18 | 19 | endmodule 20 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/struct_declaration_function_argument.sv: -------------------------------------------------------------------------------- 1 | //- @f1 defines/binding _ 2 | //- @x defines/binding X 3 | //- @y defines/binding Y 4 | //- @data defines/binding Data 5 | //- X childof Data 6 | //- Y childof Data 7 | function f1(struct { int x; int y; } data); 8 | //- @sum defines/binding _ 9 | //- @#0data ref Data 10 | //- @#1data ref Data 11 | //- @x ref X 12 | //- @y ref Y 13 | int sum = data.x + data.y; 14 | endfunction 15 | 16 | //- @f2 defines/binding _ 17 | //- @x defines/binding X1 18 | //- @y defines/binding Y1 19 | //- @h defines/binding H1 20 | //- @data defines/binding Data1 21 | //- X1 childof Data1 22 | //- Y1 childof Data1 23 | //- H1 childof X1 24 | function f2(struct { union {int h;} x; int y; } data); 25 | //- @sum defines/binding _ 26 | //- @#0data ref Data1 27 | //- @#1data ref Data1 28 | //- @x ref X1 29 | //- @y ref Y1 30 | //- @h ref H1 31 | int sum = data.x.h + data.y; 32 | endfunction 33 | 34 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/task_scoping.sv: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | package my_pkg; 5 | //- @my_task defines/binding MyTask 6 | //- MyTask.node/kind function 7 | task automatic my_task(input int a, b, output int c); 8 | c = a + b; 9 | endtask 10 | endpackage 11 | 12 | class task_class; 13 | //- @my_task defines/binding ClassTask 14 | //- ClassTask.node/kind function 15 | task my_task(input int a, b, output int c); 16 | c = a + b; 17 | endtask 18 | endclass 19 | 20 | module task_scoping; 21 | initial begin 22 | int result; 23 | 24 | //- @tc_instance defines/binding TcInstance 25 | automatic task_class tc_instance = new(); 26 | //- @tc_instance ref TcInstance 27 | //- @my_task ref/call ClassTask 28 | tc_instance.my_task(1, 2, result); 29 | 30 | //- @my_task ref/call MyTask 31 | my_pkg::my_task(1, 2, result); 32 | end 33 | endmodule 34 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/type_declaration.sv: -------------------------------------------------------------------------------- 1 | //- @S defines/binding S 2 | //- @T defines/binding T 3 | class S #(parameter type T); 4 | //- @T ref T 5 | //- @foo defines/binding _ 6 | T::member_type foo; 7 | 8 | //- @some_type defines/binding SomeType 9 | //- SomeType.node/kind talias 10 | typedef int some_type; 11 | endclass 12 | 13 | //- @S ref S 14 | //- @some_type ref SomeType 15 | //- @bar defines/binding _ 16 | S#(logic)::some_type bar; 17 | 18 | //- @m1 defines/binding _ 19 | module m1(); 20 | //- @S ref S 21 | //- @some_type ref SomeType 22 | //- @bar defines/binding _ 23 | S#(logic)::some_type bar; 24 | endmodule 25 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/testdata/while_loop.sv: -------------------------------------------------------------------------------- 1 | //- @m1 defines/binding _ 2 | module m1; 3 | //- @temp defines/binding Temp0 4 | int temp; 5 | 6 | initial begin 7 | //- @temp ref Temp0 8 | while (temp < 5) begin 9 | //- @temp defines/binding Temp8 10 | int temp; 11 | //- @temp ref Temp8 12 | assign temp = 1; 13 | end 14 | end 15 | 16 | //- @temp ref Temp0 17 | assign temp = 1; 18 | 19 | endmodule 20 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/verilog-extractor-indexing-fact-type.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "verible/verilog/tools/kythe/verilog-extractor-indexing-fact-type.h" 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | #include "absl/strings/str_cat.h" 22 | 23 | namespace verilog { 24 | 25 | std::string IndexingFactTypeEnumToString(IndexingFactType indexing_fact_type) { 26 | switch (indexing_fact_type) { 27 | #define CONSIDER(val) \ 28 | case IndexingFactType::val: \ 29 | return #val; 30 | 31 | #include "verible/verilog/tools/kythe/verilog_extractor_indexing_fact_type_foreach.inc" // IWYU pragma: keep 32 | 33 | #undef CONSIDER 34 | default: 35 | return absl::StrCat("No Associated String: ", 36 | static_cast(indexing_fact_type)); 37 | } 38 | } 39 | 40 | std::ostream &operator<<(std::ostream &stream, const IndexingFactType &e) { 41 | return stream << IndexingFactTypeEnumToString(e); 42 | } 43 | 44 | } // namespace verilog 45 | -------------------------------------------------------------------------------- /verible/verilog/tools/kythe/verilog_extractor_indexing_fact_type_foreach.inc: -------------------------------------------------------------------------------- 1 | // Copyright 2017-2020 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef CONSIDER 16 | #error \ 17 | "Define the CONSIDER macro before including this file " \ 18 | "(and undefine it after)." 19 | #endif // CONSIDER 20 | 21 | #include "verible/verilog/tools/kythe/verilog_extractor_indexing_fact_type_foreach-gen.inc" 22 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/always_comb_blocking.sv: -------------------------------------------------------------------------------- 1 | module always_comb_blocking; 2 | always_comb begin 3 | a <= b; // [Style: combinational-logic] [always-comb-blocking] 4 | end 5 | endmodule 6 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/always_comb_module.sv: -------------------------------------------------------------------------------- 1 | module always_comb_module; 2 | always @* begin 3 | a = b + c; 4 | end 5 | endmodule 6 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/always_ff_non_blocking.sv: -------------------------------------------------------------------------------- 1 | module always_ff_non_blocking; 2 | always_ff @(posedge c) begin 3 | a = b; // [Style: sequential-logic] [always-ff-non-blocking] 4 | end 5 | endmodule 6 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/bad-id-lex.sv: -------------------------------------------------------------------------------- 1 | module 654foo; // lexer should reject invalid identifier 2 | endmodule 3 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/banned_declared_name_patterns.sv: -------------------------------------------------------------------------------- 1 | module banned_declared_name_patterns; 2 | module ILLEGALNAME; 3 | endmodule : ILLEGALNAME 4 | endmodule : banned_declared_name_patterns 5 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/case_missing_default.sv: -------------------------------------------------------------------------------- 1 | // This case statement is missing a default case 2 | function automatic int foo (input bit in); 3 | case (in) 4 | 1: return 0; 5 | endcase 6 | endfunction 7 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/constraint_name_style.sv: -------------------------------------------------------------------------------- 1 | class constraints_check; 2 | logic max; 3 | // This line should trigger the constraint naming convention rule check 4 | constraint MyMax { max >= 64; } 5 | endclass 6 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/defparam_usage.sv: -------------------------------------------------------------------------------- 1 | module defparam_usage; 2 | // defparam shouldn't be used, this should trigger the forbid-defparam rule 3 | defparam p0.MY_PARAM = 1; 4 | endmodule 5 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/dff_name_style.sv: -------------------------------------------------------------------------------- 1 | module dff_name_style (); 2 | always_ff @(posedge clk) begin 3 | data_q <= data; 4 | end 5 | endmodule 6 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/disable_statement.sv: -------------------------------------------------------------------------------- 1 | module disable_statement; 2 | initial begin 3 | fork : foo 4 | begin 5 | #6; 6 | end 7 | join_any 8 | disable foo; 9 | end 10 | endmodule 11 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/endif_comment.sv: -------------------------------------------------------------------------------- 1 | package endif_comment; 2 | `ifdef FOOBAR 3 | localparam int P = 4; 4 | `endif 5 | endpackage 6 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/enum_name_style.sv: -------------------------------------------------------------------------------- 1 | // Enum names should be lower_snake_case and end with '_t' or '_e' 2 | typedef enum { 3 | Idle, Busy 4 | } camelEnum; 5 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/explicit_begin.sv: -------------------------------------------------------------------------------- 1 | module explicit_begin (); 2 | always_comb 3 | a = 1; 4 | endmodule 5 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/explicit_function_lifetime.sv: -------------------------------------------------------------------------------- 1 | function foo(); 2 | endfunction 3 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/explicit_function_parameter_type.sv: -------------------------------------------------------------------------------- 1 | // Expects all function parameters to explicitly define a storage type. 2 | function automatic int foo(bar = 1); 3 | endfunction 4 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/explicit_parameter_storage_type.sv: -------------------------------------------------------------------------------- 1 | // Expect the parameter to explicitly define a storage type 2 | parameter Bar = 1; 3 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/explicit_task_lifetime.sv: -------------------------------------------------------------------------------- 1 | // Missing explicit lifetime declaration 2 | task foo(); 3 | endtask 4 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/explicit_task_parameter_type.sv: -------------------------------------------------------------------------------- 1 | // Expects all task parameters to explicitly define a storage type. 2 | task automatic foo(bar = 1); 3 | endtask 4 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/forbid_consecutive_null_statements.sv: -------------------------------------------------------------------------------- 1 | module forbid_consecutive_null_statements; 2 | ;; // [Style: consecutive-null-statements] [forbid-consecutive-null-statements] 3 | endmodule 4 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/forbid_line_continuations.sv: -------------------------------------------------------------------------------- 1 | module forbid_line_continuations; 2 | 3 | string bad_literal = "Humpty Dumpty sat on a wall. \ 4 | Humpty Dumpty had a great fall."; 5 | 6 | string good_literal = {"Humpty Dumpty sat on a wall.", 7 | "Humpty Dumpty had a great fall."}; 8 | 9 | endmodule 10 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/forbid_negative_array_dim.sv: -------------------------------------------------------------------------------- 1 | module forbid_negative_array_dim (); 2 | reg [-1 : 0] x; 3 | endmodule 4 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/generate-label-module-body.sv: -------------------------------------------------------------------------------- 1 | // verilog_syntax: parse-as-module-body 2 | // verilog_lint: waive legacy-generate-region 3 | generate if (foo) begin 4 | baz bam; 5 | end 6 | endgenerate 7 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/generate_begin_module.sv: -------------------------------------------------------------------------------- 1 | module generate_begin_module; 2 | // verilog_lint: waive legacy-generate-region 3 | generate 4 | begin : gen_block1 5 | always @(posedge clk) begin 6 | foo <= bar; 7 | end 8 | end 9 | endgenerate 10 | endmodule 11 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/generate_label_module.sv: -------------------------------------------------------------------------------- 1 | module generate_label_module; 2 | // verilog_lint: waive legacy-generate-region 3 | generate if (foo) begin 4 | baz bam; 5 | end 6 | endgenerate 7 | endmodule 8 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/generate_label_prefix.sv: -------------------------------------------------------------------------------- 1 | module generate_label_prefix; 2 | // verilog_lint: waive legacy-genvar-declaration 3 | genvar i; 4 | for (i = 0; i < 5; ++i) begin : invalid_label 5 | end 6 | endmodule 7 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/instance-ports-module-body.sv: -------------------------------------------------------------------------------- 1 | // verilog_syntax: parse-as-module-body 2 | wire foo; 3 | bar baz(x, y, z); 4 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/instance_parameters.sv: -------------------------------------------------------------------------------- 1 | module instance_parameters; 2 | bar #(4, 8) baz; 3 | endmodule 4 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/instance_ports.sv: -------------------------------------------------------------------------------- 1 | module instance_ports; 2 | bar baz(x, y); 3 | endmodule 4 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/interface_type_name_style.sv: -------------------------------------------------------------------------------- 1 | // Interface names should be lower_snake_case and end with _if 2 | interface fooBar; 3 | endinterface 4 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/legacy_generate_region.sv: -------------------------------------------------------------------------------- 1 | // verilog_syntax: parse-as-module-body 2 | generate 3 | for (genvar k = 0; k < FooParam; k++) begin : gen_loop 4 | // code 5 | end 6 | endgenerate 7 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/legacy_genvar_declaration.sv: -------------------------------------------------------------------------------- 1 | // verilog_syntax: parse-as-module-body 2 | genvar k; 3 | for (k = 0; k < FooParam; k++) begin : gen_loop 4 | // code 5 | end 6 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/line-length-in-module-body.sv: -------------------------------------------------------------------------------- 1 | // verilog_syntax: parse-as-module-body 2 | // Test the integration of excerpt-parsing with lint-waiving. 3 | // This test case should trigger a line-length violation without a waiver. 4 | assign x = f; 5 | assign lllllllllllllllllll[1111111111] = aaaaaaaaaaa[4444444].ffffffffffffff.gggggggggggg.hhhhhhhhhhh.wwwww[555555].zzzzzzzzzz; 6 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/localparam_name_style.sv: -------------------------------------------------------------------------------- 1 | // Expected localparam name, "Hello_World" to follow UpperCamelCase 2 | // naming convention. 3 | class foo; 4 | localparam int Hello_World = 1; 5 | endclass 6 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/localparam_name_style_all_caps.sv: -------------------------------------------------------------------------------- 1 | // fail, as we expect localparam to follow ALL_CAPS naming convention 2 | class foo; 3 | localparam int HelloWorld = 1; // found Camel case instead 4 | endclass 5 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/localparam_name_style_camel_case.sv: -------------------------------------------------------------------------------- 1 | // fail, as we expect localparam to follow CamelCase naming convention 2 | class foo; 3 | localparam int HELLO_WORLD = 1; // ... found ALL_CAPS instead 4 | endclass 5 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/localparam_type_name_style.sv: -------------------------------------------------------------------------------- 1 | // Expected localparam type name, "Hello_World" to follow lower_snake_case naming convention and end with _t. 2 | class foo; 3 | localparam type Hello_World = logic; 4 | endclass 5 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/long_line.sv: -------------------------------------------------------------------------------- 1 | module long_line; 2 | initial begin 3 | aaaaaaaaaaaaaaaaaaa[12341234] <= cccccccccccccccccccccccc + ddddddddddddddddd * eeeeeeeeeeeeeeeeee; 4 | end 5 | endmodule 6 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/macro_name_style.sv: -------------------------------------------------------------------------------- 1 | // Macro name must be styled with all capital letters, underscores, or digits. 2 | `define Foo 3 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/macro_string_concatenation.sv: -------------------------------------------------------------------------------- 1 | `define FOO(arg) "foo``arg``bar" 2 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/mismatched_labels.sv: -------------------------------------------------------------------------------- 1 | module mismatched_labels( 2 | input clk_i 3 | ); 4 | 5 | always_ff @(posedge clk_i) 6 | begin : foo 7 | end : bar // This mismatched label should cause an error 8 | 9 | endmodule; 10 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/module_begin_block.sv: -------------------------------------------------------------------------------- 1 | module module_begin_block; 2 | wire foobar; 3 | begin // LRM-invalid syntax 4 | wire barfoo; 5 | end 6 | endmodule 7 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/module_filename.sv: -------------------------------------------------------------------------------- 1 | module wrong_module_name; 2 | endmodule 3 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/numeric_format_string_style.sv: -------------------------------------------------------------------------------- 1 | module numeric_format_string_style; 2 | initial begin 3 | // [Style: number-formatting] [numeric-format-string-style] 4 | $display("%h", hex); 5 | $display("%x", hex); 6 | $display("%b", bin); 7 | $display("0x%d", dec); 8 | end 9 | endmodule 10 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/object_creation_name.sv: -------------------------------------------------------------------------------- 1 | module object_creation_name; 2 | initial begin 3 | // This is good 4 | cool_driver_h = cool_driver::type_id::create("cool_driver_h", this); 5 | // This is bad 6 | cool_driver_h = cool_driver::type_id::create("not_cool_driver_h", this); 7 | end 8 | endmodule 9 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/one_module_per_file.sv: -------------------------------------------------------------------------------- 1 | // Each file should have only one module 2 | 3 | module one_module_per_file; 4 | // module name must be the same as file name 5 | endmodule 6 | module second; 7 | endmodule 8 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/package_filename_pkg.sv: -------------------------------------------------------------------------------- 1 | package does_not_match_filename_pkg; 2 | endpackage 3 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/packed_dimensions.sv: -------------------------------------------------------------------------------- 1 | // should be [3:0] according to style 2 | logic [0:3] foo; 3 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/parameter_name_style.sv: -------------------------------------------------------------------------------- 1 | // Expected parameter name, "Hello_World" to follow UpperCamelCase or ALL_CAPS naming convention. 2 | parameter int Hello_World = 1; 3 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/parameter_type_name_style.sv: -------------------------------------------------------------------------------- 1 | // Expected parameter type name, "Hello_World" to follow lower_snake_case naming convention and end with _t. 2 | parameter type Hello_World = logic; 3 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/plusarg_assignment.sv: -------------------------------------------------------------------------------- 1 | class foo; 2 | function bar; 3 | // The use of $test$plusargs() is not allowed. 4 | if ($test$plusargs("baz")) begin 5 | return 1; 6 | end 7 | endfunction 8 | endclass 9 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/port_name_suffix.sv: -------------------------------------------------------------------------------- 1 | // Expects module port 'hello_world' to follow end with _i 2 | module port_name_suffix(input bit hello_world); 3 | endmodule 4 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/positive_meaning_parameter_name.sv: -------------------------------------------------------------------------------- 1 | // Forbid parameter names starting with 'disable', use 'enable' instead. 2 | module positive_meaning_parameter_name #(parameter int DISABLE_FOO = 1); endmodule 3 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/posix_eof.sv: -------------------------------------------------------------------------------- 1 | module posix_eof; endmodule -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/proper_localparam_declaration.sv: -------------------------------------------------------------------------------- 1 | // 'localparams' should only be declared within modules' and classes' definition bodies. 2 | localparam int Foo = 1; 3 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/proper_parameter_declaration.sv: -------------------------------------------------------------------------------- 1 | // 'parameters' should only be declared within packages or parameterized modules/classes. 2 | module proper_parameter_declaration; 3 | parameter int Bar = 1; 4 | endmodule 5 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/psprintf.sv: -------------------------------------------------------------------------------- 1 | task automatic foo; 2 | $psprintf("use $display\n"); 3 | endtask 4 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/shadow_parameter.sv: -------------------------------------------------------------------------------- 1 | class jumbo_packet; // the shadowed instance 2 | const int max_size = 9 * 1024; 3 | byte payload []; 4 | function new( int size ); 5 | payload = new[ size > max_size ? max_size : size ]; 6 | int jumbo_packet = 0; // shadowing the class name, error 7 | endfunction 8 | endclass 9 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/signal_name_style.sv: -------------------------------------------------------------------------------- 1 | // Expects module port 'helloWorld' to follow lower_snake_case naming convention. 2 | module signal_name_style(input bit helloWorld_i); 3 | endmodule 4 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/struct_name_style.sv: -------------------------------------------------------------------------------- 1 | // Struct names should be lower_snake_case and end with '_t' 2 | typedef struct packed{ 3 | int x, y; 4 | } camelStruct; 5 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/suggest_parentheses_example.sv: -------------------------------------------------------------------------------- 1 | module suggest_parentheses_example; 2 | assign foo = condition_a? condition_b? a : b : c; 3 | endmodule 4 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/suspicious_semicolon.sv: -------------------------------------------------------------------------------- 1 | module suspicious_semicolon (); 2 | initial begin 3 | // verilog_lint: waive explicit-begin 4 | if (x); 5 | $display("Hi"); 6 | end 7 | endmodule 8 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/tabs.sv: -------------------------------------------------------------------------------- 1 | module tabs; // tabs bad! 2 | endmodule 3 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/trailing_spaces.sv: -------------------------------------------------------------------------------- 1 | module trailing_spaces; 2 | endmodule 3 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/truncated_numeric_literal.sv: -------------------------------------------------------------------------------- 1 | module truncated_numeric_literal; 2 | assign a = 4'h1F; 3 | endmodule 4 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/typedef_enums.sv: -------------------------------------------------------------------------------- 1 | // All enum declarations should be named with typedef 2 | enum logic [1:0] { 3 | IsIdle, 4 | IsRunning, 5 | IsBlocked 6 | } a_status; 7 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/typedef_structs.sv: -------------------------------------------------------------------------------- 1 | // All structs should be typedef'd 2 | struct { 3 | int x,y; 4 | } point; 5 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/typedef_unions.sv: -------------------------------------------------------------------------------- 1 | // All unions should be typedef'd 2 | union { 3 | bit [8:0] flags; 4 | int val; 5 | } custom; 6 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/undersized_binary_literal.sv: -------------------------------------------------------------------------------- 1 | module undersized_binary_literal; 2 | localparam logic [1:0] Foo = 2'b1; 3 | endmodule 4 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/union_name_style.sv: -------------------------------------------------------------------------------- 1 | // Union names should be lower_snake_case and end with '_t' 2 | typedef union { 3 | int val; 4 | logic [8:0] pointer; 5 | } camelUnion; 6 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/unpacked_dimensions.sv: -------------------------------------------------------------------------------- 1 | // should be [0:3] or [4] according to style 2 | logic foo [3:0]; 3 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/uvm_macro_semicolon.sv: -------------------------------------------------------------------------------- 1 | // UVM macro calls should not be followed by ';' 2 | class c; 3 | function f(); 4 | `uvm_info("msg_id", "message", UVM_LOW); 5 | endfunction 6 | endclass 7 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/uvm_warning.sv: -------------------------------------------------------------------------------- 1 | class foo; 2 | task bar; 3 | `uvm_warning("use uvm_error or uvm_info") 4 | endtask 5 | endclass 6 | -------------------------------------------------------------------------------- /verible/verilog/tools/lint/testdata/void-cast.sv: -------------------------------------------------------------------------------- 1 | class foo; 2 | function void bar(); 3 | void'(randomize()); 4 | endfunction 5 | endclass 6 | -------------------------------------------------------------------------------- /verible/verilog/tools/ls/autoexpand.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef VERILOG_TOOLS_LS_AUTOEXPAND_H 17 | #define VERILOG_TOOLS_LS_AUTOEXPAND_H 18 | 19 | #include 20 | 21 | #include "verible/common/lsp/lsp-protocol.h" 22 | #include "verible/verilog/tools/ls/lsp-parse-buffer.h" 23 | #include "verible/verilog/tools/ls/symbol-table-handler.h" 24 | 25 | // Functions for Emacs' Verilog-Mode-style AUTO expansion. 26 | 27 | namespace verilog { 28 | // Generate AUTO expansion code actions for the given code action params 29 | std::vector GenerateAutoExpandCodeActions( 30 | SymbolTableHandler *symbol_table_handler, const BufferTracker *tracker, 31 | const verible::lsp::CodeActionParams &p); 32 | 33 | } // namespace verilog 34 | #endif // VERILOG_TOOLS_LS_AUTOEXPAND_H 35 | -------------------------------------------------------------------------------- /verible/verilog/tools/ls/hover.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | #ifndef VERILOG_TOOLS_LS_HOVER_H_INCLUDED 17 | #define VERILOG_TOOLS_LS_HOVER_H_INCLUDED 18 | 19 | #include "verible/common/lsp/lsp-protocol.h" 20 | #include "verible/verilog/tools/ls/lsp-parse-buffer.h" 21 | #include "verible/verilog/tools/ls/symbol-table-handler.h" 22 | 23 | namespace verilog { 24 | // Provides hover information for given location 25 | verible::lsp::Hover CreateHoverInformation( 26 | SymbolTableHandler *symbol_table_handler, 27 | const BufferTrackerContainer &tracker, const verible::lsp::HoverParams &p); 28 | } // namespace verilog 29 | 30 | #endif // hover_h_INCLUDED 31 | -------------------------------------------------------------------------------- /verible/verilog/tools/ls/lsp-conversion.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Verible Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "verible/common/lsp/lsp-protocol.h" 16 | #include "verible/common/strings/line-column-map.h" 17 | 18 | // Simple conversion functions between verible data structures and Language 19 | // Server Protocol structs. 20 | 21 | namespace verilog { 22 | 23 | // Convert a Verible internal source code range to a language server protocol 24 | // range. 25 | inline verible::lsp::Range RangeFromLineColumn( 26 | const verible::LineColumnRange &range) { 27 | return {.start = {.line = range.start.line, .character = range.start.column}, 28 | .end = {.line = range.end.line, .character = range.end.column}}; 29 | } 30 | } // namespace verilog 31 | -------------------------------------------------------------------------------- /verible/verilog/tools/ls/vscode/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.vsix 3 | package-lock.json 4 | README.html 5 | dist/ 6 | -------------------------------------------------------------------------------- /verible/verilog/tools/ls/vscode/images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chipsalliance/verible/d42da6b978d480222da00fb45ea5f84ec1158ab5/verible/verilog/tools/ls/vscode/images/icon.png -------------------------------------------------------------------------------- /verible/verilog/tools/ls/vscode/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "ES2020", 5 | "lib": [ 6 | "ES2020" 7 | ], 8 | "sourceMap": true, 9 | "rootDir": "src", 10 | "strict": true, 11 | "noImplicitReturns": true, 12 | "noFallthroughCasesInSwitch": true, 13 | "noUnusedParameters": true 14 | }, 15 | "exclude": [ 16 | "node_modules" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /verible/verilog/tools/obfuscator/BUILD: -------------------------------------------------------------------------------- 1 | """Tool for obfuscating verilog 2 | """ 3 | 4 | load("//bazel:sh_test_with_runfiles_lib.bzl", "sh_test_with_runfiles_lib") 5 | load("//bazel:variables.bzl", "STATIC_EXECUTABLES_FEATURE") 6 | 7 | package( 8 | default_applicable_licenses = ["//:license"], 9 | default_visibility = ["//visibility:private"], 10 | features = ["layering_check"], 11 | ) 12 | 13 | cc_binary( 14 | name = "verible-verilog-obfuscate", 15 | srcs = ["verilog-obfuscate.cc"], 16 | features = STATIC_EXECUTABLES_FEATURE, 17 | visibility = ["//visibility:public"], 18 | deps = [ 19 | "//verible/common/strings:obfuscator", 20 | "//verible/common/util:file-util", 21 | "//verible/common/util:init-command-line", 22 | "//verible/verilog/analysis:extractors", 23 | "//verible/verilog/preprocessor:verilog-preprocess", 24 | "//verible/verilog/transform:obfuscate", 25 | "@abseil-cpp//absl/flags:flag", 26 | "@abseil-cpp//absl/status", 27 | "@abseil-cpp//absl/status:statusor", 28 | "@abseil-cpp//absl/strings", 29 | ], 30 | ) 31 | 32 | sh_test_with_runfiles_lib( 33 | name = "obfuscate_test", 34 | size = "small", 35 | srcs = ["obfuscate_test.sh"], 36 | args = [ 37 | "$(location :verible-verilog-obfuscate)", 38 | "$(location //verible/verilog/tools/diff:verible-verilog-diff)", 39 | ], 40 | data = [ 41 | ":verible-verilog-obfuscate", 42 | "//verible/verilog/tools/diff:verible-verilog-diff", 43 | ], 44 | ) 45 | -------------------------------------------------------------------------------- /verible/verilog/tools/project/BUILD: -------------------------------------------------------------------------------- 1 | """This package contains multi-tool for working with SystemVerilog projects. 2 | """ 3 | 4 | load("//bazel:sh_test_with_runfiles_lib.bzl", "sh_test_with_runfiles_lib") 5 | load("//bazel:variables.bzl", "STATIC_EXECUTABLES_FEATURE") 6 | 7 | package( 8 | default_applicable_licenses = ["//:license"], 9 | default_visibility = ["//visibility:private"], 10 | features = ["layering_check"], 11 | ) 12 | 13 | cc_binary( 14 | name = "verible-verilog-project", 15 | srcs = ["project-tool.cc"], 16 | features = STATIC_EXECUTABLES_FEATURE, 17 | visibility = ["//:__subpackages__"], 18 | deps = [ 19 | "//verible/common/util:init-command-line", 20 | "//verible/common/util:logging", 21 | "//verible/common/util:status-macros", 22 | "//verible/common/util:subcommand", 23 | "//verible/verilog/analysis:dependencies", 24 | "//verible/verilog/analysis:symbol-table", 25 | "//verible/verilog/analysis:verilog-filelist", 26 | "//verible/verilog/analysis:verilog-project", 27 | "@abseil-cpp//absl/flags:flag", 28 | "@abseil-cpp//absl/flags:usage", 29 | "@abseil-cpp//absl/status", 30 | "@abseil-cpp//absl/strings", 31 | ], 32 | ) 33 | 34 | sh_test_with_runfiles_lib( 35 | name = "project-tool_test", 36 | size = "small", 37 | srcs = ["project_tool_test.sh"], 38 | args = ["$(location :verible-verilog-project)"], 39 | data = [":verible-verilog-project"], 40 | deps = [], 41 | ) 42 | -------------------------------------------------------------------------------- /verible/verilog/tools/syntax/export_json_examples/README.md: -------------------------------------------------------------------------------- 1 | Some Python examples using the json export of verible-verilog-syntax 2 | to do interesting things. 3 | 4 | The BUILD.example might be a starting point in case you want to 5 | use this in a bazel project. 6 | 7 | Not officially supported. 8 | -------------------------------------------------------------------------------- /vnames.json: -------------------------------------------------------------------------------- 1 | [] --------------------------------------------------------------------------------