CIRCT  18.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 scalarizeTopModule = false;
50  bool scalarizeExtModules = false;
51 };
52 
54  mlir::MLIRContext *context,
55  mlir::TimingScope &ts,
56  FIRParserOptions options = {});
57 
58 // Decode a source locator string `spelling`, returning a pair indicating that
59 // the `spelling` was correct and an optional location attribute. The
60 // `skipParsing` option can be used to short-circuit parsing and just do
61 // validation of the `spelling`. This require both an Identifier and a
62 // FileLineColLoc to use for caching purposes and context as the cache may be
63 // updated with a new identifier.
64 //
65 // This utility exists because source locators can exist outside of normal
66 // "parsing". E.g., these can show up in annotations or in Object Model 2.0
67 // JSON.
68 //
69 // TODO: This API is super wacky and should be streamlined to hide the
70 // caching.
71 std::pair<bool, std::optional<mlir::LocationAttr>>
72 maybeStringToLocation(llvm::StringRef spelling, bool skipParsing,
73  mlir::StringAttr &locatorFilenameCache,
74  FileLineColLoc &fileLineColLocCache,
75  MLIRContext *context);
76 
78 
79 /// The FIRRTL specification version.
80 struct FIRVersion {
81  constexpr FIRVersion(uint16_t major, uint16_t minor, uint16_t patch)
82  : major{major}, minor{minor}, patch{patch} {}
83 
84  explicit constexpr operator uint64_t() const {
85  return uint64_t(major) << 32 | uint64_t(minor) << 16 | uint64_t(patch);
86  }
87 
88  constexpr bool operator<(FIRVersion rhs) const {
89  return uint64_t(*this) < uint64_t(rhs);
90  }
91 
92  constexpr bool operator>(FIRVersion rhs) const {
93  return uint64_t(*this) > uint64_t(rhs);
94  }
95 
96  constexpr bool operator<=(FIRVersion rhs) const {
97  return uint64_t(*this) <= uint64_t(rhs);
98  }
99 
100  constexpr bool operator>=(FIRVersion rhs) const {
101  return uint64_t(*this) >= uint64_t(rhs);
102  }
103 
104  uint16_t major;
105  uint16_t minor;
106  uint16_t patch;
107 };
108 
109 constexpr FIRVersion minimumFIRVersion(0, 2, 0);
110 constexpr FIRVersion nextFIRVersion(3, 3, 0);
112 constexpr FIRVersion defaultFIRVersion(1, 0, 0);
113 
114 template <typename T>
115 T &operator<<(T &os, FIRVersion version) {
116  return os << version.major << "." << version.minor << "." << version.patch;
117 }
118 
119 } // namespace firrtl
120 } // namespace circt
121 
122 #endif // CIRCT_DIALECT_FIRRTL_FIRPARSER_H
constexpr FIRVersion defaultFIRVersion(1, 0, 0)
void registerFromFIRFileTranslation()
Definition: FIRParser.cpp:5029
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={})
constexpr FIRVersion exportFIRVersion
Definition: FIRParser.h:111
T & operator<<(T &os, FIRVersion version)
Definition: FIRParser.h:115
constexpr FIRVersion minimumFIRVersion(0, 2, 0)
constexpr FIRVersion nextFIRVersion(3, 3, 0)
This file defines an intermediate representation for circuits acting as an abstraction for constraint...
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:80
constexpr bool operator<(FIRVersion rhs) const
Definition: FIRParser.h:88
constexpr bool operator>(FIRVersion rhs) const
Definition: FIRParser.h:92
constexpr bool operator>=(FIRVersion rhs) const
Definition: FIRParser.h:100
constexpr FIRVersion(uint16_t major, uint16_t minor, uint16_t patch)
Definition: FIRParser.h:81
constexpr bool operator<=(FIRVersion rhs) const
Definition: FIRParser.h:96