CIRCT  18.0.0git
esiquery.cpp
Go to the documentation of this file.
1 //===- esiquery.cpp - ESI accelerator system query tool -------------------===//
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 // (lib/dialect/ESI/runtime/cpp/lib/backends/Cosim.cpp).
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #include "esi/Accelerator.h"
17 #include "esi/Manifest.h"
18 #include "esi/StdServices.h"
19 
20 #include <iostream>
21 #include <map>
22 #include <stdexcept>
23 
24 using namespace std;
25 
26 using namespace esi;
27 
28 void printInfo(ostream &os, Accelerator &acc);
29 
30 int main(int argc, const char *argv[]) {
31  // TODO: find a command line parser library rather than doing this by hand.
32  if (argc < 3) {
33  cerr << "Expected usage: " << argv[0]
34  << " <backend> <connection specifier> [command]" << endl;
35  return -1;
36  }
37 
38  const char *backend = argv[1];
39  const char *conn = argv[2];
40  string cmd;
41  if (argc > 3)
42  cmd = argv[3];
43 
44  try {
45  unique_ptr<Accelerator> acc = registry::connect(backend, conn);
46  const auto &info = *acc->getService<services::SysInfo>();
47 
48  if (cmd == "version")
49  cout << "ESI system version: " << info.getEsiVersion() << endl;
50  else if (cmd == "json_manifest")
51  cout << info.getJsonManifest() << endl;
52  else if (cmd == "info")
53  printInfo(cout, *acc);
54  // TODO: add a command to print out the instance hierarchy.
55  else {
56  cout << "Connection successful." << endl;
57  if (!cmd.empty()) {
58  cerr << "Unknown command: " << cmd << endl;
59  return 1;
60  }
61  }
62  return 0;
63  } catch (exception &e) {
64  cerr << "Error: " << e.what() << endl;
65  return -1;
66  }
67 }
68 
69 void printInfo(ostream &os, Accelerator &acc) {
70  string jsonManifest = acc.getService<services::SysInfo>()->getJsonManifest();
71  Manifest m(jsonManifest);
72  os << "API version: " << m.getApiVersion() << endl << endl;
73  os << "********************************" << endl;
74  os << "* Design information" << endl;
75  os << "********************************" << endl;
76  os << endl;
77  for (ModuleInfo mod : m.getModuleInfos())
78  os << mod << endl;
79 
80  os << "********************************" << endl;
81  os << "* Type table" << endl;
82  os << "********************************" << endl;
83  os << endl;
84  size_t i = 0;
85  for (Type t : m.getTypeTable())
86  os << " " << i++ << ": " << t.getID() << endl;
87 }
An ESI accelerator system.
Definition: Accelerator.h:104
ServiceClass * getService(AppIDPath id={}, ServiceImplDetails details={}, HWClientDetails clients={})
Get a typed reference to a particular service type.
Definition: Accelerator.h:113
Class to parse a manifest.
Definition: Manifest.h:88
uint32_t getApiVersion() const
Definition: Manifest.cpp:422
const std::vector< std::reference_wrapper< const Type > > & getTypeTable() const
The Type Table is an ordered list of types.
Definition: Manifest.cpp:443
std::vector< ModuleInfo > getModuleInfos() const
Definition: Manifest.cpp:426
Root class of the ESI type system.
Definition: Types.h:32
Information about the Accelerator system.
Definition: StdServices.h:31
virtual uint32_t getEsiVersion() const =0
Get the ESI version number to check version compatibility.
void printInfo(ostream &os, Accelerator &acc)
Definition: esiquery.cpp:69
int main(int argc, const char *argv[])
Definition: esiquery.cpp:30
def connect(destination, source)
Definition: support.py:37
Definition: esi.py:1