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

#include <parser_options.h>

Inheritance diagram for P4::ParserOptions:
[legend]

Public Types

enum class  FrontendVersion { P4_14 , P4_16 }
 
using PreprocessorResult = std::unique_ptr<FILE, decltype(&closeFile)>
 Records the result of the preprocessor.
 
- Public Types inherited from P4::Util::Options
enum  OptionFlags { Default = 0 , Hide = 1 << 0 , OptionalArgument = 1 << 1 }
 
using OptionProcessor = std::function<bool(const char *)>
 

Public Member Functions

 ParserOptions (std::string_view defaultMessage="Parse a P4 program")
 
DebugHook getDebugHook () const
 
const char * getIncludePath () const override
 Return target specific include path.
 
bool isAnnotationDisabled (const IR::Annotation *a) const
 Check whether this particular annotation was disabled.
 
bool isv1 () const
 True if we are compiling a P4 v1.0 or v1.1 program.
 
std::optional< ParserOptions::PreprocessorResultpreprocess () const
 Returns the output of the preprocessor.
 
std::vector< const char * > * process (int argc, char *const argv[]) override
 
bool searchForIncludePath (const char *&includePathOut, std::vector< cstring > relativePaths, const char *)
 
void setInputFile ()
 Expect that the only remaining argument is the input file.
 
- Public Member Functions inherited from P4::Util::Options
cstring getBinaryName ()
 
cstring getBuildDate ()
 
cstring getCompileCommand ()
 
virtual void usage ()
 

Static Public Member Functions

static void closeFile (FILE *file)
 Tries to close the input stream associated with the result.
 

Public Attributes

cstring compilerVersion
 Compiler version.
 
bool doNotCompile = false
 if true preprocess only
 
bool doNotPreprocess = false
 if true skip preprocess
 
std::filesystem::path dumpFolder = "."
 debugging dumps of programs written in this folder
 
cstring exe_name
 Name of executable that is being run.
 
std::filesystem::path file
 file to compile (- for stdin)
 
FrontendVersion langVersion = FrontendVersion::P4_16
 Which language to compile.
 
bool noIncludes = false
 
bool optimizeParserInlining = false
 If false, optimization of callee parsers (subparsers) inlining is disabled.
 
cstring preprocessor_options = cstring::empty
 options to pass to preprocessor
 
std::vector< cstringtop4
 substrings matched against pass names
 

Protected Member Functions

void dumpPass (const char *manager, unsigned seq, const char *pass, const IR::Node *node) const
 Function that is returned by getDebugHook.
 
- Protected Member Functions inherited from P4::Util::Options
 Options (std::string_view message)
 
void registerOption (const char *option, const char *argName, OptionProcessor processor, const char *description, OptionFlags flags=OptionFlags::Default)
 
void registerUsage (const char *msg)
 
void setOutStream (std::ostream *out)
 
virtual bool validateOptions () const
 

Additional Inherited Members

- Protected Attributes inherited from P4::Util::Options
std::vector< const char * > additionalUsage
 
const char * binaryName
 
cstring buildDate
 
bool collectUnknownOptions = false
 
cstring compileCommand
 
cstring message
 
std::vector< cstringoptionOrder
 
std::map< cstring, const Option * > options
 
std::ostream * outStream = &std::cerr
 
std::vector< const char * > remainingOptions
 

Detailed Description

Base class for compiler options. This class contains the options for the front-ends. Each back-end should subclass this file.

Member Function Documentation

◆ getDebugHook()

DebugHook P4::ParserOptions::getDebugHook ( ) const

Get a debug hook function suitable for insertion in the pass managers that are executed.

◆ getIncludePath()

const char * P4::ParserOptions::getIncludePath ( ) const
overridevirtual

Return target specific include path.

Implements P4::Util::Options.

◆ process()

std::vector< const char * > * P4::ParserOptions::process ( int argc,
char *const argv[] )
overridevirtual

Process options; return list of remaining options.

If subclasses override this method, they should call the superclass implementation.

Returns
'nullptr' if an error is signaled.

Reimplemented from P4::Util::Options.

◆ searchForIncludePath()

bool P4::ParserOptions::searchForIncludePath ( const char *& includePathOut,
std::vector< cstring > relativePaths,
const char * exename )

Search and set 'includePathOut' to be the first valid path from the list of possible relative paths.

Member Data Documentation

◆ noIncludes

bool P4::ParserOptions::noIncludes = false

If true do not generate include statements. Used for debugging.