xref: /freebsd-src/contrib/llvm-project/llvm/lib/XRay/LogBuilderConsumer.cpp (revision 0b57cec536236d46e3dba9bd041533462f33dbb7)
1*0b57cec5SDimitry Andric //===- FDRRecordConsumer.h - XRay Flight Data Recorder Mode Records -------===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric #include "llvm/XRay/FDRRecordConsumer.h"
9*0b57cec5SDimitry Andric 
10*0b57cec5SDimitry Andric namespace llvm {
11*0b57cec5SDimitry Andric namespace xray {
12*0b57cec5SDimitry Andric 
consume(std::unique_ptr<Record> R)13*0b57cec5SDimitry Andric Error LogBuilderConsumer::consume(std::unique_ptr<Record> R) {
14*0b57cec5SDimitry Andric   if (!R)
15*0b57cec5SDimitry Andric     return createStringError(
16*0b57cec5SDimitry Andric         std::make_error_code(std::errc::invalid_argument),
17*0b57cec5SDimitry Andric         "Must not call RecordConsumer::consume() with a null pointer.");
18*0b57cec5SDimitry Andric   Records.push_back(std::move(R));
19*0b57cec5SDimitry Andric   return Error::success();
20*0b57cec5SDimitry Andric }
21*0b57cec5SDimitry Andric 
consume(std::unique_ptr<Record> R)22*0b57cec5SDimitry Andric Error PipelineConsumer::consume(std::unique_ptr<Record> R) {
23*0b57cec5SDimitry Andric   if (!R)
24*0b57cec5SDimitry Andric     return createStringError(
25*0b57cec5SDimitry Andric         std::make_error_code(std::errc::invalid_argument),
26*0b57cec5SDimitry Andric         "Must not call RecordConsumer::consume() with a null pointer.");
27*0b57cec5SDimitry Andric 
28*0b57cec5SDimitry Andric   // We apply all of the visitors in order, and concatenate errors
29*0b57cec5SDimitry Andric   // appropriately.
30*0b57cec5SDimitry Andric   Error Result = Error::success();
31*0b57cec5SDimitry Andric   for (auto *V : Visitors)
32*0b57cec5SDimitry Andric     Result = joinErrors(std::move(Result), R->apply(*V));
33*0b57cec5SDimitry Andric   return Result;
34*0b57cec5SDimitry Andric }
35*0b57cec5SDimitry Andric 
36*0b57cec5SDimitry Andric } // namespace xray
37*0b57cec5SDimitry Andric } // namespace llvm
38