3030#include " llvm/CAS/HierarchicalTreeBuilder.h"
3131#include " llvm/CAS/ObjectStore.h"
3232#include " llvm/CAS/TreeEntry.h"
33+ #include " llvm/MCCAS/MCCASObjectV1.h"
3334#include " llvm/Option/ArgList.h"
3435#include " llvm/Option/OptTable.h"
3536#include " llvm/Support/Debug.h"
@@ -135,7 +136,7 @@ lookupCacheKey(ObjectStore &CAS, ActionCache &Cache, ObjectRef CacheKey) {
135136bool replayCachedCompilerOutputs (
136137 ObjectStore &CAS, ActionCache &Cache, ObjectRef BaseKey,
137138 DiagnosticEngine &Diag, const FrontendInputsAndOutputs &InputsAndOutputs,
138- CachingDiagnosticsProcessor &CDP, bool CacheRemarks) {
139+ CachingDiagnosticsProcessor &CDP, bool CacheRemarks, bool UseCASBackend ) {
139140 bool CanReplayAllOutput = true ;
140141 struct OutputEntry {
141142 std::string Path;
@@ -144,6 +145,7 @@ bool replayCachedCompilerOutputs(
144145 };
145146 SmallVector<OutputEntry> OutputProxies;
146147 std::optional<OutputEntry> DiagnosticsOutput;
148+ std::string ObjFile;
147149
148150 auto replayOutputsForInputFile = [&](const std::string &InputPath,
149151 unsigned InputIndex,
@@ -177,7 +179,6 @@ bool replayCachedCompilerOutputs(
177179 CachedResultLoader Loader (CAS, **OutputRef);
178180 LLVM_DEBUG (llvm::dbgs () << " DEBUG: lookup cache key \' " << OutID.toString ()
179181 << " \' for input \' " << InputPath << " \n " ;);
180-
181182 if (auto Err = Loader.replay ([&](file_types::ID Kind,
182183 ObjectRef Ref) -> Error {
183184 auto OutputPath = Outputs.find (Kind);
@@ -189,6 +190,9 @@ bool replayCachedCompilerOutputs(
189190 if (!Proxy)
190191 return Proxy.takeError ();
191192
193+ if (Kind == file_types::ID::TY_Object && UseCASBackend)
194+ ObjFile = OutputPath->second ;
195+
192196 if (Kind == file_types::ID::TY_CachedDiagnostics) {
193197 assert (!DiagnosticsOutput && " more than 1 diagnotics found" );
194198 DiagnosticsOutput = OutputEntry{OutputPath->second , OutID, *Proxy};
@@ -282,7 +286,14 @@ bool replayCachedCompilerOutputs(
282286 toString (File.takeError ()));
283287 continue ;
284288 }
285- *File << Output.Proxy .getData ();
289+
290+ if (UseCASBackend && Output.Path == ObjFile) {
291+ auto Schema = std::make_unique<llvm::mccasformats::v1::MCSchema>(CAS);
292+ if (auto E = Schema->serializeObjectFile (Output.Proxy , *File))
293+ Diag.diagnose (SourceLoc (), diag::error_mccas, toString (std::move (E)));
294+ } else
295+ *File << Output.Proxy .getData ();
296+
286297 if (auto E = File->keep ()) {
287298 Diag.diagnose (SourceLoc (), diag::error_closing_output, Output.Path ,
288299 toString (std::move (E)));
0 commit comments