CIRCT  19.0.0git
Context.h
Go to the documentation of this file.
1 //===- Context.h - Accelerator context --------------------------*- 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_CONTEXT_H
17 #define ESI_CONTEXT_H
18 
19 #include "esi/Types.h"
20 
21 #include <exception>
22 #include <memory>
23 #include <optional>
24 
25 namespace esi {
26 class AcceleratorConnection;
27 
28 /// AcceleratorConnections, Accelerators, and Manifests must all share a
29 /// context. It owns all the types, uniquifying them.
30 class Context {
31 
32 public:
33  /// Resolve a type id to the type.
34  std::optional<const Type *> getType(Type::ID id) const {
35  if (auto f = types.find(id); f != types.end())
36  return f->second.get();
37  return std::nullopt;
38  }
39 
40  /// Register a type with the context. Takes ownership of the type and returns
41  /// the pointer which users should use.
42  void registerType(Type *type);
43 
44  /// Connect to an accelerator backend.
45  std::unique_ptr<AcceleratorConnection> connect(std::string backend,
46  std::string connection);
47 
48 private:
49  using TypeCache = std::map<Type::ID, std::unique_ptr<Type>>;
51 };
52 
53 } // namespace esi
54 
55 #endif // ESI_CONTEXT_H
AcceleratorConnections, Accelerators, and Manifests must all share a context.
Definition: Context.h:30
TypeCache types
Definition: Context.h:50
std::map< Type::ID, std::unique_ptr< Type > > TypeCache
Definition: Context.h:49
std::optional< const Type * > getType(Type::ID id) const
Resolve a type id to the type.
Definition: Context.h:34
std::unique_ptr< AcceleratorConnection > connect(std::string backend, std::string connection)
Connect to an accelerator backend.
Definition: Context.cpp:27
void registerType(Type *type)
Register a type with the context.
Definition: Context.cpp:20
Root class of the ESI type system.
Definition: Types.h:27
std::string ID
Definition: Types.h:29
Definition: esi.py:1