13 #ifndef FIRTOMLIR_FIRLEXER_H
14 #define FIRTOMLIR_FIRLEXER_H
17 #include "mlir/IR/BuiltinAttributes.h"
18 #include "llvm/Support/SourceMgr.h"
32 #define TOK_MARKER(NAME) NAME,
33 #define TOK_IDENTIFIER(NAME) NAME,
34 #define TOK_LITERAL(NAME) NAME,
35 #define TOK_PUNCTUATION(NAME, SPELLING) NAME,
36 #define TOK_KEYWORD(SPELLING) kw_##SPELLING,
37 #define TOK_LPKEYWORD(SPELLING) lp_##SPELLING,
38 #include "FIRTokenKinds.def"
53 template <
typename... T>
57 return isAny(k2, k3, others...);
63 template <
typename... T>
65 return !
isAny(k1, k2, others...);
84 llvm::SMLoc
getLoc()
const;
This is the state captured for a lexer cursor.
FIRLexerCursor(const FIRLexer &lexer)
void restore(FIRLexer &lexer)
This implements a lexer for .fir files.
FIRToken lexFileInfo(const char *tokStart)
Lex a file info specifier.
void lexToken()
Move to the next valid token.
FIRToken lexIdentifierOrKeyword(const char *tokStart)
Lex an identifier or keyword that starts with a letter.
const llvm::SourceMgr & sourceMgr
FIRToken curToken
This is the next token that hasn't been consumed yet.
FIRToken formToken(FIRToken::Kind kind, const char *tokStart)
const llvm::SourceMgr & getSourceMgr() const
FIRToken lexNumber(const char *tokStart)
Lex a number literal.
FIRToken lexString(const char *tokStart, bool isVerbatim)
StringLit ::= '"' UnquotedString? '"' VerbatimStringLit ::= '\'' UnquotedString? '\'' UnquotedString ...
friend class FIRLexerCursor
FIRLexer(const FIRLexer &)=delete
FIRLexerCursor getCursor() const
Get an opaque pointer into the lexer state that can be restored later.
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 toke...
void skipComment()
Skip a comment line, starting with a ';' and going to end of line.
FIRToken emitError(const char *loc, const Twine &message)
Emit an error message and return a FIRToken::error token.
FIRLexer(const llvm::SourceMgr &sourceMgr, mlir::MLIRContext *context)
mlir::Location translateLocation(llvm::SMLoc loc)
Encode the specified source location information into a Location object for attachment to the IR or e...
void operator=(const FIRLexer &)=delete
FIRToken lexInlineAnnotation(const char *tokStart)
Lex a non-standard inline Annotation file.
const FIRToken & getToken() const
const mlir::StringAttr bufferNameIdentifier
This represents a specific token for .fir files.
std::string getVerbatimStringValue() const
Given a token containing a verbatim string, return its value, including removing the quote characters...
StringRef getSpelling() const
bool isNot(Kind k1, Kind k2, T... others) const
Return true if this token isn't one of the specified kinds.
FIRToken(Kind kind, StringRef spelling)
StringRef spelling
A reference to the entire token contents; this is always a pointer into a memory buffer owned by the ...
llvm::SMRange getLocRange() const
bool isAny(Kind k1, Kind k2, Kind k3, T... others) const
Return true if this token is one of the specified kinds.
bool isAny(Kind k1, Kind k2) const
std::string getStringValue() const
Given a token containing a string literal, return its value, including removing the quote characters ...
Kind kind
Discriminator that indicates the sort of token this is.
llvm::SMLoc getEndLoc() const
llvm::SMLoc getLoc() const
bool isKeyword() const
Return true if this is one of the keyword token kinds (e.g. kw_wire).
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.