CIRCT 20.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 <map>
20#include <cstdint>
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
57protected:
59};
60
61/// Channels are the basic communication primitives. They are unidirectional and
62/// carry one values of one type.
63class ChannelType : public Type {
64public:
65 ChannelType(const ID &id, const Type *inner) : Type(id), inner(inner) {}
66 const Type *getInner() const { return inner; }
67 std::ptrdiff_t getBitWidth() const override { return inner->getBitWidth(); };
68
69private:
70 const Type *inner;
71};
72
73/// The "void" type is a special type which can be used to represent no type.
74class VoidType : public Type {
75public:
76 VoidType(const ID &id) : Type(id) {}
77 // 'void' is 1 bit by convention.
78 std::ptrdiff_t getBitWidth() const override { return 1; };
79};
80
81/// The "any" type is a special type which can be used to represent any type, as
82/// identified by the type id. Said type id is guaranteed to be present in the
83/// manifest. Importantly, the "any" type id over the wire may not be a string
84/// as it is in software.
85class AnyType : public Type {
86public:
87 AnyType(const ID &id) : Type(id) {}
88 std::ptrdiff_t getBitWidth() const override { return -1; };
89};
90
91/// Bit vectors include signed, unsigned, and signless integers.
92class BitVectorType : public Type {
93public:
94 BitVectorType(const ID &id, uint64_t width) : Type(id), width(width) {}
95
96 uint64_t getWidth() const { return width; }
97 std::ptrdiff_t getBitWidth() const override { return getWidth(); };
98
99private:
100 uint64_t width;
101};
102
103/// Bits are just an array of bits. They are not interpreted as a number but are
104/// identified in the manifest as "signless" ints.
105class BitsType : public BitVectorType {
106public:
108};
109
110/// Integers are bit vectors which may be signed or unsigned and are interpreted
111/// as numbers.
113public:
115};
116
117/// Signed integer.
118class SIntType : public IntegerType {
119public:
120 using IntegerType::IntegerType;
121};
122
123/// Unsigned integer.
124class UIntType : public IntegerType {
125public:
126 using IntegerType::IntegerType;
127};
128
129/// Structs are an ordered collection of fields, each with a name and a type.
130class StructType : public Type {
131public:
132 using FieldVector = std::vector<std::pair<std::string, const Type *>>;
133
134 StructType(const ID &id, const FieldVector &fields)
135 : Type(id), fields(fields) {}
136
137 const FieldVector &getFields() const { return fields; }
138 std::ptrdiff_t getBitWidth() const override {
139 std::ptrdiff_t size = 0;
140 for (auto [name, ty] : getFields()) {
141 std::ptrdiff_t fieldSize = ty->getBitWidth();
142 if (fieldSize < 0)
143 return -1;
144 size += fieldSize;
145 }
146 return size;
147 }
148
149private:
151};
152
153/// Arrays have a compile time specified (static) size and an element type.
154class ArrayType : public Type {
155public:
156 ArrayType(const ID &id, const Type *elementType, uint64_t size)
158
159 const Type *getElementType() const { return elementType; }
160 uint64_t getSize() const { return size; }
161 std::ptrdiff_t getBitWidth() const override {
162 std::ptrdiff_t elementSize = elementType->getBitWidth();
163 if (elementSize < 0)
164 return -1;
165 return elementSize * size;
166 }
167
168private:
170 uint64_t size;
171};
172
173} // namespace esi
174
175#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:85
std::ptrdiff_t getBitWidth() const override
Definition Types.h:88
AnyType(const ID &id)
Definition Types.h:87
Arrays have a compile time specified (static) size and an element type.
Definition Types.h:154
uint64_t size
Definition Types.h:170
ArrayType(const ID &id, const Type *elementType, uint64_t size)
Definition Types.h:156
const Type * elementType
Definition Types.h:169
const Type * getElementType() const
Definition Types.h:159
std::ptrdiff_t getBitWidth() const override
Definition Types.h:161
uint64_t getSize() const
Definition Types.h:160
Bit vectors include signed, unsigned, and signless integers.
Definition Types.h:92
BitVectorType(const ID &id, uint64_t width)
Definition Types.h:94
uint64_t width
Definition Types.h:100
std::ptrdiff_t getBitWidth() const override
Definition Types.h:97
uint64_t getWidth() const
Definition Types.h:96
Bits are just an array of bits.
Definition Types.h:105
Bundles represent a collection of channels.
Definition Types.h:44
BundleType(const ID &id, const ChannelVector &channels)
Definition Types.h:51
std::ptrdiff_t getBitWidth() const override
Definition Types.h:55
const ChannelVector & getChannels() const
Definition Types.h:54
ChannelVector channels
Definition Types.h:58
std::vector< std::tuple< std::string, Direction, const Type * > > ChannelVector
Definition Types.h:49
Channels are the basic communication primitives.
Definition Types.h:63
ChannelType(const ID &id, const Type *inner)
Definition Types.h:65
const Type * getInner() const
Definition Types.h:66
const Type * inner
Definition Types.h:70
std::ptrdiff_t getBitWidth() const override
Definition Types.h:67
Integers are bit vectors which may be signed or unsigned and are interpreted as numbers.
Definition Types.h:112
Signed integer.
Definition Types.h:118
Structs are an ordered collection of fields, each with a name and a type.
Definition Types.h:130
std::ptrdiff_t getBitWidth() const override
Definition Types.h:138
std::vector< std::pair< std::string, const Type * > > FieldVector
Definition Types.h:132
FieldVector fields
Definition Types.h:150
StructType(const ID &id, const FieldVector &fields)
Definition Types.h:134
const FieldVector & getFields() const
Definition Types.h:137
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:124
The "void" type is a special type which can be used to represent no type.
Definition Types.h:74
VoidType(const ID &id)
Definition Types.h:76
std::ptrdiff_t getBitWidth() const override
Definition Types.h:78
Definition esi.py:1