3939#include " llvm/CAS/BuiltinUnifiedCASDatabases.h"
4040#include " llvm/CAS/CASReference.h"
4141#include " llvm/CAS/ObjectStore.h"
42+ #include " llvm/MCCAS/MCCASObjectV1.h"
4243#include " llvm/Support/Allocator.h"
4344#include " llvm/Support/Endian.h"
4445#include " llvm/Support/Error.h"
@@ -940,6 +941,8 @@ static llvm::Error replayCompilation(SwiftScanReplayInstance &Instance,
940941 };
941942 SmallVector<OutputEntry> OutputProxies;
942943 std::optional<llvm::cas::ObjectProxy> DiagnosticsOutput;
944+ bool UseCASBackend = Invocation.getIRGenOptions ().UseCASBackend ;
945+ std::string ObjFile;
943946
944947 swift::cas::CachedResultLoader Loader (CAS, Comp.Output );
945948 if (auto Err = Loader.replay (
@@ -953,6 +956,9 @@ static llvm::Error replayCompilation(SwiftScanReplayInstance &Instance,
953956 if (!Proxy)
954957 return Proxy.takeError ();
955958
959+ if (Kind == file_types::ID::TY_Object && UseCASBackend)
960+ ObjFile = OutputPath->second ;
961+
956962 if (Kind == file_types::ID::TY_CachedDiagnostics) {
957963 assert (!DiagnosticsOutput && " more than 1 diagnostics found" );
958964 DiagnosticsOutput = std::move (*Proxy);
@@ -1000,8 +1006,13 @@ static llvm::Error replayCompilation(SwiftScanReplayInstance &Instance,
10001006 auto File = Backend.createFile (Output.Path );
10011007 if (!File)
10021008 return File.takeError ();
1003-
1004- *File << Output.Proxy .getData ();
1009+ if (UseCASBackend && Output.Path == ObjFile) {
1010+ auto Schema = std::make_unique<llvm::mccasformats::v1::MCSchema>(CAS);
1011+ if (auto E = Schema->serializeObjectFile (Output.Proxy , *File))
1012+ Inst.getDiags ().diagnose (SourceLoc (), diag::error_mccas,
1013+ toString (std::move (E)));
1014+ } else
1015+ *File << Output.Proxy .getData ();
10051016 if (auto E = File->keep ())
10061017 return E;
10071018
0 commit comments