CIRCT  20.0.0git
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
circt::firrtl::FIRLexer Class Reference

This implements a lexer for .fir files. More...

#include <FIRLexer.h>

Collaboration diagram for circt::firrtl::FIRLexer:
Collaboration graph
[legend]

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 FIRTokengetToken () 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
 

Detailed Description

This implements a lexer for .fir files.

Definition at line 100 of file FIRLexer.h.

Constructor & Destructor Documentation

◆ FIRLexer() [1/2]

circt::firrtl::FIRLexer::FIRLexer ( const llvm::SourceMgr &  sourceMgr,
mlir::MLIRContext *  context 
)

◆ FIRLexer() [2/2]

circt::firrtl::FIRLexer::FIRLexer ( const FIRLexer )
privatedelete

Member Function Documentation

◆ emitError()

FIRToken FIRLexer::emitError ( const char *  loc,
const Twine &  message 
)
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().

◆ formToken()

FIRToken circt::firrtl::FIRLexer::formToken ( FIRToken::Kind  kind,
const char *  tokStart 
)
inlineprivate

◆ getCursor()

FIRLexerCursor circt::firrtl::FIRLexer::getCursor ( ) const
inline

Get an opaque pointer into the lexer state that can be restored later.

Definition at line 168 of file FIRLexer.h.

References FIRLexerCursor.

◆ getIndentation()

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().

◆ getSourceMgr()

const llvm::SourceMgr& circt::firrtl::FIRLexer::getSourceMgr ( ) const
inline

Definition at line 104 of file FIRLexer.h.

References sourceMgr.

◆ getToken()

const FIRToken& circt::firrtl::FIRLexer::getToken ( ) const
inline

Definition at line 109 of file FIRLexer.h.

References curToken.

◆ lexFileInfo()

FIRToken FIRLexer::lexFileInfo ( const char *  tokStart)
private

Lex a file info specifier.

FileInfo ::= '@[' (']'|.)* ']'

Definition at line 319 of file FIRLexer.cpp.

References curBuffer, curPtr, emitError(), and formToken().

Referenced by lexTokenImpl().

◆ lexIdentifierOrKeyword()

FIRToken FIRLexer::lexIdentifierOrKeyword ( const char *  tokStart)
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().

◆ lexInlineAnnotation()

FIRToken FIRLexer::lexInlineAnnotation ( const char *  tokStart)
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().

◆ lexNumber()

FIRToken FIRLexer::lexNumber ( const char *  tokStart)
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().

◆ lexString()

FIRToken FIRLexer::lexString ( const char *  tokStart,
bool  isVerbatim 
)
private

StringLit ::= '"' UnquotedString? '"' VerbatimStringLit ::= '\'' UnquotedString? '\'' UnquotedString ::= ( '\\'' | '\"' | ~[\r
] )+?

Definition at line 463 of file FIRLexer.cpp.

References curBuffer, curPtr, emitError(), and formToken().

Referenced by lexTokenImpl().

◆ lexToken()

void circt::firrtl::FIRLexer::lexToken ( )
inline

Move to the next valid token.

Definition at line 107 of file FIRLexer.h.

References curToken, and lexTokenImpl().

◆ lexTokenImpl()

FIRToken FIRLexer::lexTokenImpl ( )
private

◆ operator=()

void circt::firrtl::FIRLexer::operator= ( const FIRLexer )
privatedelete

◆ skipComment()

void FIRLexer::skipComment ( )
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().

◆ translateLocation()

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().

Friends And Related Function Documentation

◆ FIRLexerCursor

friend class FIRLexerCursor
friend

Definition at line 149 of file FIRLexer.h.

Referenced by getCursor().

Member Data Documentation

◆ bufferNameIdentifier

const mlir::StringAttr circt::firrtl::FIRLexer::bufferNameIdentifier
private

Definition at line 139 of file FIRLexer.h.

Referenced by translateLocation().

◆ curBuffer

StringRef circt::firrtl::FIRLexer::curBuffer
private

◆ curPtr

const char* circt::firrtl::FIRLexer::curPtr
private

◆ curToken

FIRToken circt::firrtl::FIRLexer::curToken
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().

◆ sourceMgr

const llvm::SourceMgr& circt::firrtl::FIRLexer::sourceMgr
private

Definition at line 138 of file FIRLexer.h.

Referenced by getSourceMgr(), and translateLocation().


The documentation for this class was generated from the following files: