CIRCT  19.0.0git
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 
20 namespace llvm {
21 class SourceMgr;
22 } // namespace llvm
23 
24 namespace mlir {
25 class LocationAttr;
26 class TimingScope;
27 } // namespace mlir
28 
29 namespace circt {
30 
31 /// Options that control how Verilog input files are parsed and processed.
32 ///
33 /// See `slang::driver::Driver::Options` for inspiration. Also check out
34 /// `Driver::addStandardArgs()` for some inspiration on how to expose these on
35 /// the command line.
37  /// Limit importing to linting or parsing only.
38  enum class Mode {
39  /// Only lint the input, without elaboration and lowering to CIRCT IR.
40  OnlyLint,
41  /// Only parse and elaborate the input, without mapping to CIRCT IR.
42  OnlyParse,
43  /// Perform a full import and mapping to CIRCT IR.
44  Full
45  };
47 
48  //===--------------------------------------------------------------------===//
49  // Include paths
50  //===--------------------------------------------------------------------===//
51 
52  /// A list of include directories in which to search for files.
53  std::vector<std::string> includeDirs;
54 
55  /// A list of system include directories in which to search for files.
56  std::vector<std::string> includeSystemDirs;
57 
58  /// A list of library directories in which to search for missing modules.
59  std::vector<std::string> libDirs;
60 
61  /// A list of extensions that will be used to search for library files.
62  std::vector<std::string> libExts;
63 
64  /// A list of extensions that will be used to exclude files.
65  std::vector<std::string> excludeExts;
66 
67  /// A list of preprocessor directives to be ignored.
68  std::vector<std::string> ignoreDirectives;
69 
70  //===--------------------------------------------------------------------===//
71  // Preprocessing
72  //===--------------------------------------------------------------------===//
73 
74  /// The maximum depth of included files before an error is issued.
75  std::optional<uint32_t> maxIncludeDepth;
76 
77  /// A list of macros that should be defined in each compilation unit.
78  std::vector<std::string> defines;
79 
80  /// A list of macros that should be undefined in each compilation unit.
81  std::vector<std::string> undefines;
82 
83  /// If true, library files will inherit macro definitions from primary source
84  /// files.
85  std::optional<bool> librariesInheritMacros;
86 
87  //===--------------------------------------------------------------------===//
88  // Compilation
89  //===--------------------------------------------------------------------===//
90 
91  /// A string that indicates the default time scale to use for any design
92  /// elements that don't specify one explicitly.
93  std::optional<std::string> timeScale;
94 
95  /// If true, allow various to be referenced before they are declared.
96  std::optional<bool> allowUseBeforeDeclare;
97 
98  /// If true, ignore errors about unknown modules.
99  std::optional<bool> ignoreUnknownModules;
100 
101  /// If non-empty, specifies the list of modules that should serve as the top
102  /// modules in the design. If empty, this will be automatically determined
103  /// based on which modules are unreferenced elsewhere.
104  std::vector<std::string> topModules;
105 
106  /// A list of top-level module parameters to override, of the form
107  /// `<name>=<value>`.
108  std::vector<std::string> paramOverrides;
109 
110  //===--------------------------------------------------------------------===//
111  // Diagnostics Control
112  //===--------------------------------------------------------------------===//
113 
114  /// The maximum number of errors to print before giving up.
115  std::optional<uint32_t> errorLimit;
116 
117  /// A list of warning options that will be passed to the DiagnosticEngine.
118  std::vector<std::string> warningOptions;
119 
120  /// A list of paths in which to suppress warnings.
121  std::vector<std::string> suppressWarningsPaths;
122 
123  //===--------------------------------------------------------------------===//
124  // File lists
125  //===--------------------------------------------------------------------===//
126 
127  /// If set to true, all source files will be treated as part of a single
128  /// compilation unit, meaning all of their text will be merged together.
129  std::optional<bool> singleUnit;
130 
131  /// A list of library files to include in the compilation.
132  std::vector<std::string> libraryFiles;
133 };
134 
135 /// Parse files in a source manager as Verilog source code and populate the
136 /// given MLIR `module` with corresponding ops.
137 mlir::LogicalResult
138 importVerilog(llvm::SourceMgr &sourceMgr, mlir::MLIRContext *context,
139  mlir::TimingScope &ts, mlir::ModuleOp module,
140  const ImportVerilogOptions *options = nullptr);
141 
142 /// Run the files in a source manager through Slang's Verilog preprocessor and
143 /// emit the result to the given output stream.
144 mlir::LogicalResult
145 preprocessVerilog(llvm::SourceMgr &sourceMgr, mlir::MLIRContext *context,
146  mlir::TimingScope &ts, llvm::raw_ostream &os,
147  const ImportVerilogOptions *options = nullptr);
148 
149 /// Register the `import-verilog` MLIR translation.
151 
152 /// Return a human-readable string describing the slang frontend version linked
153 /// into CIRCT.
154 std::string getSlangVersion();
155 
156 } // namespace circt
157 
158 #endif // CIRCT_CONVERSION_IMPORTVERILOG_H
This file defines an intermediate representation for circuits acting as an abstraction for constraint...
Definition: DebugAnalysis.h:21
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.
Definition: ImportVerilog.h:36
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.
Definition: ImportVerilog.h:96
std::optional< uint32_t > maxIncludeDepth
The maximum depth of included files before an error is issued.
Definition: ImportVerilog.h:75
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.
Definition: ImportVerilog.h:68
std::vector< std::string > libExts
A list of extensions that will be used to search for library files.
Definition: ImportVerilog.h:62
std::optional< bool > librariesInheritMacros
If true, library files will inherit macro definitions from primary source files.
Definition: ImportVerilog.h:85
std::vector< std::string > defines
A list of macros that should be defined in each compilation unit.
Definition: ImportVerilog.h:78
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.
Definition: ImportVerilog.h:59
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.
Definition: ImportVerilog.h:56
std::vector< std::string > includeDirs
A list of include directories in which to search for files.
Definition: ImportVerilog.h:53
Mode
Limit importing to linting or parsing only.
Definition: ImportVerilog.h:38
@ 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.
Definition: ImportVerilog.h:81
std::vector< std::string > excludeExts
A list of extensions that will be used to exclude files.
Definition: ImportVerilog.h:65
std::vector< std::string > paramOverrides
A list of top-level module parameters to override, of the form <name>=<value>.
std::optional< bool > ignoreUnknownModules
If true, ignore errors about unknown modules.
Definition: ImportVerilog.h:99
std::optional< std::string > timeScale
A string that indicates the default time scale to use for any design elements that don't specify one ...
Definition: ImportVerilog.h:93
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.