P4C
The P4 Compiler
Loading...
Searching...
No Matches
P4::Visitor::ChangeTracker Class Reference

Assists visitors in traversing the IR. More...

Public Member Functions

 ChangeTracker (bool forceClone)
 
bool busy (const IR::Node *n) const
 
bool done (const IR::Node *n) const
 
const IR::NodefinalResult (const IR::Node *n) const
 
bool finish (const IR::Node *orig, const IR::Node *final)
 
const IR::Noderesult (const IR::Node *n) const
 
void revisit_visited ()
 
bool shouldVisitOnce (const IR::Node *n) const
 
VisitStatus try_start (const IR::Node *n, bool defaultVisitOnce)
 
void visitAgain (const IR::Node *n)
 
void visitOnce (const IR::Node *n)
 

Detailed Description

Assists visitors in traversing the IR.

A ChangeTracker object assists visitors traversing the IR by tracking each node. The start method begins tracking, and finish ends it. The done method determines whether the node has been visited, and result returns the new IR if it changed.

Member Function Documentation

◆ busy()

bool P4::Visitor::ChangeTracker::busy ( const IR::Node * n) const
inlinenodiscard

Determine whether
is currently being visited and the visitor has not finished That is, start(@n) has been invoked, and finish(@n) has not,

Returns
true if
is being visited and has not finished

◆ done()

bool P4::Visitor::ChangeTracker::done ( const IR::Node * n) const
inlinenodiscard

Determine whether
has been visited and the visitor has finished and we don't want to visit
again the next time we see it. That is, start(@n) has been invoked, followed by finish(@n), and the visitOnce field is true.

Returns
true if
has been visited and the visitor is finished and visitOnce is true

◆ finalResult()

const IR::Node * P4::Visitor::ChangeTracker::finalResult ( const IR::Node * n) const
inline

Produce the final result of visiting
.

Returns
The ultimate result of visiting
, or nullptr if finish(@n) has not been invoked.

◆ finish()

bool P4::Visitor::ChangeTracker::finish ( const IR::Node * orig,
const IR::Node * final )
inline

Mark the process of visiting @orig as finished, with @final being the final state of the node, or nullptr if the node was removed from the tree. done(@orig) will return true, and result(@orig) will return the resulting node, if any.

If @final is a new node, that node is marked as finished as well, as if start(@final); finish(@final); were invoked.

Returns
true if the node has changed or been removed or coalesced.
Exceptions
Util::CompilerBugThis method fails if `start(@orig)` has not previously been invoked.

◆ result()

const IR::Node * P4::Visitor::ChangeTracker::result ( const IR::Node * n) const
inline

Produce the result of visiting
.

Returns
The result of visiting
, or the intermediate result of visiting
if start(@n) has been invoked but not finish(@n), or
if start(@n) has not been invoked.

◆ revisit_visited()

void P4::Visitor::ChangeTracker::revisit_visited ( )
inline

Forget nodes that have already been visited, allowing them to be visited again.

◆ shouldVisitOnce()

bool P4::Visitor::ChangeTracker::shouldVisitOnce ( const IR::Node * n) const
inlinenodiscard

Return a visitOnce flag for node

◆ try_start()

VisitStatus P4::Visitor::ChangeTracker::try_start ( const IR::Node * n,
bool defaultVisitOnce )
inlinenodiscard

Begin tracking
during a visiting pass. Use finish(@n) to mark
as visited once the pass completes.

Returns
Status of the node
wrt visit: whether node is currently being visited (VisitStatus::Busy), or if node was already visited (VisitStatus::Done), node was never seen before (VisitStatus::New) or seen, but should be revisited (VisitStatus::Revisit).