P4C
The P4 Compiler
Loading...
Searching...
No Matches
model.h
1
/*
2
Copyright 2013-present Barefoot Networks, Inc.
3
4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7
8
http://www.apache.org/licenses/LICENSE-2.0
9
10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations 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
25
namespace
Model {
26
27
// Model element
28
struct
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
42
struct
Type_Model
:
public
Elem
{
43
explicit
Type_Model
(
cstring
name) :
Elem
(name) {}
44
};
45
47
struct
Enum_Model
:
public
Type_Model
{
48
explicit
Enum_Model
(
cstring
name) :
Type_Model
(name) {}
49
};
50
52
struct
Extern_Model
:
public
Type_Model
{
53
explicit
Extern_Model
(
cstring
name) :
Type_Model
(name) {}
54
};
55
57
struct
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
64
class
Model
{};
65
66
}
// namespace Model
67
68
#endif
/* FRONTENDS_COMMON_MODEL_H_ */
Model::Model
Definition
model.h:64
Util::SourceInfo
Definition
source_file.h:126
cstring
Definition
cstring.h:72
Model::Elem
Definition
model.h:28
Model::Enum_Model
Enum_Model : Type_Model.
Definition
model.h:47
Model::Extern_Model
Extern_Model : Type_Model.
Definition
model.h:52
Model::Param_Model
Param_Model : Elem.
Definition
model.h:57
Model::Type_Model
Definition
model.h:42
frontends
common
model.h
Generated on Tue Mar 26 2024 for