CIRCT  19.0.0git
APIUtilities.h
Go to the documentation of this file.
1 //===- APIUtilities.h - ESI general-purpose API utilities -------*- C++ -*-===//
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 // Utilities and classes applicable to all ESI API generators.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef CIRCT_DIALECT_ESI_APIUTILITIES_H
14 #define CIRCT_DIALECT_ESI_APIUTILITIES_H
15 
17 #include "circt/Dialect/HW/HWOps.h"
18 #include "mlir/Support/IndentedOstream.h"
19 #include "llvm/ADT/MapVector.h"
20 
21 #include <memory>
22 
23 namespace circt {
24 namespace esi {
25 
26 /// Every time we implement a breaking change in the schema generation,
27 /// increment this number. It is a seed for all the schema hashes.
28 constexpr uint64_t esiApiVersion = 1;
29 
30 // Base type for all Cosim-implementing type emitters.
31 class ESIAPIType {
32 public:
33  using FieldInfo = hw::StructType::FieldInfo;
34 
35  ESIAPIType(mlir::Type);
36  virtual ~ESIAPIType() = default;
37  bool operator==(const ESIAPIType &) const;
38 
39  /// Get the type back.
40  mlir::Type getType() const { return type; }
41 
42  /// Returns true if the type is currently supported.
43  virtual bool isSupported() const;
44 
45  llvm::ArrayRef<FieldInfo> getFields() const { return fieldTypes; }
46 
47  // API-safe name for this type which should work with most languages.
48  StringRef name() const;
49 
50  uint64_t size() const;
51 
52  // Capnproto-safe type id for this type.
53  uint64_t typeID() const;
54 
55 protected:
56  /// Cosim requires that everything be contained in a struct. ESI doesn't so
57  /// we wrap non-struct types in a struct.
58  llvm::SmallVector<FieldInfo> fieldTypes;
59 
60  mlir::Type type;
61  mutable std::string cachedName;
62  mutable std::optional<uint64_t> cachedID;
63 };
64 
65 } // namespace esi
66 } // namespace circt
67 
68 #endif // CIRCT_DIALECT_ESI_APIUTILITIES_H
StringRef name() const
For now, the name is just the type serialized.
hw::StructType::FieldInfo FieldInfo
Definition: APIUtilities.h:33
bool operator==(const ESIAPIType &) const
llvm::ArrayRef< FieldInfo > getFields() const
Definition: APIUtilities.h:45
std::string cachedName
Definition: APIUtilities.h:61
llvm::SmallVector< FieldInfo > fieldTypes
Cosim requires that everything be contained in a struct.
Definition: APIUtilities.h:58
mlir::Type getType() const
Get the type back.
Definition: APIUtilities.h:40
uint64_t size() const
std::optional< uint64_t > cachedID
Definition: APIUtilities.h:62
virtual ~ESIAPIType()=default
uint64_t typeID() const
virtual bool isSupported() const
Returns true if the type is currently supported.
constexpr uint64_t esiApiVersion
Every time we implement a breaking change in the schema generation, increment this number.
Definition: APIUtilities.h:28
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
Definition: esi.py:1