CIRCT  19.0.0git
FIRParser.h
Go to the documentation of this file.
1 //===- FIRParser.h - .fir to FIRRTL dialect parser --------------*- C++ -*-===//
2 //
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Defines the interface to the .fir file parser.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef CIRCT_DIALECT_FIRRTL_FIRPARSER_H
15 #define CIRCT_DIALECT_FIRRTL_FIRPARSER_H
16 
17 #include "circt/Support/LLVM.h"
18 #include <string>
19 #include <vector>
20 
21 namespace llvm {
22 class SourceMgr;
23 } // namespace llvm
24 
25 namespace mlir {
26 class LocationAttr;
27 class TimingScope;
28 } // namespace mlir
29 
30 namespace circt {
31 namespace firrtl {
32 
34  /// Specify how @info locators should be handled.
35  enum class InfoLocHandling {
36  /// If this is set to true, the @info locators are ignored, and the
37  /// locations are set to the location in the .fir file.
38  IgnoreInfo,
39  /// Prefer @info locators, fallback to .fir locations.
40  PreferInfo,
41  /// Attach both @info locators (when present) and .fir locations.
42  FusedInfo
43  };
44 
46 
47  /// The number of annotation files that were specified on the command line.
48  /// This, along with numOMIRFiles provides structure to the buffers in the
49  /// source manager.
51  bool scalarizePublicModules = false;
53  bool scalarizeExtModules = false;
54  std::vector<std::string> enableLayers;
55  std::vector<std::string> disableLayers;
56 };
57 
59  mlir::MLIRContext *context,
60  mlir::TimingScope &ts,
61  FIRParserOptions options = {});
62 
63 // Decode a source locator string `spelling`, returning a pair indicating that
64 // the `spelling` was correct and an optional location attribute. The
65 // `skipParsing` option can be used to short-circuit parsing and just do
66 // validation of the `spelling`. This require both an Identifier and a
67 // FileLineColLoc to use for caching purposes and context as the cache may be
68 // updated with a new identifier.
69 //
70 // This utility exists because source locators can exist outside of normal
71 // "parsing". E.g., these can show up in annotations or in Object Model 2.0
72 // JSON.
73 //
74 // TODO: This API is super wacky and should be streamlined to hide the
75 // caching.
76 std::pair<bool, std::optional<mlir::LocationAttr>>
77 maybeStringToLocation(llvm::StringRef spelling, bool skipParsing,
78  mlir::StringAttr &locatorFilenameCache,
79  FileLineColLoc &fileLineColLocCache,
80  MLIRContext *context);
81 
83 
84 /// The FIRRTL specification version.
85 struct FIRVersion {
86  constexpr FIRVersion(uint16_t major, uint16_t minor, uint16_t patch)
87  : major{major}, minor{minor}, patch{patch} {}
88 
89  explicit constexpr operator uint64_t() const {
90  return uint64_t(major) << 32 | uint64_t(minor) << 16 | uint64_t(patch);
91  }
92 
93  constexpr bool operator<(FIRVersion rhs) const {
94  return uint64_t(*this) < uint64_t(rhs);
95  }
96 
97  constexpr bool operator>(FIRVersion rhs) const {
98  return uint64_t(*this) > uint64_t(rhs);
99  }
100 
101  constexpr bool operator<=(FIRVersion rhs) const {
102  return uint64_t(*this) <= uint64_t(rhs);
103  }
104 
105  constexpr bool operator>=(FIRVersion rhs) const {
106  return uint64_t(*this) >= uint64_t(rhs);
107  }
108 
109  uint16_t major;
110  uint16_t minor;
111  uint16_t patch;
112 };
113 
114 constexpr FIRVersion minimumFIRVersion(2, 0, 0);
115 constexpr FIRVersion nextFIRVersion(3, 3, 0);
116 constexpr FIRVersion exportFIRVersion(4, 0, 0);
117 
118 template <typename T>
119 T &operator<<(T &os, FIRVersion version) {
120  return os << version.major << "." << version.minor << "." << version.patch;
121 }
122 
123 } // namespace firrtl
124 } // namespace circt
125 
126 #endif // CIRCT_DIALECT_FIRRTL_FIRPARSER_H
void registerFromFIRFileTranslation()
Definition: FIRParser.cpp:5655
constexpr FIRVersion exportFIRVersion(4, 0, 0)
std::pair< bool, std::optional< mlir::LocationAttr > > maybeStringToLocation(llvm::StringRef spelling, bool skipParsing, mlir::StringAttr &locatorFilenameCache, FileLineColLoc &fileLineColLocCache, MLIRContext *context)
mlir::OwningOpRef< mlir::ModuleOp > importFIRFile(llvm::SourceMgr &sourceMgr, mlir::MLIRContext *context, mlir::TimingScope &ts, FIRParserOptions options={})
T & operator<<(T &os, FIRVersion version)
Definition: FIRParser.h:119
constexpr FIRVersion minimumFIRVersion(2, 0, 0)
constexpr FIRVersion nextFIRVersion(3, 3, 0)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
unsigned numAnnotationFiles
The number of annotation files that were specified on the command line.
Definition: FIRParser.h:50
InfoLocHandling infoLocatorHandling
Definition: FIRParser.h:45
InfoLocHandling
Specify how @info locators should be handled.
Definition: FIRParser.h:35
@ PreferInfo
Prefer @info locators, fallback to .fir locations.
@ FusedInfo
Attach both @info locators (when present) and .fir locations.
@ IgnoreInfo
If this is set to true, the @info locators are ignored, and the locations are set to the location in ...
std::vector< std::string > enableLayers
Definition: FIRParser.h:54
std::vector< std::string > disableLayers
Definition: FIRParser.h:55
The FIRRTL specification version.
Definition: FIRParser.h:85
constexpr bool operator<(FIRVersion rhs) const
Definition: FIRParser.h:93
constexpr bool operator>(FIRVersion rhs) const
Definition: FIRParser.h:97
constexpr bool operator>=(FIRVersion rhs) const
Definition: FIRParser.h:105
constexpr FIRVersion(uint16_t major, uint16_t minor, uint16_t patch)
Definition: FIRParser.h:86
constexpr bool operator<=(FIRVersion rhs) const
Definition: FIRParser.h:101