CIRCT  19.0.0git
Design.h
Go to the documentation of this file.
1 //===- Design.h - Dynamic accelerator API -----------------------*- 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 // The dynamic API into an accelerator allows access to the accelerator's design
10 // and communication channels through various stl containers (e.g. std::vector,
11 // std::map, etc.). This allows runtime reflection against the accelerator and
12 // can be pybind'd to create a Python API.
13 //
14 // The static API, in contrast, is a compile-time API that allows access to the
15 // design and communication channels symbolically. It will be generated once
16 // (not here) then compiled into the host software.
17 //
18 // Note for hardware designers: the "design hierarchy" from the host API
19 // perspective is not the same as the hardware module instance hierarchy.
20 // Rather, it is only the relevant parts as defined by the AppID hierarchy --
21 // levels in the hardware module instance hierarchy get skipped.
22 //
23 // DO NOT EDIT!
24 // This file is distributed as part of an ESI package. The source for this file
25 // should always be modified within CIRCT.
26 //
27 //===----------------------------------------------------------------------===//
28 
29 // NOLINTNEXTLINE(llvm-header-guard)
30 #ifndef ESI_DESIGN_H
31 #define ESI_DESIGN_H
32 
33 #include "esi/Manifest.h"
34 #include "esi/Ports.h"
35 #include "esi/Services.h"
36 
37 #include <string>
38 
39 namespace esi {
40 // Forward declarations.
41 class Instance;
42 namespace services {
43 class Service;
44 } // namespace services
45 
46 /// Represents either the top level or an instance of a hardware module.
47 class HWModule {
48 protected:
49  HWModule(std::optional<ModuleInfo> info,
50  std::vector<std::unique_ptr<Instance>> children,
51  std::vector<services::Service *> services,
52  std::vector<std::unique_ptr<BundlePort>> &ports);
53 
54 public:
55  virtual ~HWModule() = default;
56 
57  /// Access the module's metadata, if any.
58  std::optional<ModuleInfo> getInfo() const { return info; }
59  /// Get a vector of the module's children in a deterministic order.
60  std::vector<const Instance *> getChildrenOrdered() const {
61  std::vector<const Instance *> ret;
62  for (const auto &c : children)
63  ret.push_back(c.get());
64  return ret;
65  }
66  /// Access the module's children by ID.
67  const std::map<AppID, Instance *> &getChildren() const { return childIndex; }
68  /// Get the module's ports in a deterministic order.
69  std::vector<std::reference_wrapper<BundlePort>> getPortsOrdered() const {
70  std::vector<std::reference_wrapper<BundlePort>> ret;
71  for (const auto &p : ports)
72  ret.push_back(*p);
73  return ret;
74  }
75  /// Access the module's ports by ID.
76  const std::map<AppID, const BundlePort &> &getPorts() const {
77  return portIndex;
78  }
79 
80 protected:
81  const std::optional<ModuleInfo> info;
82  const std::vector<std::unique_ptr<Instance>> children;
83  const std::map<AppID, Instance *> childIndex;
84  const std::vector<services::Service *> services;
85  const std::vector<std::unique_ptr<BundlePort>> ports;
86  const std::map<AppID, const BundlePort &> portIndex;
87 };
88 
89 /// Subclass of `HWModule` which represents a submodule instance. Adds an AppID,
90 /// which the top level doesn't have or need.
91 class Instance : public HWModule {
92 public:
93  Instance() = delete;
94  Instance(const Instance &) = delete;
95  ~Instance() = default;
96  Instance(AppID id, std::optional<ModuleInfo> info,
97  std::vector<std::unique_ptr<Instance>> children,
98  std::vector<services::Service *> services,
99  std::vector<std::unique_ptr<BundlePort>> &ports)
100  : HWModule(info, std::move(children), services, ports), id(id) {}
101 
102  /// Get the instance's ID, which it will always have.
103  const AppID getID() const { return id; }
104 
105 protected:
106  const AppID id;
107 };
108 
109 } // namespace esi
110 
111 #endif // ESI_DESIGN_H
Represents either the top level or an instance of a hardware module.
Definition: Design.h:47
virtual ~HWModule()=default
const std::map< AppID, Instance * > & getChildren() const
Access the module's children by ID.
Definition: Design.h:67
const std::optional< ModuleInfo > info
Definition: Design.h:81
const std::vector< std::unique_ptr< BundlePort > > ports
Definition: Design.h:85
const std::vector< std::unique_ptr< Instance > > children
Definition: Design.h:82
HWModule(std::optional< ModuleInfo > info, std::vector< std::unique_ptr< Instance >> children, std::vector< services::Service * > services, std::vector< std::unique_ptr< BundlePort >> &ports)
Definition: Design.cpp:43
const std::vector< services::Service * > services
Definition: Design.h:84
const std::map< AppID, const BundlePort & > portIndex
Definition: Design.h:86
const std::map< AppID, Instance * > childIndex
Definition: Design.h:83
std::optional< ModuleInfo > getInfo() const
Access the module's metadata, if any.
Definition: Design.h:58
const std::map< AppID, const BundlePort & > & getPorts() const
Access the module's ports by ID.
Definition: Design.h:76
std::vector< const Instance * > getChildrenOrdered() const
Get a vector of the module's children in a deterministic order.
Definition: Design.h:60
std::vector< std::reference_wrapper< BundlePort > > getPortsOrdered() const
Get the module's ports in a deterministic order.
Definition: Design.h:69
Subclass of HWModule which represents a submodule instance.
Definition: Design.h:91
Instance(const Instance &)=delete
Instance(AppID id, std::optional< ModuleInfo > info, std::vector< std::unique_ptr< Instance >> children, std::vector< services::Service * > services, std::vector< std::unique_ptr< BundlePort >> &ports)
Definition: Design.h:96
Instance()=delete
const AppID getID() const
Get the instance's ID, which it will always have.
Definition: Design.h:103
const AppID id
Definition: Design.h:106
~Instance()=default
Parent class of all APIs modeled as 'services'.
Definition: Services.h:42
Definition: esi.py:1