LLVM  12.0.0git
Public Member Functions | List of all members
llvm::msgpack::Document Class Reference

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 ()
 
DocNodegetRoot ()
 Get ref to the document's root element. More...
 
void clear ()
 Restore the Document to an empty state. More...
 
DocNode getEmptyNode ()
 Create an empty node associated with this Document. More...
 
DocNode getNode ()
 Create a nil node associated with this Document. More...
 
DocNode getNode (int64_t V)
 Create an Int node associated with this Document. More...
 
DocNode getNode (int V)
 Create an Int node associated with this Document. More...
 
DocNode getNode (uint64_t V)
 Create a UInt node associated with this Document. More...
 
DocNode getNode (unsigned V)
 Create a UInt node associated with this Document. More...
 
DocNode getNode (bool V)
 Create a Boolean node associated with this Document. More...
 
DocNode getNode (double V)
 Create a Float node associated with this Document. More...
 
DocNode getNode (StringRef V, bool Copy=false)
 Create a String node associated with this Document. More...
 
DocNode getNode (const char *V, bool Copy=false)
 Create a String node associated with this Document. More...
 
MapDocNode getMapNode ()
 Create an empty Map node associated with this Document. More...
 
ArrayDocNode getArrayNode ()
 Create an empty Array node associated with this Document. More...
 
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. More...
 
void writeToBlob (std::string &Blob)
 Write a MsgPack document to a binary MsgPack blob. More...
 
StringRef addString (StringRef S)
 Copy a string into the Document's strings list, and return the copy that is owned by the Document. More...
 
void setHexMode (bool Val=true)
 Set whether YAML output uses hex for UInt. Default off. More...
 
bool getHexMode () const
 Get Hexmode flag. More...
 
void toYAML (raw_ostream &OS)
 Convert MsgPack Document to YAML text. More...
 
bool fromYAML (StringRef S)
 Read YAML text into the MsgPack document. Returns false on failure. More...
 

Detailed Description

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 272 of file MsgPackDocument.h.

Constructor & Destructor Documentation

◆ Document()

llvm::msgpack::Document::Document ( )
inline

Definition at line 289 of file MsgPackDocument.h.

References clear(), and llvm::msgpack::Empty.

Member Function Documentation

◆ addString()

StringRef llvm::msgpack::Document::addString ( StringRef  S)
inline

Copy a string into the Document's strings list, and return the copy that is owned by the Document.

Definition at line 422 of file MsgPackDocument.h.

References llvm::StringRef::data(), and llvm::StringRef::size().

◆ clear()

void llvm::msgpack::Document::clear ( )
inline

Restore the Document to an empty state.

Definition at line 299 of file MsgPackDocument.h.

◆ fromYAML()

bool msgpack::Document::fromYAML ( StringRef  S)

Read YAML text into the MsgPack document. Returns false on failure.

Definition at line 243 of file MsgPackDocumentYAML.cpp.

References clear().

Referenced by llvm::AMDGPUTargetStreamer::EmitHSAMetadataV3(), and llvm::AMDGPU::HSAMD::MetadataStreamerV2::emitKernel().

◆ getArrayNode()

ArrayDocNode llvm::msgpack::Document::getArrayNode ( )
inline

Create an empty Array node associated with this Document.

Definition at line 380 of file MsgPackDocument.h.

References llvm::msgpack::Array, Merger, and N.

Referenced by llvm::AMDGPU::HSAMD::MetadataStreamerV2::emitKernel().

◆ getEmptyNode()

DocNode llvm::msgpack::Document::getEmptyNode ( )
inline

Create an empty node associated with this Document.

Definition at line 302 of file MsgPackDocument.h.

References llvm::msgpack::Empty, and N.

Referenced by llvm::msgpack::MapDocNode::operator[]().

◆ getHexMode()

bool llvm::msgpack::Document::getHexMode ( ) const
inline

Get Hexmode flag.

Definition at line 432 of file MsgPackDocument.h.

◆ getMapNode()

MapDocNode llvm::msgpack::Document::getMapNode ( )
inline

Create an empty Map node associated with this Document.

Definition at line 372 of file MsgPackDocument.h.

References llvm::msgpack::Map, and N.

◆ getNode() [1/9]

DocNode llvm::msgpack::Document::getNode ( )
inline

◆ getNode() [2/9]

DocNode llvm::msgpack::Document::getNode ( int64_t  V)
inline

Create an Int node associated with this Document.

Definition at line 314 of file MsgPackDocument.h.

References llvm::msgpack::Int, and N.

◆ getNode() [3/9]

DocNode llvm::msgpack::Document::getNode ( int  V)
inline

Create an Int node associated with this Document.

Definition at line 321 of file MsgPackDocument.h.

References llvm::msgpack::Int, and N.

◆ getNode() [4/9]

DocNode llvm::msgpack::Document::getNode ( uint64_t  V)
inline

Create a UInt node associated with this Document.

Definition at line 328 of file MsgPackDocument.h.

References N, and llvm::msgpack::UInt.

◆ getNode() [5/9]

DocNode llvm::msgpack::Document::getNode ( unsigned  V)
inline

Create a UInt node associated with this Document.

Definition at line 335 of file MsgPackDocument.h.

References N, and llvm::msgpack::UInt.

◆ getNode() [6/9]

DocNode llvm::msgpack::Document::getNode ( bool  V)
inline

Create a Boolean node associated with this Document.

Definition at line 342 of file MsgPackDocument.h.

References llvm::msgpack::Boolean, and N.

◆ getNode() [7/9]

DocNode llvm::msgpack::Document::getNode ( double  V)
inline

Create a Float node associated with this Document.

Definition at line 349 of file MsgPackDocument.h.

References llvm::msgpack::Float, and N.

◆ getNode() [8/9]

DocNode llvm::msgpack::Document::getNode ( StringRef  V,
bool  Copy = false 
)
inline

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 357 of file MsgPackDocument.h.

References N, and llvm::msgpack::String.

◆ getNode() [9/9]

DocNode llvm::msgpack::Document::getNode ( const char V,
bool  Copy = false 
)
inline

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 367 of file MsgPackDocument.h.

◆ getRoot()

DocNode& llvm::msgpack::Document::getRoot ( )
inline

Get ref to the document's root element.

Definition at line 296 of file MsgPackDocument.h.

Referenced by llvm::AMDGPUTargetAsmStreamer::EmitHSAMetadata(), and llvm::AMDGPUTargetELFStreamer::EmitHSAMetadata().

◆ readFromBlob()

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 127 of file MsgPackDocument.cpp.

References llvm::SmallVectorTemplateBase< T >::push_back(), llvm::msgpack::Reader::read(), and llvm::SmallVectorBase< SmallVectorSizeType< T > >::size().

◆ setHexMode()

void llvm::msgpack::Document::setHexMode ( bool  Val = true)
inline

Set whether YAML output uses hex for UInt. Default off.

Definition at line 429 of file MsgPackDocument.h.

◆ toYAML()

void msgpack::Document::toYAML ( raw_ostream OS)

◆ writeToBlob()

void Document::writeToBlob ( std::string &  Blob)

Write a MsgPack document to a binary MsgPack blob.

Definition at line 247 of file MsgPackDocument.cpp.

Referenced by llvm::AMDGPUTargetELFStreamer::EmitHSAMetadata().


The documentation for this class was generated from the following files: