//
//===----------------------------------------------------------------------===//
+#include "Error.h"
#include "CompilationGraph.h"
#include "llvm/ADT/STLExtras.h"
const std::string& CompilationGraph::getLanguage(const sys::Path& File) const {
LanguageMap::const_iterator Lang = ExtsToLangs.find(File.getSuffix());
if (Lang == ExtsToLangs.end())
- throw std::runtime_error("Unknown suffix: " + File.getSuffix() + '!');
+ throw std::runtime_error("Unknown suffix: " + File.getSuffix());
return Lang->second;
}
tools_map_type::const_iterator I = ToolsMap.find(LangName);
if (I == ToolsMap.end())
throw std::runtime_error("No tool corresponding to the language "
- + LangName + "found!");
+ + LangName + "found");
return I->second;
}
Out = MakeTempFile(TempDir, In.getBasename(), CurTool->OutputSuffix());
}
- if (CurTool->GenerateAction(In, Out).Execute() != 0)
- throw std::runtime_error("Tool returned error code!");
+ if (int ret = CurTool->GenerateAction(In, Out).Execute())
+ throw error_code(ret);
if (Last)
return;
// Find the toolchain for the input language.
const tools_vector_type& TV = getToolsVector(InLanguage);
if (TV.empty())
- throw std::runtime_error("No toolchain corresponding to language"
- + InLanguage + " found!");
+ throw std::runtime_error("No toolchain corresponding to language "
+ + InLanguage + " found");
return &getNode(ChooseEdge(TV, InLangs)->ToolName());
}
Out = MakeTempFile(TempDir, "tmp", JT->OutputSuffix());
}
- if (JT->GenerateAction(Out).Execute() != 0)
- throw std::runtime_error("Tool returned error code!");
+ if (int ret = JT->GenerateAction(Out).Execute())
+ throw error_code(ret);
if (!IsLast) {
const Node* NextNode =
O.close();
}
else {
- throw std::runtime_error("");
+ throw std::runtime_error("Error opening file for writing");
}
}
--- /dev/null
+//===--- Error.h - The LLVM Compiler Driver ---------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open
+// Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Exception classes for LLVMC.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TOOLS_LLVMC2_ERROR_H
+#define LLVM_TOOLS_LLVMC2_ERROR_H
+
+#include <stdexcept>
+
+namespace llvmc {
+
+ class error_code: public std::runtime_error {
+ int Code_;
+ public:
+ error_code (int c)
+ : std::runtime_error("Tool returned error code"), Code_(c)
+ {}
+
+ int code() const { return Code_; }
+ };
+
+}
+
+#endif //LLVM_TOOLS_LLVMC2_ERROR_H
//===----------------------------------------------------------------------===//
#include "CompilationGraph.h"
+#include "Error.h"
#include "Tool.h"
#include "llvm/System/Path.h"
return BuildTargets(graph);
}
+ catch(llvmc::error_code& ec) {
+ return ec.code();
+ }
catch(const std::exception& ex) {
std::cerr << ex.what() << '\n';
}