LLVM  16.0.0git
JSON.h
Go to the documentation of this file.
1 //===--- JSON.h - JSON values, parsing and serialization -------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===---------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file supports working with JSON data.
11 ///
12 /// It comprises:
13 ///
14 /// - classes which hold dynamically-typed parsed JSON structures
15 /// These are value types that can be composed, inspected, and modified.
16 /// See json::Value, and the related types json::Object and json::Array.
17 ///
18 /// - functions to parse JSON text into Values, and to serialize Values to text.
19 /// See parse(), operator<<, and format_provider.
20 ///
21 /// - a convention and helpers for mapping between json::Value and user-defined
22 /// types. See fromJSON(), ObjectMapper, and the class comment on Value.
23 ///
24 /// - an output API json::OStream which can emit JSON without materializing
25 /// all structures as json::Value.
26 ///
27 /// Typically, JSON data would be read from an external source, parsed into
28 /// a Value, and then converted into some native data structure before doing
29 /// real work on it. (And vice versa when writing).
30 ///
31 /// Other serialization mechanisms you may consider:
32 ///
33 /// - YAML is also text-based, and more human-readable than JSON. It's a more
34 /// complex format and data model, and YAML parsers aren't ubiquitous.
35 /// YAMLParser.h is a streaming parser suitable for parsing large documents
36 /// (including JSON, as YAML is a superset). It can be awkward to use
37 /// directly. YAML I/O (YAMLTraits.h) provides data mapping that is more
38 /// declarative than the toJSON/fromJSON conventions here.
39 ///
40 /// - LLVM bitstream is a space- and CPU- efficient binary format. Typically it
41 /// encodes LLVM IR ("bitcode"), but it can be a container for other data.
42 /// Low-level reader/writer libraries are in Bitstream/Bitstream*.h
43 ///
44 //===---------------------------------------------------------------------===//
45 
46 #ifndef LLVM_SUPPORT_JSON_H
47 #define LLVM_SUPPORT_JSON_H
48 
49 #include "llvm/ADT/DenseMap.h"
50 #include "llvm/ADT/SmallVector.h"
51 #include "llvm/ADT/StringRef.h"
53 #include "llvm/Support/Error.h"
56 #include <cmath>
57 #include <map>
58 
59 namespace llvm {
60 namespace json {
61 
62 // === String encodings ===
63 //
64 // JSON strings are character sequences (not byte sequences like std::string).
65 // We need to know the encoding, and for simplicity only support UTF-8.
66 //
67 // - When parsing, invalid UTF-8 is a syntax error like any other
68 //
69 // - When creating Values from strings, callers must ensure they are UTF-8.
70 // with asserts on, invalid UTF-8 will crash the program
71 // with asserts off, we'll substitute the replacement character (U+FFFD)
72 // Callers can use json::isUTF8() and json::fixUTF8() for validation.
73 //
74 // - When retrieving strings from Values (e.g. asString()), the result will
75 // always be valid UTF-8.
76 
77 /// Returns true if \p S is valid UTF-8, which is required for use as JSON.
78 /// If it returns false, \p Offset is set to a byte offset near the first error.
79 bool isUTF8(llvm::StringRef S, size_t *ErrOffset = nullptr);
80 /// Replaces invalid UTF-8 sequences in \p S with the replacement character
81 /// (U+FFFD). The returned string is valid UTF-8.
82 /// This is much slower than isUTF8, so test that first.
83 std::string fixUTF8(llvm::StringRef S);
84 
85 class Array;
86 class ObjectKey;
87 class Value;
88 template <typename T> Value toJSON(const llvm::Optional<T> &Opt);
89 
90 /// An Object is a JSON object, which maps strings to heterogenous JSON values.
91 /// It simulates DenseMap<ObjectKey, Value>. ObjectKey is a maybe-owned string.
92 class Object {
94  Storage M;
95 
96 public:
98  using mapped_type = Value;
102 
103  Object() = default;
104  // KV is a trivial key-value struct for list-initialization.
105  // (using std::pair forces extra copies).
106  struct KV;
107  explicit Object(std::initializer_list<KV> Properties);
108 
109  iterator begin() { return M.begin(); }
110  const_iterator begin() const { return M.begin(); }
111  iterator end() { return M.end(); }
112  const_iterator end() const { return M.end(); }
113 
114  bool empty() const { return M.empty(); }
115  size_t size() const { return M.size(); }
116 
117  void clear() { M.clear(); }
118  std::pair<iterator, bool> insert(KV E);
119  template <typename... Ts>
120  std::pair<iterator, bool> try_emplace(const ObjectKey &K, Ts &&... Args) {
121  return M.try_emplace(K, std::forward<Ts>(Args)...);
122  }
123  template <typename... Ts>
124  std::pair<iterator, bool> try_emplace(ObjectKey &&K, Ts &&... Args) {
125  return M.try_emplace(std::move(K), std::forward<Ts>(Args)...);
126  }
127  bool erase(StringRef K);
128  void erase(iterator I) { M.erase(I); }
129 
130  iterator find(StringRef K) { return M.find_as(K); }
131  const_iterator find(StringRef K) const { return M.find_as(K); }
132  // operator[] acts as if Value was default-constructible as null.
133  Value &operator[](const ObjectKey &K);
134  Value &operator[](ObjectKey &&K);
135  // Look up a property, returning nullptr if it doesn't exist.
136  Value *get(StringRef K);
137  const Value *get(StringRef K) const;
138  // Typed accessors return std::nullopt/nullptr if
139  // - the property doesn't exist
140  // - or it has the wrong type
146  const json::Object *getObject(StringRef K) const;
148  const json::Array *getArray(StringRef K) const;
150 };
151 bool operator==(const Object &LHS, const Object &RHS);
152 inline bool operator!=(const Object &LHS, const Object &RHS) {
153  return !(LHS == RHS);
154 }
155 
156 /// An Array is a JSON array, which contains heterogeneous JSON values.
157 /// It simulates std::vector<Value>.
158 class Array {
159  std::vector<Value> V;
160 
161 public:
162  using value_type = Value;
163  using iterator = std::vector<Value>::iterator;
164  using const_iterator = std::vector<Value>::const_iterator;
165 
166  Array() = default;
167  explicit Array(std::initializer_list<Value> Elements);
168  template <typename Collection> explicit Array(const Collection &C) {
169  for (const auto &V : C)
170  emplace_back(V);
171  }
172 
173  Value &operator[](size_t I);
174  const Value &operator[](size_t I) const;
175  Value &front();
176  const Value &front() const;
177  Value &back();
178  const Value &back() const;
179  Value *data();
180  const Value *data() const;
181 
182  iterator begin();
183  const_iterator begin() const;
184  iterator end();
185  const_iterator end() const;
186 
187  bool empty() const;
188  size_t size() const;
189  void reserve(size_t S);
190 
191  void clear();
192  void push_back(const Value &E);
193  void push_back(Value &&E);
194  template <typename... Args> void emplace_back(Args &&...A);
195  void pop_back();
196  // FIXME: insert() takes const_iterator since C++11, old libstdc++ disagrees.
197  iterator insert(iterator P, const Value &E);
199  template <typename It> iterator insert(iterator P, It A, It Z);
200  template <typename... Args> iterator emplace(const_iterator P, Args &&...A);
201 
202  friend bool operator==(const Array &L, const Array &R);
203 };
204 inline bool operator!=(const Array &L, const Array &R) { return !(L == R); }
205 
206 /// A Value is an JSON value of unknown type.
207 /// They can be copied, but should generally be moved.
208 ///
209 /// === Composing values ===
210 ///
211 /// You can implicitly construct Values from:
212 /// - strings: std::string, SmallString, formatv, StringRef, char*
213 /// (char*, and StringRef are references, not copies!)
214 /// - numbers
215 /// - booleans
216 /// - null: nullptr
217 /// - arrays: {"foo", 42.0, false}
218 /// - serializable things: types with toJSON(const T&)->Value, found by ADL
219 ///
220 /// They can also be constructed from object/array helpers:
221 /// - json::Object is a type like map<ObjectKey, Value>
222 /// - json::Array is a type like vector<Value>
223 /// These can be list-initialized, or used to build up collections in a loop.
224 /// json::ary(Collection) converts all items in a collection to Values.
225 ///
226 /// === Inspecting values ===
227 ///
228 /// Each Value is one of the JSON kinds:
229 /// null (nullptr_t)
230 /// boolean (bool)
231 /// number (double, int64 or uint64)
232 /// string (StringRef)
233 /// array (json::Array)
234 /// object (json::Object)
235 ///
236 /// The kind can be queried directly, or implicitly via the typed accessors:
237 /// if (Optional<StringRef> S = E.getAsString()
238 /// assert(E.kind() == Value::String);
239 ///
240 /// Array and Object also have typed indexing accessors for easy traversal:
241 /// Expected<Value> E = parse(R"( {"options": {"font": "sans-serif"}} )");
242 /// if (Object* O = E->getAsObject())
243 /// if (Object* Opts = O->getObject("options"))
244 /// if (Optional<StringRef> Font = Opts->getString("font"))
245 /// assert(Opts->at("font").kind() == Value::String);
246 ///
247 /// === Converting JSON values to C++ types ===
248 ///
249 /// The convention is to have a deserializer function findable via ADL:
250 /// fromJSON(const json::Value&, T&, Path) -> bool
251 ///
252 /// The return value indicates overall success, and Path is used for precise
253 /// error reporting. (The Path::Root passed in at the top level fromJSON call
254 /// captures any nested error and can render it in context).
255 /// If conversion fails, fromJSON calls Path::report() and immediately returns.
256 /// This ensures that the first fatal error survives.
257 ///
258 /// Deserializers are provided for:
259 /// - bool
260 /// - int and int64_t
261 /// - double
262 /// - std::string
263 /// - vector<T>, where T is deserializable
264 /// - map<string, T>, where T is deserializable
265 /// - Optional<T>, where T is deserializable
266 /// ObjectMapper can help writing fromJSON() functions for object types.
267 ///
268 /// For conversion in the other direction, the serializer function is:
269 /// toJSON(const T&) -> json::Value
270 /// If this exists, then it also allows constructing Value from T, and can
271 /// be used to serialize vector<T>, map<string, T>, and Optional<T>.
272 ///
273 /// === Serialization ===
274 ///
275 /// Values can be serialized to JSON:
276 /// 1) raw_ostream << Value // Basic formatting.
277 /// 2) raw_ostream << formatv("{0}", Value) // Basic formatting.
278 /// 3) raw_ostream << formatv("{0:2}", Value) // Pretty-print with indent 2.
279 ///
280 /// And parsed:
281 /// Expected<Value> E = json::parse("[1, 2, null]");
282 /// assert(E && E->kind() == Value::Array);
283 class Value {
284 public:
285  enum Kind {
288  /// Number values can store both int64s and doubles at full precision,
289  /// depending on what they were constructed/parsed from.
294  };
295 
296  // It would be nice to have Value() be null. But that would make {} null too.
297  Value(const Value &M) { copyFrom(M); }
298  Value(Value &&M) { moveFrom(std::move(M)); }
299  Value(std::initializer_list<Value> Elements);
300  Value(json::Array &&Elements) : Type(T_Array) {
301  create<json::Array>(std::move(Elements));
302  }
303  template <typename Elt>
304  Value(const std::vector<Elt> &C) : Value(json::Array(C)) {}
305  Value(json::Object &&Properties) : Type(T_Object) {
306  create<json::Object>(std::move(Properties));
307  }
308  template <typename Elt>
309  Value(const std::map<std::string, Elt> &C) : Value(json::Object(C)) {}
310  // Strings: types with value semantics. Must be valid UTF-8.
311  Value(std::string V) : Type(T_String) {
312  if (LLVM_UNLIKELY(!isUTF8(V))) {
313  assert(false && "Invalid UTF-8 in value used as JSON");
314  V = fixUTF8(std::move(V));
315  }
316  create<std::string>(std::move(V));
317  }
319  : Value(std::string(V.begin(), V.end())) {}
320  Value(const llvm::formatv_object_base &V) : Value(V.str()) {}
321  // Strings: types with reference semantics. Must be valid UTF-8.
322  Value(StringRef V) : Type(T_StringRef) {
323  create<llvm::StringRef>(V);
324  if (LLVM_UNLIKELY(!isUTF8(V))) {
325  assert(false && "Invalid UTF-8 in value used as JSON");
326  *this = Value(fixUTF8(V));
327  }
328  }
329  Value(const char *V) : Value(StringRef(V)) {}
330  Value(std::nullptr_t) : Type(T_Null) {}
331  // Boolean (disallow implicit conversions).
332  // (The last template parameter is a dummy to keep templates distinct.)
333  template <typename T,
334  typename = std::enable_if_t<std::is_same<T, bool>::value>,
335  bool = false>
336  Value(T B) : Type(T_Boolean) {
337  create<bool>(B);
338  }
339 
340  // Unsigned 64-bit long integers.
341  template <typename T,
342  typename = std::enable_if_t<std::is_same<T, uint64_t>::value>,
343  bool = false, bool = false>
344  Value(T V) : Type(T_UINT64) {
345  create<uint64_t>(uint64_t{V});
346  }
347 
348  // Integers (except boolean and uint64_t).
349  // Must be non-narrowing convertible to int64_t.
350  template <typename T, typename = std::enable_if_t<std::is_integral<T>::value>,
351  typename = std::enable_if_t<!std::is_same<T, bool>::value>,
352  typename = std::enable_if_t<!std::is_same<T, uint64_t>::value>>
353  Value(T I) : Type(T_Integer) {
354  create<int64_t>(int64_t{I});
355  }
356  // Floating point. Must be non-narrowing convertible to double.
357  template <typename T,
358  typename = std::enable_if_t<std::is_floating_point<T>::value>,
359  double * = nullptr>
360  Value(T D) : Type(T_Double) {
361  create<double>(double{D});
362  }
363  // Serializable types: with a toJSON(const T&)->Value function, found by ADL.
364  template <typename T,
365  typename = std::enable_if_t<std::is_same<
366  Value, decltype(toJSON(*(const T *)nullptr))>::value>,
367  Value * = nullptr>
368  Value(const T &V) : Value(toJSON(V)) {}
369 
370  Value &operator=(const Value &M) {
371  destroy();
372  copyFrom(M);
373  return *this;
374  }
376  destroy();
377  moveFrom(std::move(M));
378  return *this;
379  }
380  ~Value() { destroy(); }
381 
382  Kind kind() const {
383  switch (Type) {
384  case T_Null:
385  return Null;
386  case T_Boolean:
387  return Boolean;
388  case T_Double:
389  case T_Integer:
390  case T_UINT64:
391  return Number;
392  case T_String:
393  case T_StringRef:
394  return String;
395  case T_Object:
396  return Object;
397  case T_Array:
398  return Array;
399  }
400  llvm_unreachable("Unknown kind");
401  }
402 
403  // Typed accessors return std::nullopt/nullptr if the Value is not of this
404  // type.
406  if (LLVM_LIKELY(Type == T_Null))
407  return nullptr;
408  return std::nullopt;
409  }
411  if (LLVM_LIKELY(Type == T_Boolean))
412  return as<bool>();
413  return std::nullopt;
414  }
416  if (LLVM_LIKELY(Type == T_Double))
417  return as<double>();
418  if (LLVM_LIKELY(Type == T_Integer))
419  return as<int64_t>();
420  if (LLVM_LIKELY(Type == T_UINT64))
421  return as<uint64_t>();
422  return std::nullopt;
423  }
424  // Succeeds if the Value is a Number, and exactly representable as int64_t.
426  if (LLVM_LIKELY(Type == T_Integer))
427  return as<int64_t>();
428  if (LLVM_LIKELY(Type == T_Double)) {
429  double D = as<double>();
430  if (LLVM_LIKELY(std::modf(D, &D) == 0.0 &&
431  D >= double(std::numeric_limits<int64_t>::min()) &&
432  D <= double(std::numeric_limits<int64_t>::max())))
433  return D;
434  }
435  return std::nullopt;
436  }
438  if (Type == T_UINT64)
439  return as<uint64_t>();
440  else if (Type == T_Integer) {
441  int64_t N = as<int64_t>();
442  if (N >= 0)
443  return as<uint64_t>();
444  }
445  return std::nullopt;
446  }
448  if (Type == T_String)
449  return llvm::StringRef(as<std::string>());
450  if (LLVM_LIKELY(Type == T_StringRef))
451  return as<llvm::StringRef>();
452  return std::nullopt;
453  }
454  const json::Object *getAsObject() const {
455  return LLVM_LIKELY(Type == T_Object) ? &as<json::Object>() : nullptr;
456  }
458  return LLVM_LIKELY(Type == T_Object) ? &as<json::Object>() : nullptr;
459  }
460  const json::Array *getAsArray() const {
461  return LLVM_LIKELY(Type == T_Array) ? &as<json::Array>() : nullptr;
462  }
464  return LLVM_LIKELY(Type == T_Array) ? &as<json::Array>() : nullptr;
465  }
466 
467 private:
468  void destroy();
469  void copyFrom(const Value &M);
470  // We allow moving from *const* Values, by marking all members as mutable!
471  // This hack is needed to support initializer-list syntax efficiently.
472  // (std::initializer_list<T> is a container of const T).
473  void moveFrom(const Value &&M);
474  friend class Array;
475  friend class Object;
476 
477  template <typename T, typename... U> void create(U &&... V) {
478  new (reinterpret_cast<T *>(&Union)) T(std::forward<U>(V)...);
479  }
480  template <typename T> T &as() const {
481  // Using this two-step static_cast via void * instead of reinterpret_cast
482  // silences a -Wstrict-aliasing false positive from GCC6 and earlier.
483  void *Storage = static_cast<void *>(&Union);
484  return *static_cast<T *>(Storage);
485  }
486 
487  friend class OStream;
488 
489  enum ValueType : char16_t {
490  T_Null,
491  T_Boolean,
492  T_Double,
493  T_Integer,
494  T_UINT64,
495  T_StringRef,
496  T_String,
497  T_Object,
498  T_Array,
499  };
500  // All members mutable, see moveFrom().
501  mutable ValueType Type;
502  mutable llvm::AlignedCharArrayUnion<bool, double, int64_t, uint64_t,
503  llvm::StringRef, std::string, json::Array,
504  json::Object>
505  Union;
506  friend bool operator==(const Value &, const Value &);
507 };
508 
509 bool operator==(const Value &, const Value &);
510 inline bool operator!=(const Value &L, const Value &R) { return !(L == R); }
511 
512 // Array Methods
513 inline Value &Array::operator[](size_t I) { return V[I]; }
514 inline const Value &Array::operator[](size_t I) const { return V[I]; }
515 inline Value &Array::front() { return V.front(); }
516 inline const Value &Array::front() const { return V.front(); }
517 inline Value &Array::back() { return V.back(); }
518 inline const Value &Array::back() const { return V.back(); }
519 inline Value *Array::data() { return V.data(); }
520 inline const Value *Array::data() const { return V.data(); }
521 
522 inline typename Array::iterator Array::begin() { return V.begin(); }
523 inline typename Array::const_iterator Array::begin() const { return V.begin(); }
524 inline typename Array::iterator Array::end() { return V.end(); }
525 inline typename Array::const_iterator Array::end() const { return V.end(); }
526 
527 inline bool Array::empty() const { return V.empty(); }
528 inline size_t Array::size() const { return V.size(); }
529 inline void Array::reserve(size_t S) { V.reserve(S); }
530 
531 inline void Array::clear() { V.clear(); }
532 inline void Array::push_back(const Value &E) { V.push_back(E); }
533 inline void Array::push_back(Value &&E) { V.push_back(std::move(E)); }
534 template <typename... Args> inline void Array::emplace_back(Args &&...A) {
535  V.emplace_back(std::forward<Args>(A)...);
536 }
537 inline void Array::pop_back() { V.pop_back(); }
538 inline typename Array::iterator Array::insert(iterator P, const Value &E) {
539  return V.insert(P, E);
540 }
542  return V.insert(P, std::move(E));
543 }
544 template <typename It>
545 inline typename Array::iterator Array::insert(iterator P, It A, It Z) {
546  return V.insert(P, A, Z);
547 }
548 template <typename... Args>
550  return V.emplace(P, std::forward<Args>(A)...);
551 }
552 inline bool operator==(const Array &L, const Array &R) { return L.V == R.V; }
553 
554 /// ObjectKey is a used to capture keys in Object. Like Value but:
555 /// - only strings are allowed
556 /// - it's optimized for the string literal case (Owned == nullptr)
557 /// Like Value, strings must be UTF-8. See isUTF8 documentation for details.
558 class ObjectKey {
559 public:
560  ObjectKey(const char *S) : ObjectKey(StringRef(S)) {}
561  ObjectKey(std::string S) : Owned(new std::string(std::move(S))) {
562  if (LLVM_UNLIKELY(!isUTF8(*Owned))) {
563  assert(false && "Invalid UTF-8 in value used as JSON");
564  *Owned = fixUTF8(std::move(*Owned));
565  }
566  Data = *Owned;
567  }
569  if (LLVM_UNLIKELY(!isUTF8(Data))) {
570  assert(false && "Invalid UTF-8 in value used as JSON");
571  *this = ObjectKey(fixUTF8(S));
572  }
573  }
575  : ObjectKey(std::string(V.begin(), V.end())) {}
577 
578  ObjectKey(const ObjectKey &C) { *this = C; }
579  ObjectKey(ObjectKey &&C) : ObjectKey(static_cast<const ObjectKey &&>(C)) {}
581  if (C.Owned) {
582  Owned.reset(new std::string(*C.Owned));
583  Data = *Owned;
584  } else {
585  Data = C.Data;
586  }
587  return *this;
588  }
589  ObjectKey &operator=(ObjectKey &&) = default;
590 
591  operator llvm::StringRef() const { return Data; }
592  std::string str() const { return Data.str(); }
593 
594 private:
595  // FIXME: this is unneccesarily large (3 pointers). Pointer + length + owned
596  // could be 2 pointers at most.
597  std::unique_ptr<std::string> Owned;
598  llvm::StringRef Data;
599 };
600 
601 inline bool operator==(const ObjectKey &L, const ObjectKey &R) {
602  return llvm::StringRef(L) == llvm::StringRef(R);
603 }
604 inline bool operator!=(const ObjectKey &L, const ObjectKey &R) {
605  return !(L == R);
606 }
607 inline bool operator<(const ObjectKey &L, const ObjectKey &R) {
608  return StringRef(L) < StringRef(R);
609 }
610 
611 struct Object::KV {
614 };
615 
616 inline Object::Object(std::initializer_list<KV> Properties) {
617  for (const auto &P : Properties) {
618  auto R = try_emplace(P.K, nullptr);
619  if (R.second)
620  R.first->getSecond().moveFrom(std::move(P.V));
621  }
622 }
623 inline std::pair<Object::iterator, bool> Object::insert(KV E) {
624  return try_emplace(std::move(E.K), std::move(E.V));
625 }
626 inline bool Object::erase(StringRef K) {
627  return M.erase(ObjectKey(K));
628 }
629 
630 /// A "cursor" marking a position within a Value.
631 /// The Value is a tree, and this is the path from the root to the current node.
632 /// This is used to associate errors with particular subobjects.
633 class Path {
634 public:
635  class Root;
636 
637  /// Records that the value at the current path is invalid.
638  /// Message is e.g. "expected number" and becomes part of the final error.
639  /// This overwrites any previously written error message in the root.
640  void report(llvm::StringLiteral Message);
641 
642  /// The root may be treated as a Path.
643  Path(Root &R) : Parent(nullptr), Seg(&R) {}
644  /// Derives a path for an array element: this[Index]
645  Path index(unsigned Index) const { return Path(this, Segment(Index)); }
646  /// Derives a path for an object field: this.Field
647  Path field(StringRef Field) const { return Path(this, Segment(Field)); }
648 
649 private:
650  /// One element in a JSON path: an object field (.foo) or array index [27].
651  /// Exception: the root Path encodes a pointer to the Path::Root.
652  class Segment {
653  uintptr_t Pointer;
654  unsigned Offset;
655 
656  public:
657  Segment() = default;
658  Segment(Root *R) : Pointer(reinterpret_cast<uintptr_t>(R)) {}
659  Segment(llvm::StringRef Field)
660  : Pointer(reinterpret_cast<uintptr_t>(Field.data())),
661  Offset(static_cast<unsigned>(Field.size())) {}
662  Segment(unsigned Index) : Pointer(0), Offset(Index) {}
663 
664  bool isField() const { return Pointer != 0; }
665  StringRef field() const {
666  return StringRef(reinterpret_cast<const char *>(Pointer), Offset);
667  }
668  unsigned index() const { return Offset; }
669  Root *root() const { return reinterpret_cast<Root *>(Pointer); }
670  };
671 
672  const Path *Parent;
673  Segment Seg;
674 
675  Path(const Path *Parent, Segment S) : Parent(Parent), Seg(S) {}
676 };
677 
678 /// The root is the trivial Path to the root value.
679 /// It also stores the latest reported error and the path where it occurred.
680 class Path::Root {
681  llvm::StringRef Name;
682  llvm::StringLiteral ErrorMessage;
683  std::vector<Path::Segment> ErrorPath; // Only valid in error state. Reversed.
684 
685  friend void Path::report(llvm::StringLiteral Message);
686 
687 public:
688  Root(llvm::StringRef Name = "") : Name(Name), ErrorMessage("") {}
689  // No copy/move allowed as there are incoming pointers.
690  Root(Root &&) = delete;
691  Root &operator=(Root &&) = delete;
692  Root(const Root &) = delete;
693  Root &operator=(const Root &) = delete;
694 
695  /// Returns the last error reported, or else a generic error.
696  Error getError() const;
697  /// Print the root value with the error shown inline as a comment.
698  /// Unrelated parts of the value are elided for brevity, e.g.
699  /// {
700  /// "id": 42,
701  /// "name": /* expected string */ null,
702  /// "properties": { ... }
703  /// }
704  void printErrorContext(const Value &, llvm::raw_ostream &) const;
705 };
706 
707 // Standard deserializers are provided for primitive types.
708 // See comments on Value.
709 inline bool fromJSON(const Value &E, std::string &Out, Path P) {
710  if (auto S = E.getAsString()) {
711  Out = std::string(*S);
712  return true;
713  }
714  P.report("expected string");
715  return false;
716 }
717 inline bool fromJSON(const Value &E, int &Out, Path P) {
718  if (auto S = E.getAsInteger()) {
719  Out = *S;
720  return true;
721  }
722  P.report("expected integer");
723  return false;
724 }
725 inline bool fromJSON(const Value &E, int64_t &Out, Path P) {
726  if (auto S = E.getAsInteger()) {
727  Out = *S;
728  return true;
729  }
730  P.report("expected integer");
731  return false;
732 }
733 inline bool fromJSON(const Value &E, double &Out, Path P) {
734  if (auto S = E.getAsNumber()) {
735  Out = *S;
736  return true;
737  }
738  P.report("expected number");
739  return false;
740 }
741 inline bool fromJSON(const Value &E, bool &Out, Path P) {
742  if (auto S = E.getAsBoolean()) {
743  Out = *S;
744  return true;
745  }
746  P.report("expected boolean");
747  return false;
748 }
749 inline bool fromJSON(const Value &E, uint64_t &Out, Path P) {
750  if (auto S = E.getAsUINT64()) {
751  Out = *S;
752  return true;
753  }
754  P.report("expected uint64_t");
755  return false;
756 }
757 inline bool fromJSON(const Value &E, std::nullptr_t &Out, Path P) {
758  if (auto S = E.getAsNull()) {
759  Out = *S;
760  return true;
761  }
762  P.report("expected null");
763  return false;
764 }
765 template <typename T>
766 bool fromJSON(const Value &E, llvm::Optional<T> &Out, Path P) {
767  if (E.getAsNull()) {
768  Out = std::nullopt;
769  return true;
770  }
771  T Result;
772  if (!fromJSON(E, Result, P))
773  return false;
774  Out = std::move(Result);
775  return true;
776 }
777 template <typename T>
778 bool fromJSON(const Value &E, std::vector<T> &Out, Path P) {
779  if (auto *A = E.getAsArray()) {
780  Out.clear();
781  Out.resize(A->size());
782  for (size_t I = 0; I < A->size(); ++I)
783  if (!fromJSON((*A)[I], Out[I], P.index(I)))
784  return false;
785  return true;
786  }
787  P.report("expected array");
788  return false;
789 }
790 template <typename T>
791 bool fromJSON(const Value &E, std::map<std::string, T> &Out, Path P) {
792  if (auto *O = E.getAsObject()) {
793  Out.clear();
794  for (const auto &KV : *O)
795  if (!fromJSON(KV.second, Out[std::string(llvm::StringRef(KV.first))],
796  P.field(KV.first)))
797  return false;
798  return true;
799  }
800  P.report("expected object");
801  return false;
802 }
803 
804 // Allow serialization of Optional<T> for supported T.
805 template <typename T> Value toJSON(const llvm::Optional<T> &Opt) {
806  return Opt ? Value(*Opt) : Value(nullptr);
807 }
808 
809 /// Helper for mapping JSON objects onto protocol structs.
810 ///
811 /// Example:
812 /// \code
813 /// bool fromJSON(const Value &E, MyStruct &R, Path P) {
814 /// ObjectMapper O(E, P);
815 /// // When returning false, error details were already reported.
816 /// return O && O.map("mandatory_field", R.MandatoryField) &&
817 /// O.mapOptional("optional_field", R.OptionalField);
818 /// }
819 /// \endcode
821 public:
822  /// If O is not an object, this mapper is invalid and an error is reported.
823  ObjectMapper(const Value &E, Path P) : O(E.getAsObject()), P(P) {
824  if (!O)
825  P.report("expected object");
826  }
827 
828  /// True if the expression is an object.
829  /// Must be checked before calling map().
830  operator bool() const { return O; }
831 
832  /// Maps a property to a field.
833  /// If the property is missing or invalid, reports an error.
834  template <typename T> bool map(StringLiteral Prop, T &Out) {
835  assert(*this && "Must check this is an object before calling map()");
836  if (const Value *E = O->get(Prop))
837  return fromJSON(*E, Out, P.field(Prop));
838  P.field(Prop).report("missing value");
839  return false;
840  }
841 
842  /// Maps a property to a field, if it exists.
843  /// If the property exists and is invalid, reports an error.
844  /// (Optional requires special handling, because missing keys are OK).
845  template <typename T> bool map(StringLiteral Prop, llvm::Optional<T> &Out) {
846  assert(*this && "Must check this is an object before calling map()");
847  if (const Value *E = O->get(Prop))
848  return fromJSON(*E, Out, P.field(Prop));
849  Out = std::nullopt;
850  return true;
851  }
852 
853  /// Maps a property to a field, if it exists.
854  /// If the property exists and is invalid, reports an error.
855  /// If the property does not exist, Out is unchanged.
856  template <typename T> bool mapOptional(StringLiteral Prop, T &Out) {
857  assert(*this && "Must check this is an object before calling map()");
858  if (const Value *E = O->get(Prop))
859  return fromJSON(*E, Out, P.field(Prop));
860  return true;
861  }
862 
863 private:
864  const Object *O;
865  Path P;
866 };
867 
868 /// Parses the provided JSON source, or returns a ParseError.
869 /// The returned Value is self-contained and owns its strings (they do not refer
870 /// to the original source).
872 
873 class ParseError : public llvm::ErrorInfo<ParseError> {
874  const char *Msg;
875  unsigned Line, Column, Offset;
876 
877 public:
878  static char ID;
879  ParseError(const char *Msg, unsigned Line, unsigned Column, unsigned Offset)
880  : Msg(Msg), Line(Line), Column(Column), Offset(Offset) {}
881  void log(llvm::raw_ostream &OS) const override {
882  OS << llvm::formatv("[{0}:{1}, byte={2}]: {3}", Line, Column, Offset, Msg);
883  }
884  std::error_code convertToErrorCode() const override {
886  }
887 };
888 
889 /// Version of parse() that converts the parsed value to the type T.
890 /// RootName describes the root object and is used in error messages.
891 template <typename T>
892 Expected<T> parse(const llvm::StringRef &JSON, const char *RootName = "") {
893  auto V = parse(JSON);
894  if (!V)
895  return V.takeError();
896  Path::Root R(RootName);
897  T Result;
898  if (fromJSON(*V, Result, R))
899  return std::move(Result);
900  return R.getError();
901 }
902 
903 /// json::OStream allows writing well-formed JSON without materializing
904 /// all structures as json::Value ahead of time.
905 /// It's faster, lower-level, and less safe than OS << json::Value.
906 /// It also allows emitting more constructs, such as comments.
907 ///
908 /// Only one "top-level" object can be written to a stream.
909 /// Simplest usage involves passing lambdas (Blocks) to fill in containers:
910 ///
911 /// json::OStream J(OS);
912 /// J.array([&]{
913 /// for (const Event &E : Events)
914 /// J.object([&] {
915 /// J.attribute("timestamp", int64_t(E.Time));
916 /// J.attributeArray("participants", [&] {
917 /// for (const Participant &P : E.Participants)
918 /// J.value(P.toString());
919 /// });
920 /// });
921 /// });
922 ///
923 /// This would produce JSON like:
924 ///
925 /// [
926 /// {
927 /// "timestamp": 19287398741,
928 /// "participants": [
929 /// "King Kong",
930 /// "Miley Cyrus",
931 /// "Cleopatra"
932 /// ]
933 /// },
934 /// ...
935 /// ]
936 ///
937 /// The lower level begin/end methods (arrayBegin()) are more flexible but
938 /// care must be taken to pair them correctly:
939 ///
940 /// json::OStream J(OS);
941 // J.arrayBegin();
942 /// for (const Event &E : Events) {
943 /// J.objectBegin();
944 /// J.attribute("timestamp", int64_t(E.Time));
945 /// J.attributeBegin("participants");
946 /// for (const Participant &P : E.Participants)
947 /// J.value(P.toString());
948 /// J.attributeEnd();
949 /// J.objectEnd();
950 /// }
951 /// J.arrayEnd();
952 ///
953 /// If the call sequence isn't valid JSON, asserts will fire in debug mode.
954 /// This can be mismatched begin()/end() pairs, trying to emit attributes inside
955 /// an array, and so on.
956 /// With asserts disabled, this is undefined behavior.
957 class OStream {
958  public:
959  using Block = llvm::function_ref<void()>;
960  // If IndentSize is nonzero, output is pretty-printed.
961  explicit OStream(llvm::raw_ostream &OS, unsigned IndentSize = 0)
962  : OS(OS), IndentSize(IndentSize) {
963  Stack.emplace_back();
964  }
966  assert(Stack.size() == 1 && "Unmatched begin()/end()");
967  assert(Stack.back().Ctx == Singleton);
968  assert(Stack.back().HasValue && "Did not write top-level value");
969  }
970 
971  /// Flushes the underlying ostream. OStream does not buffer internally.
972  void flush() { OS.flush(); }
973 
974  // High level functions to output a value.
975  // Valid at top-level (exactly once), in an attribute value (exactly once),
976  // or in an array (any number of times).
977 
978  /// Emit a self-contained value (number, string, vector<string> etc).
979  void value(const Value &V);
980  /// Emit an array whose elements are emitted in the provided Block.
981  void array(Block Contents) {
982  arrayBegin();
983  Contents();
984  arrayEnd();
985  }
986  /// Emit an object whose elements are emitted in the provided Block.
987  void object(Block Contents) {
988  objectBegin();
989  Contents();
990  objectEnd();
991  }
992  /// Emit an externally-serialized value.
993  /// The caller must write exactly one valid JSON value to the provided stream.
994  /// No validation or formatting of this value occurs.
995  void rawValue(llvm::function_ref<void(raw_ostream &)> Contents) {
996  rawValueBegin();
997  Contents(OS);
998  rawValueEnd();
999  }
1000  void rawValue(llvm::StringRef Contents) {
1001  rawValue([&](raw_ostream &OS) { OS << Contents; });
1002  }
1003  /// Emit a JavaScript comment associated with the next printed value.
1004  /// The string must be valid until the next attribute or value is emitted.
1005  /// Comments are not part of standard JSON, and many parsers reject them!
1006  void comment(llvm::StringRef);
1007 
1008  // High level functions to output object attributes.
1009  // Valid only within an object (any number of times).
1010 
1011  /// Emit an attribute whose value is self-contained (number, vector<int> etc).
1012  void attribute(llvm::StringRef Key, const Value& Contents) {
1013  attributeImpl(Key, [&] { value(Contents); });
1014  }
1015  /// Emit an attribute whose value is an array with elements from the Block.
1017  attributeImpl(Key, [&] { array(Contents); });
1018  }
1019  /// Emit an attribute whose value is an object with attributes from the Block.
1021  attributeImpl(Key, [&] { object(Contents); });
1022  }
1023 
1024  // Low-level begin/end functions to output arrays, objects, and attributes.
1025  // Must be correctly paired. Allowed contexts are as above.
1026 
1027  void arrayBegin();
1028  void arrayEnd();
1029  void objectBegin();
1030  void objectEnd();
1032  void attributeEnd();
1034  void rawValueEnd();
1035 
1036 private:
1037  void attributeImpl(llvm::StringRef Key, Block Contents) {
1039  Contents();
1040  attributeEnd();
1041  }
1042 
1043  void valueBegin();
1044  void flushComment();
1045  void newline();
1046 
1047  enum Context {
1048  Singleton, // Top level, or object attribute.
1049  Array,
1050  Object,
1051  RawValue, // External code writing a value to OS directly.
1052  };
1053  struct State {
1054  Context Ctx = Singleton;
1055  bool HasValue = false;
1056  };
1057  llvm::SmallVector<State, 16> Stack; // Never empty.
1058  llvm::StringRef PendingComment;
1059  llvm::raw_ostream &OS;
1060  unsigned IndentSize;
1061  unsigned Indent = 0;
1062 };
1063 
1064 /// Serializes this Value to JSON, writing it to the provided stream.
1065 /// The formatting is compact (no extra whitespace) and deterministic.
1066 /// For pretty-printing, use the formatv() format_provider below.
1068  OStream(OS).value(V);
1069  return OS;
1070 }
1071 } // namespace json
1072 
1073 /// Allow printing json::Value with formatv().
1074 /// The default style is basic/compact formatting, like operator<<.
1075 /// A format string like formatv("{0:2}", Value) pretty-prints with indent 2.
1076 template <> struct format_provider<llvm::json::Value> {
1077  static void format(const llvm::json::Value &, raw_ostream &, StringRef);
1078 };
1079 } // namespace llvm
1080 
1081 #endif
llvm::json::Array::operator[]
Value & operator[](size_t I)
Definition: JSON.h:513
llvm::json::Object::Object
Object()=default
llvm::json::Object::erase
bool erase(StringRef K)
Definition: JSON.h:626
const_iterator
llvm::json::OStream::comment
void comment(llvm::StringRef)
Emit a JavaScript comment associated with the next printed value.
Definition: JSON.cpp:805
llvm::json::OStream::attributeBegin
void attributeBegin(llvm::StringRef Key)
Definition: JSON.cpp:880
llvm::json::Path::Root
The root is the trivial Path to the root value.
Definition: JSON.h:680
as
compiles conv shl5 shl ret i32 or10 it would be better as
Definition: README.txt:615
llvm::json::Value
A Value is an JSON value of unknown type.
Definition: JSON.h:283
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::json::Value::Value
Value(std::nullptr_t)
Definition: JSON.h:330
llvm::json::Array::end
iterator end()
Definition: JSON.h:524
llvm::json::Value::kind
Kind kind() const
Definition: JSON.h:382
llvm::json::Array::back
Value & back()
Definition: JSON.h:517
llvm::json::Value::Value
Value(const char *V)
Definition: JSON.h:329
llvm::json::Value::Value
Value(T I)
Definition: JSON.h:353
llvm::json::OStream::~OStream
~OStream()
Definition: JSON.h:965
llvm::format_provider
Definition: FormatVariadicDetails.h:19
llvm::json::Value::Boolean
@ Boolean
Definition: JSON.h:287
llvm::json::Value::Object
friend class Object
Definition: JSON.h:475
llvm::json::Array::empty
bool empty() const
Definition: JSON.h:527
StringRef.h
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::json::OStream::attributeEnd
void attributeEnd()
Definition: JSON.cpp:900
llvm::json::Object::find
const_iterator find(StringRef K) const
Definition: JSON.h:131
double
into xmm2 addss xmm2 xmm1 xmm3 addss xmm3 movaps xmm0 unpcklps xmm0 ret seems silly when it could just be one addps Expand libm rounding functions main should enable SSE DAZ mode and other fast SSE modes Think about doing i64 math in SSE regs on x86 This testcase should have no SSE instructions in and only one load from a constant double
Definition: README-SSE.txt:85
llvm::SmallVector< State, 16 >
llvm::json::Array::emplace_back
void emplace_back(Args &&...A)
Definition: JSON.h:534
llvm::json::Value::Value
Value(T V)
Definition: JSON.h:344
Error.h
llvm::json::Value::operator==
friend bool operator==(const Value &, const Value &)
Definition: JSON.cpp:183
llvm::json::Value::getAsNull
llvm::Optional< std::nullptr_t > getAsNull() const
Definition: JSON.h:405
llvm::DenseMapBase::erase
bool erase(const KeyT &Val)
Definition: DenseMap.h:302
llvm::json::ObjectKey::ObjectKey
ObjectKey(const char *S)
Definition: JSON.h:560
llvm::DenseMapIterator
Definition: DenseMap.h:57
llvm::json::OStream::Block
llvm::function_ref< void()> Block
Definition: JSON.h:959
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
DenseMap.h
llvm::json::Array::begin
iterator begin()
Definition: JSON.h:522
llvm::sys::path::end
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:235
llvm::sys::path::begin
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:226
llvm::json::Path::Root::printErrorContext
void printErrorContext(const Value &, llvm::raw_ostream &) const
Print the root value with the error shown inline as a comment.
Definition: JSON.cpp:309
llvm::json::OStream::attributeArray
void attributeArray(llvm::StringRef Key, Block Contents)
Emit an attribute whose value is an array with elements from the Block.
Definition: JSON.h:1016
llvm::json::ObjectMapper::ObjectMapper
ObjectMapper(const Value &E, Path P)
If O is not an object, this mapper is invalid and an error is reported.
Definition: JSON.h:823
llvm::Optional
Definition: APInt.h:33
llvm::json::Value::Null
@ Null
Definition: JSON.h:286
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::json::ObjectMapper::map
bool map(StringLiteral Prop, T &Out)
Maps a property to a field.
Definition: JSON.h:834
llvm::json::Object::erase
void erase(iterator I)
Definition: JSON.h:128
llvm::max
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:337
llvm::json::Value::getAsNumber
llvm::Optional< double > getAsNumber() const
Definition: JSON.h:415
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
llvm::json::ParseError::log
void log(llvm::raw_ostream &OS) const override
Print an error message to an output stream.
Definition: JSON.h:881
llvm::json::OStream::rawValue
void rawValue(llvm::StringRef Contents)
Definition: JSON.h:1000
llvm::AlignedCharArrayUnion
A suitably aligned and sized character array member which can hold elements of any type.
Definition: AlignOf.h:27
llvm::codeview::PointerMode::Pointer
@ Pointer
llvm::json::Array::operator==
friend bool operator==(const Array &L, const Array &R)
Definition: JSON.h:552
llvm::json::Array::push_back
void push_back(const Value &E)
Definition: JSON.h:532
llvm::detail::DenseMapPair< ObjectKey, Value >
llvm::json::ObjectMapper::map
bool map(StringLiteral Prop, llvm::Optional< T > &Out)
Maps a property to a field, if it exists.
Definition: JSON.h:845
llvm::json::Path::report
void report(llvm::StringLiteral Message)
Records that the value at the current path is invalid.
Definition: JSON.cpp:209
llvm::json::Array::const_iterator
std::vector< Value >::const_iterator const_iterator
Definition: JSON.h:164
new
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM ID Predecessors according to mbb< bb27, 0x8b0a7c0 > Note ADDri is not a two address instruction its result reg1037 is an operand of the PHI node in bb76 and its operand reg1039 is the result of the PHI node We should treat it as a two address code and make sure the ADDri is scheduled after any node that reads reg1039 Use info(i.e. register scavenger) to assign it a free register to allow reuse the collector could move the objects and invalidate the derived pointer This is bad enough in the first but safe points can crop up unpredictably **array_addr i32 n y store obj * new
Definition: README.txt:125
llvm::RISCVFenceField::R
@ R
Definition: RISCVBaseInfo.h:265
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::DenseMapBase< DenseMap< ObjectKey, Value, llvm::DenseMapInfo< StringRef >, llvm::detail::DenseMapPair< ObjectKey, Value > >, ObjectKey, Value, llvm::DenseMapInfo< StringRef >, llvm::detail::DenseMapPair< ObjectKey, Value > >::const_iterator
DenseMapIterator< ObjectKey, Value, llvm::DenseMapInfo< StringRef >, llvm::detail::DenseMapPair< ObjectKey, Value >, true > const_iterator
Definition: DenseMap.h:73
llvm::json::operator==
bool operator==(const Object &LHS, const Object &RHS)
Definition: JSON.cpp:85
LHS
Value * LHS
Definition: X86PartialReduction.cpp:75
llvm::formatv
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
Definition: FormatVariadic.h:251
llvm::json::ParseError::ParseError
ParseError(const char *Msg, unsigned Line, unsigned Column, unsigned Offset)
Definition: JSON.h:879
llvm::StringLiteral
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition: StringRef.h:845
llvm::json::Object::begin
const_iterator begin() const
Definition: JSON.h:110
llvm::json::Object::getString
llvm::Optional< llvm::StringRef > getString(StringRef K) const
Definition: JSON.cpp:60
llvm::json::Value::Value
Value(const Value &M)
Definition: JSON.h:297
llvm::json::Value::Value
Value(std::string V)
Definition: JSON.h:311
llvm::json::Value::Value
Value(const llvm::formatv_object_base &V)
Definition: JSON.h:320
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::json::OStream::object
void object(Block Contents)
Emit an object whose elements are emitted in the provided Block.
Definition: JSON.h:987
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::json::OStream::array
void array(Block Contents)
Emit an array whose elements are emitted in the provided Block.
Definition: JSON.h:981
llvm::json::Path::Root::Root
Root(llvm::StringRef Name="")
Definition: JSON.h:688
llvm::json::Object::KV::V
Value V
Definition: JSON.h:613
llvm::json::Object::getObject
const json::Object * getObject(StringRef K) const
Definition: JSON.cpp:65
llvm::AMDGPU::PALMD::Key
Key
PAL metadata keys.
Definition: AMDGPUMetadata.h:486
llvm::json::ObjectMapper::mapOptional
bool mapOptional(StringLiteral Prop, T &Out)
Maps a property to a field, if it exists.
Definition: JSON.h:856
llvm::dwarf::Index
Index
Definition: Dwarf.h:472
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::json::Value::operator=
Value & operator=(Value &&M)
Definition: JSON.h:375
llvm::json::Value::Number
@ Number
Number values can store both int64s and doubles at full precision, depending on what they were constr...
Definition: JSON.h:290
llvm::json::Value::Array
friend class Array
Definition: JSON.h:474
llvm::json::Array
An Array is a JSON array, which contains heterogeneous JSON values.
Definition: JSON.h:158
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
llvm::json::Value::Object
@ Object
Definition: JSON.h:293
llvm::raw_ostream::flush
void flush()
Definition: raw_ostream.h:185
STLFunctionalExtras.h
llvm::json::Value::Value
Value(json::Array &&Elements)
Definition: JSON.h:300
llvm::json::parse
llvm::Expected< Value > parse(llvm::StringRef JSON)
Parses the provided JSON source, or returns a ParseError.
Definition: JSON.cpp:684
llvm::json::Object::KV
Definition: JSON.h:611
llvm::json::Object::try_emplace
std::pair< iterator, bool > try_emplace(const ObjectKey &K, Ts &&... Args)
Definition: JSON.h:120
FormatVariadic.h
llvm::json::OStream::objectEnd
void objectEnd()
Definition: JSON.cpp:869
llvm::json::Array::size
size_t size() const
Definition: JSON.h:528
llvm::json::Value::Value
Value(T D)
Definition: JSON.h:360
llvm::json::Object::getNumber
llvm::Optional< double > getNumber(StringRef K) const
Definition: JSON.cpp:50
llvm::json::ObjectKey::ObjectKey
ObjectKey(const llvm::formatv_object_base &V)
Definition: JSON.h:576
llvm::json::Value::Value
Value(StringRef V)
Definition: JSON.h:322
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLFunctionalExtras.h:36
llvm::json::ObjectKey::ObjectKey
ObjectKey(std::string S)
Definition: JSON.h:561
llvm::json::Object::try_emplace
std::pair< iterator, bool > try_emplace(ObjectKey &&K, Ts &&... Args)
Definition: JSON.h:124
llvm::json::Object::find
iterator find(StringRef K)
Definition: JSON.h:130
llvm::json::Value::getAsArray
json::Array * getAsArray()
Definition: JSON.h:463
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:264
llvm::json::Value::getAsArray
const json::Array * getAsArray() const
Definition: JSON.h:460
llvm::json::OStream::rawValueEnd
void rawValueEnd()
Definition: JSON.cpp:915
llvm::json::fromJSON
bool fromJSON(const Value &E, std::string &Out, Path P)
Definition: JSON.h:709
llvm::json::OStream
json::OStream allows writing well-formed JSON without materializing all structures as json::Value ahe...
Definition: JSON.h:957
llvm::AMDGPU::Hwreg::Offset
Offset
Definition: SIDefines.h:419
llvm::json::Object::get
Value * get(StringRef K)
Definition: JSON.cpp:28
Index
uint32_t Index
Definition: ELFObjHandler.cpp:83
uint64_t
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
const
aarch64 promote const
Definition: AArch64PromoteConstant.cpp:232
llvm::DenseMapBase< DenseMap< ObjectKey, Value, llvm::DenseMapInfo< StringRef >, llvm::detail::DenseMapPair< ObjectKey, Value > >, ObjectKey, Value, llvm::DenseMapInfo< StringRef >, llvm::detail::DenseMapPair< ObjectKey, Value > >::value_type
llvm::detail::DenseMapPair< ObjectKey, Value > value_type
Definition: DenseMap.h:69
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::json::OStream::arrayBegin
void arrayBegin()
Definition: JSON.cpp:842
llvm::DenseMap< ObjectKey, Value, llvm::DenseMapInfo< StringRef > >
llvm::json::Object::operator[]
Value & operator[](const ObjectKey &K)
Definition: JSON.cpp:22
llvm::json::ParseError
Definition: JSON.h:873
llvm::json::Value::getAsInteger
llvm::Optional< int64_t > getAsInteger() const
Definition: JSON.h:425
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::json::Array::data
Value * data()
Definition: JSON.h:519
llvm::json::Path::index
Path index(unsigned Index) const
Derives a path for an array element: this[Index].
Definition: JSON.h:645
llvm::json::operator!=
bool operator!=(const Object &LHS, const Object &RHS)
Definition: JSON.h:152
TemplateParamKind::Type
@ Type
llvm::AMDGPU::HSAMD::ValueType
ValueType
Value types.
Definition: AMDGPUMetadata.h:100
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1861
llvm::json::ObjectKey::ObjectKey
ObjectKey(llvm::StringRef S)
Definition: JSON.h:568
llvm::json::fixUTF8
std::string fixUTF8(llvm::StringRef S)
Replaces invalid UTF-8 sequences in S with the replacement character (U+FFFD).
Definition: JSON.cpp:709
llvm::json::Object::empty
bool empty() const
Definition: JSON.h:114
llvm::ErrorInfo
Base class for user error types.
Definition: Error.h:347
llvm::json::Array::Array
Array()=default
llvm::size
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition: STLExtras.h:1715
llvm::json::ParseError::convertToErrorCode
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: JSON.h:884
llvm::json::Value::getAsBoolean
llvm::Optional< bool > getAsBoolean() const
Definition: JSON.h:410
llvm::json::Array::iterator
std::vector< Value >::iterator iterator
Definition: JSON.h:163
llvm::json::Array::pop_back
void pop_back()
Definition: JSON.h:537
llvm::json::Value::getAsUINT64
llvm::Optional< uint64_t > getAsUINT64() const
Definition: JSON.h:437
llvm::min
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:357
llvm::json::Object::size
size_t size() const
Definition: JSON.h:115
llvm::json::ObjectKey::ObjectKey
ObjectKey(const ObjectKey &C)
Definition: JSON.h:578
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::json::Object::getInteger
llvm::Optional< int64_t > getInteger(StringRef K) const
Definition: JSON.cpp:55
llvm::json::Object::end
iterator end()
Definition: JSON.h:111
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
A
* A
Definition: README_ALTIVEC.txt:89
llvm::json::Path::field
Path field(StringRef Field) const
Derives a path for an object field: this.Field.
Definition: JSON.h:647
llvm::json::Value::Value
Value(const llvm::SmallVectorImpl< char > &V)
Definition: JSON.h:318
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::json::Array::reserve
void reserve(size_t S)
Definition: JSON.h:529
llvm::json::Object::clear
void clear()
Definition: JSON.h:117
llvm::json::toJSON
Value toJSON(const llvm::Optional< T > &Opt)
Definition: JSON.h:805
llvm::json::ObjectKey::operator=
ObjectKey & operator=(const ObjectKey &C)
Definition: JSON.h:580
llvm::json::Object::end
const_iterator end() const
Definition: JSON.h:112
llvm::format
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
llvm::json::Array::emplace
iterator emplace(const_iterator P, Args &&...A)
Definition: JSON.h:549
llvm::json::ParseError::ID
static char ID
Definition: JSON.h:878
llvm::json::Value::~Value
~Value()
Definition: JSON.h:380
llvm::PointerUnion< const Value *, const PseudoSourceValue * >
llvm::json::Array::front
Value & front()
Definition: JSON.h:515
llvm::json::Path::Root::getError
Error getError() const
Returns the last error reported, or else a generic error.
Definition: JSON.cpp:224
llvm::json::Value::Value
Value(T B)
Definition: JSON.h:336
std
Definition: BitVector.h:851
llvm::inconvertibleErrorCode
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:79
llvm::json::Value::getAsObject
const json::Object * getAsObject() const
Definition: JSON.h:454
llvm::json::Value::Value
Value(const std::map< std::string, Elt > &C)
Definition: JSON.h:309
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::json::ObjectKey::str
std::string str() const
Definition: JSON.h:592
llvm::json::Array::insert
iterator insert(iterator P, const Value &E)
Definition: JSON.h:538
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::ARCCC::Z
@ Z
Definition: ARCInfo.h:41
llvm::json::OStream::value
void value(const Value &V)
Emit a self-contained value (number, string, vector<string> etc).
Definition: JSON.cpp:756
llvm::json::Object::getArray
const json::Array * getArray(StringRef K) const
Definition: JSON.cpp:75
llvm::HasValue
detail::ValueMatchesPoly< M > HasValue(M Matcher)
Definition: Error.h:221
llvm::json::operator<<
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const Value &V)
Serializes this Value to JSON, writing it to the provided stream.
Definition: JSON.h:1067
llvm::json::Value::String
@ String
Definition: JSON.h:291
llvm::json::Path::Path
Path(Root &R)
The root may be treated as a Path.
Definition: JSON.h:643
llvm::json::ObjectKey::ObjectKey
ObjectKey(const llvm::SmallVectorImpl< char > &V)
Definition: JSON.h:574
llvm::DenseMapBase< DenseMap< ObjectKey, Value, llvm::DenseMapInfo< StringRef >, llvm::detail::DenseMapPair< ObjectKey, Value > >, ObjectKey, Value, llvm::DenseMapInfo< StringRef >, llvm::detail::DenseMapPair< ObjectKey, Value > >::iterator
DenseMapIterator< ObjectKey, Value, llvm::DenseMapInfo< StringRef >, llvm::detail::DenseMapPair< ObjectKey, Value > > iterator
Definition: DenseMap.h:71
SmallVector.h
llvm::json::Value::Array
@ Array
Definition: JSON.h:292
llvm::json::Value::Value
Value(Value &&M)
Definition: JSON.h:298
llvm::json::Value::Value
Value(const std::vector< Elt > &C)
Definition: JSON.h:304
N
#define N
P
#define P(N)
llvm::json::OStream::arrayEnd
void arrayEnd()
Definition: JSON.cpp:850
llvm::json::Value::getAsObject
json::Object * getAsObject()
Definition: JSON.h:457
LLVM_LIKELY
#define LLVM_LIKELY(EXPR)
Definition: Compiler.h:209
llvm::json::Array::Array
Array(const Collection &C)
Definition: JSON.h:168
llvm::SmallVectorImpl< char >
llvm::json::Value::Value
Value(json::Object &&Properties)
Definition: JSON.h:305
llvm::json::OStream::attributeObject
void attributeObject(llvm::StringRef Key, Block Contents)
Emit an attribute whose value is an object with attributes from the Block.
Definition: JSON.h:1020
llvm::json::Value::Kind
Kind
Definition: JSON.h:285
llvm::StringRef::str
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:221
llvm::json::Value::Value
Value(const T &V)
Definition: JSON.h:368
llvm::formatv_object_base
Definition: FormatVariadic.h:66
llvm::json::isUTF8
bool isUTF8(llvm::StringRef S, size_t *ErrOffset=nullptr)
Returns true if S is valid UTF-8, which is required for use as JSON.
Definition: JSON.cpp:695
llvm::OptimizedStructLayoutField
A field in a structure.
Definition: OptimizedStructLayout.h:45
llvm::json::ObjectKey
ObjectKey is a used to capture keys in Object.
Definition: JSON.h:558
llvm::json::ObjectKey::ObjectKey
ObjectKey(ObjectKey &&C)
Definition: JSON.h:579
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:394
llvm::json::OStream::attribute
void attribute(llvm::StringRef Key, const Value &Contents)
Emit an attribute whose value is self-contained (number, vector<int> etc).
Definition: JSON.h:1012
LLVM_UNLIKELY
#define LLVM_UNLIKELY(EXPR)
Definition: Compiler.h:210
raw_ostream.h
llvm::json::Object
An Object is a JSON object, which maps strings to heterogenous JSON values.
Definition: JSON.h:92
llvm::json::Value::getAsString
llvm::Optional< llvm::StringRef > getAsString() const
Definition: JSON.h:447
llvm::json::Object::insert
std::pair< iterator, bool > insert(KV E)
Definition: JSON.h:623
llvm::json::Object::KV::K
ObjectKey K
Definition: JSON.h:612
llvm::json::OStream::rawValueBegin
raw_ostream & rawValueBegin()
Definition: JSON.cpp:908
llvm::json::Object::getBoolean
llvm::Optional< bool > getBoolean(StringRef K) const
Definition: JSON.cpp:45
llvm::json::Array::clear
void clear()
Definition: JSON.h:531
llvm::json::OStream::objectBegin
void objectBegin()
Definition: JSON.cpp:861
llvm::json::Path
A "cursor" marking a position within a Value.
Definition: JSON.h:633
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::json::OStream::OStream
OStream(llvm::raw_ostream &OS, unsigned IndentSize=0)
Definition: JSON.h:961
llvm::json::OStream::flush
void flush()
Flushes the underlying ostream. OStream does not buffer internally.
Definition: JSON.h:972
SpecialSubKind::string
@ string
llvm::json::Path::Root::operator=
Root & operator=(Root &&)=delete
llvm::json::ObjectMapper
Helper for mapping JSON objects onto protocol structs.
Definition: JSON.h:820
llvm::json::Object::begin
iterator begin()
Definition: JSON.h:109
llvm::SmallVectorImpl::emplace_back
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:941
llvm::json::OStream::rawValue
void rawValue(llvm::function_ref< void(raw_ostream &)> Contents)
Emit an externally-serialized value.
Definition: JSON.h:995
llvm::json::operator<
bool operator<(const ObjectKey &L, const ObjectKey &R)
Definition: JSON.h:607
llvm::json::Object::getNull
llvm::Optional< std::nullptr_t > getNull(StringRef K) const
Definition: JSON.cpp:40
llvm::json::Value::operator=
Value & operator=(const Value &M)
Definition: JSON.h:370