39
39
#include " llvm/CAS/BuiltinUnifiedCASDatabases.h"
40
40
#include " llvm/CAS/CASReference.h"
41
41
#include " llvm/CAS/ObjectStore.h"
42
+ #include " llvm/MCCAS/MCCASObjectV1.h"
42
43
#include " llvm/Support/Allocator.h"
43
44
#include " llvm/Support/Endian.h"
44
45
#include " llvm/Support/Error.h"
@@ -940,6 +941,8 @@ static llvm::Error replayCompilation(SwiftScanReplayInstance &Instance,
940
941
};
941
942
SmallVector<OutputEntry> OutputProxies;
942
943
std::optional<llvm::cas::ObjectProxy> DiagnosticsOutput;
944
+ bool UseCASBackend = Invocation.getIRGenOptions ().UseCASBackend ;
945
+ std::string ObjFile;
943
946
944
947
swift::cas::CachedResultLoader Loader (CAS, Comp.Output );
945
948
if (auto Err = Loader.replay (
@@ -953,6 +956,9 @@ static llvm::Error replayCompilation(SwiftScanReplayInstance &Instance,
953
956
if (!Proxy)
954
957
return Proxy.takeError ();
955
958
959
+ if (Kind == file_types::ID::TY_Object && UseCASBackend)
960
+ ObjFile = OutputPath->second ;
961
+
956
962
if (Kind == file_types::ID::TY_CachedDiagnostics) {
957
963
assert (!DiagnosticsOutput && " more than 1 diagnostics found" );
958
964
DiagnosticsOutput = std::move (*Proxy);
@@ -1000,8 +1006,13 @@ static llvm::Error replayCompilation(SwiftScanReplayInstance &Instance,
1000
1006
auto File = Backend.createFile (Output.Path );
1001
1007
if (!File)
1002
1008
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 ();
1005
1016
if (auto E = File->keep ())
1006
1017
return E;
1007
1018
0 commit comments