[llvm-commits] [llvm] r165542 - /llvm/trunk/lib/TableGen/Main.cpp
Sean Silva
silvas at purdue.edu
Tue Oct 9 13:29:04 PDT 2012
Author: silvas
Date: Tue Oct 9 15:29:03 2012
New Revision: 165542
URL: http://llvm.org/viewvc/llvm-project?rev=165542&view=rev
Log:
tblgen: Move dependency file output to a separate function.
This keeps it out of the main flow of TableGenMain.
Modified:
llvm/trunk/lib/TableGen/Main.cpp
Modified: llvm/trunk/lib/TableGen/Main.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/Main.cpp?rev=165542&r1=165541&r2=165542&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/Main.cpp (original)
+++ llvm/trunk/lib/TableGen/Main.cpp Tue Oct 9 15:29:03 2012
@@ -47,6 +47,34 @@
cl::value_desc("directory"), cl::Prefix);
}
+/// \brief Create a dependency file for `-d` option.
+///
+/// This functionality is really only for the benefit of the build system.
+/// It is similar to GCC's `-M*` family of options.
+static int handleDependencies(const TGParser &Parser, const char *argv0) {
+ if (OutputFilename == "-") {
+ errs() << argv0 << ": the option -d must be used together with -o\n";
+ return 1;
+ }
+ std::string Error;
+ tool_output_file DepOut(DependFilename.c_str(), Error);
+ if (!Error.empty()) {
+ errs() << argv0 << ": error opening " << DependFilename
+ << ":" << Error << "\n";
+ return 1;
+ }
+ DepOut.os() << OutputFilename << ":";
+ const std::vector<std::string> &Dependencies = Parser.getDependencies();
+ for (std::vector<std::string>::const_iterator I = Dependencies.begin(),
+ E = Dependencies.end();
+ I != E; ++I) {
+ DepOut.os() << " " << (*I);
+ }
+ DepOut.os() << "\n";
+ DepOut.keep();
+ return 0;
+}
+
namespace llvm {
int TableGenMain(char *argv0, TableGenMainFn *MainFn) {
@@ -82,27 +110,9 @@
<< ":" << Error << "\n";
return 1;
}
- if (!DependFilename.empty()) {
- if (OutputFilename == "-") {
- errs() << argv0 << ": the option -d must be used together with -o\n";
- return 1;
- }
- tool_output_file DepOut(DependFilename.c_str(), Error);
- if (!Error.empty()) {
- errs() << argv0 << ": error opening " << DependFilename
- << ":" << Error << "\n";
- return 1;
- }
- DepOut.os() << OutputFilename << ":";
- const std::vector<std::string> &Dependencies = Parser.getDependencies();
- for (std::vector<std::string>::const_iterator I = Dependencies.begin(),
- E = Dependencies.end();
- I != E; ++I) {
- DepOut.os() << " " << (*I);
- }
- DepOut.os() << "\n";
- DepOut.keep();
- }
+ if (!DependFilename.empty())
+ if (int Ret = handleDependencies(Parser, argv0))
+ return Ret;
if (MainFn(Out.os(), Records))
return 1;
More information about the llvm-commits
mailing list