17#ifdef CIRCT_LIBFST_ENABLED
35 const char *args,
ArcState *mutableState)
43 std::cout <<
"[ArcRuntime] "
47 std::cout <<
"[ArcRuntime] Model \"" <<
getModelName() <<
"\"";
48 if (hasTraceInstrumentation)
49 std::cout <<
" has trace instrumentation." << std::endl;
51 std::cout <<
" does not have trace instrumentation." << std::endl;
56 <<
"[ArcRuntime] WARNING: "
57 <<
"Tracing has been requested but model \"" <<
getModelName()
58 <<
"\" contains no instrumentation."
59 <<
" No trace will be produced.\n\t\tMake sure to compile the model"
60 " with tracing enabled and that it contains observed signals."
63 if (hasTraceInstrumentation) {
67 std::make_unique<DummyTraceEncoder>(
modelInfo, mutableState);
74#ifdef CIRCT_LIBFST_ENABLED
78 std::cerr <<
"[ArcRuntime] ERROR: FST tracing was requested but CIRCT "
79 "was not built with FST support (CIRCT_LIBFST_ENABLED=OFF)."
82 std::make_unique<DummyTraceEncoder>(
modelInfo, mutableState);
93 std::cout <<
"[ArcRuntime] "
94 <<
"Deleting instance"
97 <<
" step(s)" << std::endl;
99 assert(
state->
impl ==
static_cast<void *
>(
this) &&
"Inconsistent ArcState");
107 if (it !=
arguments.end() && it->second.has_value())
108 return std::filesystem::path(*it->second);
110 std::string saneName;
113 for (
auto &c : saneName) {
114 if (c ==
' ' || c ==
'/' || c ==
'\\')
120 return std::filesystem::current_path() / std::filesystem::path(saneName);
136 std::cout <<
"[ArcRuntime] "
137 <<
"Instance with ID " <<
instanceID <<
" initialized"
145 "swapTraceBuffer called on model without trace instrumentation");
147 std::cout <<
"[ArcRuntime] Consuming trace buffer of size "
158static std::map<std::string, std::optional<std::string>>
160 std::map<std::string, std::optional<std::string>> result;
162 enum class State { Key, AfterEq, Unquoted, Quoted, Escape, AfterQuote, Skip };
163 State state = State::Key;
167 bool hasValue =
false;
169 auto warn = [&](
const char *msg) {
170 std::cerr <<
"[ArcRuntime] WARNING: Malformed runtime argument: " << msg;
172 std::cerr <<
" for key \"" << key <<
"\"";
173 std::cerr <<
", ignoring\n";
177 result[std::move(key)] =
178 hasValue ? std::optional(std::move(value)) : std::nullopt;
185 auto skipToNext = [&] {
192 for (
size_t i = 0; i <= argStr.size(); ++i) {
193 const bool atEnd = (i == argStr.size());
194 const char c = atEnd ?
'\0' : argStr[i];
198 if (atEnd || c ==
';') {
201 }
else if (std::isgraph(
static_cast<unsigned char>(c)) && c !=
'"' &&
204 }
else if (c ==
'=' && !key.empty()) {
206 state = State::AfterEq;
214 if (c ==
'"' && !atEnd) {
215 state = State::Quoted;
216 }
else if (atEnd || c ==
';') {
220 state = State::Unquoted;
224 case State::Unquoted:
225 if (atEnd || c ==
';') {
227 }
else if (c ==
'"') {
228 warn(
"Unquoted value contains forbidden character '\"'");
237 warn(
"Unterminated quoted value");
239 }
else if (c ==
'"') {
240 state = State::AfterQuote;
241 }
else if (c ==
'\\') {
242 state = State::Escape;
250 warn(
"Truncated escape sequence in quoted value");
252 }
else if (c ==
'"' || c ==
'\\') {
254 state = State::Quoted;
256 warn(
"Invalid escape sequence in quoted value");
261 case State::AfterQuote:
262 if (atEnd || c ==
';') {
265 warn(
"Unexpected content after closing quote");
271 if (!atEnd && c ==
';')
283 auto argStr = std::string_view(args);
295 std::cout <<
"[ArcRuntime] Argument string for instance ID " <<
instanceID
296 <<
": " << argStr << std::endl;
297 std::cout <<
"[ArcRuntime] Parsed argument(s):" << std::endl;
298 for (
const auto &[key, value] :
arguments) {
299 std::cout <<
"[ArcRuntime] " << key;
300 if (value.has_value())
301 std::cout <<
" = \"" << *value <<
"\"";
302 std::cout << std::endl;
assert(baseType &&"element must be base type")
std::filesystem::path getTraceFilePath(const std::string &suffix)
void onEval(ArcState *mutableState)
void parseArgs(const char *args)
std::unique_ptr< TraceEncoder > traceEncoder
std::map< std::string, std::optional< std::string > > arguments
const ArcState *const state
const uint64_t instanceID
void onInitialized(ArcState *mutableState)
const char * getModelName() const
uint64_t * swapTraceBuffer()
const ArcRuntimeModelInfo *const modelInfo
static std::map< std::string, std::optional< std::string > > parseArgsToMap(std::string_view argStr)
static void fatalError(const char *message)
Raise an irrecoverable error.
static uint64_t instanceIDsGlobal
Static information for a compiled hardware model, generated by the MLIR lowering.
struct ArcModelTraceInfo * traceInfo
Signal tracing information. NULL iff the model is not trace instrumented.
const char * modelName
Name of the compiled model.
Combined runtime and model state for a hardware model instance.
void * impl
Runtime implementation specific data. Usually points to a custom struct.
uint32_t traceBufferSize
Number of valid elements in the active trace buffer.