LLVM 22.0.0git
|
Simple in-memory representation of a document of msgpack objects with ability to find and create array and map elements. More...
#include "llvm/BinaryFormat/MsgPackDocument.h"
Public Member Functions | |
Document () | |
DocNode & | getRoot () |
Get ref to the document's root element. | |
void | clear () |
Restore the Document to an empty state. | |
DocNode | getEmptyNode () |
Create an empty node associated with this Document. | |
DocNode | getNode () |
Create a nil node associated with this Document. | |
DocNode | getNode (int64_t V) |
Create an Int node associated with this Document. | |
DocNode | getNode (int V) |
Create an Int node associated with this Document. | |
DocNode | getNode (uint64_t V) |
Create a UInt node associated with this Document. | |
DocNode | getNode (unsigned V) |
Create a UInt node associated with this Document. | |
DocNode | getNode (bool V) |
Create a Boolean node associated with this Document. | |
DocNode | getNode (double V) |
Create a Float node associated with this Document. | |
DocNode | getNode (StringRef V, bool Copy=false) |
Create a String node associated with this Document. | |
DocNode | getNode (const char *V, bool Copy=false) |
Create a String node associated with this Document. | |
DocNode | getNode (MemoryBufferRef V, bool Copy=false) |
Create a Binary node associated with this Document. | |
MapDocNode | getMapNode () |
Create an empty Map node associated with this Document. | |
ArrayDocNode | getArrayNode () |
Create an empty Array node associated with this Document. | |
LLVM_ABI bool | readFromBlob (StringRef Blob, bool Multi, function_ref< int(DocNode *DestNode, DocNode SrcNode, DocNode MapKey)> Merger=[](DocNode *DestNode, DocNode SrcNode, DocNode MapKey) { return -1;}) |
Read a document from a binary msgpack blob, merging into anything already in the Document. | |
LLVM_ABI void | writeToBlob (std::string &Blob) |
Write a MsgPack document to a binary MsgPack blob. | |
StringRef | addString (StringRef S) |
Copy a string into the Document's strings list, and return the copy that is owned by the Document. | |
void | setHexMode (bool Val=true) |
Set whether YAML output uses hex for UInt. Default off. | |
bool | getHexMode () const |
Get Hexmode flag. | |
LLVM_ABI void | toYAML (raw_ostream &OS) |
Convert MsgPack Document to YAML text. | |
LLVM_ABI bool | fromYAML (StringRef S) |
Read YAML text into the MsgPack document. Returns false on failure. | |
Simple in-memory representation of a document of msgpack objects with ability to find and create array and map elements.
Does not currently cope with any extension types.
Definition at line 280 of file MsgPackDocument.h.
|
inline |
Definition at line 297 of file MsgPackDocument.h.
References clear(), llvm::msgpack::Empty, and T.
Copy a string into the Document's strings list, and return the copy that is owned by the Document.
Definition at line 441 of file MsgPackDocument.h.
References llvm::StringRef::data(), and llvm::StringRef::size().
Referenced by getNode().
|
inline |
Restore the Document to an empty state.
Definition at line 307 of file MsgPackDocument.h.
References getEmptyNode(), and getRoot().
Referenced by Document(), and llvm::AMDGPUPALMetadata::reset().
Read YAML text into the MsgPack document. Returns false on failure.
Definition at line 242 of file MsgPackDocumentYAML.cpp.
References getRoot().
Referenced by llvm::AMDGPUTargetStreamer::EmitHSAMetadataV3(), llvm::AMDGPUPALMetadata::setFromString(), and llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV4::verify().
|
inline |
Create an empty Array node associated with this Document.
Definition at line 399 of file MsgPackDocument.h.
References llvm::msgpack::Array, and N.
Referenced by llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV4::emitKernelLanguage(), and readFromBlob().
|
inline |
Create an empty node associated with this Document.
Definition at line 310 of file MsgPackDocument.h.
References llvm::msgpack::Empty, and N.
Referenced by clear(), getNode(), llvm::msgpack::MapDocNode::operator[](), and llvm::AMDGPUPALMetadata::reset().
|
inline |
Get Hexmode flag.
Definition at line 451 of file MsgPackDocument.h.
Referenced by llvm::msgpack::DocNode::toString().
|
inline |
Create an empty Map node associated with this Document.
Definition at line 391 of file MsgPackDocument.h.
References llvm::msgpack::Map, and N.
Referenced by readFromBlob(), llvm::AMDGPUPALMetadata::setFromString(), and llvm::AMDGPUPALMetadata::toString().
|
inline |
Create a nil node associated with this Document.
Definition at line 316 of file MsgPackDocument.h.
References N, and llvm::msgpack::Nil.
Referenced by llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV4::emitKernelAttrs(), llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV5::emitKernelAttrs(), llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV4::emitKernelLanguage(), llvm::msgpack::DocNode::fromString(), getNode(), getNode(), llvm::AMDGPUPALMetadata::getRegister(), llvm::msgpack::DocNode::operator=(), llvm::msgpack::MapDocNode::operator[](), readFromBlob(), llvm::AMDGPUPALMetadata::setEntryPoint(), llvm::AMDGPUPALMetadata::setFromString(), llvm::AMDGPUPALMetadata::setFunctionLdsSize(), llvm::AMDGPUPALMetadata::setFunctionNumUsedSgprs(), llvm::AMDGPUPALMetadata::setFunctionNumUsedVgprs(), llvm::AMDGPUPALMetadata::setFunctionScratchSize(), llvm::AMDGPUPALMetadata::setNumUsedSgprs(), llvm::AMDGPUPALMetadata::setNumUsedVgprs(), llvm::AMDGPUPALMetadata::setRegister(), llvm::AMDGPUPALMetadata::setScratchSize(), and llvm::AMDGPUPALMetadata::toString().
Create a Boolean node associated with this Document.
Definition at line 350 of file MsgPackDocument.h.
References llvm::msgpack::Boolean, and N.
Create a String node associated with this Document.
If !Copy, the passed string must remain valid for the lifetime of the Document.
Definition at line 375 of file MsgPackDocument.h.
References getNode().
|
inline |
Create a Float node associated with this Document.
Definition at line 357 of file MsgPackDocument.h.
References llvm::msgpack::Float, and N.
|
inline |
Create an Int node associated with this Document.
Definition at line 329 of file MsgPackDocument.h.
References llvm::msgpack::Int, and N.
|
inline |
Create an Int node associated with this Document.
Definition at line 322 of file MsgPackDocument.h.
References llvm::msgpack::Int, and N.
|
inline |
Create a Binary node associated with this Document.
If !Copy, the passed buffer must remain valid for the lifetime of the Document.
Definition at line 381 of file MsgPackDocument.h.
References addString(), llvm::msgpack::Binary, and N.
Create a String node associated with this Document.
If !Copy, the passed string must remain valid for the lifetime of the Document.
Definition at line 365 of file MsgPackDocument.h.
References addString(), N, and llvm::msgpack::String.
Create a UInt node associated with this Document.
Definition at line 336 of file MsgPackDocument.h.
References N, and llvm::msgpack::UInt.
Create a UInt node associated with this Document.
Definition at line 343 of file MsgPackDocument.h.
References N, and llvm::msgpack::UInt.
|
inline |
Get ref to the document's root element.
Definition at line 304 of file MsgPackDocument.h.
Referenced by clear(), llvm::AMDGPUTargetAsmStreamer::EmitHSAMetadata(), llvm::AMDGPUTargetELFStreamer::EmitHSAMetadata(), llvm::AMDGPUPALMetadata::toString(), and writeToBlob().
bool Document::readFromBlob | ( | StringRef | Blob, |
bool | Multi, | ||
function_ref< int(DocNode *DestNode, DocNode SrcNode, DocNode MapKey)> | Merger = [](DocNode *DestNode, DocNode SrcNode, DocNode MapKey) { return -1; } |
||
) |
Read a document from a binary msgpack blob, merging into anything already in the Document.
The blob data must remain valid for the lifetime of this Document (because a string object in the document contains a StringRef into the original blob). If Multi, then this sets root to an array and adds top-level objects to it. If !Multi, then it only reads a single top-level object, even if there are more, and sets root to that. Returns false if failed due to illegal format or merge error.
The Merger arg is a callback function that is called when the merge has a conflict, that is, it is trying to set an item that is already set. If the conflict cannot be resolved, the callback function returns -1. If the conflict can be resolved, the callback returns a non-negative number and sets *DestNode to the resolved node. The returned non-negative number is significant only for an array node; it is then the array index to start populating at. That allows Merger to choose whether to merge array elements (returns 0) or append new elements (returns existing size).
If SrcNode is an array or map, the resolution must be that *DestNode is an array or map respectively, although it could be the array or map (respectively) that was already there. MapKey is the key if *DestNode is a map entry, a nil node otherwise.
The default for Merger is to disallow any conflict.
Definition at line 135 of file MsgPackDocument.cpp.
References llvm::msgpack::Array, assert(), llvm::msgpack::Binary, llvm::msgpack::Object::Bool, llvm::msgpack::Boolean, llvm::consumeError(), llvm::msgpack::Float, llvm::msgpack::Object::Float, llvm::Expected< T >::get(), getArrayNode(), llvm::msgpack::DocNode::getKind(), getMapNode(), getNode(), llvm::msgpack::Int, llvm::msgpack::Object::Int, llvm::msgpack::DocNode::isArray(), llvm::msgpack::DocNode::isEmpty(), llvm::msgpack::DocNode::isMap(), llvm::msgpack::Object::Kind, llvm::msgpack::Object::Length, llvm::msgpack::Map, Merger, llvm::msgpack::Nil, llvm::msgpack::Object::Raw, llvm::msgpack::Reader::read(), llvm::msgpack::String, llvm::Expected< T >::takeError(), llvm::msgpack::UInt, and llvm::msgpack::Object::UInt.
|
inline |
Set whether YAML output uses hex for UInt. Default off.
Definition at line 448 of file MsgPackDocument.h.
Referenced by llvm::AMDGPUPALMetadata::toString().
void msgpack::Document::toYAML | ( | raw_ostream & | OS | ) |
Convert MsgPack Document to YAML text.
Definition at line 236 of file MsgPackDocumentYAML.cpp.
Referenced by llvm::AMDGPUTargetAsmStreamer::EmitHSAMetadata(), llvm::AMDGPUPALMetadata::toString(), and llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV4::verify().
void Document::writeToBlob | ( | std::string & | Blob | ) |
Write a MsgPack document to a binary MsgPack blob.
Definition at line 264 of file MsgPackDocument.cpp.
References llvm::msgpack::Array, llvm::msgpack::Binary, llvm::msgpack::Boolean, llvm::msgpack::Empty, llvm::msgpack::Float, getRoot(), llvm::msgpack::Int, llvm_unreachable, llvm::msgpack::Map, llvm::msgpack::Nil, OS, llvm::msgpack::String, llvm::msgpack::UInt, llvm::msgpack::Writer::write(), llvm::msgpack::Writer::writeArraySize(), llvm::msgpack::Writer::writeMapSize(), and llvm::msgpack::Writer::writeNil().
Referenced by llvm::AMDGPUTargetELFStreamer::EmitHSAMetadata().