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

#include <toP4.h>

Inheritance diagram for P4::ToP4:
[legend]

Classes

struct  ListPrint
 
struct  VecPrint
 

Public Member Functions

 ToP4 (std::ostream *outStream, bool showIR)
 
 ToP4 (std::ostream *outStream, bool showIR, std::filesystem::path mainFile)
 
 ToP4 (Util::SourceCodeBuilder &builder, bool showIR)
 
 ToP4 (Util::SourceCodeBuilder &builder, bool showIR, std::filesystem::path mainFile)
 
void end_apply (const IR::Node *node) override
 
Visitor::profile_t init_apply (const IR::Node *node) override
 
bool preorder (const IR::AbstractSlice *slice) override
 
bool preorder (const IR::ActionList *v) override
 
bool preorder (const IR::ActionListElement *ale) override
 
bool preorder (const IR::Annotation *a) override
 
bool preorder (const IR::Argument *arg) override
 
bool preorder (const IR::ArrayIndex *a) override
 
bool preorder (const IR::AssignmentStatement *s) override
 
bool preorder (const IR::BlockStatement *s) override
 
bool preorder (const IR::BoolLiteral *b) override
 
bool preorder (const IR::BreakStatement *s) override
 
bool preorder (const IR::Cast *c) override
 
bool preorder (const IR::Constant *c) override
 
bool preorder (const IR::ConstructorCallExpression *e) override
 
bool preorder (const IR::ContinueStatement *s) override
 
bool preorder (const IR::Declaration_Constant *cst) override
 
bool preorder (const IR::Declaration_Instance *t) override
 
bool preorder (const IR::Declaration_MatchKind *d) override
 
bool preorder (const IR::Declaration_Variable *v) override
 
bool preorder (const IR::DefaultExpression *e) override
 
bool preorder (const IR::Dots *e) override
 
bool preorder (const IR::EmptyStatement *s) override
 
bool preorder (const IR::EntriesList *l) override
 
bool preorder (const IR::Entry *e) override
 
bool preorder (const IR::ExitStatement *s) override
 
bool preorder (const IR::ExpressionValue *v) override
 
bool preorder (const IR::ForInStatement *s) override
 
bool preorder (const IR::ForStatement *s) override
 
bool preorder (const IR::Function *function) override
 
bool preorder (const IR::HeaderStackExpression *e) override
 
bool preorder (const IR::IfStatement *s) override
 
bool preorder (const IR::IndexedVector< IR::Declaration > *v) override
 
bool preorder (const IR::IndexedVector< IR::Declaration_ID > *v) override
 
bool preorder (const IR::IndexedVector< IR::Node > *v) override
 
bool preorder (const IR::IndexedVector< IR::ParserState > *v) override
 
bool preorder (const IR::IndexedVector< IR::StatOrDecl > *v) override
 
bool preorder (const IR::Invalid *e) override
 
bool preorder (const IR::InvalidHeader *e) override
 
bool preorder (const IR::InvalidHeaderUnion *e) override
 
bool preorder (const IR::Key *v) override
 
bool preorder (const IR::ListExpression *e) override
 
bool preorder (const IR::Member *e) override
 
bool preorder (const IR::Method *p) override
 
bool preorder (const IR::MethodCallExpression *e) override
 
bool preorder (const IR::MethodCallStatement *s) override
 
bool preorder (const IR::Mux *a) override
 
bool preorder (const IR::NamedDots *e) override
 
bool preorder (const IR::NamedExpression *ne) override
 
virtual bool preorder (const IR::Node *)
 
bool preorder (const IR::Operation_Binary *b) override
 
bool preorder (const IR::Operation_Unary *u) override
 
bool preorder (const IR::P4Action *c) override
 
bool preorder (const IR::P4Control *c) override
 
bool preorder (const IR::P4ListExpression *e) override
 
bool preorder (const IR::P4Parser *c) override
 
bool preorder (const IR::P4Program *program) override
 
bool preorder (const IR::P4Table *c) override
 
bool preorder (const IR::P4ValueSet *c) override
 
bool preorder (const IR::Parameter *p) override
 
bool preorder (const IR::ParameterList *p) override
 
bool preorder (const IR::ParserState *s) override
 
bool preorder (const IR::Path *p) override
 
bool preorder (const IR::PathExpression *p) override
 
bool preorder (const IR::Property *p) override
 
bool preorder (const IR::ReturnStatement *s) override
 
bool preorder (const IR::SelectCase *e) override
 
bool preorder (const IR::SelectExpression *e) override
 
bool preorder (const IR::StringLiteral *s) override
 
bool preorder (const IR::StructExpression *e) override
 
bool preorder (const IR::SwitchCase *s) override
 
