TableGen: Make 2nd arg `MainFn` of `TableGenMain(argv0, MainFn)` optional.
authorNAKAMURA Takumi <geek4civic@gmail.com>
Tue, 21 Mar 2023 03:58:57 +0000 (12:58 +0900)
committerNAKAMURA Takumi <geek4civic@gmail.com>
Tue, 21 Mar 2023 07:21:27 +0000 (16:21 +0900)
llvm/include/llvm/TableGen/Main.h
llvm/lib/TableGen/Main.cpp

index 4e05da3..4639ec7 100644 (file)
@@ -13,6 +13,8 @@
 #ifndef LLVM_TABLEGEN_MAIN_H
 #define LLVM_TABLEGEN_MAIN_H
 
+#include <functional>
+
 namespace llvm {
 
 class raw_ostream;
@@ -22,7 +24,8 @@ class RecordKeeper;
 /// Returns true on error, false otherwise.
 using TableGenMainFn = bool (raw_ostream &OS, RecordKeeper &Records);
 
-int TableGenMain(const char *argv0, TableGenMainFn *MainFn);
+int TableGenMain(const char *argv0,
+                 std::function<TableGenMainFn> MainFn = nullptr);
 
 } // end namespace llvm
 
index 2f9ac86..ee72b4b 100644 (file)
@@ -95,7 +95,8 @@ static int createDependencyFile(const TGParser &Parser, const char *argv0) {
   return 0;
 }
 
-int llvm::TableGenMain(const char *argv0, TableGenMainFn *MainFn) {
+int llvm::TableGenMain(const char *argv0,
+                       std::function<TableGenMainFn> MainFn) {
   RecordKeeper Records;
 
   if (TimePhases)
@@ -129,7 +130,11 @@ int llvm::TableGenMain(const char *argv0, TableGenMainFn *MainFn) {
   Records.startBackendTimer("Backend overall");
   std::string OutString;
   raw_string_ostream Out(OutString);
-  unsigned status = MainFn(Out, Records);
+  unsigned status = 0;
+  if (MainFn)
+    status = MainFn(Out, Records);
+  else
+    return 1;
   Records.stopBackendTimer();
   if (status)
     return 1;