CIRCT  19.0.0git
Common.h
Go to the documentation of this file.
1 //===- Common.h - Commonly used classes w/o dependencies --------*- 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 // DO NOT EDIT!
10 // This file is distributed as part of an ESI package. The source for this file
11 // should always be modified within CIRCT.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 // NOLINTNEXTLINE(llvm-header-guard)
16 #ifndef ESI_COMMON_H
17 #define ESI_COMMON_H
18 
19 #include <any>
20 #include <cstdint>
21 #include <map>
22 #include <optional>
23 #include <string>
24 #include <vector>
25 
26 namespace esi {
27 
28 //===----------------------------------------------------------------------===//
29 // Common accelerator description types.
30 //===----------------------------------------------------------------------===//
31 
32 struct AppID {
33  std::string name;
34  std::optional<uint32_t> idx;
35 
36  AppID(const AppID &) = default;
37  AppID(const std::string &name, std::optional<uint32_t> idx = std::nullopt)
38  : name(name), idx(idx) {}
39 
40  bool operator==(const AppID &other) const {
41  return name == other.name && idx == other.idx;
42  }
43  bool operator!=(const AppID &other) const { return !(*this == other); }
44 };
45 bool operator<(const AppID &a, const AppID &b);
46 
47 class AppIDPath : public std::vector<AppID> {
48 public:
49  using std::vector<AppID>::vector;
50 
51  AppIDPath operator+(const AppIDPath &b);
52  std::string toStr() const;
53 };
54 bool operator<(const AppIDPath &a, const AppIDPath &b);
55 
56 struct ModuleInfo {
57  const std::optional<std::string> name;
58  const std::optional<std::string> summary;
59  const std::optional<std::string> version;
60  const std::optional<std::string> repo;
61  const std::optional<std::string> commitHash;
62  const std::map<std::string, std::any> extra;
63 };
64 
65 /// A description of a service port. Used pretty exclusively in setting up the
66 /// design.
68  std::string name;
69  std::string portName;
70 };
71 
72 /// A description of a hardware client. Used pretty exclusively in setting up
73 /// the design.
77  std::map<std::string, std::any> implOptions;
78 };
79 using HWClientDetails = std::vector<HWClientDetail>;
80 using ServiceImplDetails = std::map<std::string, std::any>;
81 
82 /// A logical chunk of data representing serialized data. Currently, just a
83 /// wrapper for a vector of bytes, which is not efficient in terms of memory
84 /// copying. This will change in the future as will the API.
85 class MessageData {
86 public:
87  /// Adopts the data vector buffer.
88  MessageData() = default;
89  MessageData(std::vector<uint8_t> &data) : data(std::move(data)) {}
90  ~MessageData() = default;
91 
92  const uint8_t *getBytes() const { return data.data(); }
93  /// Get the size of the data in bytes.
94  size_t getSize() const { return data.size(); }
95 
96 private:
97  std::vector<uint8_t> data;
98 };
99 
100 } // namespace esi
101 
102 std::ostream &operator<<(std::ostream &, const esi::ModuleInfo &);
103 std::ostream &operator<<(std::ostream &, const esi::AppID &);
104 
105 //===----------------------------------------------------------------------===//
106 // Functions which should be in the standard library.
107 //===----------------------------------------------------------------------===//
108 
109 namespace esi {
110 std::string toHex(uint32_t val);
111 } // namespace esi
112 
113 #endif // ESI_COMMON_H
std::ostream & operator<<(std::ostream &, const esi::ModuleInfo &)
AppIDPath operator+(const AppIDPath &b)
Definition: Manifest.cpp:596
std::string toStr() const
Definition: Manifest.cpp:602
A logical chunk of data representing serialized data.
Definition: Common.h:85
~MessageData()=default
size_t getSize() const
Get the size of the data in bytes.
Definition: Common.h:94
MessageData()=default
Adopts the data vector buffer.
MessageData(std::vector< uint8_t > &data)
Definition: Common.h:89
std::vector< uint8_t > data
Definition: Common.h:97
const uint8_t * getBytes() const
Definition: Common.h:92
Definition: esi.py:1
std::map< std::string, std::any > ServiceImplDetails
Definition: Common.h:80
std::string toHex(uint32_t val)
Definition: Common.cpp:20
bool operator<(const AppID &a, const AppID &b)
Definition: Manifest.cpp:608
std::vector< HWClientDetail > HWClientDetails
Definition: Common.h:79
std::string name
Definition: Common.h:33
bool operator!=(const AppID &other) const
Definition: Common.h:43
bool operator==(const AppID &other) const
Definition: Common.h:40
AppID(const AppID &)=default
std::optional< uint32_t > idx
Definition: Common.h:34
AppID(const std::string &name, std::optional< uint32_t > idx=std::nullopt)
Definition: Common.h:37
A description of a hardware client.
Definition: Common.h:74
std::map< std::string, std::any > implOptions
Definition: Common.h:77
AppIDPath relPath
Definition: Common.h:75
ServicePortDesc port
Definition: Common.h:76
const std::optional< std::string > commitHash
Definition: Common.h:61
const std::optional< std::string > repo
Definition: Common.h:60
const std::optional< std::string > version
Definition: Common.h:59
const std::optional< std::string > summary
Definition: Common.h:58
const std::map< std::string, std::any > extra
Definition: Common.h:62
const std::optional< std::string > name
Definition: Common.h:57
A description of a service port.
Definition: Common.h:67
std::string name
Definition: Common.h:68
std::string portName
Definition: Common.h:69