CIRCT 22.0.0git
Loading...
Searching...
No Matches
ModelInstance.cpp
Go to the documentation of this file.
1//===- ModelInstance.cpp - Instance of a model in the ArcRuntime ----------===//
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 implements the context for a model instance in the ArcRuntime library.
10//
11//===----------------------------------------------------------------------===//
12
14
15#include <cassert>
16#include <iostream>
17#include <string_view>
18#include <vector>
19
20namespace circt::arc::runtime {
21
22// Global counter for instances
23static uint64_t instanceIDsGlobal = 0;
24
26 const char *args, ArcState *state)
27 : instanceID(instanceIDsGlobal++), modelInfo(modelInfo), state(state) {
28 parseArgs(args);
29 if (verbose) {
30 std::cout << "[ArcRuntime] "
31 << "Created instance"
32 << " of model \"" << getModelName() << "\""
33 << " with ID " << instanceID << std::endl;
34 }
35}
36
38 if (verbose) {
39 std::cout << "[ArcRuntime] "
40 << "Deleting instance"
41 << " of model \"" << getModelName() << "\""
42 << " with ID " << instanceID << " after " << stepCounter
43 << " step(s)" << std::endl;
44 }
45 assert(state->impl == static_cast<void *>(this) && "Inconsistent ArcState");
46 state->impl = nullptr;
47}
48
49void ModelInstance::parseArgs(const char *args) {
50 if (!args)
51 return;
52
53 // Split the argument string at semicolon delimiters
54 auto argStr = std::string_view(args);
55 if (argStr.empty())
56 return;
57 std::vector<std::string_view> options;
58 size_t start = 0;
59 size_t end = 0;
60
61 while ((end = argStr.find(";", start)) != std::string_view::npos) {
62 options.push_back(argStr.substr(start, end - start));
63 start = end + 1;
64 }
65 if (start <= argStr.size())
66 options.push_back(argStr.substr(start));
67
68 // Parse the individual options
69 for (auto &option : options) {
70 if (option == "debug")
71 verbose = true;
72 }
73}
74
75} // namespace circt::arc::runtime
assert(baseType &&"element must be base type")
const char * getModelName() const
static uint64_t instanceIDsGlobal
Static information for a compiled hardware model, generated by the MLIR lowering.
Definition Common.h:57
Combined runtime and model state for a hardware model instance.
Definition Common.h:40
void * impl
Runtime implementation specific data. Usually points to a custom struct.
Definition Common.h:42