CIRCT 21.0.0git
Loading...
Searching...
No Matches
ImportVerilog.h
Go to the documentation of this file.
1//===- ImportVerilog.h - Slang Verilog frontend integration ---------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Defines the interface to the Verilog frontend.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef CIRCT_CONVERSION_IMPORTVERILOG_H
14#define CIRCT_CONVERSION_IMPORTVERILOG_H
15
16#include "circt/Support/LLVM.h"
17#include <optional>
18#include <string>
19#include <vector>
20
21namespace llvm {
22class SourceMgr;
23} // namespace llvm
24
25namespace mlir {
26class LocationAttr;
27class TimingScope;
28} // namespace mlir
29
30namespace circt {
31
32/// Options that control how Verilog input files are parsed and processed.
33///
34/// See `slang::driver::Driver::Options` for inspiration. Also check out
35/// `Driver::addStandardArgs()` for some inspiration on how to expose these on
36/// the command line.
38 /// Limit importing to linting or parsing only.
39 enum class Mode {
40 /// Only lint the input, without elaboration and lowering to CIRCT IR.
42 /// Only parse and elaborate the input, without mapping to CIRCT IR.
44 /// Perform a full import and mapping to CIRCT IR.
45 Full
46 };
48
49 /// Generate debug information in the form of debug dialect ops in the IR.
50 bool debugInfo = false;
51
52 /// Interpret `always @(*)` as `always_comb`.
54
55 //===--------------------------------------------------------------------===//
56 // Include paths
57 //===--------------------------------------------------------------------===//
58
59 /// A list of include directories in which to search for files.
60 std::vector<std::string> includeDirs;
61
62 /// A list of system include directories in which to search for files.
63 std::vector<std::string> includeSystemDirs;
64
65 /// A list of library directories in which to search for missing modules.
66 std::vector<std::string> libDirs;
67
68 /// A list of extensions that will be used to search for library files.
69 std::vector<std::string> libExts;
70
71 /// A list of extensions that will be used to exclude files.
72 std::vector<std::string> excludeExts;
73
74 /// A list of preprocessor directives to be ignored.
75 std::vector<std::string> ignoreDirectives;
76
77 //===--------------------------------------------------------------------===//
78 // Preprocessing
79 //===--------------------------------------------------------------------===//
80
81 /// The maximum depth of included files before an error is issued.
82 std::optional<uint32_t> maxIncludeDepth;
83
84 /// A list of macros that should be defined in each compilation unit.
85 std::vector<std::string> defines;
86
87 /// A list of macros that should be undefined in each compilation unit.
88 std::vector<std::string> undefines;
89
90 /// If true, library files will inherit macro definitions from primary source
91 /// files.
92 std::optional<bool> librariesInheritMacros;
93
94 //===--------------------------------------------------------------------===//
95 // Compilation
96 //===--------------------------------------------------------------------===//
97
98 /// A string that indicates the default time scale to use for any design
99 /// elements that don't specify one explicitly.
100 std::optional<std::string> timeScale;
101
102 /// If true, allow various to be referenced before they are declared.
103 std::optional<bool> allowUseBeforeDeclare;
104
105 /// If true, ignore errors about unknown modules.
106 std::optional<bool> ignoreUnknownModules;
107
108 /// If non-empty, specifies the list of modules that should serve as the top
109 /// modules in the design. If empty, this will be automatically determined
110 /// based on which modules are unreferenced elsewhere.
111 std::vector<std::string> topModules;
112
113 /// A list of top-level module parameters to override, of the form
114 /// `<name>=<value>`.
115 std::vector<std::string> paramOverrides;
116
117 //===--------------------------------------------------------------------===//
118 // Diagnostics Control
119 //===--------------------------------------------------------------------===//
120
121 /// The maximum number of errors to print before giving up.
122 std::optional<uint32_t> errorLimit;
123
124 /// A list of warning options that will be passed to the DiagnosticEngine.
125 std::vector<std::string> warningOptions;
126
127 /// A list of paths in which to suppress warnings.
128 std::vector<std::string> suppressWarningsPaths;
129
130 //===--------------------------------------------------------------------===//
131 // File lists
132 //===--------------------------------------------------------------------===//
133
134 /// If set to true, all source files will be treated as part of a single
135 /// compilation unit, meaning all of their text will be merged together.
136 std::optional<bool> singleUnit;
137
138 /// A list of library files to include in the compilation.
139 std::vector<std::string> libraryFiles;
140};
141
142/// Parse files in a source manager as Verilog source code and populate the
143/// given MLIR `module` with corresponding ops.
144mlir::LogicalResult
145importVerilog(llvm::SourceMgr &sourceMgr, mlir::MLIRContext *context,
146 mlir::TimingScope &ts, mlir::ModuleOp module,
147 const ImportVerilogOptions *options = nullptr);
148
149/// Run the files in a source manager through Slang's Verilog preprocessor and
150/// emit the result to the given output stream.
151mlir::LogicalResult
152preprocessVerilog(llvm::SourceMgr &sourceMgr, mlir::MLIRContext *context,
153 mlir::TimingScope &ts, llvm::raw_ostream &os,
154 const ImportVerilogOptions *options = nullptr);
155
156/// Register the `import-verilog` MLIR translation.
158
159/// Return a human-readable string describing the slang frontend version linked
160/// into CIRCT.
161std::string getSlangVersion();
162
163} // namespace circt
164
165#endif // CIRCT_CONVERSION_IMPORTVERILOG_H
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
std::string getSlangVersion()
Return a human-readable string describing the slang frontend version linked into CIRCT.
mlir::LogicalResult importVerilog(llvm::SourceMgr &sourceMgr, mlir::MLIRContext *context, mlir::TimingScope &ts, mlir::ModuleOp module, const ImportVerilogOptions *options=nullptr)
Parse files in a source manager as Verilog source code and populate the given MLIR module with corres...
mlir::LogicalResult preprocessVerilog(llvm::SourceMgr &sourceMgr, mlir::MLIRContext *context, mlir::TimingScope &ts, llvm::raw_ostream &os, const ImportVerilogOptions *options=nullptr)
Run the files in a source manager through Slang's Verilog preprocessor and emit the result to the giv...
void registerFromVerilogTranslation()
Register the import-verilog MLIR translation.
Options that control how Verilog input files are parsed and processed.
std::vector< std::string > libraryFiles
A list of library files to include in the compilation.
std::optional< bool > allowUseBeforeDeclare
If true, allow various to be referenced before they are declared.
std::optional< uint32_t > maxIncludeDepth
The maximum depth of included files before an error is issued.
std::vector< std::string > warningOptions
A list of warning options that will be passed to the DiagnosticEngine.
std::vector< std::string > ignoreDirectives
A list of preprocessor directives to be ignored.
std::vector< std::string > libExts
A list of extensions that will be used to search for library files.
std::optional< bool > librariesInheritMacros
If true, library files will inherit macro definitions from primary source files.
std::vector< std::string > defines
A list of macros that should be defined in each compilation unit.
bool lowerAlwaysAtStarAsComb
Interpret always @(*) as always_comb.
std::optional< bool > singleUnit
If set to true, all source files will be treated as part of a single compilation unit,...
std::vector< std::string > libDirs
A list of library directories in which to search for missing modules.
std::vector< std::string > suppressWarningsPaths
A list of paths in which to suppress warnings.
std::vector< std::string > includeSystemDirs
A list of system include directories in which to search for files.
std::vector< std::string > includeDirs
A list of include directories in which to search for files.
Mode
Limit importing to linting or parsing only.
@ OnlyLint
Only lint the input, without elaboration and lowering to CIRCT IR.
@ OnlyParse
Only parse and elaborate the input, without mapping to CIRCT IR.
@ Full
Perform a full import and mapping to CIRCT IR.
std::vector< std::string > undefines
A list of macros that should be undefined in each compilation unit.
std::vector< std::string > excludeExts
A list of extensions that will be used to exclude files.
std::vector< std::string > paramOverrides
A list of top-level module parameters to override, of the form <name>=<value>.
bool debugInfo
Generate debug information in the form of debug dialect ops in the IR.
std::optional< bool > ignoreUnknownModules
If true, ignore errors about unknown modules.
std::optional< std::string > timeScale
A string that indicates the default time scale to use for any design elements that don't specify one ...
std::vector< std::string > topModules
If non-empty, specifies the list of modules that should serve as the top modules in the design.
std::optional< uint32_t > errorLimit
The maximum number of errors to print before giving up.