CIRCT 21.0.0git
Loading...
Searching...
No Matches
Types.h
Go to the documentation of this file.
1//===- Types.h - ESI type system -------------------------------*- 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_TYPES_H
17#define ESI_TYPES_H
18
19#include <cstdint>
20#include <map>
21#include <string>
22#include <vector>
23
24namespace esi {
25
26/// Root class of the ESI type system.
27class Type {
28public:
29 using ID = std::string;
30 Type(const ID &id) : id(id) {}
31 virtual ~Type() = default;
32
33 ID getID() const { return id; }
34 virtual std::ptrdiff_t getBitWidth() const { return -1; }
35
36protected:
38};
39
40/// Bundles represent a collection of channels. Services exclusively expose
41/// bundles (sometimes of just one channel). As such, they are the type of
42/// accessible ports on an accelerator, from a host API perspective.
43/// TODO: Add a good description of direction?
44class BundleType : public Type {
45public:
46 enum Direction { To, From };
47
49 std::vector<std::tuple<std::string, Direction, const Type *>>;
50
52 : Type(id), channels(channels) {}
53
54 const ChannelVector &getChannels() const { return channels; }
55 std::ptrdiff_t getBitWidth() const override { return -1; };
56
57 std::pair<const Type *, Direction> findChannel(std::string name) const {
58 for (auto [channelName, dir, type] : channels)
59 if (channelName == name)
60 return std::make_pair(type, dir);
61 throw std::runtime_error("Channel '" + name + "' not found in bundle");
62 }
63
64protected:
66};
67
68/// Channels are the basic communication primitives. They are unidirectional and
69/// carry one values of one type.
70class ChannelType : public Type {
71public:
72 ChannelType(const ID &id, const Type *inner) : Type(id), inner(inner) {}
73 const Type *getInner() const { return inner; }
74 std::ptrdiff_t getBitWidth() const override { return inner->getBitWidth(); };
75
76private:
77 const Type *inner;
78};
79
80/// The "void" type is a special type which can be used to represent no type.
81class VoidType : public Type {
82public:
83 VoidType(const ID &id) : Type(id) {}
84 // 'void' is 1 bit by convention.
85 std::ptrdiff_t getBitWidth() const override { return 1; };
86};
87
88/// The "any" type is a special type which can be used to represent any type, as
89/// identified by the type id. Said type id is guaranteed to be present in the
90/// manifest. Importantly, the "any" type id over the wire may not be a string
91/// as it is in software.
92class AnyType : public Type {
93public:
94 AnyType(const ID &id) : Type(id) {}
95 std::ptrdiff_t getBitWidth() const override { return -1; };
96};
97
98/// Bit vectors include signed, unsigned, and signless integers.
99class BitVectorType : public Type {
100public:
101 BitVectorType(const ID &id, uint64_t width) : Type(id), width(width) {}
102
103 uint64_t getWidth() const { return width; }
104 std::ptrdiff_t getBitWidth() const override { return getWidth(); };
105
106private:
107 uint64_t width;
108};
109
110/// Bits are just an array of bits. They are not interpreted as a number but are
111/// identified in the manifest as "signless" ints.
112class BitsType : public BitVectorType {
113public:
115};
116
117/// Integers are bit vectors which may be signed or unsigned and are interpreted
118/// as numbers.
120public:
122};
123
124/// Signed integer.
125class SIntType : public IntegerType {
126public:
127 using IntegerType::IntegerType;
128};
129
130/// Unsigned integer.
131class UIntType : public IntegerType {
132public:
133 using IntegerType::IntegerType;
134};
135
136/// Structs are an ordered collection of fields, each with a name and a type.
137class StructType : public Type {
138public:
139 using FieldVector = std::vector<std::pair<std::string, const Type *>>;
140
141 StructType(const ID &id, const FieldVector &fields)
142 : Type(id), fields(fields) {}
143
144 const FieldVector &getFields() const { return fields; }
145 std::ptrdiff_t getBitWidth() const override {
146 std::ptrdiff_t size = 0;
147 for (auto [name, ty] : getFields()) {
148 std::ptrdiff_t fieldSize = ty->getBitWidth();
149 if (fieldSize < 0)
150 return -1;
151 size += fieldSize;
152 }
153 return size;
154 }
155
156private:
158};
159
160/// Arrays have a compile time specified (static) size and an element type.
161class ArrayType : public Type {
162public:
163 ArrayType(const ID &id, const Type *elementType, uint64_t size)
165
166 const Type *getElementType() const { return elementType; }
167 uint64_t getSize() const { return size; }
168 std::ptrdiff_t getBitWidth() const override {
169 std::ptrdiff_t elementSize = elementType->getBitWidth();
170 if (elementSize < 0)
171 return -1;
172 return elementSize * size;
173 }
174
175private:
177 uint64_t size;
178};
179
180} // namespace esi
181
182#endif // ESI_TYPES_H
The "any" type is a special type which can be used to represent any type, as identified by the type i...
Definition Types.h:92
std::ptrdiff_t getBitWidth() const override
Definition Types.h:95
AnyType(const ID &id)
Definition Types.h:94
Arrays have a compile time specified (static) size and an element type.
Definition Types.h:161
uint64_t size
Definition Types.h:177
ArrayType(const ID &id, const Type *elementType, uint64_t size)
Definition Types.h:163
const Type * elementType
Definition Types.h:176
const Type * getElementType() const
Definition Types.h:166
std::ptrdiff_t getBitWidth() const override
Definition Types.h:168
uint64_t getSize() const
Definition Types.h:167
Bit vectors include signed, unsigned, and signless integers.
Definition Types.h:99
BitVectorType(const ID &id, uint64_t width)
Definition Types.h:101
uint64_t width
Definition Types.h:107
std::ptrdiff_t getBitWidth() const override
Definition Types.h:104
uint64_t getWidth() const
Definition Types.h:103
Bits are just an array of bits.
Definition Types.h:112
Bundles represent a collection of channels.
Definition Types.h:44
BundleType(const ID &id, const ChannelVector &channels)
Definition Types.h:51
std::pair< const Type *, Direction > findChannel(std::string name) const
Definition Types.h:57
std::ptrdiff_t getBitWidth() const override
Definition Types.h:55
const ChannelVector & getChannels() const
Definition Types.h:54
ChannelVector channels
Definition Types.h:65
std::vector< std::tuple< std::string, Direction, const Type * > > ChannelVector
Definition Types.h:49
Channels are the basic communication primitives.
Definition Types.h:70
ChannelType(const ID &id, const Type *inner)
Definition Types.h:72
const Type * getInner() const
Definition Types.h:73
const Type * inner
Definition Types.h:77
std::ptrdiff_t getBitWidth() const override
Definition Types.h:74
Integers are bit vectors which may be signed or unsigned and are interpreted as numbers.
Definition Types.h:119
Signed integer.
Definition Types.h:125
Structs are an ordered collection of fields, each with a name and a type.
Definition Types.h:137
std::ptrdiff_t getBitWidth() const override
Definition Types.h:145
std::vector< std::pair< std::string, const Type * > > FieldVector
Definition Types.h:139
FieldVector fields
Definition Types.h:157
StructType(const ID &id, const FieldVector &fields)
Definition Types.h:141
const FieldVector & getFields() const
Definition Types.h:144
Root class of the ESI type system.
Definition Types.h:27
ID id
Definition Types.h:37
virtual ~Type()=default
Type(const ID &id)
Definition Types.h:30
virtual std::ptrdiff_t getBitWidth() const
Definition Types.h:34
std::string ID
Definition Types.h:29
ID getID() const
Definition Types.h:33
Unsigned integer.
Definition Types.h:131
The "void" type is a special type which can be used to represent no type.
Definition Types.h:81
VoidType(const ID &id)
Definition Types.h:83
std::ptrdiff_t getBitWidth() const override
Definition Types.h:85
Definition esi.py:1