LLVM: include/llvm/BinaryFormat/MsgPackDocument.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17#ifndef LLVM_BINARYFORMAT_MSGPACKDOCUMENT_H

18#define LLVM_BINARYFORMAT_MSGPACKDOCUMENT_H

19

22#include

23

24namespace llvm {

26

30

31

36

37

38

40 friend Document;

41

42public:

43 typedef std::map<DocNode, DocNode> MapTy;

44 typedef std::vector ArrayTy;

45

46private:

47

48

49

50

52

53protected:

54

55 union {

63 };

64

65public:

66

67

68 DocNode() : KindAndDoc(nullptr) {}

69

70

75

76

77

78

81 Document *getDocument() const { return KindAndDoc->Doc; }

82

87

92

97

102

107

112

117

122

127

132

133

134

138 convertToArray();

139 }

140

141 return *reinterpret_cast<ArrayDocNode *>(this);

142 }

143

144

145

149 convertToMap();

150 }

151

152 return *reinterpret_cast<MapDocNode *>(this);

153 }

154

155

157

158

160 return false;

161 if (Lhs.KindAndDoc != Rhs.KindAndDoc) {

163 return true;

165 }

168 return Lhs.Int < Rhs.Int;

172 return false;

179 return Lhs.Raw < Rhs.Raw;

180 default:

182 }

183 }

184

185

187 return !(Lhs < Rhs) && !(Rhs < Lhs);

188 }

189

190

192 return !(Lhs == Rhs);

193 }

194

195

197

198

199

200

202

203

204

205

206

207

217

218private:

219

221

222 LLVM_ABI void convertToArray();

223 LLVM_ABI void convertToMap();

224};

225

226

228public:

231

232

233 size_t size() const { return Map->size(); }

235 MapTy::iterator begin() { return Map->begin(); }

236 MapTy::iterator end() { return Map->end(); }

239 MapTy::iterator erase(MapTy::const_iterator I) { return Map->erase(I); }

241 MapTy::iterator erase(MapTy::const_iterator First,

242 MapTy::const_iterator Second) {

243 return Map->erase(First, Second);

244 }

245

246

248

254};

255

256

258public:

261

262

263 size_t size() const { return Array->size(); }

266 ArrayTy::iterator begin() { return Array->begin(); }

267 ArrayTy::iterator end() { return Array->end(); }

272

273

275};

276

277

278

279

281

282

283 std::vector<std::unique_ptrDocNode::MapTy> Maps;

284 std::vector<std::unique_ptrDocNode::ArrayTy> Arrays;

285 std::vector<std::unique_ptr<char[]>> Strings;

286

287

289

290

292

293

294 bool HexMode = false;

295

296public:

300 KindAndDocs[T] = {this, Type(T)};

301 }

302

303

305

306

308

309

314

315

320

321

324 N.Int = V;

325 return N;

326 }

327

328

331 N.Int = V;

332 return N;

333 }

334

335

338 N.UInt = V;

339 return N;

340 }

341

342

345 N.UInt = V;

346 return N;

347 }

348

349

352 N.Bool = V;

353 return N;

354 }

355

356

359 N.Float = V;

360 return N;

361 }

362

363

364

366 if (Copy)

369 N.Raw = V;

370 return N;

371 }

372

373

374

378

379

380

382 auto Raw = V.getBuffer();

383 if (Copy)

386 N.Raw = Raw;

387 return N;

388 }

389

390

393 Maps.push_back(std::make_uniqueDocNode::MapTy());

394 N.Map = Maps.back().get();

395 return N.getMap();

396 }

397

398

401 Arrays.push_back(std::make_uniqueDocNode::ArrayTy());

402 N.Array = Arrays.back().get();

403 return N.getArray();

404 }

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

433 return -1;

434 });

435

436

438

439

440

442 Strings.push_back(std::unique_ptr<char[]>(new char[S.size()]));

443 memcpy(&Strings.back()[0], S.data(), S.size());

445 }

446

447

448 void setHexMode(bool Val = true) { HexMode = Val; }

449

450

452

453

455

456

458};

459

460}

461}

462

463#endif

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

This is a MessagePack reader.

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.

Definition MsgPackDocument.h:257

ArrayDocNode(DocNode &N)

Definition MsgPackDocument.h:260

bool empty() const

Definition MsgPackDocument.h:264

ArrayTy::iterator end()

Definition MsgPackDocument.h:267

DocNode & back() const

Definition MsgPackDocument.h:265

void push_back(DocNode N)

Definition MsgPackDocument.h:268

LLVM_ABI DocNode & operator[](size_t Index)

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

size_t size() const

Definition MsgPackDocument.h:263

ArrayTy::iterator begin()

Definition MsgPackDocument.h:266

A node in a MsgPack Document.

Definition MsgPackDocument.h:39

MapDocNode & getMap(bool Convert=false)

Get a MapDocNode for a map node.

Definition MsgPackDocument.h:146

LLVM_ABI StringRef fromString(StringRef S, StringRef Tag="")

Convert the StringRef and use it to set this DocNode (assuming scalar).

DocNode()

Definition MsgPackDocument.h:68

uint64_t & getUInt()

Definition MsgPackDocument.h:88

StringRef Raw

Definition MsgPackDocument.h:60

bool Bool

Definition MsgPackDocument.h:58

uint64_t UInt

