forked from OSchip/llvm-project
Change SourgeMgr to const reference in Parser/Lexer.
SourceMgr is not be mutated during parsing/lexing. PiperOrigin-RevId: 212145759
This commit is contained in:
parent
3bae041e5d
commit
9afa796d42
|
@ -35,7 +35,7 @@ class MLIRContext;
|
|||
/// This parses the file specified by the indicated SourceMgr and returns an
|
||||
/// MLIR module if it was valid. If not, the error message is emitted through
|
||||
/// the error handler registered in the context, and a null pointer is returned.
|
||||
Module *parseSourceFile(llvm::SourceMgr &sourceMgr, MLIRContext *context);
|
||||
Module *parseSourceFile(const llvm::SourceMgr &sourceMgr, MLIRContext *context);
|
||||
|
||||
/// This parses the module string to a MLIR module if it was valid. If not, the
|
||||
/// error message is emitted through / the error handler registered in the
|
||||
|
|
|
@ -33,7 +33,7 @@ static bool isPunct(char c) {
|
|||
return c == '$' || c == '.' || c == '_' || c == '-';
|
||||
}
|
||||
|
||||
Lexer::Lexer(llvm::SourceMgr &sourceMgr, MLIRContext *context)
|
||||
Lexer::Lexer(const llvm::SourceMgr &sourceMgr, MLIRContext *context)
|
||||
: sourceMgr(sourceMgr), context(context) {
|
||||
auto bufferID = sourceMgr.getMainFileID();
|
||||
curBuffer = sourceMgr.getMemoryBuffer(bufferID)->getBuffer();
|
||||
|
|
|
@ -30,18 +30,10 @@ class Location;
|
|||
|
||||
/// This class breaks up the current file into a token stream.
|
||||
class Lexer {
|
||||
llvm::SourceMgr &sourceMgr;
|
||||
MLIRContext *context;
|
||||
|
||||
StringRef curBuffer;
|
||||
const char *curPtr;
|
||||
|
||||
Lexer(const Lexer&) = delete;
|
||||
void operator=(const Lexer&) = delete;
|
||||
public:
|
||||
explicit Lexer(llvm::SourceMgr &sourceMgr, MLIRContext *context);
|
||||
explicit Lexer(const llvm::SourceMgr &sourceMgr, MLIRContext *context);
|
||||
|
||||
llvm::SourceMgr &getSourceMgr() { return sourceMgr; }
|
||||
const llvm::SourceMgr &getSourceMgr() { return sourceMgr; }
|
||||
|
||||
Token lexToken();
|
||||
|
||||
|
@ -69,6 +61,15 @@ private:
|
|||
Token lexPrefixedIdentifier(const char *tokStart);
|
||||
Token lexNumber(const char *tokStart);
|
||||
Token lexString(const char *tokStart);
|
||||
|
||||
const llvm::SourceMgr &sourceMgr;
|
||||
MLIRContext *context;
|
||||
|
||||
StringRef curBuffer;
|
||||
const char *curPtr;
|
||||
|
||||
Lexer(const Lexer &) = delete;
|
||||
void operator=(const Lexer &) = delete;
|
||||
};
|
||||
|
||||
} // end namespace mlir
|
||||
|
|
|
@ -57,7 +57,7 @@ class Parser;
|
|||
/// methods to access this.
|
||||
class ParserState {
|
||||
public:
|
||||
ParserState(llvm::SourceMgr &sourceMgr, Module *module)
|
||||
ParserState(const llvm::SourceMgr &sourceMgr, Module *module)
|
||||
: context(module->getContext()), module(module), lex(sourceMgr, context),
|
||||
curToken(lex.lexToken()), operationSet(OperationSet::get(context)) {}
|
||||
|
||||
|
@ -113,7 +113,7 @@ public:
|
|||
MLIRContext *getContext() const { return state.context; }
|
||||
Module *getModule() { return state.module; }
|
||||
OperationSet &getOperationSet() const { return state.operationSet; }
|
||||
llvm::SourceMgr &getSourceMgr() { return state.lex.getSourceMgr(); }
|
||||
const llvm::SourceMgr &getSourceMgr() { return state.lex.getSourceMgr(); }
|
||||
|
||||
/// Return the current token the parser is inspecting.
|
||||
const Token &getToken() const { return state.curToken; }
|
||||
|
@ -3005,7 +3005,7 @@ ParseResult ModuleParser::parseModule() {
|
|||
|
||||
/// This parses the file specified by the indicated SourceMgr and returns an
|
||||
/// MLIR module if it was valid. If not, it emits diagnostics and returns null.
|
||||
Module *mlir::parseSourceFile(llvm::SourceMgr &sourceMgr,
|
||||
Module *mlir::parseSourceFile(const llvm::SourceMgr &sourceMgr,
|
||||
MLIRContext *context) {
|
||||
|
||||
// This is the result module we are parsing into.
|
||||
|
|
Loading…
Reference in New Issue