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 pointer type.
41  void registerType(Type *type);
42 
43  /// Connect to an accelerator backend.
44  std::unique_ptr<AcceleratorConnection> connect(std::string backend,
45  std::string connection);
46 
47 private:
48  using TypeCache = std::map<Type::ID, std::unique_ptr<Type>>;
50 };
51 
52 } // namespace esi
53 
54 #endif // ESI_CONTEXT_H
AcceleratorConnections, Accelerators, and Manifests must all share a context.
Definition: Context.h:30
TypeCache types
Definition: Context.h:49
std::map< Type::ID, std::unique_ptr< Type > > TypeCache
Definition: Context.h:48
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. Takes ownership of the pointer type.
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