Parsers can have local vars like controls
@@ -17,6 +17,7 @@ from utils.codegen import format_expr, format_statement, statement_buffer_value,
#[ #include "dpdk_lib.h"
+#[ #include "util_packet.h"
#[ extern int get_var_width_bitwidth();
@@ -79,25 +80,34 @@ def gen_extract_header_2(hdrinst, hdrtype, w):
################################################################################
+# TODO more than one parser can be present
parser = hlir16.objects['P4Parser'][0]
+
+#{ void init_parser_state(parser_state_t* pstate) {
for l in parser.parserLocals:
- #[ ${format_declaration(l)}
+ if l.node_type == 'Declaration_Instance':
+ #[ ${l.type.type_ref.name}_t_init(pstate->${l.name});
+#} }
for s in parser.states:
#[ static void parser_state_${s.name}(packet_descriptor_t* pd, uint8_t* buf, lookup_table_t** tables, parser_state_t* pstate);
for s in parser.states:
- if s.node_type != 'ParserState': continue
-
#[ static void parser_state_${s.name}(packet_descriptor_t* pd, uint8_t* buf, lookup_table_t** tables, parser_state_t* pstate) {
#[ uint32_t value32; (void)value32;
#[ uint32_t res32; (void)res32;
+ #[ parser_state_t* local_vars = pstate;
#[ debug(" :::: Parser state $$[parserstate]{s.name}\n");
for c in s.components:
- if hasattr(c, 'call'):
- if c.call == 'extract_header':
+ if not hasattr(c, 'call'):
+ #[ ${format_statement(c, parser)}
+ continue
+
+ if c.call != 'extract_header':
+ continue
+
hdrtype = c.header.type_ref if hasattr(c.header, 'type_ref') else c.header
# TODO find a more universal way to get to the header instance
@@ -136,8 +146,6 @@ for s in parser.states:
#[ dbg_bytes(pstate->${hdrinst.ref.name}, (($hdr_width + $var_width)+7)/8,
#[ " :: Extracted header $$[header]{hdrinst.path.name} of type $${hdrinst.type.name}: ($${hdr_width}+$${}{%d} bits, $${}{%d} bytes): ",
#[ $var_width, (($hdr_width + $var_width)+7)/8);
- else:
- #[ ${format_statement(c)}
if not hasattr(s, 'selectExpression'):
if s.name == 'accept':
