P4C
The P4 Compiler
Loading...
Searching...
No Matches
tofino/shared_program_info.h
1/*******************************************************************************
2 * Copyright (C) 2024 Intel Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing,
11 * software distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions
14 * and limitations under the License.
15 *
16 *
17 * SPDX-License-Identifier: Apache-2.0
18 ******************************************************************************/
19
20#ifndef TESTGEN_TARGETS_TOFINO_SHARED_PROGRAM_INFO_H_
21#define TESTGEN_TARGETS_TOFINO_SHARED_PROGRAM_INFO_H_
22
23#include <vector>
24
25#include "backends/p4tools/modules/testgen/core/program_info.h"
26#include "backends/p4tools/modules/testgen/targets/tofino/compiler_result.h"
27
28namespace P4::P4Tools::P4Testgen::Tofino {
29
30class TofinoSharedProgramInfo : public ProgramInfo {
31 public:
32 using PipeInfo = struct {
33 cstring pipeName;
35 };
36
37 protected:
39 const std::vector<PipeInfo> pipes;
40
42 const std::map<int, gress_t> declIdToGress;
43
45 const std::map<int, size_t> declIdToPipe;
46
48 static const IR::Type_Bits parserErrBits;
49
50 public:
51 explicit TofinoSharedProgramInfo(const TofinoCompilerResult &compilerResult,
52 std::vector<PipeInfo> inputPipes,
53 std::map<int, gress_t> declIdToGress,
54 std::map<int, size_t> declIdToPipe);
55
57 gress_t getGress(const IR::Type_Declaration *decl) const;
58
60 size_t getPipeIdx(const IR::Type_Declaration *decl) const;
61
62 // @returns whether the current program is a multi-pipe program.
63 [[nodiscard]] bool isMultiPipe() const;
64
66 const IR::P4Table *getTableofDirectExtern(const IR::IDeclaration *directExternDecl) const;
67
69 [[nodiscard]] const std::vector<PipeInfo> *getPipes() const;
70
72 [[nodiscard]] virtual std::vector<std::vector<Continuation::Command>> ingressCmds() const = 0;
73
75 [[nodiscard]] virtual std::vector<std::vector<Continuation::Command>> egressCmds() const = 0;
76
79 static const IR::Expression *getBackendConstraint(const IR::StateVariable &portVar);
80
81 [[nodiscard]] virtual const IR::Expression *getValidPortConstraint(
82 const IR::StateVariable &portVar) const = 0;
83
84 [[nodiscard]] virtual std::optional<const IR::Expression *> getPipePortRangeConstraint(
85 const IR::StateVariable &portVar, size_t pipeIdx) const = 0;
86
87 IR::StateVariable getParserParamVar(const IR::P4Parser *parser, const IR::Type *type,
88 size_t paramIndex, cstring paramLabel) const;
89
90 [[nodiscard]] const IR::Type_Bits *getParserErrorType() const override;
91
92 [[nodiscard]] const TofinoCompilerResult &getCompilerResult() const override;
93
94 DECLARE_TYPEINFO(TofinoSharedProgramInfo, ProgramInfo);
95};
96
97} // namespace P4::P4Tools::P4Testgen::Tofino
98
99#endif /* TESTGEN_TARGETS_TOFINO_SHARED_PROGRAM_INFO_H_ */
The Declaration interface, representing objects with names.
Definition declaration.h:26
Extends the CompilerResult with information specific to the V1Model running on BMv2.
Definition modules/testgen/targets/tofino/compiler_result.h:10
const std::vector< PipeInfo > * getPipes() const
Definition tofino/shared_program_info.cpp:80
static const IR::Expression * getBackendConstraint(const IR::StateVariable &portVar)
Definition tofino/shared_program_info.cpp:86
const std::map< int, size_t > declIdToPipe
The declid of each top-level parser type, mapped to its corresponding Tofino pipe.
Definition tofino/shared_program_info.h:45
const TofinoCompilerResult & getCompilerResult() const override
Definition tofino/shared_program_info.cpp:136
static const IR::Type_Bits parserErrBits
The bit width of standard_metadata.parser_error.
Definition tofino/shared_program_info.h:48
virtual std::vector< std::vector< Continuation::Command > > ingressCmds() const =0
const IR::P4Table * getTableofDirectExtern(const IR::IDeclaration *directExternDecl) const
Definition tofino/shared_program_info.cpp:70
const std::map< int, gress_t > declIdToGress
The declid of each top-level parser type, mapped to its corresponding gress.
Definition tofino/shared_program_info.h:42
const std::vector< PipeInfo > pipes
The parser, MAU, and deparser, for each gress and pipe in the program.
Definition tofino/shared_program_info.h:39
virtual std::vector< std::vector< Continuation::Command > > egressCmds() const =0
gress_t getGress(const IR::Type_Declaration *decl) const
Definition tofino/shared_program_info.cpp:60
size_t getPipeIdx(const IR::Type_Declaration *decl) const
Definition tofino/shared_program_info.cpp:64
Definition cstring.h:85
Definition ordered_map.h:32