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
toolName, std::string deviceName, 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 BUG_CHECK(instances.count(
toolName),
"Architecture %1% on device %2% not supported for %3%",
87 curTarget->archName, curTarget->deviceName,
toolName);
89 const auto *instance = instances.at(
toolName);
90 const auto *casted =
dynamic_cast<const TargetImpl *
>(instance);
91 BUG_CHECK(casted,
"%1%/%2% implementation for %3% has wrong type", curTarget->deviceName,
98 static std::optional<Spec> curTarget;
101 static std::map<Spec, std::map<std::string, const Target *>> registry;
104 static std::map<std::string, std::string> defaultArchByDevice;
107 static std::map<std::string, std::string> defaultDeviceByArch;