xref: /llvm-project/llvm/lib/XRay/LogBuilderConsumer.cpp (revision 2946cd701067404b99c39fb29dc9c74bd7193eb3)
1146d5791SDean Michael Berris //===- FDRRecordConsumer.h - XRay Flight Data Recorder Mode Records -------===//
2146d5791SDean Michael Berris //
3*2946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*2946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
5*2946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6146d5791SDean Michael Berris //
7146d5791SDean Michael Berris //===----------------------------------------------------------------------===//
8146d5791SDean Michael Berris #include "llvm/XRay/FDRRecordConsumer.h"
9146d5791SDean Michael Berris 
10146d5791SDean Michael Berris namespace llvm {
11146d5791SDean Michael Berris namespace xray {
12146d5791SDean Michael Berris 
consume(std::unique_ptr<Record> R)13146d5791SDean Michael Berris Error LogBuilderConsumer::consume(std::unique_ptr<Record> R) {
14146d5791SDean Michael Berris   if (!R)
15146d5791SDean Michael Berris     return createStringError(
16146d5791SDean Michael Berris         std::make_error_code(std::errc::invalid_argument),
17146d5791SDean Michael Berris         "Must not call RecordConsumer::consume() with a null pointer.");
18146d5791SDean Michael Berris   Records.push_back(std::move(R));
19146d5791SDean Michael Berris   return Error::success();
20146d5791SDean Michael Berris }
21146d5791SDean Michael Berris 
consume(std::unique_ptr<Record> R)22146d5791SDean Michael Berris Error PipelineConsumer::consume(std::unique_ptr<Record> R) {
23146d5791SDean Michael Berris   if (!R)
24146d5791SDean Michael Berris     return createStringError(
25146d5791SDean Michael Berris         std::make_error_code(std::errc::invalid_argument),
26146d5791SDean Michael Berris         "Must not call RecordConsumer::consume() with a null pointer.");
27146d5791SDean Michael Berris 
28146d5791SDean Michael Berris   // We apply all of the visitors in order, and concatenate errors
29146d5791SDean Michael Berris   // appropriately.
30146d5791SDean Michael Berris   Error Result = Error::success();
31146d5791SDean Michael Berris   for (auto *V : Visitors)
32146d5791SDean Michael Berris     Result = joinErrors(std::move(Result), R->apply(*V));
33146d5791SDean Michael Berris   return Result;
34146d5791SDean Michael Berris }
35146d5791SDean Michael Berris 
36146d5791SDean Michael Berris } // namespace xray
37146d5791SDean Michael Berris } // namespace llvm
38