1#ifndef BACKENDS_P4TOOLS_COMMON_CORE_TARGET_H_
2#define BACKENDS_P4TOOLS_COMMON_CORE_TARGET_H_
9#include "lib/exceptions.h"
21 std::string deviceName;
25 Spec(std::string deviceName, std::string archName);
35 static bool init(std::string deviceName, std::string archName);
43 static bool setDevice(std::string deviceName);
51 static bool setArch(std::string archName);
68 bool forceTaint)
const;
73 Target(std::string_view
toolName,
const std::string &deviceName,
const std::string &archName);
78 template <
class TargetImpl>
80 if (curTarget == std::nullopt) {
82 "Target not initialized. Please provide a target using the --target option.");
85 const auto &instances = registry.at(*curTarget);
86 auto instance = instances.find(
toolName);
87 BUG_CHECK(instance != instances.end(),
88 "Architecture %1% on device %2% not supported for %3%", curTarget->archName,
91 const auto *casted =
dynamic_cast<const TargetImpl *
>(instance->second);
92 BUG_CHECK(casted,
"%1%/%2% implementation for %3% has wrong type", curTarget->deviceName,
99 static std::optional<Spec> curTarget;
102 static std::map<Spec, std::map<std::string, const Target *, std::less<>>> registry;
105 static std::map<std::string, std::string, std::less<>> defaultArchByDevice;
108 static std::map<std::string, std::string, std::less<>> defaultDeviceByArch;