P4C
The P4 Compiler
Loading...
Searching...
No Matches
enumInstance.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_ENUMINSTANCE_H_
9#define FRONTENDS_P4_ENUMINSTANCE_H_
10
11#include "frontends/p4/typeMap.h"
12#include "ir/ir.h"
13#include "methodInstance.h"
14
15namespace P4 {
16
17// helps resolving references to compile-time enum fields, e.g., X.a
18class EnumInstance : public InstanceBase {
19 protected:
20 EnumInstance(const IR::ID name, const IR::Type *type, const P4::TypeMap *typeMap)
21 : name(name), type(type), typeMap(typeMap) {}
22
23 public:
24 const IR::ID name;
25 const IR::Type *type;
26 const P4::TypeMap *typeMap;
27
30 static EnumInstance *resolve(const IR::Expression *expression, const P4::TypeMap *typeMap);
31 bool equals(const EnumInstance *other) const {
32 return typeMap->equivalent(type, other->type) && name.name == other->name.name;
33 }
34
35 DECLARE_TYPEINFO(EnumInstance, InstanceBase);
36};
37
39class SimpleEnumInstance : public EnumInstance {
40 public:
41 SimpleEnumInstance(const IR::Type_Enum *type, const IR::ID name, const P4::TypeMap *typeMap)
42 : EnumInstance(name, type, typeMap) {}
43
44 DECLARE_TYPEINFO(SimpleEnumInstance, EnumInstance);
45};
46
49class SerEnumInstance : public EnumInstance {
50 public:
51 const IR::Expression *value;
52 SerEnumInstance(const IR::Type_SerEnum *type, const IR::ID name, const IR::Expression *value,
53 const P4::TypeMap *typeMap)
54 : EnumInstance(name, type, typeMap), value(value) {}
55
56 DECLARE_TYPEINFO(SerEnumInstance, EnumInstance);
57};
58
59} // namespace P4
60
61#endif /* FRONTENDS_P4_ENUMINSTANCE_H_ */
static EnumInstance * resolve(const IR::Expression *expression, const P4::TypeMap *typeMap)
Definition enumInstance.cpp:11
Definition methodInstance.h:18
Definition typeMap.h:32
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13
Definition id.h:19