From f42a6741de5eda904a7c7b02731f0b019bbe0c5c Mon Sep 17 00:00:00 2001 From: Sean Silva Date: Wed, 3 Oct 2012 21:29:18 +0000 Subject: tblgen: Put new TableGenMain API in place. In order to avoid rev-lock with Clang when moving to the new API, also preserve the current API temporarily and insert a shim to implement the new API in terms of the old. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165165 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/TableGen/Main.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'lib/TableGen/Main.cpp') diff --git a/lib/TableGen/Main.cpp b/lib/TableGen/Main.cpp index 7aeef56..83bc66f 100644 --- a/lib/TableGen/Main.cpp +++ b/lib/TableGen/Main.cpp @@ -22,6 +22,7 @@ #include "llvm/Support/ToolOutputFile.h" #include "llvm/Support/system_error.h" #include "llvm/TableGen/Error.h" +#include "llvm/TableGen/Main.h" #include "llvm/TableGen/Record.h" #include "llvm/TableGen/TableGenAction.h" #include @@ -47,8 +48,26 @@ namespace { cl::value_desc("directory"), cl::Prefix); } +namespace { +// XXX: this is a crutch for transitioning to the new TableGenMain API +// (with a TableGenMainFn* instead of a pointless class). +class StubTransitionalTableGenAction : public TableGenAction { + TableGenMainFn *MainFn; +public: + StubTransitionalTableGenAction(TableGenMainFn *M) : MainFn(M) {} + bool operator()(raw_ostream &OS, RecordKeeper &Records) { + return MainFn(OS, Records); + } +}; +} + namespace llvm { +int TableGenMain(char *argv0, TableGenMainFn *MainFn) { + StubTransitionalTableGenAction Action(MainFn); + return TableGenMain(argv0, Action); +} + int TableGenMain(char *argv0, TableGenAction &Action) { RecordKeeper Records; -- cgit v1.1 From 3c0962878cbc3bd5e3c482d458a242636fbbe140 Mon Sep 17 00:00:00 2001 From: Sean Silva Date: Wed, 3 Oct 2012 21:31:08 +0000 Subject: tblgen: Remove last traces of old TableGenMain API. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165168 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/TableGen/Main.cpp | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) (limited to 'lib/TableGen/Main.cpp') diff --git a/lib/TableGen/Main.cpp b/lib/TableGen/Main.cpp index 83bc66f..2c37aa7 100644 --- a/lib/TableGen/Main.cpp +++ b/lib/TableGen/Main.cpp @@ -24,7 +24,6 @@ #include "llvm/TableGen/Error.h" #include "llvm/TableGen/Main.h" #include "llvm/TableGen/Record.h" -#include "llvm/TableGen/TableGenAction.h" #include #include using namespace llvm; @@ -48,27 +47,9 @@ namespace { cl::value_desc("directory"), cl::Prefix); } -namespace { -// XXX: this is a crutch for transitioning to the new TableGenMain API -// (with a TableGenMainFn* instead of a pointless class). -class StubTransitionalTableGenAction : public TableGenAction { - TableGenMainFn *MainFn; -public: - StubTransitionalTableGenAction(TableGenMainFn *M) : MainFn(M) {} - bool operator()(raw_ostream &OS, RecordKeeper &Records) { - return MainFn(OS, Records); - } -}; -} - namespace llvm { int TableGenMain(char *argv0, TableGenMainFn *MainFn) { - StubTransitionalTableGenAction Action(MainFn); - return TableGenMain(argv0, Action); -} - -int TableGenMain(char *argv0, TableGenAction &Action) { RecordKeeper Records; try { @@ -123,7 +104,7 @@ int TableGenMain(char *argv0, TableGenAction &Action) { DepOut.keep(); } - if (Action(Out.os(), Records)) + if (MainFn(Out.os(), Records)) return 1; // Declare success. -- cgit v1.1 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/Main.cpp') 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 From 1ed3b427fa0de2569351149fc5cb4638a41e9e98 Mon Sep 17 00:00:00 2001 From: Sean Silva Date: Tue, 9 Oct 2012 20:39:28 +0000 Subject: tblgen: Rename handleDependencies -> createDependencyFile git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165544 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/TableGen/Main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/TableGen/Main.cpp') diff --git a/lib/TableGen/Main.cpp b/lib/TableGen/Main.cpp index 84de925..d87d175 100644 --- a/lib/TableGen/Main.cpp +++ b/lib/TableGen/Main.cpp @@ -51,7 +51,7 @@ namespace { /// /// 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) { +static int createDependencyFile(const TGParser &Parser, const char *argv0) { if (OutputFilename == "-") { errs() << argv0 << ": the option -d must be used together with -o\n"; return 1; @@ -111,7 +111,7 @@ int TableGenMain(char *argv0, TableGenMainFn *MainFn) { return 1; } if (!DependFilename.empty()) - if (int Ret = handleDependencies(Parser, argv0)) + if (int Ret = createDependencyFile(Parser, argv0)) return Ret; if (MainFn(Out.os(), Records)) -- cgit v1.1 From 61131ab15fd593a2e295d79fe2714e7bc21f2ec8 Mon Sep 17 00:00:00 2001 From: Joerg Sonnenberger Date: Thu, 25 Oct 2012 20:33:17 +0000 Subject: Remove exception handling usage from tblgen. Most places can use PrintFatalError as the unwinding mechanism was not used for anything other than printing the error. The single exception was CodeGenDAGPatterns.cpp, where intermediate errors during type resolution were ignored to simplify incremental platform development. This use is replaced by an error flag in TreePattern and bailout earlier in various places if it is set. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166712 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/TableGen/Main.cpp | 88 +++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 49 deletions(-) (limited to 'lib/TableGen/Main.cpp') diff --git a/lib/TableGen/Main.cpp b/lib/TableGen/Main.cpp index d87d175..d0ca756 100644 --- a/lib/TableGen/Main.cpp +++ b/lib/TableGen/Main.cpp @@ -80,56 +80,46 @@ namespace llvm { int TableGenMain(char *argv0, TableGenMainFn *MainFn) { RecordKeeper Records; - try { - // Parse the input file. - OwningPtr File; - if (error_code ec = - MemoryBuffer::getFileOrSTDIN(InputFilename.c_str(), File)) { - errs() << "Could not open input file '" << InputFilename << "': " - << ec.message() <<"\n"; - return 1; - } - MemoryBuffer *F = File.take(); - - // Tell SrcMgr about this buffer, which is what TGParser will pick up. - SrcMgr.AddNewSourceBuffer(F, SMLoc()); - - // Record the location of the include directory so that the lexer can find - // it later. - SrcMgr.setIncludeDirs(IncludeDirs); - - TGParser Parser(SrcMgr, Records); - - if (Parser.ParseFile()) - return 1; - - std::string Error; - tool_output_file Out(OutputFilename.c_str(), Error); - if (!Error.empty()) { - errs() << argv0 << ": error opening " << OutputFilename - << ":" << Error << "\n"; - return 1; - } - if (!DependFilename.empty()) - if (int Ret = createDependencyFile(Parser, argv0)) - return Ret; - - if (MainFn(Out.os(), Records)) - return 1; - - // Declare success. - Out.keep(); - return 0; - - } catch (const TGError &Error) { - PrintError(Error); - } catch (const std::string &Error) { - PrintError(Error); - } catch (const char *Error) { - PrintError(Error); - } catch (...) { - errs() << argv0 << ": Unknown unexpected exception occurred.\n"; + // Parse the input file. + OwningPtr File; + if (error_code ec = + MemoryBuffer::getFileOrSTDIN(InputFilename.c_str(), File)) { + errs() << "Could not open input file '" << InputFilename << "': " + << ec.message() <<"\n"; + return 1; } + MemoryBuffer *F = File.take(); + + // Tell SrcMgr about this buffer, which is what TGParser will pick up. + SrcMgr.AddNewSourceBuffer(F, SMLoc()); + + // Record the location of the include directory so that the lexer can find + // it later. + SrcMgr.setIncludeDirs(IncludeDirs); + + TGParser Parser(SrcMgr, Records); + + if (Parser.ParseFile()) + return 1; + + std::string Error; + tool_output_file Out(OutputFilename.c_str(), Error); + if (!Error.empty()) { + errs() << argv0 << ": error opening " << OutputFilename + << ":" << Error << "\n"; + return 1; + } + if (!DependFilename.empty()) { + if (int Ret = createDependencyFile(Parser, argv0)) + return Ret; + } + + if (MainFn(Out.os(), Records)) + return 1; + + // Declare success. + Out.keep(); + return 0; return 1; } -- cgit v1.1