7#ifndef BACKENDS_P4TOOLS_COMMON_CORE_TARGET_H_
8#define BACKENDS_P4TOOLS_COMMON_CORE_TARGET_H_
16#include "lib/compile_context.h"
17#include "lib/exceptions.h"
30 std::string deviceName;
34 Spec(std::string_view deviceName, std::string_view archName);
44 static bool init(std::string_view deviceName, std::string_view archName);
52 static bool setDevice(std::string_view deviceName);
60 static bool setArch(std::string_view archName);
77 bool forceTaint)
const;
82 const std::vector<const char *> &args);
84 std::string_view target,
85 std::string_view arch);
90 Target(std::string_view
toolName,
const std::string &deviceName,
const std::string &archName);
98 template <
class TargetImpl>
100 if (curTarget == std::nullopt) {
102 "Target not initialized. Please provide a target using the --target option.");
105 const auto &instances = registry.at(*curTarget);
106 auto instance = instances.find(
toolName);
107 BUG_CHECK(instance != instances.end(),
108 "Architecture %1% on device %2% not supported for %3%", curTarget->archName,
111 const auto *casted =
dynamic_cast<const TargetImpl *
>(instance->second);
112 BUG_CHECK(casted,
"%1%/%2% implementation for %3% has wrong type", curTarget->deviceName,
119 static std::optional<Spec> curTarget;
122 static std::map<Spec, std::map<std::string, const Target *, std::less<>>> registry;
125 static std::map<std::string, std::string, std::less<>> defaultArchByDevice;
128 static std::map<std::string, std::string, std::less<>> defaultDeviceByArch;
Definition compile_context.h:23