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

Encapsulates the details of invoking the P4 compiler for a target device and architecture. More...

#include <compiler_target.h>

Inheritance diagram for P4::P4Tools::CompilerTarget:
[legend]

Static Public Member Functions

static CompilerResultOrError runCompiler (const CompilerOptions &options, std::string_view toolName)
 
static CompilerResultOrError runCompiler (const CompilerOptions &options, std::string_view toolName, const std::string &source)
 
- Static Public Member Functions inherited from P4::P4Tools::Target
static bool init (std::string_view deviceName, std::string_view archName)
 
static std::optional< ICompileContext * > initializeTarget (std::string_view toolName, const std::vector< const char * > &args)
 
static std::optional< ICompileContext * > initializeTarget (std::string_view toolName, std::string_view target, std::string_view arch)
 
static bool setArch (std::string_view archName)
 
static bool setDevice (std::string_view deviceName)
 

Protected Member Functions

 CompilerTarget (std::string_view toolName, const std::string &deviceName, const std::string &archName)
 
virtual P4::FrontEnd mkFrontEnd () const
 A factory method for providing a target-specific front end implementation.
 
virtual MidEnd mkMidEnd (const CompilerOptions &options) const
 A factory method for providing a target-specific mid end implementation.
 
virtual CompilerResultOrError runCompilerImpl (const CompilerOptions &options, const IR::P4Program *) const
 
const IR::P4Program * runFrontend (const CompilerOptions &options, const IR::P4Program *program) const
 
const IR::P4Program * runMidEnd (const CompilerOptions &options, const IR::P4Program *program) const
 
- Protected Member Functions inherited from P4::P4Tools::Target
 Target (std::string_view toolName, const std::string &deviceName, const std::string &archName)
 
virtual ICompileContextmakeContext () const =0
 

Static Protected Member Functions

static const IR::P4Program * runParser (const ParserOptions &options)
 
- Static Protected Member Functions inherited from P4::P4Tools::Target
template<class TargetImpl >
static const TargetImpl & get (std::string_view toolName)
 

Additional Inherited Members

- Public Member Functions inherited from P4::P4Tools::Target
virtual const IR::Expression * createTargetUninitialized (const IR::Type *type, bool forceTaint) const
 
- Public Attributes inherited from P4::P4Tools::Target
Spec spec
 The device and architecture supported by this instance.
 
std::string toolName
 The name of the tool supported by this instance.
 

Detailed Description

Encapsulates the details of invoking the P4 compiler for a target device and architecture.

Member Function Documentation

◆ runCompiler() [1/2]

CompilerResultOrError P4::P4Tools::CompilerTarget::runCompiler ( const CompilerOptions & options,
std::string_view toolName )
static

Runs the P4 compiler to produce an IR and various other kinds of information on the input program.

Returns
std::nullopt if an error occurs during compilation.

◆ runCompiler() [2/2]

CompilerResultOrError P4::P4Tools::CompilerTarget::runCompiler ( const CompilerOptions & options,
std::string_view toolName,
const std::string & source )
static

Runs the P4 compiler to produce an IR and other information for the given source code.

Returns
std::nullopt if an error occurs during compilation.

◆ runCompilerImpl()

CompilerResultOrError P4::P4Tools::CompilerTarget::runCompilerImpl ( const CompilerOptions & options,
const IR::P4Program * program ) const
protectedvirtual
See also
runCompiler.

Reimplemented in P4::P4Tools::P4Testgen::TestgenTarget.

◆ runFrontend()

const IR::P4Program * P4::P4Tools::CompilerTarget::runFrontend ( const CompilerOptions & options,
const IR::P4Program * program ) const
protected

Runs the front end of the P4 compiler on the given program.

Returns
nullptr if an error occurs during compilation.

◆ runMidEnd()

const IR::P4Program * P4::P4Tools::CompilerTarget::runMidEnd ( const CompilerOptions & options,
const IR::P4Program * program ) const
protected

Runs the mid end provided by @mkMidEnd on the given program.

Returns
nullptr if an error occurs during compilation.

◆ runParser()

const IR::P4Program * P4::P4Tools::CompilerTarget::runParser ( const ParserOptions & options)
staticprotected

Parses the P4 program specified on the command line.

Returns
nullptr if an error occurs during parsing.