CIRCT
20.0.0git
|
This implements a lexer for .fir files. More...
#include <FIRLexer.h>
Public Member Functions | |
FIRLexer (const llvm::SourceMgr &sourceMgr, mlir::MLIRContext *context) | |
const llvm::SourceMgr & | getSourceMgr () const |
void | lexToken () |
Move to the next valid token. More... | |
const FIRToken & | getToken () const |
mlir::Location | translateLocation (llvm::SMLoc loc) |
Encode the specified source location information into a Location object for attachment to the IR or error reporting. More... | |
std::optional< unsigned > | getIndentation (const FIRToken &tok) const |
Return the indentation level of the specified token or None if this token is preceded by another token on the same line. More... | |
FIRLexerCursor | getCursor () const |
Get an opaque pointer into the lexer state that can be restored later. More... | |
Private Member Functions | |
FIRToken | lexTokenImpl () |
FIRToken | formToken (FIRToken::Kind kind, const char *tokStart) |
FIRToken | emitError (const char *loc, const Twine &message) |
Emit an error message and return a FIRToken::error token. More... | |
FIRToken | lexFileInfo (const char *tokStart) |
Lex a file info specifier. More... | |
FIRToken | lexInlineAnnotation (const char *tokStart) |
Lex a non-standard inline Annotation file. More... | |
FIRToken | lexIdentifierOrKeyword (const char *tokStart) |
Lex an identifier or keyword that starts with a letter. More... | |
FIRToken | lexNumber (const char *tokStart) |
Lex a number literal. More... | |
void | skipComment () |
Skip a comment line, starting with a ';' and going to end of line. More... | |
FIRToken | lexString (const char *tokStart, bool isVerbatim) |
StringLit ::= '"' UnquotedString? '"' VerbatimStringLit ::= '\'' UnquotedString? '\'' UnquotedString ::= ( '\\'' | '\"' | ~[\r ] )+? More... | |
FIRLexer (const FIRLexer &)=delete | |
void | operator= (const FIRLexer &)=delete |
Private Attributes | |
const llvm::SourceMgr & | sourceMgr |
const mlir::StringAttr | bufferNameIdentifier |
StringRef | curBuffer |
const char * | curPtr |
FIRToken | curToken |
This is the next token that hasn't been consumed yet. More... | |
Friends | |
class | FIRLexerCursor |
This implements a lexer for .fir files.
Definition at line 100 of file FIRLexer.h.
circt::firrtl::FIRLexer::FIRLexer | ( | const llvm::SourceMgr & | sourceMgr, |
mlir::MLIRContext * | context | ||
) |
|
privatedelete |
|
private |
Emit an error message and return a FIRToken::error token.
Definition at line 179 of file FIRLexer.cpp.
References formToken(), and translateLocation().
Referenced by lexFileInfo(), lexIdentifierOrKeyword(), lexInlineAnnotation(), lexNumber(), lexString(), and lexTokenImpl().
|
inlineprivate |
Definition at line 124 of file FIRLexer.h.
References curPtr.
Referenced by emitError(), lexFileInfo(), lexIdentifierOrKeyword(), lexInlineAnnotation(), lexNumber(), lexString(), and lexTokenImpl().
|
inline |
Get an opaque pointer into the lexer state that can be restored later.
Definition at line 168 of file FIRLexer.h.
References FIRLexerCursor.
std::optional< unsigned > FIRLexer::getIndentation | ( | const FIRToken & | tok | ) | const |
Return the indentation level of the specified token or None if this token is preceded by another token on the same line.
Return the indentation level of the specified token.
Definition at line 185 of file FIRLexer.cpp.
References curBuffer, and circt::firrtl::FIRToken::getSpelling().
|
inline |
Definition at line 104 of file FIRLexer.h.
References sourceMgr.
|
inline |
Definition at line 109 of file FIRLexer.h.
References curToken.
|
private |
Lex a file info specifier.
FileInfo ::= '@[' (']'|.)* ']'
Definition at line 319 of file FIRLexer.cpp.
References curBuffer, curPtr, emitError(), and formToken().
Referenced by lexTokenImpl().
|
private |
Lex an identifier or keyword that starts with a letter.
LegalStartChar ::= [a-zA-Z_] LegalIdChar ::= LegalStartChar | [0-9] | '$'
Id ::= LegalStartChar (LegalIdChar)* LiteralId ::= [a-zA-Z0-9$_]+
Definition at line 391 of file FIRLexer.cpp.
References curPtr, emitError(), and formToken().
Referenced by lexTokenImpl().
|
private |
Lex a non-standard inline Annotation file.
InlineAnnotation ::= '%[' (.)* ']'
Definition at line 350 of file FIRLexer.cpp.
References curBuffer, curPtr, emitError(), and formToken().
Referenced by lexTokenImpl().
|
private |
Lex a number literal.
UnsignedInt ::= '0' | PosInt PosInt ::= [1-9] ([0-9])* DoubleLit ::= ( '+' | '-' )? Digit+ '.' Digit+ ( 'E' ( '+' | '-' )? Digit+ )? TripleLit ::= Digit+ '.' Digit+ '.' Digit+ Radix-specified Integer ::= ( '-' )? '0' ( 'b' | 'o' | 'd' | 'h' ) LegalDigit*
Definition at line 512 of file FIRLexer.cpp.
References assert(), curPtr, emitError(), and formToken().
Referenced by lexTokenImpl().
|
private |
StringLit ::= '"' UnquotedString? '"' VerbatimStringLit ::= '\'' UnquotedString? '\'' UnquotedString ::= ( '\\'' | '\"' | ~[\r
] )+?
Definition at line 463 of file FIRLexer.cpp.
References curBuffer, curPtr, emitError(), and formToken().
Referenced by lexTokenImpl().
|
inline |
Move to the next valid token.
Definition at line 107 of file FIRLexer.h.
References curToken, and lexTokenImpl().
|
private |
Definition at line 210 of file FIRLexer.cpp.
References curBuffer, curPtr, emitError(), formToken(), lexFileInfo(), lexIdentifierOrKeyword(), lexInlineAnnotation(), lexNumber(), lexString(), and skipComment().
Referenced by lexToken().
|
privatedelete |
|
private |
Skip a comment line, starting with a ';' and going to end of line.
Definition at line 438 of file FIRLexer.cpp.
References curBuffer, and curPtr.
Referenced by lexTokenImpl().
Location FIRLexer::translateLocation | ( | llvm::SMLoc | loc | ) |
Encode the specified source location information into a Location object for attachment to the IR or error reporting.
Definition at line 170 of file FIRLexer.cpp.
References assert(), bufferNameIdentifier, circt::calyx::direction::get(), and sourceMgr.
Referenced by emitError().
|
friend |
Definition at line 149 of file FIRLexer.h.
Referenced by getCursor().
|
private |
Definition at line 139 of file FIRLexer.h.
Referenced by translateLocation().
|
private |
Definition at line 141 of file FIRLexer.h.
Referenced by getIndentation(), lexFileInfo(), lexInlineAnnotation(), lexString(), lexTokenImpl(), and skipComment().
|
private |
Definition at line 142 of file FIRLexer.h.
Referenced by formToken(), lexFileInfo(), lexIdentifierOrKeyword(), lexInlineAnnotation(), lexNumber(), lexString(), lexTokenImpl(), circt::firrtl::FIRLexerCursor::restore(), and skipComment().
|
private |
This is the next token that hasn't been consumed yet.
Definition at line 145 of file FIRLexer.h.
Referenced by getToken(), lexToken(), and circt::firrtl::FIRLexerCursor::restore().
|
private |
Definition at line 138 of file FIRLexer.h.
Referenced by getSourceMgr(), and translateLocation().