bool preorder (const IR::SwitchStatement *s) override
 
bool preorder (const IR::TableProperties *t) override
 
bool preorder (const IR::This *e) override
 
bool preorder (const IR::Type *t) override
 
bool preorder (const IR::Type_BaseList *t) override
 
bool preorder (const IR::Type_Bits *t) override
 
bool preorder (const IR::Type_Boolean *t) override
 
bool preorder (const IR::Type_Control *t) override
 
bool preorder (const IR::Type_Dontcare *t) override
 
bool preorder (const IR::Type_Enum *t) override
 
bool preorder (const IR::Type_Error *t) override
 
bool preorder (const IR::Type_Extern *t) override
 
bool preorder (const IR::Type_Header *t) override
 
bool preorder (const IR::Type_HeaderUnion *t) override
 
bool preorder (const IR::Type_InfInt *t) override
 
bool preorder (const IR::Type_Name *t) override
 
bool preorder (const IR::Type_Newtype *t) override
 
bool preorder (const IR::Type_Package *t) override
 
bool preorder (const IR::Type_Parser *t) override
 
bool preorder (const IR::Type_SerEnum *t) override
 
bool preorder (const IR::Type_Specialized *t) override
 
bool preorder (const IR::Type_SpecializedCanonical *t) override
 
bool preorder (const IR::Type_Stack *t) override
 
bool preorder (const IR::Type_String *t) override
 
bool preorder (const IR::Type_Struct *t) override
 
bool preorder (const IR::Type_Typedef *t) override
 
bool preorder (const IR::Type_Unknown *t) override
 
bool preorder (const IR::Type_Var *t) override
 
bool preorder (const IR::Type_Varbits *t) override
 
bool preorder (const IR::Type_Void *t) override
 
bool preorder (const IR::TypeNameExpression *e) override
 
bool preorder (const IR::TypeParameters *p) override
 
bool preorder (const IR::V1Program *) override
 
bool preorder (const IR::Vector< IR::ActionListElement > *v) override
 
bool preorder (const IR::Vector< IR::Annotation > *v) override
 
bool preorder (const IR::Vector< IR::Argument > *v) override
 
bool preorder (const IR::Vector< IR::Entry > *v) override
 
bool preorder (const IR::Vector< IR::Expression > *v) override
 
bool preorder (const IR::Vector< IR::KeyElement > *v) override
 
bool preorder (const IR::Vector< IR::Method > *v) override
 
bool preorder (const IR::Vector< IR::Node > *v) override
 
bool preorder (const IR::Vector< IR::SelectCase > *v) override
 
bool preorder (const IR::Vector< IR::SwitchCase > *v) override
 
bool preorder (const IR::Vector< IR::Type > *v) override
 
bool process (const IR::Type_StructLike *t, const char *name)
 
void setListTerm (const char *start, const char *end)
 
void setnoIncludesArg (bool condition)
 
- Public Member Functions inherited from P4::Inspector
const IR::Nodeapply_visitor (const IR::Node *, const char *name=0) override
 
virtual void loop_revisit (const IR::Node *)
 
virtual void postorder (const IR::Node *)
 
virtual void revisit (const IR::Node *)
 
void revisit_visited ()
 
bool visit_in_progress (const IR::Node *n) const
 
void visitAgain () const override
 
void visitOnce () const override
 
- Public Member Functions inherited from P4::Visitor
virtual bool check_global (cstring)
 
virtual void clear_globals ()
 
virtual Visitorclone () const
 
virtual ControlFlowVisitorcontrolFlowVisitor ()
 
virtual void end_apply ()
 
virtual void erase_global (cstring)
 
template<class T >
const T * findContext () const
 
template<class T >
const T * findContext (const Context *&c) const
 
template<class T >
const T * findOrigCtxt () const
 
template<class T >
const T * findOrigCtxt (const Context *&c) const
 
virtual Visitorflow_clone ()
 
virtual void flow_merge (Visitor &)
 
virtual bool flow_merge_closure (Visitor &)
 
virtual void flow_merge_global_from (cstring)
 
virtual void flow_merge_global_to (cstring)
 
const ContextgetChildContext () const
 
int getChildrenVisited () const
 
const ContextgetContext () const
 
int getContextDepth () const
 
const IR::NodegetCurrentNode () const
 
template<class T >
const T * getCurrentNode () const
 
const IR::NodegetOriginal () const
 
template<class T >
const T * getOriginal () const
 
template<class T >
const T * getParent () const
 
virtual bool has_flow_joins () const
 
profile_t init_apply (const IR::Node *root, const Context *parent_context)
 
bool isInContext (const IR::Node *n) const
 
