CIRCT 22.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 "mlir/Pass/PassOptions.h"
18#include "llvm/Support/CommandLine.h"
19#include <cstdint>
20#include <optional>
21#include <string>
22#include <vector>
23
24namespace llvm {
25class SourceMgr;
26} // namespace llvm
27
28namespace mlir {
29class LocationAttr;
30class PassManager;
31class TimingScope;
32} // namespace mlir
33
34namespace circt {
35
36/// Options that control how Verilog input files are parsed and processed.
37///
38/// See `slang::driver::Driver::Options` for inspiration. Also check out
39/// `Driver::addStandardArgs()` for some inspiration on how to expose these on
40/// the command line.
42 /// Limit importing to linting or parsing only.
43 enum class Mode {
44 /// Only lint the input, without elaboration and lowering to CIRCT IR.
46 /// Only parse and elaborate the input, without mapping to CIRCT IR.
48 /// Perform a full import and mapping to CIRCT IR.
49 Full
50 };
52
53 /// Generate debug information in the form of debug dialect ops in the IR.
54 bool debugInfo = false;
55
56 /// Interpret `always @(*)` as `always_comb`.
58
59 //===--------------------------------------------------------------------===//
60 // Include paths
61 //===--------------------------------------------------------------------===//
62
63 /// A list of include directories in which to search for files.
64 std::vector<std::string> includeDirs;
65
66 /// A list of system include directories in which to search for files.
67 std::vector<std::string> includeSystemDirs;
68
69 /// A list of library directories in which to search for missing modules.
70 std::vector<std::string> libDirs;
71
72 /// A list of extensions that will be used to search for library files.
73 std::vector<std::string> libExts;
74
75 /// A list of extensions that will be used to exclude files.
76 std::vector<std::string> excludeExts;
77
78 /// A list of preprocessor directives to be ignored.
79 std::vector<std::string> ignoreDirectives;
80
81 //===--------------------------------------------------------------------===//
82 // Preprocessing
83 //===--------------------------------------------------------------------===//
84
85 /// The maximum depth of included files before an error is issued.
86 std::optional<uint32_t> maxIncludeDepth;
87
88 /// A list of macros that should be defined in each compilation unit.
89 std::vector<std::string> defines;
90
91 /// A list of macros that should be undefined in each compilation unit.
92 std::vector<std::string> undefines;
93
94 /// If true, library files will inherit macro definitions from primary source
95 /// files.
96 std::optional<bool> librariesInheritMacros;
97
98 //===--------------------------------------------------------------------===//
99 // Compilation
100 //===--------------------------------------------------------------------===//
101
102 /// A string that indicates the default time scale to use for any design
103 /// elements that don't specify one explicitly.
104 std::optional<std::string> timeScale;
105
106 /// If true, allow various to be referenced before they are declared.
107 std::optional<bool> allowUseBeforeDeclare;
108
109 /// If true, ignore errors about unknown modules.
110 std::optional<bool> ignoreUnknownModules;
111
112 /// If non-empty, specifies the list of modules that should serve as the top
113 /// modules in the design. If empty, this will be automatically determined
114 /// based on which modules are unreferenced elsewhere.
115 std::vector<std::string> topModules;
116
117 /// A list of top-level module parameters to override, of the form
118 /// `<name>=<value>`.
119 std::vector<std::string> paramOverrides;
120
121 //===--------------------------------------------------------------------===//
122 // Diagnostics Control
123 //===--------------------------------------------------------------------===//
124
125 /// The maximum number of errors to print before giving up.
126 std::optional<uint32_t> errorLimit;
127
128 /// A list of warning options that will be passed to the DiagnosticEngine.
129 std::vector<std::string> warningOptions;
130
131 /// A list of paths in which to suppress warnings.
132 std::vector<std::string> suppressWarningsPaths;
133
134 //===--------------------------------------------------------------------===//
135 // File lists
136 //===--------------------------------------------------------------------===//
137
138 /// If set to true, all source files will be treated as part of a single
139 /// compilation unit, meaning all of their text will be merged together.
140 std::optional<bool> singleUnit;
141
142 /// A list of library files to include in the compilation.
143 std::vector<std::string> libraryFiles;
144
145 /// A list of command files to process for compilation.
146 std::vector<std::string> commandFiles;
147};
148
149/// Parse files in a source manager as Verilog source code and populate the
150/// given MLIR `module` with corresponding ops.
151mlir::LogicalResult
152importVerilog(llvm::SourceMgr &sourceMgr, mlir::MLIRContext *context,
153 mlir::TimingScope &ts, mlir::ModuleOp module,
154 const ImportVerilogOptions *options = nullptr);
155
156/// Optimize and simplify the Moore dialect IR.
157void populateVerilogToMoorePipeline(mlir::OpPassManager &pm);
158
159/// Convert Moore dialect IR into core dialect IR
160void populateMooreToCorePipeline(mlir::OpPassManager &pm);
161
162/// Convert LLHD dialect IR into core dialect IR
164 : mlir::PassPipelineOptions<LlhdToCorePipelineOptions> {
165 Option<bool> detectMemories{
166 *this, "detect-memories",
167 llvm::cl::desc("Detect memories and lower them to `seq.firmem`"),
168 llvm::cl::init(true)};
169};
170void populateLlhdToCorePipeline(mlir::OpPassManager &pm,
171 const LlhdToCorePipelineOptions &options);
172
173/// Run the files in a source manager through Slang's Verilog preprocessor and
174/// emit the result to the given output stream.
175mlir::LogicalResult
176preprocessVerilog(llvm::SourceMgr &sourceMgr, mlir::MLIRContext *context,
177 mlir::TimingScope &ts, llvm::raw_ostream &os,
178 const ImportVerilogOptions *options = nullptr);
179
180/// Register the `import-verilog` MLIR translation.
182
183/// Return a human-readable string describing the slang frontend version linked
184/// into CIRCT.
185std::string getSlangVersion();
186
187} // namespace circt
188
189#endif // CIRCT_CONVERSION_IMPORTVERILOG_H
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
void populateVerilogToMoorePipeline(mlir::OpPassManager &pm)
Optimize and simplify the Moore dialect IR.
void populateMooreToCorePipeline(mlir::OpPassManager &pm)
Convert Moore dialect IR into core dialect IR.
void populateLlhdToCorePipeline(mlir::OpPassManager &pm, const LlhdToCorePipelineOptions &options)
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 > commandFiles
A list of command files to process for compilation.
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.
Convert LLHD dialect IR into core dialect IR.