P4C
The P4 Compiler
Loading...
Searching...
No Matches
JsonObjects.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 BACKENDS_BMV2_COMMON_JSONOBJECTS_H_
18#define BACKENDS_BMV2_COMMON_JSONOBJECTS_H_
19
20#include <map>
21
22#include "lib/json.h"
23#include "lib/ordered_map.h"
24
25namespace P4::BMV2 {
26
28 public:
34
37 void add_program_info(const cstring &name);
38
40 void add_meta_info();
41
48 unsigned add_header_type(const cstring &name, Util::JsonArray *&fields, unsigned max_length);
49
54 unsigned add_union_type(const cstring &name, Util::JsonArray *&fields);
55
61 unsigned add_union(const cstring &type, Util::JsonArray *&fields, const cstring &name);
62
69 unsigned add_header_type(const cstring &name);
70
74 void add_header_field(const cstring &name, Util::JsonArray *&field);
75
80 unsigned add_header(const cstring &type, const cstring &name);
81
86 unsigned add_metadata(const cstring &type, const cstring &name);
87
93 void add_header_stack(const cstring &type, const cstring &name, const unsigned size,
94 const std::vector<unsigned> &header_ids);
95
101 void add_header_union_stack(const cstring &type, const cstring &name, const unsigned size,
102 const std::vector<unsigned> &header_ids);
103
107 void add_error(const cstring &name, const unsigned type);
108
113 void add_enum(const cstring &enum_name, const cstring &entry_name, const unsigned entry_value);
114
118 unsigned add_parser(const cstring &name);
119
124 unsigned add_parser_state(const unsigned id, const cstring &state_name);
125
129 void add_parser_transition(const unsigned id, Util::IJson *transition);
130
134 void add_parser_op(const unsigned id, Util::IJson *op);
135
139 void add_parser_transition_key(const unsigned id, Util::IJson *key);
140
145 void add_parse_vset(const cstring &name, const unsigned bitwidth, const big_int &size);
146
152 unsigned add_action(const cstring &name, Util::JsonArray *&params, Util::JsonArray *&body);
153
159 void add_extern_attribute(const cstring &name, const cstring &type, const cstring &value,
160 Util::JsonArray *attributes);
161
166 void add_extern(const cstring &name, const cstring &type, Util::JsonArray *attributes);
167
170 JsonObjects();
171
175
180
185
196 Util::JsonArray *get_field_list_contents(unsigned id) const;
197
198 std::map<unsigned, Util::JsonObject *> map_parser;
199 std::map<unsigned, Util::JsonObject *> map_parser_state;
200
201 Util::JsonObject *toplevel;
202 Util::JsonObject *meta;
203 Util::JsonArray *actions;
204 Util::JsonArray *calculations;
205 Util::JsonArray *checksums;
206 Util::JsonArray *counters;
207 Util::JsonArray *deparsers;
208 Util::JsonArray *enums;
209 Util::JsonArray *errors;
210 Util::JsonArray *externs;
211 Util::JsonArray *field_lists;
212 Util::JsonArray *headers;
213 Util::JsonArray *header_stacks;
214 Util::JsonArray *header_types;
215 Util::JsonArray *header_union_types;
216 Util::JsonArray *header_unions;
217 Util::JsonArray *header_union_stacks;
220 Util::JsonArray *learn_lists;
221 Util::JsonArray *meter_arrays;
222 Util::JsonArray *parsers;
223 Util::JsonArray *parse_vsets;
224 Util::JsonArray *pipelines;
225 Util::JsonArray *register_arrays;
226 Util::JsonArray *force_arith;
227 Util::JsonArray *field_aliases;
228};
229
230} // namespace P4::BMV2
231
232#endif /* BACKENDS_BMV2_COMMON_JSONOBJECTS_H_ */
Definition JsonObjects.h:27
void add_extern(const cstring &name, const cstring &type, Util::JsonArray *attributes)
Adds an extern instance to the JSON representation.
Definition JsonObjects.cpp:379
void add_header_stack(const cstring &type, const cstring &name, const unsigned size, const std::vector< unsigned > &header_ids)
Adds a header stack to the JSON representation.
Definition JsonObjects.cpp:217
void add_header_field(const cstring &name, Util::JsonArray *&field)
Adds a set of fields to an existing header type.
Definition JsonObjects.cpp:169
Util::JsonArray * create_parameters(Util::JsonObject *object)
Creates a JSON array named 'parameters' in a parent JsonObject.
Definition JsonObjects.cpp:89
void add_parse_vset(const cstring &name, const unsigned bitwidth, const big_int &size)
Adds a parse vset to the JSON representation.
Definition JsonObjects.cpp:345
void add_program_info(const cstring &name)
Adds program information to the top-level JsonObject.
Definition JsonObjects.cpp:93
void add_parser_op(const unsigned id, Util::IJson *op)
Adds a parser operation to an existing parser state in the JSON representation.
Definition JsonObjects.cpp:324
Util::JsonArray * append_array(Util::JsonArray *parent)
Appends a JSON array to a parent JSON array.
Definition JsonObjects.cpp:83
void add_error(const cstring &name, const unsigned type)
Adds an error to the JSON representation.
Definition JsonObjects.cpp:249
unsigned add_metadata(const cstring &type, const cstring &name)
Creates a metadata header instance in JSON.
Definition JsonObjects.cpp:204
unsigned add_header(const cstring &type, const cstring &name)
Creates a header instance in JSON.
Definition JsonObjects.cpp:177
unsigned add_action(const cstring &name, Util::JsonArray *&params, Util::JsonArray *&body)
Adds an action to the JSON representation.
Definition JsonObjects.cpp:356
unsigned add_parser_state(const unsigned id, const cstring &state_name)
Adds a parser state to an existing parser in the JSON representation.
Definition JsonObjects.cpp:293
unsigned add_header_type(const cstring &name, Util::JsonArray *&fields, unsigned max_length)
Create a header type in json.
Definition JsonObjects.cpp:110
static Util::JsonObject * find_object_by_name(Util::JsonArray *array, const cstring &name)
Finds an object in a JSON array by its name.
Definition JsonObjects.cpp:66
void add_parser_transition_key(const unsigned id, Util::IJson *key)
Adds a parser transition key to an existing parser state in the JSON representation.
Definition JsonObjects.cpp:333
unsigned add_parser(const cstring &name)
Adds a parser to the JSON representation.
Definition JsonObjects.cpp:279
void add_enum(const cstring &enum_name, const cstring &entry_name, const unsigned entry_value)
Adds a single enum entry to the JSON representation.
Definition JsonObjects.cpp:255
Util::JsonObject * create_primitive(Util::JsonArray *parent, cstring name)
Creates a primitive JsonObject in a parent JsonArray with the given name.
Util::JsonArray * insert_array_field(Util::JsonObject *parent, cstring name)
Inserts a JSON array into a parent object under a specified key.
Definition JsonObjects.cpp:77
void add_meta_info()
Adds meta information to the JsonObject.
Definition JsonObjects.cpp:95
Util::JsonArray * get_field_list_contents(unsigned id) const
Retrieves the contents of a field list identified by its ID.
Definition JsonObjects.cpp:55
void add_extern_attribute(const cstring &name, const cstring &type, const cstring &value, Util::JsonArray *attributes)
Adds an extern attribute to the JSON representation.
Definition JsonObjects.cpp:370
unsigned add_union(const cstring &type, Util::JsonArray *&fields, const cstring &name)
Creates a header union instance in JSON.
Definition JsonObjects.cpp:190
unsigned add_union_type(const cstring &name, Util::JsonArray *&fields)
Creates a union type in JSON.
Definition JsonObjects.cpp:133
JsonObjects()
Constructs a new JsonObjects instance. Initializes the top-level JsonObject and other member arrays.
Definition JsonObjects.cpp:27
void add_header_union_stack(const cstring &type, const cstring &name, const unsigned size, const std::vector< unsigned > &header_ids)
Adds a header union stack to the JSON representation.
Definition JsonObjects.cpp:233
void add_parser_transition(const unsigned id, Util::IJson *transition)
Adds a parser transition to an existing parser state in the JSON representation.
Definition JsonObjects.cpp:313
Definition json.h:40
Definition json.h:115
Definition json.h:164
Definition cstring.h:85
Definition ordered_map.h:32
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition action.cpp:21