summaryrefslogtreecommitdiff
path: root/tools/gccas
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2004-12-30 05:36:08 +0000
committerReid Spencer <rspencer@reidspencer.com>2004-12-30 05:36:08 +0000
commit1ef8bdaedbd98bee35a573b8bc87149f2182cb5e (patch)
treedc21da7903997dfbcf6061f19b35a2a522c740b9 /tools/gccas
parentc18671cdcd53df08cbeff7ecf443475f61971b9d (diff)
downloadllvm-1ef8bdaedbd98bee35a573b8bc87149f2182cb5e.tar.gz
llvm-1ef8bdaedbd98bee35a573b8bc87149f2182cb5e.tar.bz2
llvm-1ef8bdaedbd98bee35a573b8bc87149f2182cb5e.tar.xz
For PR351:
* Place a try/catch block around the entire tool to Make sure std::string exceptions are caught and printed before exiting the tool. * Make sure we catch unhandled exceptions at the top level so that we don't abort with a useless message but indicate than an unhandled exception was generated. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19192 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/gccas')
-rw-r--r--tools/gccas/gccas.cpp122
1 files changed, 65 insertions, 57 deletions
diff --git a/tools/gccas/gccas.cpp b/tools/gccas/gccas.cpp
index 813042cf50..c222c6e183 100644
--- a/tools/gccas/gccas.cpp
+++ b/tools/gccas/gccas.cpp
@@ -128,77 +128,85 @@ void AddConfiguredTransformationPasses(PassManager &PM) {
int main(int argc, char **argv) {
- cl::ParseCommandLineOptions(argc, argv, " 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;
- }
+ cl::ParseCommandLineOptions(argc, argv,
+ " 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;
+ }
- if (M.get() == 0) {
- std::cerr << argv[0] << ": assembly didn't read correctly.\n";
- return 1;
- }
+ if (M.get() == 0) {
+ std::cerr << argv[0] << ": assembly didn't read correctly.\n";
+ return 1;
+ }
- std::ostream *Out = 0;
- if (OutputFilename == "") { // Didn't specify an output filename?
- if (InputFilename == "-") {
- OutputFilename = "-";
- } else {
- std::string IFN = InputFilename;
- int Len = IFN.length();
- if (IFN[Len-2] == '.' && IFN[Len-1] == 's') { // Source ends in .s?
- OutputFilename = std::string(IFN.begin(), IFN.end()-2);
+ std::ostream *Out = 0;
+ if (OutputFilename == "") { // Didn't specify an output filename?
+ if (InputFilename == "-") {
+ OutputFilename = "-";
} else {
- OutputFilename = IFN; // Append a .o to it
+ std::string IFN = InputFilename;
+ int Len = IFN.length();
+ if (IFN[Len-2] == '.' && IFN[Len-1] == 's') { // Source ends in .s?
+ OutputFilename = std::string(IFN.begin(), IFN.end()-2);
+ } else {
+ OutputFilename = IFN; // Append a .o to it
+ }
+ OutputFilename += ".o";
}
- OutputFilename += ".o";
}
- }
- if (OutputFilename == "-")
- Out = &std::cout;
- else {
- Out = new std::ofstream(OutputFilename.c_str(), std::ios::out);
+ if (OutputFilename == "-")
+ Out = &std::cout;
+ else {
+ Out = new std::ofstream(OutputFilename.c_str(), std::ios::out);
- // Make sure that the Out file gets unlinked from the disk if we get a
- // signal
- sys::RemoveFileOnSignal(sys::Path(OutputFilename));
- }
+ // Make sure that the Out file gets unlinked from the disk if we get a
+ // signal
+ sys::RemoveFileOnSignal(sys::Path(OutputFilename));
+ }
-
- if (!Out->good()) {
- std::cerr << argv[0] << ": error opening " << OutputFilename << "!\n";
- return 1;
- }
+
+ if (!Out->good()) {
+ std::cerr << argv[0] << ": error opening " << OutputFilename << "!\n";
+ return 1;
+ }
- // In addition to just parsing the input from GCC, we also want to spiff it up
- // a little bit. Do this now.
- //
- PassManager Passes;
+ // In addition to just parsing the input from GCC, we also want to spiff it up
+ // a little bit. Do this now.
+ //
+ PassManager Passes;
- // Add an appropriate TargetData instance for this module...
- Passes.add(new TargetData("gccas", M.get()));
+ // Add an appropriate TargetData instance for this module...
+ Passes.add(new TargetData("gccas", M.get()));
- // Add all of the transformation passes to the pass manager to do the cleanup
- // and optimization of the GCC output.
- //
- AddConfiguredTransformationPasses(Passes);
+ // Add all of the transformation passes to the pass manager to do the cleanup
+ // and optimization of the GCC output.
+ //
+ AddConfiguredTransformationPasses(Passes);
- // Make sure everything is still good.
- Passes.add(createVerifierPass());
+ // Make sure everything is still good.
+ Passes.add(createVerifierPass());
- // Write bytecode to file...
- Passes.add(new WriteBytecodePass(Out,false,!NoCompress));
+ // Write bytecode to file...
+ Passes.add(new WriteBytecodePass(Out,false,!NoCompress));
- // Run our queue of passes all at once now, efficiently.
- Passes.run(*M.get());
+ // Run our queue of passes all at once now, efficiently.
+ Passes.run(*M.get());
- if (Out != &std::cout) delete Out;
- return 0;
+ if (Out != &std::cout) delete Out;
+ return 0;
+ } catch (const std::string& msg) {
+ std::cerr << argv[0] << ": " << msg << "\n";
+ } catch (...) {
+ std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
+ }
+ return 1;
}