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