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 std::vector< const char * > * initCompiler (std::string_view toolName, int argc, char **argv)
 
static ICompileContextmakeContext (std::string_view toolName)
 
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 deviceName, std::string archName)
 
static bool setArch (std::string archName)
 
static bool setDevice (std::string deviceName)
 

Protected Member Functions

 CompilerTarget (std::string_view toolName, const std::string &deviceName, const std::string &archName)
 
virtual std::vector< const char * > * initCompilerImpl (int argc, char **argv) const
 
virtual ICompileContextmakeContextImpl () const
 
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)
 

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

◆ initCompiler()

std::vector< const char * > * P4::P4Tools::CompilerTarget::initCompiler ( std::string_view toolName,
int argc,
char ** argv )
static

Initializes the P4 compiler with the given compiler-specific command-line arguments.

Returns
any unprocessed arguments, or nullptr if there was an error.

◆ initCompilerImpl()

std::vector< const char * > * P4::P4Tools::CompilerTarget::initCompilerImpl ( int argc,
char ** argv ) const
protectedvirtual

This implementation just forwards the given arguments to the compiler.

See also
@initCompiler.

◆ makeContext()

ICompileContext * P4::P4Tools::CompilerTarget::makeContext ( std::string_view toolName)
static
Returns
a new compilation context for the compiler.

◆ makeContextImpl()

ICompileContext * P4::P4Tools::CompilerTarget::makeContextImpl ( ) const
nodiscardprotectedvirtual
See also
@makeContext.

◆ 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.