P4C
The P4 Compiler
Loading...
Searching...
No Matches
frontends/common/model.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_COMMON_MODEL_H_
18#define FRONTENDS_COMMON_MODEL_H_
19
20#include "ir/id.h"
21#include "lib/cstring.h"
22
23// Classes for representing various P4 program models inside the compiler
24
25namespace P4::Model {
26
27// Model element
28struct Elem {
29 explicit Elem(cstring name) : name(name) {}
30 Elem() = delete;
31
32 cstring name;
33 IR::ID Id() const { return IR::ID(name); }
34 IR::ID Id(Util::SourceInfo srcInfo) const { return IR::ID(srcInfo, name); }
35 IR::ID Id(Util::SourceInfo srcInfo, cstring originalName) const {
36 return IR::ID(srcInfo, name, originalName);
37 }
38 const char *str() const { return name.c_str(); }
39 cstring toString() const { return name; }
40};
41
42struct Type_Model : public Elem {
43 explicit Type_Model(cstring name) : Elem(name) {}
44};
45
47struct Enum_Model : public Type_Model {
48 explicit Enum_Model(cstring name) : Type_Model(name) {}
49};
50
52struct Extern_Model : public Type_Model {
53 explicit Extern_Model(cstring name) : Type_Model(name) {}
54};
55
57struct Param_Model : public Elem {
58 const Type_Model type;
59 const unsigned index;
60 Param_Model(cstring name, Type_Model type, unsigned index)
61 : Elem(name), type(type), index(index) {}
62};
63
64class Model {};
65
66} // namespace P4::Model
67
68#endif /* FRONTENDS_COMMON_MODEL_H_ */
Definition frontends/common/model.h:64
Definition source_file.h:125
Definition cstring.h:85
Definition id.h:28
Definition frontends/common/model.h:28
Enum_Model : Type_Model.
Definition frontends/common/model.h:47
Extern_Model : Type_Model.
Definition frontends/common/model.h:52
Param_Model : Elem.
Definition frontends/common/model.h:57
Definition frontends/common/model.h:42