-
Notifications
You must be signed in to change notification settings - Fork 0
/
portableSwitch.h
105 lines (87 loc) · 3.4 KB
/
portableSwitch.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
Copyright 2013-present Barefoot Networks, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef _BACKENDS_BMV2_PORTABLESWITCH_H_
#define _BACKENDS_BMV2_PORTABLESWITCH_H_
#include "ir/ir.h"
#include "lower.h"
#include "lib/gmputil.h"
#include "lib/json.h"
#include "frontends/common/resolveReferences/referenceMap.h"
#include "frontends/p4/coreLibrary.h"
#include "frontends/p4/enumInstance.h"
#include "frontends/p4/methodInstance.h"
#include "frontends/p4/typeMap.h"
#include "helpers.h"
namespace P4 {
using ::Model::Elem;
using ::Model::Type_Model;
using ::Model::Param_Model;
// Block has a name and a collection of elements
template<typename T>
struct Block_Model : public Type_Model {
std::vector<T> elems;
explicit Block_Model(cstring name) :
::Model::Type_Model(name) {}
};
/// Enum_Model : Block_Model<Elem> : Type_Model
struct Enum_Model : public Block_Model<Elem> {
::Model::Type_Model type;
explicit Enum_Model(cstring name) :
Block_Model(name), type("Enum") {}
};
/// Parser_Model : Block_Model<Param_Model> : Type_Model
struct Parser_Model : public Block_Model<Param_Model> {
::Model::Type_Model type;
explicit Parser_Model(cstring name) :
Block_Model<Param_Model>(name), type("Parser") {}
};
/// Control_Model : Block_Model<Param_Model> : Type_Model
struct Control_Model : public Block_Model<Param_Model> {
::Model::Type_Model type;
explicit Control_Model(cstring name) :
Block_Model<Param_Model>(name), type("Control") {}
};
/// Method_Model : Block_Model<Param_Model> : Type_Model
struct Method_Model : public Block_Model<Param_Model> {
::Model::Type_Model type;
explicit Method_Model(cstring name) :
Block_Model<Param_Model>(name), type("Method") {}
};
/// Extern_Model : Block_Model<Method_Model> : Type_Model
struct Extern_Model : public Block_Model<Method_Model> {
::Model::Type_Model type;
explicit Extern_Model(cstring name) :
Block_Model<Method_Model>(name), type("Extern") {}
};
/// PortableModel : Model::Model
class PortableModel : public ::Model::Model {
public:
std::vector<Parser_Model*> parsers;
std::vector<Control_Model*> controls;
std::vector<Extern_Model*> externs;
std::vector<Type_Model*> match_kinds;
bool find_match_kind(cstring kind_name);
bool find_extern(cstring extern_name);
static PortableModel instance;
PortableModel() : ::Model::Model("0.2") {}
};
} // namespace P4
std::ostream& operator<<(std::ostream &out, Model::Type_Model& m);
std::ostream& operator<<(std::ostream &out, Model::Param_Model& p);
std::ostream& operator<<(std::ostream &out, P4::PortableModel& e);
std::ostream& operator<<(std::ostream &out, P4::Method_Model& p);
std::ostream& operator<<(std::ostream &out, P4::Parser_Model* p);
std::ostream& operator<<(std::ostream &out, P4::Control_Model* p);
std::ostream& operator<<(std::ostream &out, P4::Extern_Model* p);
// portableSwitch
#endif /* _BACKENDS_BMV2_PORTABLESWITCH_H_ */