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 BMV2 {
26
28 public:
29 static Util::JsonObject *find_object_by_name(Util::JsonArray *array, const cstring &name);
30
31 void add_program_info(const cstring &name);
32 void add_meta_info();
33 unsigned add_header_type(const cstring &name, Util::JsonArray *&fields, unsigned max_length);
34 unsigned add_union_type(const cstring &name, Util::JsonArray *&fields);
35 unsigned add_union(const cstring &type, Util::JsonArray *&fields, const cstring &name);
36 unsigned add_header_type(const cstring &name);
37 void add_header_field(const cstring &name, Util::JsonArray *&field);
38 unsigned add_header(const cstring &type, const cstring &name);
39 unsigned add_metadata(const cstring &type, const cstring &name);
40 void add_header_stack(const cstring &type, const cstring &name, const unsigned size,
41 const std::vector<unsigned> &header_ids);
42 void add_header_union_stack(const cstring &type, const cstring &name, const unsigned size,
43 const std::vector<unsigned> &header_ids);
44 void add_error(const cstring &name, const unsigned type);
45 void add_enum(const cstring &enum_name, const cstring &entry_name, const unsigned entry_value);
46 unsigned add_parser(const cstring &name);
47 unsigned add_parser_state(const unsigned id, const cstring &state_name);
48 void add_parser_transition(const unsigned id, Util::IJson *transition);
49 void add_parser_op(const unsigned id, Util::IJson *op);
50 void add_parser_transition_key(const unsigned id, Util::IJson *key);
51 void add_parse_vset(const cstring &name, const unsigned bitwidth, const big_int &size);
52 unsigned add_action(const cstring &name, Util::JsonArray *&params, Util::JsonArray *&body);
53 void add_extern_attribute(const cstring &name, const cstring &type, const cstring &value,
55 void add_extern(const cstring &name, const cstring &type, Util::JsonArray *attributes);
60 Util::JsonObject *create_primitive(Util::JsonArray *parent, cstring name);
61 // Given a field list id returns the array of values called "elements"
62 Util::JsonArray *get_field_list_contents(unsigned id) const;
63
64 std::map<unsigned, Util::JsonObject *> map_parser;
65 std::map<unsigned, Util::JsonObject *> map_parser_state;
66
67 Util::JsonObject *toplevel;
68 Util::JsonObject *meta;
69 Util::JsonArray *actions;
70 Util::JsonArray *calculations;
71 Util::JsonArray *checksums;
72 Util::JsonArray *counters;
73 Util::JsonArray *deparsers;
74 Util::JsonArray *enums;
75 Util::JsonArray *errors;
76 Util::JsonArray *externs;
77 Util::JsonArray *field_lists;
78 Util::JsonArray *headers;
79 Util::JsonArray *header_stacks;
80 Util::JsonArray *header_types;
81 Util::JsonArray *header_union_types;
82 Util::JsonArray *header_unions;
83 Util::JsonArray *header_union_stacks;
86 Util::JsonArray *learn_lists;
87 Util::JsonArray *meter_arrays;
88 Util::JsonArray *parsers;
89 Util::JsonArray *parse_vsets;
90 Util::JsonArray *pipelines;
91 Util::JsonArray *register_arrays;
92 Util::JsonArray *force_arith;
93 Util::JsonArray *field_aliases;
94};
95
96} // namespace BMV2
97
98#endif /* BACKENDS_BMV2_COMMON_JSONOBJECTS_H_ */
Definition JsonObjects.h:27
unsigned add_header_type(const cstring &name, Util::JsonArray *&fields, unsigned max_length)
Definition JsonObjects.cpp:116
void add_error(const cstring &name, const unsigned type)
Add an error to json.
Definition JsonObjects.cpp:261
unsigned add_parser_state(const unsigned id, const cstring &state_name)
Definition JsonObjects.cpp:309
Util::JsonArray * create_parameters(Util::JsonObject *object)
Insert a json array named 'parameters' in a parent json object.
Definition JsonObjects.cpp:92
Util::JsonArray * insert_array_field(Util::JsonObject *parent, cstring name)
Insert a json array to a parent object under key 'name'.
Definition JsonObjects.cpp:78
Util::JsonArray * append_array(Util::JsonArray *parent)
Append a json array to a parent json array.
Definition JsonObjects.cpp:85
void add_enum(const cstring &enum_name, const cstring &entry_name, const unsigned entry_value)
Definition JsonObjects.cpp:269
unsigned add_union(const cstring &type, Util::JsonArray *&fields, const cstring &name)
Create a header_union instance in json.
Definition JsonObjects.cpp:201
unsigned add_header(const cstring &type, const cstring &name)
Create a header instance in json.
Definition JsonObjects.cpp:187
void add_header_field(const cstring &name, Util::JsonArray *&field)
Definition JsonObjects.cpp:178
Definition sharedActionSelectorCheck.h:40
Definition json.h:40
Definition json.h:111
Definition json.h:158
Definition cstring.h:72