Loading [MathJax]/extensions/tex2jax.js
CIRCT 22.0.0git
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 <stdexcept>
24#include <string>
25#include <vector>
26
27namespace esi {
28class Type;
29
30//===----------------------------------------------------------------------===//
31// Common accelerator description types.
32//===----------------------------------------------------------------------===//
33
34struct AppID {
35 std::string name;
36 std::optional<uint32_t> idx;
37
38 AppID(const std::string &name, std::optional<uint32_t> idx = std::nullopt)
39 : name(name), idx(idx) {}
40
41 bool operator==(const AppID &other) const {
42 return name == other.name && idx == other.idx;
43 }
44 bool operator!=(const AppID &other) const { return !(*this == other); }
45};
46bool operator<(const AppID &a, const AppID &b);
47
48class AppIDPath : public std::vector<AppID> {
49public:
50 using std::vector<AppID>::vector;
51
53 std::string toStr() const;
54};
55bool operator<(const AppIDPath &a, const AppIDPath &b);
56
57struct Constant {
58 std::any value;
59 std::optional<const Type *> type;
60};
61
62struct ModuleInfo {
63 std::optional<std::string> name;
64 std::optional<std::string> summary;
65 std::optional<std::string> version;
66 std::optional<std::string> repo;
67 std::optional<std::string> commitHash;
68 std::map<std::string, Constant> constants;
69 std::map<std::string, std::any> extra;
70};
71
72/// A description of a service port. Used pretty exclusively in setting up the
73/// design.
75 std::string name;
76 std::string portName;
77};
78
79/// Details about how to connect to a particular channel.
81 /// The name of the type of connection. Typically, the name of the DMA engine
82 /// or "cosim" if a cosimulation channel is being used.
83 std::string type;
84 /// Implementation-specific options.
85 std::map<std::string, std::any> implOptions;
86};
87using ChannelAssignments = std::map<std::string, ChannelAssignment>;
88
89/// A description of a hardware client. Used pretty exclusively in setting up
90/// the design.
97using HWClientDetails = std::vector<HWClientDetail>;
98using ServiceImplDetails = std::map<std::string, std::any>;
99
100/// A logical chunk of data representing serialized data. Currently, just a
101/// wrapper for a vector of bytes, which is not efficient in terms of memory
102/// copying. This will change in the future as will the API.
104public:
105 /// Adopts the data vector buffer.
106 MessageData() = default;
107 MessageData(std::vector<uint8_t> &data) : data(std::move(data)) {}
108 MessageData(std::vector<uint8_t> &&data) : data(std::move(data)) {}
109 MessageData(const uint8_t *data, size_t size) : data(data, data + size) {}
110 ~MessageData() = default;
111
112 const uint8_t *getBytes() const { return data.data(); }
113
114 /// Get the data as a vector of bytes.
115 const std::vector<uint8_t> &getData() const { return data; }
116
117 /// Move the data out of this object.
118 std::vector<uint8_t> takeData() { return std::move(data); }
119
120 /// Get the size of the data in bytes.
121 size_t getSize() const { return data.size(); }
122
123 /// Returns true if this message contains no data.
124 bool empty() const { return data.empty(); }
125
126 /// Cast to a type. Throws if the size of the data does not match the size of
127 /// the message. The lifetime of the resulting pointer is tied to the lifetime
128 /// of this object.
129 template <typename T>
130 const T *as() const {
131 if (data.size() != sizeof(T))
132 throw std::runtime_error("Data size does not match type size. Size is " +
133 std::to_string(data.size()) + ", expected " +
134 std::to_string(sizeof(T)) + ".");
135 return reinterpret_cast<const T *>(data.data());
136 }
137
138 /// Cast from a type to its raw bytes.
139 template <typename T>
140 static MessageData from(T &t) {
141 return MessageData(reinterpret_cast<const uint8_t *>(&t), sizeof(T));
142 }
143
144 /// Convert the data to a hex string.
145 std::string toHex() const;
146
147private:
148 std::vector<uint8_t> data;
149};
150
151} // namespace esi
152
153std::ostream &operator<<(std::ostream &, const esi::ModuleInfo &);
154std::ostream &operator<<(std::ostream &, const esi::AppID &);
155
156//===----------------------------------------------------------------------===//
157// Functions which should be in the standard library.
158//===----------------------------------------------------------------------===//
159
160namespace esi {
161std::string toHex(void *val);
162std::string toHex(uint64_t val);
163} // namespace esi
164
165#endif // ESI_COMMON_H
std::ostream & operator<<(std::ostream &, const esi::ModuleInfo &)
std::string toStr() const
Definition Manifest.cpp:733
AppIDPath operator+(const AppIDPath &b)
Definition Manifest.cpp:727
A logical chunk of data representing serialized data.
Definition Common.h:103
const std::vector< uint8_t > & getData() const
Get the data as a vector of bytes.
Definition Common.h:115
const uint8_t * getBytes() const
Definition Common.h:112
std::string toHex() const
Convert the data to a hex string.
Definition Common.cpp:22
~MessageData()=default
const T * as() const
Cast to a type.
Definition Common.h:130
std::vector< uint8_t > takeData()
Move the data out of this object.
Definition Common.h:118
size_t getSize() const
Get the size of the data in bytes.
Definition Common.h:121
MessageData()=default
Adopts the data vector buffer.
MessageData(const uint8_t *data, size_t size)
Definition Common.h:109
MessageData(std::vector< uint8_t > &data)
Definition Common.h:107
bool empty() const
Returns true if this message contains no data.
Definition Common.h:124
static MessageData from(T &t)
Cast from a type to its raw bytes.
Definition Common.h:140
std::vector< uint8_t > data
Definition Common.h:148
MessageData(std::vector< uint8_t > &&data)
Definition Common.h:108
Definition esi.py:1
std::map< std::string, std::any > ServiceImplDetails
Definition Common.h:98
std::string toHex(void *val)
Definition Common.cpp:37
std::map< std::string, ChannelAssignment > ChannelAssignments
Definition Common.h:87
bool operator<(const AppID &a, const AppID &b)
Definition Manifest.cpp:739
std::vector< HWClientDetail > HWClientDetails
Definition Common.h:97
std::string name
Definition Common.h:35
bool operator!=(const AppID &other) const
Definition Common.h:44
bool operator==(const AppID &other) const
Definition Common.h:41
std::optional< uint32_t > idx
Definition Common.h:36
AppID(const std::string &name, std::optional< uint32_t > idx=std::nullopt)
Definition Common.h:38
Details about how to connect to a particular channel.
Definition Common.h:80
std::map< std::string, std::any > implOptions
Implementation-specific options.
Definition Common.h:85
std::string type
The name of the type of connection.
Definition Common.h:83
std::any value
Definition Common.h:58
std::optional< const Type * > type
Definition Common.h:59
A description of a hardware client.
Definition Common.h:91
std::map< std::string, std::any > implOptions
Definition Common.h:95
AppIDPath relPath
Definition Common.h:92
ChannelAssignments channelAssignments
Definition Common.h:94
ServicePortDesc port
Definition Common.h:93
std::optional< std::string > version
Definition Common.h:65
std::optional< std::string > name
Definition Common.h:63
std::map< std::string, Constant > constants
Definition Common.h:68
std::optional< std::string > commitHash
Definition Common.h:67
std::optional< std::string > repo
Definition Common.h:66
std::map< std::string, std::any > extra
Definition Common.h:69
std::optional< std::string > summary
Definition Common.h:64
A description of a service port.
Definition Common.h:74
std::string name
Definition Common.h:75
std::string portName
Definition Common.h:76