1#ifndef BACKENDS_P4TOOLS_COMMON_CORE_TARGET_H_
2#define BACKENDS_P4TOOLS_COMMON_CORE_TARGET_H_
10#include "lib/compile_context.h"
11#include "lib/exceptions.h"
24 std::string deviceName;
28 Spec(std::string_view deviceName, std::string_view archName);
38 static bool init(std::string_view deviceName, std::string_view archName);
46 static bool setDevice(std::string_view deviceName);
54 static bool setArch(std::string_view archName);
71 bool forceTaint)
const;
76 const std::vector<const char *> &args);
78 std::string_view target,
79 std::string_view arch);
84 Target(std::string_view
toolName,
const std::string &deviceName,
const std::string &archName);
92 template <
class TargetImpl>
94 if (curTarget == std::nullopt) {
96 "Target not initialized. Please provide a target using the --target option.");
99 const auto &instances = registry.at(*curTarget);
100 auto instance = instances.find(
toolName);
101 BUG_CHECK(instance != instances.end(),
102 "Architecture %1% on device %2% not supported for %3%", curTarget->archName,
105 const auto *casted =
dynamic_cast<const TargetImpl *
>(instance->second);
106 BUG_CHECK(casted,
"%1%/%2% implementation for %3% has wrong type", curTarget->deviceName,
113 static std::optional<Spec> curTarget;
116 static std::map<Spec, std::map<std::string, const Target *, std::less<>>> registry;
119 static std::map<std::string, std::string, std::less<>> defaultArchByDevice;
122 static std::map<std::string, std::string, std::less<>> defaultDeviceByArch;
Definition compile_context.h:32