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 
19 namespace llvm {
20 class SourceMgr;
21 } // namespace llvm
22 
23 namespace mlir {
24 class LocationAttr;
25 class TimingScope;
26 } // namespace mlir
27 
28 namespace circt {
29 namespace firrtl {
30 
32  /// Specify how @info locators should be handled.
33  enum class InfoLocHandling {
34  /// If this is set to true, the @info locators are ignored, and the
35  /// locations are set to the location in the .fir file.
36  IgnoreInfo,
37  /// Prefer @info locators, fallback to .fir locations.
38  PreferInfo,
39  /// Attach both @info locators (when present) and .fir locations.
40  FusedInfo
41  };
42 
44 
45  /// The number of annotation files that were specified on the command line.
46  /// This, along with numOMIRFiles provides structure to the buffers in the
47  /// source manager.
49  bool scalarizePublicModules = false;
51  bool scalarizeExtModules = false;
52 };
53 
55  mlir::MLIRContext *context,
56  mlir::TimingScope &ts,
57  FIRParserOptions options = {});
58 
59 // Decode a source locator string `spelling`, returning a pair indicating that
60 // the `spelling` was correct and an optional location attribute. The
61 // `skipParsing` option can be used to short-circuit parsing and just do
62 // validation of the `spelling`. This require both an Identifier and a
63 // FileLineColLoc to use for caching purposes and context as the cache may be
64 // updated with a new identifier.
65 //
66 // This utility exists because source locators can exist outside of normal
67 // "parsing". E.g., these can show up in annotations or in Object Model 2.0
68 // JSON.
69 //
70 // TODO: This API is super wacky and should be streamlined to hide the
71 // caching.
72 std::pair<bool, std::optional<mlir::LocationAttr>>
73 maybeStringToLocation(llvm::StringRef spelling, bool skipParsing,
74  mlir::StringAttr &locatorFilenameCache,
75  FileLineColLoc &fileLineColLocCache,
76  MLIRContext *context);
77 
79 
80 /// The FIRRTL specification version.
81 struct FIRVersion {
82  constexpr FIRVersion(uint16_t major, uint16_t minor, uint16_t patch)
83  : major{major}, minor{minor}, patch{patch} {}
84 
85  explicit constexpr operator uint64_t() const {
86  return uint64_t(major) << 32 | uint64_t(minor) << 16 | uint64_t(patch);
87  }
88 
89  constexpr bool operator<(FIRVersion rhs) const {
90  return uint64_t(*this) < uint64_t(rhs);
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  uint16_t major;
106  uint16_t minor;
107  uint16_t patch;
108 };
109 
110 constexpr FIRVersion minimumFIRVersion(0, 2, 0);
111 constexpr FIRVersion nextFIRVersion(3, 3, 0);
112 constexpr FIRVersion exportFIRVersion(4, 0, 0);
113 constexpr FIRVersion defaultFIRVersion(1, 0, 0);
114 
115 template <typename T>
116 T &operator<<(T &os, FIRVersion version) {
117  return os << version.major << "." << version.minor << "." << version.patch;
118 }
119 
120 } // namespace firrtl
121 } // namespace circt
122 
123 #endif // CIRCT_DIALECT_FIRRTL_FIRPARSER_H
constexpr FIRVersion defaultFIRVersion(1, 0, 0)
void registerFromFIRFileTranslation()
Definition: FIRParser.cpp:5654
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:116
constexpr FIRVersion minimumFIRVersion(0, 2, 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:48
InfoLocHandling infoLocatorHandling
Definition: FIRParser.h:43
InfoLocHandling
Specify how @info locators should be handled.
Definition: FIRParser.h:33
@ 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 ...
The FIRRTL specification version.
Definition: FIRParser.h:81
constexpr bool operator<(FIRVersion rhs) const
Definition: FIRParser.h:89
constexpr bool operator>(FIRVersion rhs) const
Definition: FIRParser.h:93
constexpr bool operator>=(FIRVersion rhs) const
Definition: FIRParser.h:101
constexpr FIRVersion(uint16_t major, uint16_t minor, uint16_t patch)
Definition: FIRParser.h:82
constexpr bool operator<=(FIRVersion rhs) const
Definition: FIRParser.h:97