CIRCT 22.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#ifdef ESI_RUNTIME_TRACE
39 add_flag("--trace", trace, "Enable trace logging");
40#endif
41 add_flag("-v,--verbose", verbose, "Enable verbose (info) logging");
42 require_subcommand(0, 1);
43 }
44
45 /// Run the parser.
46 int esiParse(int argc, const char **argv) {
47 CLI11_PARSE(*this, argc, argv);
48 if (trace)
49 ctxt = Context::withLogger<ConsoleLogger>(Logger::Level::Trace);
50 else if (debug)
51 ctxt = Context::withLogger<ConsoleLogger>(Logger::Level::Debug);
52 else if (verbose)
53 ctxt = Context::withLogger<ConsoleLogger>(Logger::Level::Info);
54 else
55 ctxt = Context::withLogger<ConsoleLogger>(Logger::Level::Warning);
56 return 0;
57 }
58
59 /// Connect to the accelerator using the specified backend and connection.
61
62 /// Get the context.
63 Context &getContext() { return *ctxt; }
64
65protected:
66 std::unique_ptr<Context> ctxt;
67
68 std::string backend;
69 std::string connStr;
70 bool trace = false;
71 bool debug = false;
72 bool verbose = false;
73};
74
75} // namespace esi
76
77#endif // ESI_CLI_H
Abstract class representing a connection to an accelerator.
Definition Accelerator.h:79
Common options and code for ESI runtime tools.
Definition CLI.h:29
Context & getContext()
Get the context.
Definition CLI.h:63
bool verbose
Definition CLI.h:72
AcceleratorConnection * connect()
Connect to the accelerator using the specified backend and connection.
Definition CLI.h:60
std::unique_ptr< Context > ctxt
Definition CLI.h:66
int esiParse(int argc, const char **argv)
Run the parser.
Definition CLI.h:46
bool trace
Definition CLI.h:70
std::string backend
Definition CLI.h:68
std::string connStr
Definition CLI.h:69
CliParser(const std::string &toolName)
Definition CLI.h:31
AcceleratorConnections, Accelerators, and Manifests must all share a context.
Definition Context.h:34
Definition debug.py:1
Definition esi.py:1