[llvm] [readtapi] Add Merge functionality (PR #72656)

Juergen Ributzka via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 17 08:19:38 PST 2023


================
@@ -81,28 +89,37 @@ bool handleCompareAction(const Context &Ctx) {
     ExitOnErr(make_error<TextAPIError>(TextAPIErrorCode::InvalidInputFormat,
                                        "compare only supports 2 input files"));
   }
-  StringRef InputFileName = Ctx.Inputs.front();
-  ExitOnErr.setBanner("error: '" + InputFileName.str() + "' ");
-  auto BinLHS = ExitOnErr(convertFileToBinary(InputFileName));
-
-  TapiUniversal *FileLHS = dyn_cast<TapiUniversal>(BinLHS.get());
-  if (!FileLHS) {
-    ExitOnErr(createStringError(std::errc::executable_format_error,
-                                "unsupported file format"));
-  }
 
-  StringRef CompareInputFileName = Ctx.Inputs.at(1);
-  ExitOnErr.setBanner("error: '" + CompareInputFileName.str() + "' ");
-  auto BinRHS = ExitOnErr(convertFileToBinary(CompareInputFileName));
+  auto LeftIF = getInterfaceFile(Ctx.Inputs.front(), ExitOnErr);
+  auto RightIF = getInterfaceFile(Ctx.Inputs.at(1), ExitOnErr);
+
+  raw_ostream &OS = Ctx.OutStream ? *Ctx.OutStream : outs();
+  return DiffEngine(LeftIF.get(), RightIF.get()).compareFiles(OS);
+}
 
-  TapiUniversal *FileRHS = dyn_cast<TapiUniversal>(BinRHS.get());
-  if (!FileRHS) {
-    ExitOnErr(createStringError(std::errc::executable_format_error,
-                                "unsupported file format"));
+bool handleMergeAction(const Context &Ctx) {
+  ExitOnError ExitOnErr("error: ");
+  if (Ctx.Inputs.size() < 2) {
+    ExitOnErr(
+        make_error<TextAPIError>(TextAPIErrorCode::InvalidInputFormat,
+                                 "merge requires at least two input files"));
+  }
+  std::unique_ptr<InterfaceFile> Out;
+  for (StringRef FileName : Ctx.Inputs) {
+    auto IF = getInterfaceFile(FileName, ExitOnErr);
+    if (!Out) {
----------------
ributzka wrote:

A comment would be helpful here. For example: Copy the first input file directly to the output and skip the merge.

https://github.com/llvm/llvm-project/pull/72656


More information about the llvm-commits mailing list