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};
41 bool width_unknown{
false};
42 bool has_methodcall{
false};
43 bool in_action{
false};
47 const IR::Type *ret_type =
nullptr;
48 Properties() =
default;
54 static std::vector<IR::Vector<IR::Node> *>
scope;
60 static std::map<cstring, std::map<int, std::set<cstring>>>
lvalMap;
63 static std::map<cstring, std::map<int, std::set<cstring>>>
lvalMapRw;
86 static void addToScope(
const IR::Node *n);
87 static void startLocalScope();
88 static void endLocalScope();
90 static void addLval(
const IR::Type *tp,
cstring name,
bool read_only =
false);
91 static bool checkLval(
const IR::Type *tp,
bool must_write =
false);
92 static cstring pickLval(
const IR::Type *tp,
bool must_write =
false);
93 static void deleteLval(
const IR::Type *tp,
cstring name);
94 static std::set<cstring> getCandidateLvals(
const IR::Type *tp,
bool must_write =
true);
95 static bool hasWriteableLval(
cstring typeKey);
96 static std::optional<std::map<int, std::set<cstring>>> getWriteableLvalForTypeKey(
99 static const IR::Type_Bits *pickDeclaredBitType(
bool must_write =
false);
101 static const IR::Type_Declaration *getTypeByName(
cstring name);
105 template <
typename T>
106 static std::vector<const T *> getDecls() {
107 std::vector<const T *> ret;
109 for (
auto *subScope :
scope) {
110 for (
const auto *node : *subScope) {
111 if (
const T *tmpObj = node->to<T>()) {
112 ret.push_back(tmpObj);
119 static std::vector<const IR::Type_Declaration *> getFilteredDecls(std::set<cstring> filter);
120 static std::set<const IR::P4Table *> *getCallableTables();