llvm.org GIT mirror llvm / 6b67062
This patch relies upon non-incorporated patches. --- Reverse-merging r142156 into '.': U include/llvm/Support/SourceMgr.h U lib/MC/MCParser/AsmParser.cpp git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_30@142161 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 9 years ago
2 changed file(s) with 29 addition(s) and 43 deletion(s). Raw diff Collapse all Expand all
7676 DiagHandler = DH;
7777 DiagContext = Ctx;
7878 }
79
80 DiagHandlerTy getDiagHandler() const { return DiagHandler; }
81 void *getDiagContext() const { return DiagContext; }
8279
8380 const SrcBuffer &getBufferInfo(unsigned i) const {
8481 assert(i < Buffers.size() && "Invalid Buffer ID!");
8686 MCStreamer &Out;
8787 const MCAsmInfo &MAI;
8888 SourceMgr &SrcMgr;
89 SourceMgr::DiagHandlerTy SavedDiagHandler;
90 void *SavedDiagContext;
9189 MCAsmParserExtension *GenericParser;
9290 MCAsmParserExtension *PlatformParser;
9391
143141 virtual MCContext &getContext() { return Ctx; }
144142 virtual MCStreamer &getStreamer() { return Out; }
145143
146 virtual bool Warning(SMLoc L, const Twine &Msg,
147 ArrayRef Ranges = ArrayRef());
148 virtual bool Error(SMLoc L, const Twine &Msg,
149 ArrayRef Ranges = ArrayRef());
144 virtual bool Warning(SMLoc L, const Twine &Msg);
145 virtual bool Error(SMLoc L, const Twine &Msg);
150146
151147 const AsmToken &Lex();
152148
172168 void HandleMacroExit();
173169
174170 void PrintMacroInstantiations();
175 void PrintMessage(SMLoc Loc, SourceMgr::DiagKind Kind, const Twine &Msg,
176 ArrayRef Ranges = ArrayRef()) const {
177 SrcMgr.PrintMessage(Loc, Kind, Msg, Ranges);
171 void PrintMessage(SMLoc Loc, const Twine &Msg, const char *Type,
172 bool ShowLine = true) const {
173 SrcMgr.PrintMessage(Loc, Msg, Type, ShowLine);
178174 }
179175 static void DiagHandler(const SMDiagnostic &Diag, void *Context);
180176
354350 : Lexer(_MAI), Ctx(_Ctx), Out(_Out), MAI(_MAI), SrcMgr(_SM),
355351 GenericParser(new GenericAsmParser), PlatformParser(0),
356352 CurBuffer(0), MacrosEnabled(true), CppHashLineNumber(0) {
357 // Save the old handler.
358 SavedDiagHandler = SrcMgr.getDiagHandler();
359 SavedDiagContext = SrcMgr.getDiagContext();
360 // Set our own handler which calls the saved handler.
361353 SrcMgr.setDiagHandler(DiagHandler, this);
362354 Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer));
363355
396388 // Print the active macro instantiation stack.
397389 for (std::vector::const_reverse_iterator
398390 it = ActiveMacros.rbegin(), ie = ActiveMacros.rend(); it != ie; ++it)
399 PrintMessage((*it)->InstantiationLoc, SourceMgr::DK_Note,
400 "while in macro instantiation");
401 }
402
403 bool AsmParser::Warning(SMLoc L, const Twine &Msg, ArrayRef Ranges) {
391 PrintMessage((*it)->InstantiationLoc, "while in macro instantiation",
392 "note");
393 }
394
395 bool AsmParser::Warning(SMLoc L, const Twine &Msg) {
404396 if (FatalAssemblerWarnings)
405 return Error(L, Msg, Ranges);
406 PrintMessage(L, SourceMgr::DK_Warning, Msg, Ranges);
397 return Error(L, Msg);
398 PrintMessage(L, Msg, "warning");
407399 PrintMacroInstantiations();
408400 return false;
409401 }
410402
411 bool AsmParser::Error(SMLoc L, const Twine &Msg, ArrayRef Ranges) {
403 bool AsmParser::Error(SMLoc L, const Twine &Msg) {
412404 HadError = true;
413 PrintMessage(L, SourceMgr::DK_Error, Msg, Ranges);
405 PrintMessage(L, Msg, "error");
414406 PrintMacroInstantiations();
415407 return true;
416408 }
502494 // FIXME: We would really like to refer back to where the symbol was
503495 // first referenced for a source location. We need to add something
504496 // to track that. Currently, we just point to the end of the file.
505 PrintMessage(getLexer().getLoc(), SourceMgr::DK_Error,
506 "assembler local symbol '" + Sym->getName() +
507 "' not defined");
497 PrintMessage(getLexer().getLoc(), "assembler local symbol '" +
498 Sym->getName() + "' not defined", "error", false);
508499 }
509500 }
510501
12071198 }
12081199 OS << "]";
12091200
1210 PrintMessage(IDLoc, SourceMgr::DK_Note, OS.str());
1201 PrintMessage(IDLoc, OS.str(), "note");
12111202 }
12121203
12131204 // If parsing succeeded, match the instruction.
12811272 // Like SourceMgr::PrintMessage() we need to print the include stack if any
12821273 // before printing the message.
12831274 int DiagCurBuffer = DiagSrcMgr.FindBufferContainingLoc(DiagLoc);
1284 if (!Parser->SavedDiagHandler && DiagCurBuffer > 0) {
1275 if (DiagCurBuffer > 0) {
12851276 SMLoc ParentIncludeLoc = DiagSrcMgr.getParentIncludeLoc(DiagCurBuffer);
12861277 DiagSrcMgr.PrintIncludeStack(ParentIncludeLoc, OS);
12871278 }
12921283 if (!Parser->CppHashLineNumber ||
12931284 &DiagSrcMgr != &Parser->SrcMgr ||
12941285 DiagBuf != CppHashBuf) {
1295 if (Parser->SavedDiagHandler)
1296 Parser->SavedDiagHandler(Diag, Parser->SavedDiagContext);
1297 else
1298 Diag.print(0, OS);
1286 Diag.Print(0, OS);
12991287 return;
13001288 }
13011289
13101298 int LineNo = Parser->CppHashLineNumber - 1 +
13111299 (DiagLocLineNo - CppHashLocLineNo);
13121300
1313 SMDiagnostic NewDiag(*Diag.getSourceMgr(), Diag.getLoc(),
1314 Filename, LineNo, Diag.getColumnNo(),
1315 Diag.getKind(), Diag.getMessage(),
1316 Diag.getLineContents(), Diag.getRanges());
1317
1318 if (Parser->SavedDiagHandler)
1319 Parser->SavedDiagHandler(NewDiag, Parser->SavedDiagContext);
1320 else
1321 NewDiag.print(0, OS);
1301 SMDiagnostic NewDiag(*Diag.getSourceMgr(),
1302 Diag.getLoc(),
1303 Filename,
1304 LineNo,
1305 Diag.getColumnNo(),
1306 Diag.getMessage(),
1307 Diag.getLineContents(),
1308 Diag.getShowLine());
1309
1310 NewDiag.Print(0, OS);
13221311 }
13231312
13241313 bool AsmParser::expandMacro(SmallString<256> &Buf, StringRef Body,