LLVM: lib/BinaryFormat/MsgPackDocument.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

19

20using namespace llvm;

22

23

25

26

28

29

33

34

35

39

40

44 if (N.isEmpty()) {

45

47 }

48 return N;

49}

50

51

64

65

67 if (size() <= Index) {

68

70 }

71 return (*Array)[Index];

72}

73

74

75

76

77

78

111

112

125

126

127

128

129

130

131

132

133

134

141 if (Multi) {

142

144 Stack.push_back(StackLevel(Root, 0, (size_t)-1));

145 }

146 do {

147

148

151 if (!ReadObj) {

152

154 return false;

155 }

156 if (!ReadObj.get()) {

157 if (Multi && Stack.size() == 1) {

158

159 break;

160 }

161 return false;

162 }

163

165 switch (Obj.Kind) {

168 break;

171 break;

174 break;

177 break;

180 break;

183 break;

186 break;

189 break;

192 break;

193 default:

194 return false;

195 }

196

197

198 DocNode *DestNode = nullptr;

199 if (Stack.empty())

200 DestNode = &Root;

201 else if (Stack.back().Node.getKind() == Type::Array) {

202

203 auto &Array = Stack.back().Node.getArray();

204 DestNode = &Array[Stack.back().Index++];

205 } else {

206 auto &Map = Stack.back().Node.getMap();

207 if (!Stack.back().MapEntry) {

208

209 Stack.back().MapKey = Node;

210 Stack.back().MapEntry = &Map[Node];

211 continue;

212 }

213

214 DestNode = Stack.back().MapEntry;

215 Stack.back().MapEntry = nullptr;

216 ++Stack.back().Index;

217 }

218 int MergeResult = 0;

219 if (!DestNode->isEmpty()) {

220

221

222

223 DocNode MapKey = !Stack.empty() && !Stack.back().MapKey.isEmpty()

224 ? Stack.back().MapKey

226 MergeResult = Merger(DestNode, Node, MapKey);

227 if (MergeResult < 0)

228 return false;

230 (Node.isArray() && !DestNode->isArray())));

231 } else

232 *DestNode = Node;

233

234

235 switch (DestNode->getKind()) {

238 Stack.push_back(StackLevel(*DestNode, MergeResult, Obj.Length, nullptr));

239 break;

240 default:

241 break;

242 }

243

244

245 while (!Stack.empty()) {

246 if (Stack.back().MapEntry)

247 break;

248 if (Stack.back().Index != Stack.back().End)

249 break;

250 Stack.pop_back();

251 }

252 } while (!Stack.empty());

253 return true;

254}

255

258 DocNode::MapTy::iterator MapIt;

261};

262

263

265 Blob.clear();

270 for (;;) {

274 Stack.push_back(

275 {Node, DocNode::MapTy::iterator(), Node.getArray().begin(), false});

276 break;

279 Stack.push_back(

280 {Node, Node.getMap().begin(), DocNode::ArrayTy::iterator(), true});

281 break;

284 break;

287 break;

290 break;

293 break;

295 MPWriter.write(Node.getString());

296 break;

298 MPWriter.write(Node.getBinary());

299 break;

302 break;

305 default:

307 }

308

309 while (!Stack.empty()) {

310 if (Stack.back().Node.getKind() == Type::Map) {

311 if (Stack.back().MapIt != Stack.back().Node.getMap().end())

312 break;

313 } else {

314 if (Stack.back().ArrayIt != Stack.back().Node.getArray().end())

315 break;

316 }

317 Stack.pop_back();

318 }

319 if (Stack.empty())

320 break;

321

322 if (Stack.back().Node.getKind() == Type::Map) {

323 if (Stack.back().OnKey) {

324

325 Node = Stack.back().MapIt->first;

326 Stack.back().OnKey = false;

327 } else {

328 Node = Stack.back().MapIt->second;

329 ++Stack.back().MapIt;

330 Stack.back().OnKey = true;

331 }

332 } else {

333 Node = *Stack.back().ArrayIt;

334 ++Stack.back().ArrayIt;

335 }

336 }

337}

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

static msgpack::DocNode getNode(msgpack::DocNode DN, msgpack::Type Type, MCValue Val)

This file declares a class that exposes a simple in-memory representation of a document of MsgPack ob...

This file contains a MessagePack writer.

Tagged union holding either a T or a Error.

Error takeError()

Take ownership of the stored error.

reference get()

Returns a reference to the stored T value.

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

StringRef - Represent a constant reference to a string, i.e.

An efficient, type-erasing, non-owning reference to a callable.

LLVM_ABI DocNode & operator[](size_t Index)

Element access. This extends the array if necessary, with empty nodes.

Definition MsgPackDocument.cpp:66

A node in a MsgPack Document.

DocNode & operator=(const char *Val)

Convenience assignment operators.

Document * getDocument() const

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()

Create a nil node associated with this Document.

ArrayDocNode getArrayNode()

Create an empty Array node associated with this Document.

LLVM_ABI void writeToBlob(std::string &Blob)

Write a MsgPack document to a binary MsgPack blob.

Definition MsgPackDocument.cpp:264

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.

Definition MsgPackDocument.cpp:135

MapTy::iterator find(DocNode Key)

LLVM_ABI DocNode & operator[](StringRef S)

Member access.

Definition MsgPackDocument.cpp:36

Reads MessagePack objects from memory, one at a time.

LLVM_ABI Expected< bool > read(Object &Obj)

Read one object from the input buffer, advancing past it.

Writes MessagePack objects to an output stream, one at a time.

LLVM_ABI void writeNil()

Write a Nil to the output stream.

LLVM_ABI void writeMapSize(uint32_t Size)

Write the header for a Map of the given size.

LLVM_ABI void writeArraySize(uint32_t Size)

Write the header for an Array of the given size.

LLVM_ABI void write(bool b)

Write a Boolean to the output stream.

A raw_ostream that writes to an std::string.

#define llvm_unreachable(msg)

Marks that the current location is not supposed to be reachable.

This is an optimization pass for GlobalISel generic memory operations.

LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key

void consumeError(Error Err)

Consume a Error without doing anything.

StackLevel(DocNode Node, size_t StartIndex, size_t Length, DocNode *MapEntry=nullptr)

Definition MsgPackDocument.cpp:114

DocNode * MapEntry

Definition MsgPackDocument.cpp:122

DocNode Node

Definition MsgPackDocument.cpp:118

size_t End

Definition MsgPackDocument.cpp:120

size_t Index

Definition MsgPackDocument.cpp:119

DocNode MapKey

Definition MsgPackDocument.cpp:123

DocNode Node

Definition MsgPackDocument.cpp:257

DocNode::MapTy::iterator MapIt

Definition MsgPackDocument.cpp:258

DocNode::ArrayTy::iterator ArrayIt

Definition MsgPackDocument.cpp:259

bool OnKey

Definition MsgPackDocument.cpp:260

MessagePack object, represented as a tagged union of C++ types.