P4C
The P4 Compiler
Loading...
Searching...
No Matches
externInstance.h
1/*
2 * SPDX-FileCopyrightText: 2013 Barefoot Networks, Inc.
3 * Copyright 2013-present Barefoot Networks, Inc.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef FRONTENDS_P4_EXTERNINSTANCE_H_
9#define FRONTENDS_P4_EXTERNINSTANCE_H_
10
11#include <optional>
12
13#include "frontends/p4/parameterSubstitution.h"
14#include "lib/cstring.h"
15
16namespace P4::IR {
17class ConstructorCallExpression;
18class Expression;
19class IAnnotated;
20class PathExpression;
21class Type_Extern;
22class TypeMap;
23template <typename T>
24class Vector;
25} // namespace P4::IR
26
27namespace P4 {
28
29class ReferenceMap;
30class TypeMap;
31
42struct ExternInstance final {
43 const std::optional<cstring> name; // The instance's name, if any.
44 const IR::Expression *expression; // The original expression passed to resolve().
45 const IR::Type_Extern *type; // The type of the instance.
46 const IR::Vector<IR::Type> *typeArguments; // The instance's type arguments;
47 const IR::Vector<IR::Argument> *arguments; // The instance's constructor arguments.
48 ParameterSubstitution substitution; // Mapping from parameter names to arguments
49 const IR::IAnnotated *annotations; // If non-null, the instance's annotations.
50
61 static std::optional<ExternInstance> resolve(
62 const IR::Expression *expr, ReferenceMap *refMap, TypeMap *typeMap,
63 const std::optional<cstring> &defaultName = std::nullopt);
64
69 static std::optional<ExternInstance> resolve(const IR::PathExpression *path,
70 ReferenceMap *refMap, TypeMap *typeMap);
71
79 static std::optional<ExternInstance> resolve(
80 const IR::ConstructorCallExpression *constructorCallExpr, ReferenceMap *refMap,
81 TypeMap *typeMap, const std::optional<cstring> &name = std::nullopt);
82};
83
84} // namespace P4
85
86#endif /* FRONTENDS_P4_EXTERNINSTANCE_H_ */
Definition ir/vector.h:59
Definition parameterSubstitution.h:30
Class used to encode maps from paths to declarations.
Definition referenceMap.h:67
Definition typeMap.h:32
Definition constantParsing.h:22
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13
Definition externInstance.h:42
static std::optional< ExternInstance > resolve(const IR::Expression *expr, ReferenceMap *refMap, TypeMap *typeMap, const std::optional< cstring > &defaultName=std::nullopt)
Definition externInstance.cpp:15