17#ifndef LLVM_BINARYFORMAT_MSGPACKDOCUMENT_H
18#define LLVM_BINARYFORMAT_MSGPACKDOCUMENT_H
43 typedef std::map<DocNode, DocNode>
MapTy;
161 if (Lhs.KindAndDoc != Rhs.KindAndDoc) {
187 return !(Lhs < Rhs) && !(Rhs < Lhs);
192 return !(Lhs == Rhs);
236 MapTy::iterator
end() {
return Map->end(); }
239 MapTy::iterator
erase(MapTy::const_iterator
I) {
return Map->erase(
I); }
242 MapTy::const_iterator Second) {
283 std::vector<std::unique_ptr<DocNode::MapTy>> Maps;
284 std::vector<std::unique_ptr<DocNode::ArrayTy>> Arrays;
285 std::vector<std::unique_ptr<char[]>> Strings;
294 bool HexMode =
false;
300 KindAndDocs[
T] = {
this,
Type(
T)};
382 auto Raw = V.getBuffer();
393 Maps.push_back(std::make_unique<DocNode::MapTy>());
394 N.Map = Maps.back().get();
401 Arrays.push_back(std::make_unique<DocNode::ArrayTy>());
402 N.Array = Arrays.back().get();
442 Strings.push_back(std::unique_ptr<
char[]>(
new char[S.
size()]));
443 memcpy(&Strings.back()[0], S.
data(), S.
size());
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
StringRef - Represent a constant reference to a string, i.e.
constexpr size_t size() const
size - Get the string size.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
An efficient, type-erasing, non-owning reference to a callable.
A DocNode that is an array.
void push_back(DocNode N)
LLVM_ABI DocNode & operator[](size_t Index)
Element access. This extends the array if necessary, with empty nodes.
ArrayTy::iterator begin()
A node in a MsgPack Document.
MapDocNode & getMap(bool Convert=false)
Get a MapDocNode for a map node.
LLVM_ABI StringRef fromString(StringRef S, StringRef Tag="")
Convert the StringRef and use it to set this DocNode (assuming scalar).
friend bool operator!=(const DocNode &Lhs, const DocNode &Rhs)
Inequality operator.
std::map< DocNode, DocNode > MapTy
ArrayDocNode & getArray(bool Convert=false)
Get an ArrayDocNode for an array node.
MemoryBufferRef getBinary() const
StringRef getString() const
LLVM_ABI std::string toString() const
Convert this node to a string, assuming it is scalar.
std::vector< DocNode > ArrayTy
DocNode & operator=(const char *Val)
Convenience assignment operators.
friend bool operator==(const DocNode &Lhs, const DocNode &Rhs)
Equality operator.
friend bool operator<(const DocNode &Lhs, const DocNode &Rhs)
Comparison operator, used for map keys.
Document * getDocument() const
Simple in-memory representation of a document of msgpack objects with ability to find and create arra...
bool getHexMode() const
Get Hexmode flag.
DocNode getNode(unsigned V)
Create a UInt node associated with this Document.
DocNode getNode(StringRef V, bool Copy=false)
Create a String node associated with this Document.
DocNode getNode(double V)
Create a Float node associated with this Document.
MapDocNode getMapNode()
Create an empty Map node associated with this Document.
DocNode getEmptyNode()
Create an empty node associated with this Document.
DocNode & getRoot()
Get ref to the document's root element.
DocNode getNode(uint64_t V)
Create a UInt node associated with this Document.
void clear()
Restore the Document to an empty state.
DocNode getNode()
Create a nil node associated with this Document.
ArrayDocNode getArrayNode()
Create an empty Array node associated with this Document.
DocNode getNode(int64_t V)
Create an Int node associated with this Document.
void setHexMode(bool Val=true)
Set whether YAML output uses hex for UInt. Default off.
LLVM_ABI void toYAML(raw_ostream &OS)
Convert MsgPack Document to YAML text.
DocNode getNode(bool V)
Create a Boolean node associated with this Document.
LLVM_ABI void writeToBlob(std::string &Blob)
Write a MsgPack document to a binary MsgPack blob.
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.
StringRef addString(StringRef S)
Copy a string into the Document's strings list, and return the copy that is owned by the Document.
DocNode getNode(int V)
Create an Int node associated with this Document.
LLVM_ABI bool fromYAML(StringRef S)
Read YAML text into the MsgPack document. Returns false on failure.
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.
MapTy::iterator find(DocNode Key)
MapTy::iterator erase(MapTy::const_iterator First, MapTy::const_iterator Second)
size_t erase(DocNode Key)
LLVM_ABI DocNode & operator[](StringRef S)
Member access.
MapTy::iterator erase(MapTy::const_iterator I)
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
This is an optimization pass for GlobalISel generic memory operations.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
The kind of a DocNode and its owning Document.