P4C
The P4 Compiler
Loading...
Searching...
No Matches
ResolveNegativeExtract::CollectNegativeExtractStates Struct Reference

#include <resolve_negative_extract.h>

Inheritance diagram for ResolveNegativeExtract::CollectNegativeExtractStates:
[legend]

Public Member Functions

 CollectNegativeExtractStates (const CollectParserInfo &pi)
 
void end_apply () override
 
profile_t init_apply (const IR::Node *node) override
 
bool preorder (const IR::BFN::PacketRVal *rval) override
 

Public Attributes

const CollectParserInfoparserInfo
 
std::map< const IR::BFN::Transition *, unsigned > remainder_before_exit
 Transitions exiting parser with unconsumed bytes in the packet buffer.
 
std::map< const IR::BFN::Transition *, std::pair< const IR::BFN::ParserState *, int > > state_to_duplicate
 Duplicate the given node and set the shift value.
 
std::map< cstring, unsigned > state_to_shift
 In-buffer offsets of states.
 
std::map< cstring, std::map< const IR::BFN::ParserMatchValue *, unsigned > > transition_shift
 Output shift values for given transitions - key is the source node and value is a map transition -> value.
 

Detailed Description

Colect all negative extract states and compute corresponding shift values for transitions and states

Member Data Documentation

◆ state_to_duplicate

std::map<const IR::BFN::Transition *, std::pair<const IR::BFN::ParserState *, int> > ResolveNegativeExtract::CollectNegativeExtractStates::state_to_duplicate

Duplicate the given node and set the shift value.

The state_to_duplicate variable is used to store the states that need to be duplicated. The key is the transition that needs to be duplicated and the value is a pair of the state to be duplicated and the shift value.

For example, the following parser:

A(shift = 36) ----> B(shift = 2) | ^ | | |----> C(shift = 0) —|

is transformed to

A(shift = 31) ----> B'(shift = 5) | |----> C(shift = 5) -----> B(shift = 2)

We need to duplicate state B and set its shift value to 5. The transition from A to B is the key and the value is a pair of B and 5.

Before this fix, the parser graph is transformed into:

A(shift = 31) ----> B(shift = 7) | ^ | | |---> C(shift = 5) -—|

This would be wrong, as the total shift amount on the packet that goes though A -> C -> B is 31 + 5 + 7 = 43, which is 5 bytes more than the the correct shift value 38.