P4C
The P4 Compiler
Loading...
Searching...
No Matches
externInstance.h
1/*
2Copyright 2013-present Barefoot Networks, Inc.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#ifndef FRONTENDS_P4_EXTERNINSTANCE_H_
18#define FRONTENDS_P4_EXTERNINSTANCE_H_
19
20#include <optional>
21
22#include "frontends/p4/parameterSubstitution.h"
23#include "lib/cstring.h"
24
25namespace P4::IR {
26class ConstructorCallExpression;
27class Expression;
28class IAnnotated;
29class PathExpression;
30class Type_Extern;
31class TypeMap;
32template <typename T>
33class Vector;
34} // namespace P4::IR
35
36namespace P4 {
37
38class ReferenceMap;
39class TypeMap;
40
51struct ExternInstance final {
52 const std::optional<cstring> name; // The instance's name, if any.
53 const IR::Expression *expression; // The original expression passed to resolve().
54 const IR::Type_Extern *type; // The type of the instance.
55 const IR::Vector<IR::Type> *typeArguments; // The instance's type arguments;
56 const IR::Vector<IR::Argument> *arguments; // The instance's constructor arguments.
57 ParameterSubstitution substitution; // Mapping from parameter names to arguments
58 const IR::IAnnotated *annotations; // If non-null, the instance's annotations.
59
70 static std::optional<ExternInstance> resolve(
71 const IR::Expression *expr, ReferenceMap *refMap, TypeMap *typeMap,
72 const std::optional<cstring> &defaultName = std::nullopt);
73
78 static std::optional<ExternInstance> resolve(const IR::PathExpression *path,
79 ReferenceMap *refMap, TypeMap *typeMap);
80
88 static std::optional<ExternInstance> resolve(
89 const IR::ConstructorCallExpression *constructorCallExpr, ReferenceMap *refMap,
90 TypeMap *typeMap, const std::optional<cstring> &name = std::nullopt);
91};
92
93} // namespace P4
94
95#endif /* FRONTENDS_P4_EXTERNINSTANCE_H_ */
Definition vector.h:59
Definition parameterSubstitution.h:30
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition typeMap.h:41
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
Definition externInstance.h:51
static std::optional< ExternInstance > resolve(const IR::Expression *expr, ReferenceMap *refMap, TypeMap *typeMap, const std::optional< cstring > &defaultName=std::nullopt)
Definition externInstance.cpp:26