[llvm] f675ec6 - TableGen: Make 2nd arg `MainFn` of `TableGenMain(argv0, MainFn)` optional.
NAKAMURA Takumi via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 21 00:22:22 PDT 2023
Author: NAKAMURA Takumi
Date: 2023-03-21T16:21:27+09:00
New Revision: f675ec6165ab6add5e57cd43a2e9fa1a9bc21d81
URL: https://github.com/llvm/llvm-project/commit/f675ec6165ab6add5e57cd43a2e9fa1a9bc21d81
DIFF: https://github.com/llvm/llvm-project/commit/f675ec6165ab6add5e57cd43a2e9fa1a9bc21d81.diff
LOG: TableGen: Make 2nd arg `MainFn` of `TableGenMain(argv0, MainFn)` optional.
Added:
Modified:
llvm/include/llvm/TableGen/Main.h
llvm/lib/TableGen/Main.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/TableGen/Main.h b/llvm/include/llvm/TableGen/Main.h
index 4e05da36168f7..4639ec756e9b1 100644
--- a/llvm/include/llvm/TableGen/Main.h
+++ b/llvm/include/llvm/TableGen/Main.h
@@ -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
diff --git a/llvm/lib/TableGen/Main.cpp b/llvm/lib/TableGen/Main.cpp
index 2f9ac86e1f07b..ee72b4b2e9e74 100644
--- a/llvm/lib/TableGen/Main.cpp
+++ b/llvm/lib/TableGen/Main.cpp
@@ -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;
More information about the llvm-commits
mailing list