For PR797:
Rid the Assembly Parser of exceptions. This is a really gross hack but it
will do until the Assembly Parser is re-written as a recursive descent.
The basic premise is that wherever the old "ThrowException" function was
called (new name: GenerateError) we set a flag (TriggerError). Every
production checks that flag and calls YYERROR if it is set. Additionally,
each call to ThrowException in the grammar is replaced with GEN_ERROR
which calls GenerateError and then YYERROR immediately. This prevents
the remaining production from continuing after an error condition.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29763 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/bugpoint/BugDriver.cpp b/tools/bugpoint/BugDriver.cpp
index 9d82e8b..e499477 100644
--- a/tools/bugpoint/BugDriver.cpp
+++ b/tools/bugpoint/BugDriver.cpp
@@ -73,15 +73,10 @@
/// return it, or return null if not possible.
///
Module *llvm::ParseInputFile(const std::string &InputFilename) {
- Module *Result = 0;
- try {
- Result = ParseBytecodeFile(InputFilename);
- if (!Result && !(Result = ParseAssemblyFile(InputFilename))){
- std::cerr << "bugpoint: could not read input file '"
- << InputFilename << "'!\n";
- }
- } catch (const ParseException &E) {
- std::cerr << "bugpoint: " << E.getMessage() << '\n';
+ ParseError Err;
+ Module *Result = ParseBytecodeFile(InputFilename);
+ if (!Result && !(Result = ParseAssemblyFile(InputFilename,&Err))) {
+ std::cerr << "bugpoint: " << Err.getMessage() << "\n";
Result = 0;
}
return Result;
diff --git a/tools/gccas/gccas.cpp b/tools/gccas/gccas.cpp
index aeef9b1..c46b296 100644
--- a/tools/gccas/gccas.cpp
+++ b/tools/gccas/gccas.cpp
@@ -137,17 +137,10 @@
" llvm .s -> .o assembler for GCC\n");
sys::PrintStackTraceOnErrorSignal();
- std::auto_ptr<Module> M;
- try {
- // Parse the file now...
- M.reset(ParseAssemblyFile(InputFilename));
- } catch (const ParseException &E) {
- std::cerr << argv[0] << ": " << E.getMessage() << "\n";
- return 1;
- }
-
+ ParseError Err;
+ std::auto_ptr<Module> M(ParseAssemblyFile(InputFilename,&Err));
if (M.get() == 0) {
- std::cerr << argv[0] << ": assembly didn't read correctly.\n";
+ std::cerr << argv[0] << ": " << Err.getMessage() << "\n";
return 1;
}
diff --git a/tools/llvm-as/llvm-as.cpp b/tools/llvm-as/llvm-as.cpp
index 9547ad1..4a1b9ad 100644
--- a/tools/llvm-as/llvm-as.cpp
+++ b/tools/llvm-as/llvm-as.cpp
@@ -57,9 +57,10 @@
std::ostream *Out = 0;
try {
// Parse the file now...
- std::auto_ptr<Module> M(ParseAssemblyFile(InputFilename));
+ ParseError Err;
+ std::auto_ptr<Module> M(ParseAssemblyFile(InputFilename,&Err));
if (M.get() == 0) {
- std::cerr << argv[0] << ": assembly didn't read correctly.\n";
+ std::cerr << argv[0] << ": " << Err.getMessage() << "\n";
return 1;
}
@@ -129,9 +130,6 @@
if (Force || !CheckBytecodeOutputToConsole(Out,true)) {
WriteBytecodeToFile(M.get(), *Out, !NoCompress);
}
- } catch (const ParseException &E) {
- std::cerr << argv[0] << ": " << E.getMessage() << "\n";
- exitCode = 1;
} catch (const std::string& msg) {
std::cerr << argv[0] << ": " << msg << "\n";
exitCode = 1;
diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp
index b67892b..18b4a8c 100644
--- a/tools/opt/opt.cpp
+++ b/tools/opt/opt.cpp
@@ -169,17 +169,13 @@
if (AnalyzeOnly) {
Module *CurMod = 0;
- try {
#if 0
- TimeRegion RegionTimer(BytecodeLoadTimer);
+ TimeRegion RegionTimer(BytecodeLoadTimer);
#endif
- CurMod = ParseBytecodeFile(InputFilename);
- if (!CurMod && !(CurMod = ParseAssemblyFile(InputFilename))){
- std::cerr << argv[0] << ": input file didn't read correctly.\n";
- return 1;
- }
- } catch (const ParseException &E) {
- std::cerr << argv[0] << ": " << E.getMessage() << "\n";
+ CurMod = ParseBytecodeFile(InputFilename);
+ ParseError Err;
+ if (!CurMod && !(CurMod = ParseAssemblyFile(InputFilename,&Err))){
+ std::cerr << argv[0] << ": " << Err.getMessage() << "\n";
return 1;
}