A ParserDriver that can parse P4-14 programs.
More...
#include <parserDriver.h>
|
static const IR::V1Program * | parse (FILE *in, std::string_view sourceFile, unsigned sourceLine=1) |
|
static const IR::V1Program * | parse (std::istream &in, std::string_view sourceFile, unsigned sourceLine=1) |
|
|
void | addPragma (IR::Annotation *pragma) |
| Add @pragma to the list of active pragmas.
|
|
void | clearPragmas () |
| Clear the list of active pragmas.
|
|
IR::Constant * | constantFold (IR::Expression *expr) |
|
IR::Vector< IR::Expression > | makeExpressionList (const IR::NameList *list) |
|
IR::Vector< IR::Annotation > | takePragmasAsVector () |
|
void | onParseError (const Util::SourceInfo &location, const std::string &message) |
|
void | onReadComment (const char *text, bool lineComment) |
|
void | onReadFileName (const char *text) |
| Notify that the lexer read a filename from a line directive.
|
|
void | onReadIdentifier (cstring id) |
| Notify that the lexer read an identifier, @id.
|
|
void | onReadLineNumber (const char *text) |
| Notify that the lexer read a line number from a line directive.
|
|
void | onReadToken (const char *text) |
| Notify that the lexer read a token. @text is the matched source text.
|
|
|
IR::V1Program * | global = nullptr |
| The root of the IR tree we're constructing.
|
|
int | saveState = -1 |
| Scratch storage for the lexer to remember its previous state.
|
|
Util::InputSources * | sources |
| The input sources that comprise the P4 program we're parsing.
|
|
Util::SourceInfo | yylloc |
| The location of the most recent token.
|
|
|
class | V1::V1Lexer |
|
class | V1::V1Parser |
|
A ParserDriver that can parse P4-14 programs.
◆ constantFold()
IR::Constant * P4::V1::V1ParserDriver::constantFold |
( |
IR::Expression * | expr | ) |
|
|
protected |
The P4-14 parser performs constant folding to ensure that constant expressions in the grammar actually produce IR::Constant values in the resulting IR.
- Returns
- an IR::Constant containing the value of @expr, if @expr is a constant expression, or null otherwise.
◆ makeExpressionList()
IR::Vector< IR::Expression > P4::V1::V1ParserDriver::makeExpressionList |
( |
const IR::NameList * | list | ) |
|
|
protected |
- Returns
- a vector of IR::Expressions containing an IR::StringLiteral for name in @list.
◆ parse()
const IR::V1Program * P4::V1::V1ParserDriver::parse |
( |
std::istream & | in, |
|
|
std::string_view | sourceFile, |
|
|
unsigned | sourceLine = 1 ) |
|
static |
Parse a P4-14 program.
- Parameters
-
in | The input source to read the program from. |
sourceFile | The logical source filename. This doesn't have to be a real filename, though it normally will be. This is used for logging and to set the initial source location. |
sourceLine | The logical source line number. For programs parsed from a file, this will normally be 1. This is used to set the initial source location. |
- Returns
- a V1Program object if parsing was successful, or null otherwise.
◆ takePragmasAsVector()
IR::Vector< IR::Annotation > P4::V1::V1ParserDriver::takePragmasAsVector |
( |
| ) |
|
|
protected |
- Returns
- a IR::Vector containing the active pragmas, and clear the list.