CIRCT 21.0.0git
Loading...
Searching...
No Matches
CLI.h
Go to the documentation of this file.
1//===- CLI.h - ESI runtime tool CLI parser common ---------------*- 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// This file contains the common CLI parser code for ESI runtime tools. Exposed
10// publicly so that out-of-tree tools can use it. This is a header-only library
11// to make compilation easier for out-of-tree tools.
12//
13// DO NOT EDIT!
14// This file is distributed as part of an ESI package. The source for this file
15// should always be modified within CIRCT (lib/dialect/ESI/runtime/cpp).
16//
17//===----------------------------------------------------------------------===//
18
19// NOLINTNEXTLINE(llvm-header-guard)
20#ifndef ESI_CLI_H
21#define ESI_CLI_H
22
23#include "CLI/CLI.hpp"
24#include "esi/Context.h"
25
26namespace esi {
27
28/// Common options and code for ESI runtime tools.
29class CliParser : public CLI::App {
30public:
31 CliParser(const std::string &toolName)
32 : CLI::App(toolName), debug(false), verbose(false) {
33 add_option("backend", backend, "Backend to use for connection")->required();
34 add_option("connection", connStr,
35 "Connection string to use for accelerator communication")
36 ->required();
37 add_flag("--debug", debug, "Enable debug logging");
38 add_flag("-v,--verbose", verbose, "Enable verbose (info) logging");
39 require_subcommand(0, 1);
40 }
41
42 /// Run the parser.
43 int esiParse(int argc, const char **argv) {
44 CLI11_PARSE(*this, argc, argv);
45 if (debug)
46 ctxt = Context::withLogger<ConsoleLogger>(Logger::Level::Debug);
47 else if (verbose)
48 ctxt = Context::withLogger<ConsoleLogger>(Logger::Level::Info);
49 return 0;
50 }
51
52 /// Connect to the accelerator using the specified backend and connection.
53 std::unique_ptr<AcceleratorConnection> connect() {
54 return ctxt.connect(backend, connStr);
55 }
56
57 /// Get the context.
58 Context &getContext() { return ctxt; }
59
60protected:
62
63 std::string backend;
64 std::string connStr;
65 bool debug;
66 bool verbose;
67};
68
69} // namespace esi
70
71#endif // ESI_CLI_H
Common options and code for ESI runtime tools.
Definition CLI.h:29
Context & getContext()
Get the context.
Definition CLI.h:58
bool verbose
Definition CLI.h:66
std::unique_ptr< AcceleratorConnection > connect()
Connect to the accelerator using the specified backend and connection.
Definition CLI.h:53
bool debug
Definition CLI.h:65
int esiParse(int argc, const char **argv)
Run the parser.
Definition CLI.h:43
std::string backend
Definition CLI.h:63
Context ctxt
Definition CLI.h:61
std::string connStr
Definition CLI.h:64
CliParser(const std::string &toolName)
Definition CLI.h:31
AcceleratorConnections, Accelerators, and Manifests must all share a context.
Definition Context.h:31
std::unique_ptr< AcceleratorConnection > connect(std::string backend, std::string connection)
Connect to an accelerator backend.
Definition Context.cpp:27
Definition debug.py:1
Definition esi.py:1