virtual const char * name () const
 
template<class T >
void parallel_visit (const IR::Vector< T > &v, const char *name, int cidx)
 
template<class T >
void parallel_visit (const IR::Vector< T > &v, const char *name=0)
 
template<class T >
void parallel_visit (IR::Vector< T > &v, const char *name, int cidx)
 
template<class T >
void parallel_visit (IR::Vector< T > &v, const char *name=0)
 
void print_context () const
 
const VisitorsetCalledBy (const Visitor *visitor)
 
void setName (const char *name)
 
void visit (const IR::Node &n, const char *name, int cidx)
 
void visit (const IR::Node &n, const char *name=0)
 
void visit (const IR::Node *&n, const char *name, int cidx)
 
void visit (const IR::Node *&n, const char *name=0)
 
void visit (const IR::Node *const &n, const char *name, int cidx)
 
void visit (const IR::Node *const &n, const char *name=0)
 
void visit (IR::Node &n, const char *name, int cidx)
 
void visit (IR::Node &n, const char *name=0)
 
void visit (IR::Node *&, const char *=0, int=0)
 
template<class T , typename = std::enable_if_t<Util::has_SourceInfo_v<T> && !std::is_pointer_v<T>>, class... Args>
void warn (const int kind, const char *format, const T &node, Args &&...args)
 The const ref variant of the above.
 
template<class T , typename = std::enable_if_t<Util::has_SourceInfo_v<T>>, class... Args>
void warn (const int kind, const char *format, const T *node, Args &&...args)
 
bool warning_enabled (int warning_kind) const
 

Public Attributes

Util::SourceCodeBuilderbuilder
 
std::optional< std::filesystem::path > mainFile
 
std::ostream * outStream = nullptr
 
- Public Attributes inherited from P4::Visitor
const Visitorcalled_by = nullptr
 
cstring internalName
 
SplitFlowVisit_base *& split_link
 
SplitFlowVisit_basesplit_link_mem = nullptr
 

Protected Member Functions

unsigned curDepth () const
 
void doneList ()
 
void doneVec ()
 
void dump (unsigned depth, const IR::Node *node=nullptr, unsigned adjDepth=0)
 dump node IR tree up to depth - in the form of a comment
 
VecPrint getSep ()
 
std::optional< cstringifSystemFile (const IR::Node *node)
 
bool printAnnotations (const IR::IAnnotated *ann)
 
void setVecSep (const char *sep, const char *term=nullptr)
 
- Protected Member Functions inherited from P4::Visitor
virtual void init_join_flows (const IR::Node *)
 
virtual bool join_flows (const IR::Node *)
 
virtual void post_join_flows (const IR::Node *, const IR::Node *)
 
void visit_children (const IR::Node *, std::function< void()> fn)
 

Protected Attributes

int expressionPrecedence = DBPrint::Prec_Low
 precedence of current IR::Operation
 
bool isDeclaration = true
 
std::vector< ListPrintlistTerminators
 
size_t listTerminators_init_apply_size = 0
 
bool noIncludes = false
 if true we are within a method call argument
 
bool showIR
 current type is a declaration
 
std::vector< VecPrintvectorSeparator
 
size_t vectorSeparator_init_apply_size = 0
 
bool withinArgument = false
 if true dump IR as comments
 
- Protected Attributes inherited from P4::Visitor
bool dontForwardChildrenBeforePreorder = false
 
bool joinFlows = false
 
bool visitDagOnce = true
 

Additional Inherited Members

- Public Types inherited from P4::Visitor
typedef Visitor_Context Context
 
- Static Public Member Functions inherited from P4::Visitor
static cstring demangle (const char *)
 
static bool warning_enabled (const Visitor *visitor, int warning_kind)
 

Detailed Description

This pass converts a P4-16 IR into a P4 source (text) program. It can optionally emit as comments a representation of the program IR.

Member Function Documentation

◆ end_apply()

void P4::ToP4::end_apply ( const IR::Node * node)
overridevirtual

Reimplemented from P4::Visitor.

◆ ifSystemFile()

std::optional< cstring > P4::ToP4::ifSystemFile ( const IR::Node * node)
protected
Returns
the file that contains the node, if the node is part of a system file.

◆ init_apply()

Visitor::profile_t P4::ToP4::init_apply ( const IR::Node * node)
overridevirtual

Reimplemented from P4::Inspector.

◆ preorder()

virtual bool P4::Inspector::preorder ( const IR::Node * )
inlinevirtual

Reimplemented from P4::Inspector.

Member Data Documentation

◆ mainFile

std::optional<std::filesystem::path> P4::ToP4::mainFile

If this is set to non-empty, some declarations that come from libraries and models are not emitted.