P4C
The P4 Compiler
Loading...
Searching...
No Matches
enumInstance.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_ENUMINSTANCE_H_
18#define FRONTENDS_P4_ENUMINSTANCE_H_
19
20#include "frontends/p4/typeMap.h"
21#include "ir/ir.h"
22#include "methodInstance.h"
23
24namespace P4 {
25
26// helps resolving references to compile-time enum fields, e.g., X.a
27class EnumInstance : public InstanceBase {
28 protected:
29 EnumInstance(const IR::ID name, const IR::Type *type, const P4::TypeMap *typeMap)
30 : name(name), type(type), typeMap(typeMap) {}
31
32 public:
33 const IR::ID name;
34 const IR::Type *type;
35 const P4::TypeMap *typeMap;
36
39 static EnumInstance *resolve(const IR::Expression *expression, const P4::TypeMap *typeMap);
40 bool equals(const EnumInstance *other) const {
41 return typeMap->equivalent(type, other->type) && name.name == other->name.name;
42 }
43
44 DECLARE_TYPEINFO(EnumInstance, InstanceBase);
45};
46
49 public:
50 SimpleEnumInstance(const IR::Type_Enum *type, const IR::ID name, const P4::TypeMap *typeMap)
51 : EnumInstance(name, type, typeMap) {}
52
53 DECLARE_TYPEINFO(SimpleEnumInstance, EnumInstance);
54};
55
59 public:
60 const IR::Expression *value;
61 SerEnumInstance(const IR::Type_SerEnum *type, const IR::ID name, const IR::Expression *value,
62 const P4::TypeMap *typeMap)
63 : EnumInstance(name, type, typeMap), value(value) {}
64
65 DECLARE_TYPEINFO(SerEnumInstance, EnumInstance);
66};
67
68} // namespace P4
69
70#endif /* FRONTENDS_P4_ENUMINSTANCE_H_ */
Definition enumInstance.h:27
static EnumInstance * resolve(const IR::Expression *expression, const P4::TypeMap *typeMap)
Definition enumInstance.cpp:22
Definition methodInstance.h:27
Definition enumInstance.h:58
An instance of a simple enum, e.g., X.A from enum X { A, B }.
Definition enumInstance.h:48
Definition typeMap.h:41
bool equivalent(const IR::Type *left, const IR::Type *right, bool strict=false) const
Definition typeMap.cpp:140
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
Definition id.h:28