Definition MsgPackDocument.h:57

friend bool operator!=(const DocNode &Lhs, const DocNode &Rhs)

Inequality operator.

Definition MsgPackDocument.h:191

Type getKind() const

Definition MsgPackDocument.h:80

std::map< DocNode, DocNode > MapTy

Definition MsgPackDocument.h:43

ArrayTy * Array

Definition MsgPackDocument.h:61

bool isMap() const

Definition MsgPackDocument.h:71

bool isArray() const

Definition MsgPackDocument.h:72

ArrayDocNode & getArray(bool Convert=false)

Get an ArrayDocNode for an array node.

Definition MsgPackDocument.h:135

MemoryBufferRef getBinary() const

Definition MsgPackDocument.h:128

int64_t & getInt()

Definition MsgPackDocument.h:83

uint64_t getUInt() const

Definition MsgPackDocument.h:108

int64_t getInt() const

Definition MsgPackDocument.h:103

StringRef getString() const

Definition MsgPackDocument.h:123

bool getBool() const

Definition MsgPackDocument.h:113

double getFloat() const

Definition MsgPackDocument.h:118

LLVM_ABI std::string toString() const

Convert this node to a string, assuming it is scalar.

bool isEmpty() const

Definition MsgPackDocument.h:79

double Float

Definition MsgPackDocument.h:59

int64_t Int

Definition MsgPackDocument.h:56

bool isScalar() const

Definition MsgPackDocument.h:73

std::vector< DocNode > ArrayTy

Definition MsgPackDocument.h:44

double & getFloat()

Definition MsgPackDocument.h:98

MapTy * Map

Definition MsgPackDocument.h:62

DocNode & operator=(const char *Val)

Convenience assignment operators.

Definition MsgPackDocument.h:208

friend bool operator==(const DocNode &Lhs, const DocNode &Rhs)

Equality operator.

Definition MsgPackDocument.h:186

bool isString() const

Definition MsgPackDocument.h:74

bool & getBool()

Definition MsgPackDocument.h:93

friend bool operator<(const DocNode &Lhs, const DocNode &Rhs)

Comparison operator, used for map keys.

Definition MsgPackDocument.h:156

Document * getDocument() const

Definition MsgPackDocument.h:81

Simple in-memory representation of a document of msgpack objects with ability to find and create arra...

Definition MsgPackDocument.h:280

bool getHexMode() const

Get Hexmode flag.

Definition MsgPackDocument.h:451

DocNode getNode(unsigned V)

Create a UInt node associated with this Document.

Definition MsgPackDocument.h:343

DocNode getNode(StringRef V, bool Copy=false)

Create a String node associated with this Document.

Definition MsgPackDocument.h:365

DocNode getNode(double V)

Create a Float node associated with this Document.

Definition MsgPackDocument.h:357

MapDocNode getMapNode()

Create an empty Map node associated with this Document.

Definition MsgPackDocument.h:391

DocNode getEmptyNode()

Create an empty node associated with this Document.

Definition MsgPackDocument.h:310

DocNode & getRoot()

Get ref to the document's root element.

Definition MsgPackDocument.h:304

DocNode getNode(uint64_t V)

Create a UInt node associated with this Document.

Definition MsgPackDocument.h:336

void clear()

Restore the Document to an empty state.

Definition MsgPackDocument.h:307

DocNode getNode()

Create a nil node associated with this Document.

Definition MsgPackDocument.h:316

ArrayDocNode getArrayNode()

Create an empty Array node associated with this Document.

Definition MsgPackDocument.h:399

DocNode getNode(int64_t V)

Create an Int node associated with this Document.

Definition MsgPackDocument.h:322

void setHexMode(bool Val=true)

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

Definition MsgPackDocument.h:448

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.

Definition MsgPackDocument.h:350

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.

Definition MsgPackDocument.h:441

DocNode getNode(int V)

Create an Int node associated with this Document.

Definition MsgPackDocument.h:329

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.

Definition MsgPackDocument.h:375

Document()

Definition MsgPackDocument.h:297

DocNode getNode(MemoryBufferRef V, bool Copy=false)

Create a Binary node associated with this Document.

Definition MsgPackDocument.h:381

A DocNode that is a map.

Definition MsgPackDocument.h:227

MapTy::iterator begin()

Definition MsgPackDocument.h:235

MapTy::iterator find(DocNode Key)

Definition MsgPackDocument.h:237

size_t size() const

Definition MsgPackDocument.h:233

MapTy::iterator erase(MapTy::const_iterator First, MapTy::const_iterator Second)

Definition MsgPackDocument.h:241

MapDocNode(DocNode &N)

Definition MsgPackDocument.h:230

size_t erase(DocNode Key)

Definition MsgPackDocument.h:240

bool empty() const

Definition MsgPackDocument.h:234

MapTy::iterator end()

Definition MsgPackDocument.h:236

LLVM_ABI DocNode & operator[](StringRef S)

Member access.

MapTy::iterator erase(MapTy::const_iterator I)

Definition MsgPackDocument.h:239

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.

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

@ First

Helpers to iterate all locations in the MemoryEffectsBase class.

The kind of a DocNode and its owning Document.

Definition MsgPackDocument.h:32

Type Kind

Definition MsgPackDocument.h:34

Document * Doc

Definition MsgPackDocument.h:33