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 std::string_view
toolName,
const std::vector<const char *> &args);
84 std::string_view
toolName, std::string_view target, std::string_view arch);
89 Target(std::string_view
toolName,
const std::string &deviceName,
const std::string &archName);
97 template <
class TargetImpl>
99 if (curTarget == std::nullopt) {
101 "Target not initialized. Please provide a target using the --target option.");
104 const auto &instances = registry.at(*curTarget);
105 auto instance = instances.find(
toolName);
106 BUG_CHECK(instance != instances.end(),
107 "Architecture %1% on device %2% not supported for %3%", curTarget->archName,
110 const auto *casted =
dynamic_cast<const TargetImpl *
>(instance->second);
111 BUG_CHECK(casted,
"%1%/%2% implementation for %3% has wrong type", curTarget->deviceName,
118 static std::optional<Spec> curTarget;
121 static std::map<Spec, std::map<std::string, const Target *, std::less<>>> registry;
124 static std::map<std::string, std::string, std::less<>> defaultArchByDevice;
127 static std::map<std::string, std::string, std::less<>> defaultDeviceByArch;
Definition compile_context.h:24