1#ifndef BACKENDS_P4TOOLS_MODULES_SMITH_COMMON_SCOPE_H_
2#define BACKENDS_P4TOOLS_MODULES_SMITH_COMMON_SCOPE_H_
13#include "lib/cstring.h"
15namespace P4::P4Tools::P4Smith {
18 bool require_scalar{
false};
19 bool compile_time_known{
false};
20 bool no_methodcalls{
false};
22 bool not_negative{
false};
23 bool byte_align_headers{
false};
31 bool const_header_stack_index{
false};
32 bool const_lshift_count{
false};
33 bool single_stage_actions{
false};
34 int max_phv_container_width{0};
37 int max_bitwidth{128};
44 bool width_unknown{
false};
45 bool has_methodcall{
false};
46 bool in_action{
false};
50 const IR::Type *ret_type =
nullptr;
57 static std::vector<IR::Vector<IR::Node> *>
scope;
63 static std::map<cstring, std::map<int, std::set<cstring>>>
lvalMap;
66 static std::map<cstring, std::map<int, std::set<cstring>>>
lvalMapRw;
89 static void addToScope(
const IR::Node *n);
90 static void startLocalScope();
91 static void endLocalScope();
93 static void addLval(
const IR::Type *tp,
cstring name,
bool read_only =
false);
94 static bool checkLval(
const IR::Type *tp,
bool must_write =
false);
95 static cstring pickLval(
const IR::Type *tp,
bool must_write =
false);
96 static void deleteLval(
const IR::Type *tp,
cstring name);
97 static std::set<cstring> getCandidateLvals(
const IR::Type *tp,
bool must_write =
true);
98 static bool hasWriteableLval(
cstring typeKey);
99 static std::optional<std::map<int, std::set<cstring>>> getWriteableLvalForTypeKey(
102 static const IR::Type_Bits *pickDeclaredBitType(
bool must_write =
false);
104 static const IR::Type_Declaration *getTypeByName(
cstring name);
108 template <
typename T>
109 static std::vector<const T *> getDecls() {
110 std::vector<const T *> ret;
112 for (
auto *subScope :
scope) {
113 for (
const auto *node : *subScope) {
114 if (
const T *tmpObj = node->to<T>()) {
115 ret.push_back(tmpObj);
122 static std::vector<const IR::Type_Declaration *> getFilteredDecls(std::set<cstring> filter);
123 static std::set<const IR::P4Table *> *getCallableTables();
Definition tofino/bf-p4c/phv/constraints/constraints.cpp:21