P4C
The P4 Compiler
Loading...
Searching...
No Matches
P4::P4Tools::Target Class Referenceabstract

#include <target.h>

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

Classes

struct  Spec
 Specifies a target device and architecture by their names in lower case. More...
 

Public Member Functions

virtual const IR::Expression * createTargetUninitialized (const IR::Type *type, bool forceTaint) const
 

Static Public Member Functions

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)
 

Public Attributes

Spec spec
 The device and architecture supported by this instance.
 
std::string toolName
 The name of the tool supported by this instance.
 

Protected Member Functions

 Target (std::string_view toolName, const std::string &deviceName, const std::string &archName)
 
virtual ICompileContextmakeContext () const =0
 

Static Protected Member Functions

template<class TargetImpl >
static const TargetImpl & get (std::string_view toolName)
 

Detailed Description

Encapsulates the details of a target device and architecture for a single tool. Implementations are singletons and must provide a default constructor. Instances are automatically registered into a central registry. The active target is set by calling @init. The suite of instances for all supported tools for the active target can be obtained by calling @get.

Constructor & Destructor Documentation

◆ Target()

P4::P4Tools::Target::Target ( std::string_view toolName,
const std::string & deviceName,
const std::string & archName )
protected

Creates and registers a new Target instance for the given @toolName, @deviceName, and @archName.

Member Function Documentation

◆ createTargetUninitialized()

const IR::Expression * P4::P4Tools::Target::createTargetUninitialized ( const IR::Type * type,
bool forceTaint ) const
virtual
Returns
the default value for uninitialized variables for this particular target. This can be a taint variable or simply 0 (bits) or false (booleans). If
Parameters
forceTaintis active, this function always returns a taint variable. Can be overridden by sub-targets.

◆ get()

template<class TargetImpl >
static const TargetImpl & P4::P4Tools::Target::get ( std::string_view toolName)
inlinestaticprotected
Returns
the target instance for the given tool and active target, as selected by @init.

◆ init()

bool P4::P4Tools::Target::init ( std::string_view deviceName,
std::string_view archName )
static

Initializes the global target device and architecture to @deviceName and @archName.

Returns
true on success. If initialization fails, false is returned, and nothing is changed.

◆ initializeTarget()

std::optional< ICompileContext * > P4::P4Tools::Target::initializeTarget ( std::string_view toolName,
const std::vector< const char * > & args )
static

Initializes the global target device and architecture to @deviceName and @archName. Returns 0 on success. If initialization fails, returns -1.

◆ makeContext()

virtual ICompileContext * P4::P4Tools::Target::makeContext ( ) const
nodiscardprotectedpure virtual
Returns
a new compilation context for the compiler.

Implemented in P4::P4Tools::P4Smith::SmithTarget, and P4::P4Tools::P4Testgen::TestgenTarget.

◆ setArch()

bool P4::P4Tools::Target::setArch ( std::string_view archName)
static

Initializes the global target architecture to @archName without changing the device. If no device was previously selected, then the first device registered for the architecture is chosen.

Returns
true on success. If initialization fails, false is returned, and nothing is changed.

◆ setDevice()

bool P4::P4Tools::Target::setDevice ( std::string_view deviceName)
static

Initializes the global target device to @deviceName without changing the architecture. If no architecture was previously selected, then the first architecture registered for the device is chosen.

Returns
true on success. If initialization fails, false is returned, and nothing is changed.