From 88dbc5e6c3f29276fb9d4d1110094c08b1550e42 Mon Sep 17 00:00:00 2001 From: Sean Silva Date: Tue, 9 Oct 2012 20:29:03 +0000 Subject: tblgen: Move dependency file output to a separate function. This keeps it out of the main flow of TableGenMain. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165542 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/TableGen/Main.cpp | 52 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 21 deletions(-) (limited to 'lib/TableGen') diff --git a/lib/TableGen/Main.cpp b/lib/TableGen/Main.cpp index 2c37aa7..84de925 100644 --- a/lib/TableGen/Main.cpp +++ b/lib/TableGen/Main.cpp @@ -47,6 +47,34 @@ namespace { 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 &Dependencies = Parser.getDependencies(); + for (std::vector::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 @@ int TableGenMain(char *argv0, TableGenMainFn *MainFn) { << ":" << 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 &Dependencies = Parser.getDependencies(); - for (std::vector::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; -- cgit v1.1