2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
15 #ifndef included_vlib_parse_h
16 #define included_vlib_parse_h
18 #include <vlib/vlib.h>
20 #include <vppinfra/mhash.h>
23 /* Word aligned value. */
25 u8 as_u8[32 - 1 * sizeof (u16)];
32 /* 16 bit type at end so that 30 bytes of value are aligned. */
34 } __attribute ((packed)) vlib_parse_value_t;
36 /* Instance of a type. */
51 /* Index of item for this node. */
54 /* Graph index of peer (sibling) node (linked list of peers). */
57 /* Graph index of deeper (child) node (linked list of children). */
61 #define foreach_parse_match_type \
72 #define _(a) VLIB_PARSE_##a,
73 foreach_parse_match_type
77 struct vlib_parse_type;
78 struct vlib_parse_main;
80 typedef vlib_parse_match_t (vlib_parse_match_function_t)
81 (struct vlib_parse_main *,
82 struct vlib_parse_type *,
84 vlib_parse_value_t *);
85 typedef void (vlib_parse_value_cleanup_function_t) (vlib_parse_value_t *);
87 typedef struct vlib_parse_type {
91 vlib_parse_match_function_t * match_function;
93 vlib_parse_value_cleanup_function_t * value_cleanup_function;
95 format_function_t * format_value;
104 } parse_registration_t;
106 typedef struct vlib_parse_main {
107 /* (type, origin, help, value) tuples */
108 vlib_parse_item_t *parse_items;
109 mhash_t parse_item_hash;
111 /* (item, peer, deeper) tuples */
112 vlib_parse_graph_t *parse_graph;
118 vlib_parse_type_t * parse_types;
119 uword *parse_type_by_name_hash;
121 /* Vector of MATCH_VALUEs */
122 vlib_parse_value_t * parse_value;
125 /* Parse registrations */
126 parse_registration_t **parse_registrations;
129 vlib_lex_token_t *tokens;
130 u32 current_token_index;
132 vlib_lex_main_t *lex_main;
133 vlib_main_t *vlib_main;
136 vlib_parse_main_t vlib_parse_main;
138 typedef vlib_parse_match_t (vlib_parse_eval_function_t)
139 (vlib_parse_main_t *,
141 vlib_parse_value_t *);
143 vlib_parse_match_t vlib_parse_eval (u8 * input);
145 format_function_t format_vlib_parse_value;
147 /* FIXME need these to be global? */
148 vlib_parse_match_function_t rule_match, eof_match, word_match, number_match;
150 #define _PARSE_REGISTRATION_DATA(x) \
151 VLIB_ELF_SECTION_DATA(x##_registration,parse_registration_t,parse_registrations)
153 #define PARSE_INIT(x, s, e) \
154 static _PARSE_REGISTRATION_DATA(x) = { \
159 #define _PARSE_TYPE_REGISTRATION_DATA(x) \
160 VLIB_ELF_SECTION_DATA(x##_type_registration,vlib_parse_type_t, \
161 parse_type_registrations)
163 #define PARSE_TYPE_INIT(n, m, c, f) \
164 static _PARSE_TYPE_REGISTRATION_DATA(n) = { \
166 .match_function = m, \
167 .value_cleanup_function = c, \
171 #endif /* included_vlib_parse_h */