Change SourgeMgr to const reference in Parser/Lexer.

SourceMgr is not be mutated during parsing/lexing.

PiperOrigin-RevId: 212145759
diff --git a/include/mlir/Parser.h b/include/mlir/Parser.h
index c5b5e06..b715a44 100644
--- a/include/mlir/Parser.h
+++ b/include/mlir/Parser.h
@@ -35,7 +35,7 @@
 /// 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
diff --git a/lib/Parser/Lexer.cpp b/lib/Parser/Lexer.cpp
index b4f8e1d..6b1fcd4 100644
--- a/lib/Parser/Lexer.cpp
+++ b/lib/Parser/Lexer.cpp
@@ -33,7 +33,7 @@
   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();
diff --git a/lib/Parser/Lexer.h b/lib/Parser/Lexer.h
index cbd4d0d..220860c 100644
--- a/lib/Parser/Lexer.h
+++ b/lib/Parser/Lexer.h
@@ -30,18 +30,10 @@
 
 /// 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 @@
   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
diff --git a/lib/Parser/Parser.cpp b/lib/Parser/Parser.cpp
index bc6585c..cde5341 100644
--- a/lib/Parser/Parser.cpp
+++ b/lib/Parser/Parser.cpp
@@ -57,7 +57,7 @@
 /// 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 @@
   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 @@
 
 /// 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.