17#ifndef FRONTENDS_PARSERS_PARSERDRIVER_H_
18#define FRONTENDS_PARSERS_PARSERDRIVER_H_
25#include "frontends/p4/symbol_table.h"
26#include "frontends/parsers/p4/abstractP4Lexer.hpp"
27#include "frontends/parsers/p4/p4AnnotationLexer.hpp"
29#include "lib/cstring.h"
30#include "lib/source_file.h"
88 int lineDirectiveLine = 0;
113 static const IR::P4Program *
parse(std::istream &in, std::string_view sourceFile,
114 unsigned sourceLine = 1);
115 static const IR::P4Program *
parse(FILE *in, std::string_view sourceFile,
116 unsigned sourceLine = 1);
122 std::istream &in, std::string_view sourceFile,
unsigned sourceLine = 1);
125 FILE *in, std::string_view sourceFile,
unsigned sourceLine = 1);
150 static const IR::Expression *parseExpression(
const Util::SourceInfo &srcInfo,
156 static const IR::Expression *parseConstantOrStringLiteral(
159 static const IR::StringLiteral *parseStringLiteral(
const Util::SourceInfo &srcInfo,
187 friend class P4::P4Lexer;
188 friend class P4::P4Parser;
210 bool template_args =
false;
216 bool parse(AbstractP4Lexer &lexer, std::string_view sourceFile,
unsigned sourceLine = 1);
219 template <
typename T>
226 IR::Type_Error *allErrors =
nullptr;
252 static const IR::V1Program *
parse(std::istream &in, std::string_view sourceFile,
253 unsigned sourceLine = 1);
254 static const IR::V1Program *
parse(FILE *in, std::string_view sourceFile,
255 unsigned sourceLine = 1);
258 friend class V1::V1Lexer;
259 friend class V1::V1Parser;
Definition parserDriver.h:39
void onParseError(const Util::SourceInfo &location, const std::string &message)
Definition parserDriver.cpp:105
Util::SourceInfo yylloc
The location of the most recent token.
Definition parserDriver.h:81
void onReadToken(const char *text)
Notify that the lexer read a token. @text is the matched source text.
Definition parserDriver.cpp:76
void onReadComment(const char *text, bool lineComment)
Definition parserDriver.cpp:94
void onReadFileName(const char *text)
Notify that the lexer read a filename from a line directive.
Definition parserDriver.cpp:98
void onReadLineNumber(const char *text)
Notify that the lexer read a line number from a line directive.
Definition parserDriver.cpp:83
int saveState
Scratch storage for the lexer to remember its previous state.
Definition parserDriver.h:84
Util::InputSources * sources
The input sources that comprise the P4 program we're parsing.
Definition parserDriver.h:78
void onReadIdentifier(cstring id)
Notify that the lexer read an identifier, @id.
Definition parserDriver.cpp:103
A ParserDriver that can parse P4-16 programs.
Definition parserDriver.h:98
Util::ProgramStructure * structure
Semantic information about the program being parsed.
Definition parserDriver.h:198
void onReadErrorDeclaration(IR::Type_Error *error)
Notify that the parser parsed a P4 error declaration.
Definition parserDriver.cpp:298
static const IR::Vector< IR::Expression > * parseExpressionList(const Util::SourceInfo &srcInfo, const IR::Vector< IR::AnnotationToken > &body)
Definition parserDriver.cpp:191
static std::pair< const IR::P4Program *, const Util::InputSources * > parseProgramSources(std::istream &in, std::string_view sourceFile, unsigned sourceLine=1)
Definition parserDriver.cpp:157
IR::Vector< IR::Node > * nodes
Definition parserDriver.h:202
std::string stringLiteral
Definition parserDriver.h:206
static const IR::P4Program * parse(std::istream &in, std::string_view sourceFile, unsigned sourceLine=1)
Definition parserDriver.cpp:139
Definition symbol_table.h:39
Definition source_file.h:125
A ParserDriver that can parse P4-14 programs.
Definition parserDriver.h:237
void addPragma(IR::Annotation *pragma)
Add @pragma to the list of active pragmas.
Definition parserDriver.cpp:355
IR::Vector< IR::Annotation > takePragmasAsVector()
Definition parserDriver.cpp:359
static const IR::V1Program * parse(std::istream &in, std::string_view sourceFile, unsigned sourceLine=1)
Definition parserDriver.cpp:313
IR::Vector< IR::Expression > makeExpressionList(const IR::NameList *list)
Definition parserDriver.cpp:347
const IR::Annotations * takePragmasAsAnnotations()
Definition parserDriver.cpp:365
IR::V1Program * global
The root of the IR tree we're constructing.
Definition parserDriver.h:293
void clearPragmas()
Clear the list of active pragmas.
Definition parserDriver.cpp:353
IR::Constant * constantFold(IR::Expression *expr)
Definition parserDriver.cpp:341
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
void error(const char *format, Args &&...args)
Report an error with the given message.
Definition lib/error.h:51