CIRCT 23.0.0git
Loading...
Searching...
No Matches
TypedPorts.h
Go to the documentation of this file.
1//===- TypedPorts.h - Strongly-typed ESI port wrappers ----------*- 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// Thin, non-owning wrappers around WriteChannelPort / ReadChannelPort that
16// verify type compatibility at connect() time and provide strongly-typed
17// write/read APIs. Purely additive — no changes to the untyped port classes.
18//
19//===----------------------------------------------------------------------===//
20
21// NOLINTNEXTLINE(llvm-header-guard)
22#ifndef ESI_TYPED_PORTS_H
23#define ESI_TYPED_PORTS_H
24
25#include "esi/Ports.h"
26#include "esi/Services.h"
27#include "esi/Types.h"
28
29#include <cstdint>
30#include <cstring>
31#include <functional>
32#include <future>
33#include <stdexcept>
34#include <string>
35#include <string_view>
36#include <type_traits>
37#include <typeinfo>
38
39namespace esi {
40
41//===----------------------------------------------------------------------===//
42// AcceleratorMismatchError — thrown for type mismatches and port-not-found.
43//===----------------------------------------------------------------------===//
44
45class AcceleratorMismatchError : public std::runtime_error {
46public:
47 using std::runtime_error::runtime_error;
48};
49
50//===----------------------------------------------------------------------===//
51// Helpers: unwrap TypeAliasType and width-aware serialization.
52//===----------------------------------------------------------------------===//
53
54/// Unwrap TypeAliasType (possibly recursively) to get the underlying type.
55inline const Type *unwrapTypeAlias(const Type *t) {
56 while (auto *alias = dynamic_cast<const TypeAliasType *>(t))
57 t = alias->getInnerType();
58 return t;
59}
60
61/// Compute the wire byte count for a port type. Returns 0 if not a
62/// BitVectorType (meaning sizeof(T) should be used instead).
63/// Wire format info for a port type, cached at connect() time.
64struct WireInfo {
65 size_t bytes = 0; // (bitWidth+7)/8, or 0 if not a BitVectorType.
66 size_t bitWidth = 0;
67};
68
69inline WireInfo getWireInfo(const Type *portType) {
70 const Type *inner = unwrapTypeAlias(portType);
71 if (auto *bv = dynamic_cast<const BitVectorType *>(inner))
72 return {(bv->getWidth() + 7) / 8, bv->getWidth()};
73 return {};
74}
75
76/// Pack a C++ integral value into a MessageData with the given wire byte count.
77/// If wi.bytes is 0, falls back to sizeof(T).
78template <typename T>
80 if constexpr (std::is_integral_v<T> && !std::is_same_v<T, bool>) {
81 if (wi.bytes > 0 && wi.bytes != sizeof(T)) {
82 std::vector<uint8_t> buf(wi.bytes, 0);
83 std::memcpy(buf.data(), &data, std::min(wi.bytes, sizeof(T)));
84 return MessageData(std::move(buf));
85 }
86 }
87 return MessageData(reinterpret_cast<const uint8_t *>(&data), sizeof(T));
88}
89
90/// Unpack a MessageData into a C++ integral value with the given wire info.
91/// If the wire size differs from sizeof(T), copies available bytes into
92/// a zero-initialized value and sign-extends for signed types using the
93/// actual bit width to locate the sign bit.
94template <typename T>
96 if constexpr (std::is_integral_v<T> && !std::is_same_v<T, bool>) {
97 if (wi.bytes > 0 && msg.getSize() == wi.bytes &&
98 wi.bitWidth < sizeof(T) * 8) {
99 // Copy wire bytes into a zero-initialized value.
100 T val = 0;
101 std::memcpy(&val, msg.getBytes(), std::min(wi.bytes, sizeof(T)));
102 // Sign-extend for signed types if the sign bit is set.
103 if constexpr (std::is_signed_v<T>) {
104 size_t signBit = wi.bitWidth - 1;
105 size_t signByte = signBit / 8;
106 uint8_t signMask = uint8_t(1) << (signBit % 8);
107 if (signByte < wi.bytes && (msg.getBytes()[signByte] & signMask)) {
108 // Set all bits above the sign bit to 1.
109 if (wi.bitWidth < sizeof(T) * 8)
110 val |= static_cast<T>(~T(0)) << wi.bitWidth;
111 }
112 }
113 return val;
114 }
115 }
116 return *msg.as<T>();
117}
118
119//===----------------------------------------------------------------------===//
120// Type-trait: detect T::_ESI_ID (a static constexpr std::string_view).
121//===----------------------------------------------------------------------===//
122
123template <typename T, typename = void>
124struct has_esi_id : std::false_type {};
125
126template <typename T>
127struct has_esi_id<T, std::void_t<decltype(T::_ESI_ID)>>
128 : std::is_convertible<decltype(T::_ESI_ID), std::string_view> {};
129
130template <typename T>
131inline constexpr bool has_esi_id_v = has_esi_id<T>::value;
132
133//===----------------------------------------------------------------------===//
134// verifyTypeCompatibility<T>(const Type *portType)
135//
136// Checks that the ESI runtime Type is compatible with the C++ type T.
137// Dispatch order: _ESI_ID → void → bool → signed int → unsigned int → error.
138//===----------------------------------------------------------------------===//
139
140template <typename T>
141void verifyTypeCompatibility(const Type *portType) {
142 if (!portType)
143 throw AcceleratorMismatchError("Port type is null");
144
145 // Unwrap TypeAliasType to get the inner type for verification.
146 portType = unwrapTypeAlias(portType);
147
148 if constexpr (has_esi_id_v<T>) {
149 // Highest priority: user-defined ESI ID string comparison.
150 if (std::string_view(portType->getID()) != T::_ESI_ID)
152 "ESI type mismatch: C++ type has _ESI_ID '" +
153 std::string(T::_ESI_ID) + "' but port type is '" +
154 portType->toString(/*oneLine=*/true) + "'");
155 } else if constexpr (std::is_void_v<T>) {
156 if (!dynamic_cast<const VoidType *>(portType))
157 throw AcceleratorMismatchError("ESI type mismatch: expected VoidType for "
158 "void, but port type is '" +
159 portType->toString(/*oneLine=*/true) +
160 "'");
161 } else if constexpr (std::is_same_v<T, bool>) {
162 // bool maps to signless i1, which is BitsType with width <= 1.
163 auto *bits = dynamic_cast<const BitsType *>(portType);
164 if (!bits || bits->getWidth() > 1)
166 "ESI type mismatch: expected BitsType with width <= 1 for "
167 "bool, but port type is '" +
168 portType->toString(/*oneLine=*/true) + "'");
169 } else if constexpr (std::is_integral_v<T> && std::is_signed_v<T>) {
170 auto *sint = dynamic_cast<const SIntType *>(portType);
171 if (!sint)
173 "ESI type mismatch: expected SIntType for signed integer, "
174 "but port type is '" +
175 portType->toString(/*oneLine=*/true) + "'");
176 if (sint->getWidth() > sizeof(T) * 8)
178 "ESI type mismatch: SIntType width " +
179 std::to_string(sint->getWidth()) + " does not fit in " +
180 std::to_string(sizeof(T) * 8) + "-bit signed integer");
181 // Require closest-size match: reject if a smaller C++ type would suffice.
182 if (sizeof(T) > 1 && sint->getWidth() <= (sizeof(T) / 2) * 8)
183 throw AcceleratorMismatchError("ESI type mismatch: SIntType width " +
184 std::to_string(sint->getWidth()) +
185 " should use a smaller C++ type than " +
186 std::to_string(sizeof(T) * 8) + "-bit");
187 } else if constexpr (std::is_integral_v<T> && std::is_unsigned_v<T>) {
188 // Accept UIntType (uiM) or BitsType (iM, signless).
189 auto *uintPort = dynamic_cast<const UIntType *>(portType);
190 auto *bits = dynamic_cast<const BitsType *>(portType);
191 if (!uintPort && !bits)
193 "ESI type mismatch: expected UIntType or BitsType for unsigned "
194 "integer, but port type is '" +
195 portType->toString(/*oneLine=*/true) + "'");
196 uint64_t width = uintPort ? uintPort->getWidth() : bits->getWidth();
197 if (width > sizeof(T) * 8)
199 "ESI type mismatch: bit width " + std::to_string(width) +
200 " does not fit in " + std::to_string(sizeof(T) * 8) +
201 "-bit unsigned integer");
202 // Require closest-size match: reject if a smaller C++ type would suffice.
203 if (sizeof(T) > 1 && width <= (sizeof(T) / 2) * 8)
204 throw AcceleratorMismatchError("ESI type mismatch: bit width " +
205 std::to_string(width) +
206 " should use a smaller C++ type than " +
207 std::to_string(sizeof(T) * 8) + "-bit");
208 } else {
210 std::string("Cannot verify type compatibility for C++ type '") +
211 typeid(T).name() + "' against ESI port type '" +
212 portType->toString(/*oneLine=*/true) + "'");
213 }
214}
215
216//===----------------------------------------------------------------------===//
217// TypedWritePort<T, CheckValue>
218//
219// When CheckValue is true, write() and tryWrite() verify that the value fits
220// in the ESI port's actual bit width before sending.
221//===----------------------------------------------------------------------===//
222
223template <typename T, bool CheckValue = false>
225public:
226 explicit TypedWritePort(WriteChannelPort &port) : inner(&port) {}
227 // NOLINTNEXTLINE(google-explicit-constructor)
229
230 void connect(const ChannelPort::ConnectOptions &opts = {}) {
231 if (!inner)
232 throw AcceleratorMismatchError("TypedWritePort: null port pointer");
233 verifyTypeCompatibility<T>(inner->getType());
235 inner->connect(opts);
236 }
237
238 void write(const T &data) {
239 if constexpr (CheckValue)
240 checkValueRange(data);
242 }
243
244 bool tryWrite(const T &data) {
245 if constexpr (CheckValue)
246 checkValueRange(data);
247 return inner->tryWrite(toMessageData(data, wireInfo_));
248 }
249
250 bool flush() { return inner->flush(); }
252 bool isConnected() const { return inner && inner->isConnected(); }
253
254 WriteChannelPort &raw() { return *inner; }
255 const WriteChannelPort &raw() const { return *inner; }
256
257private:
260
261 void checkValueRange(const T &data) {
262 static_assert(std::is_integral_v<T>,
263 "Value range checking only supported for integral types");
264 const Type *pt = unwrapTypeAlias(inner->getType());
265 auto *bvType = dynamic_cast<const BitVectorType *>(pt);
266 if (!bvType)
267 return;
268 uint64_t width = bvType->getWidth();
269 if (width >= sizeof(T) * 8)
270 return; // Full-width; any value is valid.
271 if constexpr (std::is_signed_v<T>) {
272 int64_t minVal = -(int64_t(1) << (width - 1));
273 int64_t maxVal = (int64_t(1) << (width - 1)) - 1;
274 if (data < minVal || data > maxVal)
276 "Value " + std::to_string(data) + " out of range for " +
277 std::to_string(width) + "-bit signed type");
278 } else {
279 uint64_t maxVal = (uint64_t(1) << width) - 1;
280 if (static_cast<uint64_t>(data) > maxVal)
282 "Value " + std::to_string(data) + " out of range for " +
283 std::to_string(width) + "-bit unsigned type");
284 }
285 }
286};
287
288/// Specialization for void — write takes no data argument.
289template <>
290class TypedWritePort<void> {
291public:
292 explicit TypedWritePort(WriteChannelPort &port) : inner(&port) {}
293 // NOLINTNEXTLINE(google-explicit-constructor)
295
296 void connect(const ChannelPort::ConnectOptions &opts = {}) {
297 if (!inner)
298 throw AcceleratorMismatchError("TypedWritePort: null port pointer");
299 verifyTypeCompatibility<void>(inner->getType());
300 inner->connect(opts);
301 }
302
303 void write() {
304 uint8_t zero = 0;
305 inner->write(MessageData(&zero, 1));
306 }
307
308 bool tryWrite() {
309 uint8_t zero = 0;
310 return inner->tryWrite(MessageData(&zero, 1));
311 }
312
313 bool flush() { return inner->flush(); }
315 bool isConnected() const { return inner && inner->isConnected(); }
316
317 WriteChannelPort &raw() { return *inner; }
318 const WriteChannelPort &raw() const { return *inner; }
319
320private:
322};
323
324//===----------------------------------------------------------------------===//
325// TypedReadPort<T>
326//===----------------------------------------------------------------------===//
327
328template <typename T>
330public:
331 explicit TypedReadPort(ReadChannelPort &port) : inner(&port) {}
332 // NOLINTNEXTLINE(google-explicit-constructor)
334
335 void connect(const ChannelPort::ConnectOptions &opts = {}) {
336 if (!inner)
337 throw AcceleratorMismatchError("TypedReadPort: null port pointer");
338 verifyTypeCompatibility<T>(inner->getType());
340 inner->connect(opts);
341 }
342
343 void connect(std::function<bool(const T &)> callback,
344 const ChannelPort::ConnectOptions &opts = {}) {
345 if (!inner)
346 throw AcceleratorMismatchError("TypedReadPort: null port pointer");
347 verifyTypeCompatibility<T>(inner->getType());
349 WireInfo wb = wireInfo_;
350 inner->connect(
351 [cb = std::move(callback), wb](MessageData data) -> bool {
352 return cb(fromMessageData<T>(data, wb));
353 },
354 opts);
355 }
356
357 T read() {
358 MessageData outData;
359 inner->read(outData);
360 return fromMessageData<T>(outData, wireInfo_);
361 }
362
363 std::future<T> readAsync() {
364 WireInfo wb = wireInfo_;
365 auto innerFuture = inner->readAsync();
366 return std::async(std::launch::deferred,
367 [f = std::move(innerFuture), wb]() mutable -> T {
368 MessageData data = f.get();
369 return fromMessageData<T>(data, wb);
370 });
371 }
372
374 bool isConnected() const { return inner && inner->isConnected(); }
375
376 ReadChannelPort &raw() { return *inner; }
377 const ReadChannelPort &raw() const { return *inner; }
378
379private:
382};
383
384/// Specialization for void — read discards data and returns nothing.
385template <>
386class TypedReadPort<void> {
387public:
388 explicit TypedReadPort(ReadChannelPort &port) : inner(&port) {}
389 // NOLINTNEXTLINE(google-explicit-constructor)
391
392 void connect(const ChannelPort::ConnectOptions &opts = {}) {
393 if (!inner)
394 throw AcceleratorMismatchError("TypedReadPort: null port pointer");
395 verifyTypeCompatibility<void>(inner->getType());
396 inner->connect(opts);
397 }
398
399 void connect(std::function<bool()> callback,
400 const ChannelPort::ConnectOptions &opts = {}) {
401 if (!inner)
402 throw AcceleratorMismatchError("TypedReadPort: null port pointer");
403 verifyTypeCompatibility<void>(inner->getType());
404 inner->connect(
405 [cb = std::move(callback)](MessageData) -> bool { return cb(); }, opts);
406 }
407
408 void read() {
409 MessageData outData;
410 inner->read(outData);
411 }
412
413 std::future<void> readAsync() {
414 auto innerFuture = inner->readAsync();
415 return std::async(
416 std::launch::deferred,
417 [f = std::move(innerFuture)]() mutable -> void { f.get(); });
418 }
419
421 bool isConnected() const { return inner && inner->isConnected(); }
422
423 ReadChannelPort &raw() { return *inner; }
424 const ReadChannelPort &raw() const { return *inner; }
425
426private:
428};
429
430//===----------------------------------------------------------------------===//
431// TypedFunction<ArgT, ResultT>
432//
433// Non-owning wrapper around FuncService::Function that provides strongly-typed
434// call() and connect() APIs. Implicitly constructible from Function* (the
435// return type of BundlePort::getAs<FuncService::Function>()).
436//===----------------------------------------------------------------------===//
437
438template <typename ArgT, typename ResultT>
440public:
441 /// Implicit conversion from Function* (returned by getAs<>()).
442 // NOLINTNEXTLINE(google-explicit-constructor)
444
445 void connect() {
446 if (!inner)
448 "TypedFunction: null Function pointer (getAs failed or wrong type)");
449 verifyTypeCompatibility<ArgT>(inner->getArgType());
450 verifyTypeCompatibility<ResultT>(inner->getResultType());
453 inner->connect();
454 }
455
456 std::future<ResultT> call(const ArgT &arg) {
458 auto f = inner->call(toMessageData(arg, argWireInfo_));
459 return std::async(std::launch::deferred,
460 [fut = std::move(f), rwb]() mutable -> ResultT {
461 MessageData data = fut.get();
462 return fromMessageData<ResultT>(data, rwb);
463 });
464 }
465
467 const services::FuncService::Function &raw() const { return *inner; }
468
469private:
473};
474
475/// Partial specialization: void argument, typed result.
476template <typename ResultT>
477class TypedFunction<void, ResultT> {
478public:
479 // NOLINTNEXTLINE(google-explicit-constructor)
481
482 void connect() {
483 if (!inner)
485 "TypedFunction: null Function pointer (getAs failed or wrong type)");
486 verifyTypeCompatibility<void>(inner->getArgType());
487 verifyTypeCompatibility<ResultT>(inner->getResultType());
488 inner->connect();
489 }
490
491 std::future<ResultT> call() {
492 uint8_t zero = 0;
493 const Type *resType = inner->getResultType();
494 auto f = inner->call(MessageData(&zero, 1));
495 return std::async(std::launch::deferred,
496 [fut = std::move(f), resType]() mutable -> ResultT {
497 MessageData data = fut.get();
498 return fromMessageData<ResultT>(data, resType);
499 });
500 }
501
503 const services::FuncService::Function &raw() const { return *inner; }
504
505private:
507};
508
509/// Partial specialization: typed argument, void result.
510template <typename ArgT>
511class TypedFunction<ArgT, void> {
512public:
513 // NOLINTNEXTLINE(google-explicit-constructor)
515
516 void connect() {
517 if (!inner)
519 "TypedFunction: null Function pointer (getAs failed or wrong type)");
520 verifyTypeCompatibility<ArgT>(inner->getArgType());
521 verifyTypeCompatibility<void>(inner->getResultType());
523 inner->connect();
524 }
525
526 std::future<void> call(const ArgT &arg) {
527 auto f = inner->call(toMessageData(arg, argWireInfo_));
528 return std::async(std::launch::deferred,
529 [fut = std::move(f)]() mutable -> void { fut.get(); });
530 }
531
533 const services::FuncService::Function &raw() const { return *inner; }
534
535private:
538};
539
540/// Full specialization: void argument, void result.
541template <>
542class TypedFunction<void, void> {
543public:
544 // NOLINTNEXTLINE(google-explicit-constructor)
546
547 void connect() {
548 if (!inner)
550 "TypedFunction: null Function pointer (getAs failed or wrong type)");
551 verifyTypeCompatibility<void>(inner->getArgType());
552 verifyTypeCompatibility<void>(inner->getResultType());
553 inner->connect();
554 }
555
556 std::future<void> call() {
557 uint8_t zero = 0;
558 auto f = inner->call(MessageData(&zero, 1));
559 return std::async(std::launch::deferred,
560 [fut = std::move(f)]() mutable -> void { fut.get(); });
561 }
562
564 const services::FuncService::Function &raw() const { return *inner; }
565
566private:
568};
569
570//===----------------------------------------------------------------------===//
571// TypedCallback<ArgT, ResultT>
572//
573// Non-owning wrapper around CallService::Callback that provides strongly-typed
574// connect() and automatic MessageData conversion. Implicitly constructible
575// from Callback* (the return type of BundlePort::getAs<Callback>()).
576//===----------------------------------------------------------------------===//
577
578template <typename ArgT, typename ResultT>
580public:
581 // NOLINTNEXTLINE(google-explicit-constructor)
583
584 void connect(std::function<ResultT(const ArgT &)> callback,
585 bool quick = false) {
586 if (!inner)
588 "TypedCallback: null Callback pointer (getAs failed or wrong type)");
589 verifyTypeCompatibility<ArgT>(inner->getArgType());
590 verifyTypeCompatibility<ResultT>(inner->getResultType());
591 inner->connect(
592 [cb = std::move(callback), argType = inner->getArgType(),
593 resType = inner->getResultType()](
594 const MessageData &argData) -> MessageData {
595 ResultT result = cb(fromMessageData<ArgT>(argData, argType));
596 return toMessageData(result, resType);
597 },
598 quick);
599 }
600
602 const services::CallService::Callback &raw() const { return *inner; }
603
604private:
606};
607
608/// Partial specialization: void argument, typed result.
609template <typename ResultT>
610class TypedCallback<void, ResultT> {
611public:
612 // NOLINTNEXTLINE(google-explicit-constructor)
614
615 void connect(std::function<ResultT()> callback, bool quick = false) {
616 if (!inner)
618 "TypedCallback: null Callback pointer (getAs failed or wrong type)");
619 verifyTypeCompatibility<void>(inner->getArgType());
620 verifyTypeCompatibility<ResultT>(inner->getResultType());
622 inner->connect(
623 [cb = std::move(callback), rwb](const MessageData &) -> MessageData {
624 ResultT result = cb();
625 return toMessageData(result, rwb);
626 },
627 quick);
628 }
629
631 const services::CallService::Callback &raw() const { return *inner; }
632
633private:
635};
636
637/// Partial specialization: typed argument, void result.
638template <typename ArgT>
639class TypedCallback<ArgT, void> {
640public:
641 // NOLINTNEXTLINE(google-explicit-constructor)
643
644 void connect(std::function<void(const ArgT &)> callback, bool quick = false) {
645 if (!inner)
647 "TypedCallback: null Callback pointer (getAs failed or wrong type)");
648 verifyTypeCompatibility<ArgT>(inner->getArgType());
649 verifyTypeCompatibility<void>(inner->getResultType());
650 inner->connect(
651 [cb = std::move(callback), argType = inner->getArgType()](
652 const MessageData &argData) -> MessageData {
653 cb(fromMessageData<ArgT>(argData, argType));
654 uint8_t zero = 0;
655 return MessageData(&zero, 1);
656 },
657 quick);
658 }
659
661 const services::CallService::Callback &raw() const { return *inner; }
662
663private:
665};
666
667/// Full specialization: void argument, void result.
668template <>
669class TypedCallback<void, void> {
670public:
671 // NOLINTNEXTLINE(google-explicit-constructor)
673
674 void connect(std::function<void()> callback, bool quick = false) {
675 if (!inner)
677 "TypedCallback: null Callback pointer (getAs failed or wrong type)");
678 verifyTypeCompatibility<void>(inner->getArgType());
679 verifyTypeCompatibility<void>(inner->getResultType());
680 inner->connect(
681 [cb = std::move(callback)](const MessageData &) -> MessageData {
682 cb();
683 uint8_t zero = 0;
684 return MessageData(&zero, 1);
685 },
686 quick);
687 }
688
690 const services::CallService::Callback &raw() const { return *inner; }
691
692private:
694};
695
696} // namespace esi
697
698#endif // ESI_TYPED_PORTS_H
Bit vectors include signed, unsigned, and signless integers.
Definition Types.h:186
uint64_t getWidth() const
Definition Types.h:190
Bits are just an array of bits.
Definition Types.h:199
const Type * getType() const
Definition Ports.h:130
A logical chunk of data representing serialized data.
Definition Common.h:113
const uint8_t * getBytes() const
Definition Common.h:124
const T * as() const
Cast to a type.
Definition Common.h:148
size_t getSize() const
Get the size of the data in bytes.
Definition Common.h:138
A ChannelPort which reads data from the accelerator.
Definition Ports.h:318
virtual std::future< MessageData > readAsync()
Asynchronous read.
Definition Ports.cpp:126
virtual bool isConnected() const override
Definition Ports.h:324
virtual void connect(std::function< bool(MessageData)> callback, const ConnectOptions &options={})
Definition Ports.cpp:69
virtual void disconnect() override
Definition Ports.h:323
virtual void read(MessageData &outData)
Specify a buffer to read into.
Definition Ports.h:358
Signed integer.
Definition Types.h:217
Type aliases provide a named type which forwards to an inner type.
Definition Types.h:159
Root class of the ESI type system.
Definition Types.h:36
std::string toString(bool oneLine=false) const
Definition Types.cpp:103
ID getID() const
Definition Types.h:42
services::CallService::Callback & raw()
Definition TypedPorts.h:660
void connect(std::function< void(const ArgT &)> callback, bool quick=false)
Definition TypedPorts.h:644
TypedCallback(services::CallService::Callback *cb)
Definition TypedPorts.h:642
const services::CallService::Callback & raw() const
Definition TypedPorts.h:661
services::CallService::Callback * inner
Definition TypedPorts.h:664
const services::CallService::Callback & raw() const
Definition TypedPorts.h:631
TypedCallback(services::CallService::Callback *cb)
Definition TypedPorts.h:613
services::CallService::Callback & raw()
Definition TypedPorts.h:630
services::CallService::Callback * inner
Definition TypedPorts.h:634
void connect(std::function< ResultT()> callback, bool quick=false)
Definition TypedPorts.h:615
const services::CallService::Callback & raw() const
Definition TypedPorts.h:690
void connect(std::function< void()> callback, bool quick=false)
Definition TypedPorts.h:674
services::CallService::Callback * inner
Definition TypedPorts.h:693
TypedCallback(services::CallService::Callback *cb)
Definition TypedPorts.h:672
services::CallService::Callback & raw()
Definition TypedPorts.h:689
TypedCallback(services::CallService::Callback *cb)
Definition TypedPorts.h:582
const services::CallService::Callback & raw() const
Definition TypedPorts.h:602
services::CallService::Callback * inner
Definition TypedPorts.h:605
services::CallService::Callback & raw()
Definition TypedPorts.h:601
void connect(std::function< ResultT(const ArgT &)> callback, bool quick=false)
Definition TypedPorts.h:584
services::FuncService::Function * inner
Definition TypedPorts.h:536
TypedFunction(services::FuncService::Function *func)
Definition TypedPorts.h:514
std::future< void > call(const ArgT &arg)
Definition TypedPorts.h:526
services::FuncService::Function & raw()
Definition TypedPorts.h:532
const services::FuncService::Function & raw() const
Definition TypedPorts.h:533
TypedFunction(services::FuncService::Function *func)
Definition TypedPorts.h:480
services::FuncService::Function * inner
Definition TypedPorts.h:506
services::FuncService::Function & raw()
Definition TypedPorts.h:502
const services::FuncService::Function & raw() const
Definition TypedPorts.h:503
std::future< ResultT > call()
Definition TypedPorts.h:491
std::future< void > call()
Definition TypedPorts.h:556
services::FuncService::Function * inner
Definition TypedPorts.h:567
services::FuncService::Function & raw()
Definition TypedPorts.h:563
const services::FuncService::Function & raw() const
Definition TypedPorts.h:564
TypedFunction(services::FuncService::Function *func)
Definition TypedPorts.h:545
WireInfo resWireInfo_
Definition TypedPorts.h:472
TypedFunction(services::FuncService::Function *func)
Implicit conversion from Function* (returned by getAs<>()).
Definition TypedPorts.h:443
WireInfo argWireInfo_
Definition TypedPorts.h:471
std::future< ResultT > call(const ArgT &arg)
Definition TypedPorts.h:456
services::FuncService::Function & raw()
Definition TypedPorts.h:466
services::FuncService::Function * inner
Definition TypedPorts.h:470
const services::FuncService::Function & raw() const
Definition TypedPorts.h:467
ReadChannelPort * inner
Definition TypedPorts.h:427
TypedReadPort(ReadChannelPort &port)
Definition TypedPorts.h:388
void connect(const ChannelPort::ConnectOptions &opts={})
Definition TypedPorts.h:392
TypedReadPort(ReadChannelPort *port)
Definition TypedPorts.h:390
std::future< void > readAsync()
Definition TypedPorts.h:413
ReadChannelPort & raw()
Definition TypedPorts.h:423
const ReadChannelPort & raw() const
Definition TypedPorts.h:424
void connect(std::function< bool()> callback, const ChannelPort::ConnectOptions &opts={})
Definition TypedPorts.h:399
bool isConnected() const
Definition TypedPorts.h:374
TypedReadPort(ReadChannelPort &port)
Definition TypedPorts.h:331
ReadChannelPort & raw()
Definition TypedPorts.h:376
TypedReadPort(ReadChannelPort *port)
Definition TypedPorts.h:333
std::future< T > readAsync()
Definition TypedPorts.h:363
void connect(const ChannelPort::ConnectOptions &opts={})
Definition TypedPorts.h:335
const ReadChannelPort & raw() const
Definition TypedPorts.h:377
void connect(std::function< bool(const T &)> callback, const ChannelPort::ConnectOptions &opts={})
Definition TypedPorts.h:343
ReadChannelPort * inner
Definition TypedPorts.h:380
WriteChannelPort * inner
Definition TypedPorts.h:321
void connect(const ChannelPort::ConnectOptions &opts={})
Definition TypedPorts.h:296
TypedWritePort(WriteChannelPort &port)
Definition TypedPorts.h:292
TypedWritePort(WriteChannelPort *port)
Definition TypedPorts.h:294
WriteChannelPort & raw()
Definition TypedPorts.h:317
const WriteChannelPort & raw() const
Definition TypedPorts.h:318
const WriteChannelPort & raw() const
Definition TypedPorts.h:255
WriteChannelPort & raw()
Definition TypedPorts.h:254
TypedWritePort(WriteChannelPort &port)
Definition TypedPorts.h:226
void connect(const ChannelPort::ConnectOptions &opts={})
Definition TypedPorts.h:230
WriteChannelPort * inner
Definition TypedPorts.h:258
bool tryWrite(const T &data)
Definition TypedPorts.h:244
void write(const T &data)
Definition TypedPorts.h:238
TypedWritePort(WriteChannelPort *port)
Definition TypedPorts.h:228
bool isConnected() const
Definition TypedPorts.h:252
void checkValueRange(const T &data)
Definition TypedPorts.h:261
Unsigned integer.
Definition Types.h:228
The "void" type is a special type which can be used to represent no type.
Definition Types.h:136
A ChannelPort which sends data to the accelerator.
Definition Ports.h:206
virtual bool isConnected() const override
Definition Ports.h:218
virtual void disconnect() override
Definition Ports.h:217
void write(const MessageData &data)
A very basic blocking write API.
Definition Ports.h:222
bool flush()
Flush any buffered data.
Definition Ports.h:259
bool tryWrite(const MessageData &data)
A basic non-blocking write API.
Definition Ports.h:241
virtual void connect(const ConnectOptions &options={}) override
Set up a connection to the accelerator.
Definition Ports.h:210
A function call which gets attached to a service port.
Definition Services.h:343
const esi::Type * getArgType() const
Definition Services.h:360
const esi::Type * getResultType() const
Definition Services.h:365
void connect(std::function< MessageData(const MessageData &)> callback, bool quick=false)
Connect a callback to code which will be executed when the accelerator invokes the callback.
Definition Services.cpp:274
A function call which gets attached to a service port.
Definition Services.h:291
const esi::Type * getArgType() const
Definition Services.h:302
const esi::Type * getResultType() const
Definition Services.h:307
std::future< MessageData > call(const MessageData &arg)
Definition Services.cpp:239
Definition esi.py:1
void verifyTypeCompatibility(const Type *portType)
Definition TypedPorts.h:141
MessageData toMessageData(const T &data, WireInfo wi)
Pack a C++ integral value into a MessageData with the given wire byte count.
Definition TypedPorts.h:79
WireInfo getWireInfo(const Type *portType)
Definition TypedPorts.h:69
constexpr bool has_esi_id_v
Definition TypedPorts.h:131
const Type * unwrapTypeAlias(const Type *t)
Unwrap TypeAliasType (possibly recursively) to get the underlying type.
Definition TypedPorts.h:55
T fromMessageData(const MessageData &msg, WireInfo wi)
Unpack a MessageData into a C++ integral value with the given wire info.
Definition TypedPorts.h:95
Compute the wire byte count for a port type.
Definition TypedPorts.h:64
size_t bitWidth
Definition TypedPorts.h:66