19#ifndef BACKENDS_TOFINO_BF_P4C_ARCH_PROGRAM_STRUCTURE_H_
20#define BACKENDS_TOFINO_BF_P4C_ARCH_PROGRAM_STRUCTURE_H_
22#include "bf-p4c/ir/gress.h"
23#include "frontends/common/resolveReferences/resolveReferences.h"
24#include "frontends/p4/evaluator/evaluator.h"
26#include "ir/namemap.h"
27#include "lib/ordered_set.h"
32using SimpleNameMap = std::map<cstring, cstring>;
51 : structName(sn), fieldName(fn), width(w), offset(0), isCG(
false) {}
54 : structName(sn), fieldName(fn), width(w), offset(o), isCG(
false) {}
57 : structName(sn), fieldName(fn), width(w), offset(0), isCG(isCG) {}
60 : structName(sn), fieldName(fn), width(w), offset(o), isCG(isCG) {}
62 cstring name() {
return structName +
"." + fieldName; }
65 if (structName != other.structName)
return structName < other.structName;
66 return fieldName < other.fieldName;
70 return structName == other.structName && fieldName == other.fieldName;
73 bool operator!=(
const MetadataField &a)
const {
return !(*
this == a); }
81 static const cstring INGRESS_PARSER;
83 static const cstring INGRESS_DEPARSER;
84 static const cstring EGRESS_PARSER;
86 static const cstring EGRESS_DEPARSER;
107 std::vector<const IR::Type_Action *> action_types;
113 std::set<cstring>
unique_names = {
"checksum"_cs,
"hash"_cs,
"random"_cs};
120 bool isIngressParser(
const IR::P4Parser *parser);
121 bool isIngress(
const IR::P4Control *control);
122 bool isIngressDeparser(
const IR::P4Control *control);
123 bool isEgressParser(
const IR::P4Parser *parser);
124 bool isEgress(
const IR::P4Control *control);
125 bool isEgressDeparser(
const IR::P4Control *control);
129 std::vector<const IR::Declaration *> ingressParserDeclarations;
130 std::vector<const IR::Declaration *> egressParserDeclarations;
131 std::vector<const IR::Declaration *> ingressDeclarations;
132 std::vector<const IR::Declaration *> egressDeclarations;
133 std::vector<const IR::Declaration *> ingressDeparserDeclarations;
134 std::vector<const IR::Declaration *> egressDeparserDeclarations;
138 std::vector<const IR::StatOrDecl *> ingressStatements;
139 std::vector<const IR::StatOrDecl *> egressStatements;
140 std::vector<const IR::StatOrDecl *> ingressDeparserStatements;
141 std::vector<const IR::StatOrDecl *> egressDeparserStatements;
156 std::map<MetadataField, MetadataField> egressMetadataNameMap;
157 std::set<MetadataField> targetMetadataSet;
161 (gress == gress_t::INGRESS) ? ingressMetadataNameMap : egressMetadataNameMap;
162 auto itr = nameMap.emplace(src, dst);
165 itr.first->second == dst,
166 "Cannot add metadata mapping %1% - %2% as mapping already exists to %1% - %3%",
167 src.name(), dst.name(), itr.first->second.name());
169 targetMetadataSet.insert(dst);
170 LOG3(
"Adding Metadata map on thread '" << gress);
171 LOG3(
" src : " << src <<
", dst : " << dst);
175 addMetadata(gress_t::INGRESS, src, dst);
176 addMetadata(gress_t::EGRESS, src, dst);
181 void createTofinoArch();
183 void createActions();
184 virtual void createParsers() = 0;
185 virtual void createControls() = 0;
186 virtual void createMain() = 0;
187 virtual const IR::P4Program *create(
const IR::P4Program *program) = 0;
Definition backends/common/programStructure.h:32
Definition ordered_map.h:32
Definition ordered_set.h:32
The namespace encapsulating Barefoot/Intel-specific stuff.
Definition add_t2na_meta.cpp:21
ordered_map< cstring, const IR::P4Control * > controls
Definition program_structure.h:103
ordered_map< const IR::Member *, const IR::Member * > pathsToDo
maintain the paths to translate and their thread info
Definition program_structure.h:149
ordered_map< const IR::Node *, const IR::Node * > _map
the translation map.
Definition program_structure.h:79
const IR::ToplevelBlock * toplevel
program control block names from P14
Definition program_structure.h:110
void include(cstring filename, IR::Vector< IR::Node > *decls)
ordered_map< cstring, cstring > blockNames
Definition program_structure.h:117
std::map< MetadataField, MetadataField > ingressMetadataNameMap
Definition program_structure.h:155
ordered_set< cstring > errors
target architecture types
Definition program_structure.h:95
std::set< cstring > unique_names
all unique names in the program
Definition program_structure.h:113