P4C
The P4 Compiler
Loading...
Searching...
No Matches
targets/tofino/tofino/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 BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_TOFINO_TOFINO_PROGRAM_INFO_H_
21#define BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_TOFINO_TOFINO_PROGRAM_INFO_H_
22
23#include <cstddef>
24#include <map>
25#include <vector>
26
27#include "backends/tofino/bf-p4c/ir/gress.h"
28#include "ir/ir.h"
29
30#include "backends/p4tools/modules/testgen/lib/continuation.h"
31#include "backends/p4tools/modules/testgen/targets/tofino/shared_program_info.h"
32
33namespace P4::P4Tools::P4Testgen::Tofino {
34
35class TofinoProgramInfo : public TofinoSharedProgramInfo {
36 private:
39 std::vector<Continuation::Command> processDeclaration(const IR::Type_Declaration *typeDecl,
40 size_t pipeIdx) const;
41
42 [[nodiscard]] std::vector<std::vector<Continuation::Command>> pipelineCmds(gress_t gress) const;
43
44 [[nodiscard]] std::optional<const IR::Expression *> getPipePortRangeConstraint(
45 const IR::StateVariable &portVar, size_t pipeIdx) const override;
46
47 [[nodiscard]] const IR::Expression *getValidPortConstraint(
48 const IR::StateVariable &portVar) const override;
49
50 public:
51 TofinoProgramInfo(const TofinoCompilerResult &compilerResult, std::vector<PipeInfo> inputPipes,
52 std::map<int, gress_t> declIdToGress, std::map<int, size_t> declIdToPipe);
53
55 [[nodiscard]] const ArchSpec &getArchSpec() const override;
56
57 [[nodiscard]] const IR::StateVariable &getTargetInputPortVar() const override;
58
59 [[nodiscard]] const IR::StateVariable &getTargetOutputPortVar() const override;
60
61 [[nodiscard]] const IR::Expression *dropIsActive() const override;
62
63 [[nodiscard]] std::vector<std::vector<Continuation::Command>> ingressCmds() const override;
64
65 [[nodiscard]] std::vector<std::vector<Continuation::Command>> egressCmds() const override;
66
68 static const ArchSpec ARCH_SPEC;
69
70 DECLARE_TYPEINFO(TofinoProgramInfo, TofinoSharedProgramInfo);
71};
72
73} // namespace P4::P4Tools::P4Testgen::Tofino
74
75#endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_TOFINO_TOFINO_PROGRAM_INFO_H_ */
Specifies a canonical representation of the target pipeline as documented in P4 code.
Definition p4tools/common/lib/arch_spec.h:13
Extends the CompilerResult with information specific to the V1Model running on BMv2.
Definition modules/testgen/targets/tofino/compiler_result.h:10
static const ArchSpec ARCH_SPEC
Definition targets/tofino/tofino/program_info.h:68
const IR::Expression * dropIsActive() const override
Definition targets/tofino/tofino/program_info.cpp:280
const IR::StateVariable & getTargetInputPortVar() const override
Definition targets/tofino/tofino/program_info.cpp:268
const IR::StateVariable & getTargetOutputPortVar() const override
Definition targets/tofino/tofino/program_info.cpp:274
const ArchSpec & getArchSpec() const override
Definition targets/tofino/tofino/program_info.cpp:285
std::vector< std::vector< Continuation::Command > > ingressCmds() const override
Definition targets/tofino/tofino/program_info.cpp:44
std::vector< std::vector< Continuation::Command > > egressCmds() const override
Definition targets/tofino/tofino/program_info.cpp:48
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 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