LLVM  14.0.0git
Path.cpp
Go to the documentation of this file.
1 //===-- Path.cpp - Implement OS Path Concept ------------------------------===//
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 // This file implements the operating system Path API.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "llvm/Support/Path.h"
14 #include "llvm/ADT/ArrayRef.h"
15 #include "llvm/Config/llvm-config.h"
16 #include "llvm/Support/Endian.h"
17 #include "llvm/Support/Errc.h"
20 #include "llvm/Support/Process.h"
21 #include "llvm/Support/Signals.h"
22 #include <cctype>
23 #include <cstring>
24 
25 #if !defined(_MSC_VER) && !defined(__MINGW32__)
26 #include <unistd.h>
27 #else
28 #include <io.h>
29 #endif
30 
31 using namespace llvm;
32 using namespace llvm::support::endian;
33 
34 namespace {
35  using llvm::StringRef;
38 
39  inline Style real_style(Style style) {
40 #ifdef _WIN32
41  return (style == Style::posix) ? Style::posix : Style::windows;
42 #else
43  return (style == Style::windows) ? Style::windows : Style::posix;
44 #endif
45  }
46 
47  inline const char *separators(Style style) {
48  if (real_style(style) == Style::windows)
49  return "\\/";
50  return "/";
51  }
52 
53  inline char preferred_separator(Style style) {
54  if (real_style(style) == Style::windows)
55  return '\\';
56  return '/';
57  }
58 
59  StringRef find_first_component(StringRef path, Style style) {
60  // Look for this first component in the following order.
61  // * empty (in this case we return an empty string)
62  // * either C: or {//,\\}net.
63  // * {/,\}
64  // * {file,directory}name
65 
66  if (path.empty())
67  return path;
68 
69  if (real_style(style) == Style::windows) {
70  // C:
71  if (path.size() >= 2 &&
72  std::isalpha(static_cast<unsigned char>(path[0])) && path[1] == ':')
73  return path.substr(0, 2);
74  }
75 
76  // //net
77  if ((path.size() > 2) && is_separator(path[0], style) &&
78  path[0] == path[1] && !is_separator(path[2], style)) {
79  // Find the next directory separator.
80  size_t end = path.find_first_of(separators(style), 2);
81  return path.substr(0, end);
82  }
83 
84  // {/,\}
85  if (is_separator(path[0], style))
86  return path.substr(0, 1);
87 
88  // * {file,directory}name
89  size_t end = path.find_first_of(separators(style));
90  return path.substr(0, end);
91  }
92 
93  // Returns the first character of the filename in str. For paths ending in
94  // '/', it returns the position of the '/'.
95  size_t filename_pos(StringRef str, Style style) {
96  if (str.size() > 0 && is_separator(str[str.size() - 1], style))
97  return str.size() - 1;
98 
99  size_t pos = str.find_last_of(separators(style), str.size() - 1);
100 
101  if (real_style(style) == Style::windows) {
102  if (pos == StringRef::npos)
103  pos = str.find_last_of(':', str.size() - 2);
104  }
105 
106  if (pos == StringRef::npos || (pos == 1 && is_separator(str[0], style)))
107  return 0;
108 
109  return pos + 1;
110  }
111 
112  // Returns the position of the root directory in str. If there is no root
113  // directory in str, it returns StringRef::npos.
114  size_t root_dir_start(StringRef str, Style style) {
115  // case "c:/"
116  if (real_style(style) == Style::windows) {
117  if (str.size() > 2 && str[1] == ':' && is_separator(str[2], style))
118  return 2;
119  }
120 
121  // case "//net"
122  if (str.size() > 3 && is_separator(str[0], style) && str[0] == str[1] &&
123  !is_separator(str[2], style)) {
124  return str.find_first_of(separators(style), 2);
125  }
126 
127  // case "/"
128  if (str.size() > 0 && is_separator(str[0], style))
129  return 0;
130 
131  return StringRef::npos;
132  }
133 
134  // Returns the position past the end of the "parent path" of path. The parent
135  // path will not end in '/', unless the parent is the root directory. If the
136  // path has no parent, 0 is returned.
137  size_t parent_path_end(StringRef path, Style style) {
138  size_t end_pos = filename_pos(path, style);
139 
140  bool filename_was_sep =
141  path.size() > 0 && is_separator(path[end_pos], style);
142 
143  // Skip separators until we reach root dir (or the start of the string).
144  size_t root_dir_pos = root_dir_start(path, style);
145  while (end_pos > 0 &&
146  (root_dir_pos == StringRef::npos || end_pos > root_dir_pos) &&
147  is_separator(path[end_pos - 1], style))
148  --end_pos;
149 
150  if (end_pos == root_dir_pos && !filename_was_sep) {
151  // We've reached the root dir and the input path was *not* ending in a
152  // sequence of slashes. Include the root dir in the parent path.
153  return root_dir_pos + 1;
154  }
155 
156  // Otherwise, just include before the last slash.
157  return end_pos;
158  }
159 } // end unnamed namespace
160 
161 enum FSEntity {
165 };
166 
167 static std::error_code
168 createUniqueEntity(const Twine &Model, int &ResultFD,
169  SmallVectorImpl<char> &ResultPath, bool MakeAbsolute,
171  unsigned Mode = 0) {
172 
173  // Limit the number of attempts we make, so that we don't infinite loop. E.g.
174  // "permission denied" could be for a specific file (so we retry with a
175  // different name) or for the whole directory (retry would always fail).
176  // Checking which is racy, so we try a number of times, then give up.
177  std::error_code EC;
178  for (int Retries = 128; Retries > 0; --Retries) {
179  sys::fs::createUniquePath(Model, ResultPath, MakeAbsolute);
180  // Try to open + create the file.
181  switch (Type) {
182  case FS_File: {
183  EC = sys::fs::openFileForReadWrite(Twine(ResultPath.begin()), ResultFD,
184  sys::fs::CD_CreateNew, Flags, Mode);
185  if (EC) {
186  // errc::permission_denied happens on Windows when we try to open a file
187  // that has been marked for deletion.
188  if (EC == errc::file_exists || EC == errc::permission_denied)
189  continue;
190  return EC;
191  }
192 
193  return std::error_code();
194  }
195 
196  case FS_Name: {
197  EC = sys::fs::access(ResultPath.begin(), sys::fs::AccessMode::Exist);
199  return std::error_code();
200  if (EC)
201  return EC;
202  continue;
203  }
204 
205  case FS_Dir: {
206  EC = sys::fs::create_directory(ResultPath.begin(), false);
207  if (EC) {
208  if (EC == errc::file_exists)
209  continue;
210  return EC;
211  }
212  return std::error_code();
213  }
214  }
215  llvm_unreachable("Invalid Type");
216  }
217  return EC;
218 }
219 
220 namespace llvm {
221 namespace sys {
222 namespace path {
223 
226  i.Path = path;
227  i.Component = find_first_component(path, style);
228  i.Position = 0;
229  i.S = style;
230  return i;
231 }
232 
235  i.Path = path;
236  i.Position = path.size();
237  return i;
238 }
239 
240 const_iterator &const_iterator::operator++() {
241  assert(Position < Path.size() && "Tried to increment past end!");
242 
243  // Increment Position to past the current component
244  Position += Component.size();
245 
246  // Check for end.
247  if (Position == Path.size()) {
248  Component = StringRef();
249  return *this;
250  }
251 
252  // Both POSIX and Windows treat paths that begin with exactly two separators
253  // specially.
254  bool was_net = Component.size() > 2 && is_separator(Component[0], S) &&
255  Component[1] == Component[0] && !is_separator(Component[2], S);
256 
257  // Handle separators.
258  if (is_separator(Path[Position], S)) {
259  // Root dir.
260  if (was_net ||
261  // c:/
262  (real_style(S) == Style::windows && Component.endswith(":"))) {
263  Component = Path.substr(Position, 1);
264  return *this;
265  }
266 
267  // Skip extra separators.
268  while (Position != Path.size() && is_separator(Path[Position], S)) {
269  ++Position;
270  }
271 
272  // Treat trailing '/' as a '.', unless it is the root dir.
273  if (Position == Path.size() && Component != "/") {
274  --Position;
275  Component = ".";
276  return *this;
277  }
278  }
279 
280  // Find next component.
281  size_t end_pos = Path.find_first_of(separators(S), Position);
282  Component = Path.slice(Position, end_pos);
283 
284  return *this;
285 }
286 
288  return Path.begin() == RHS.Path.begin() && Position == RHS.Position;
289 }
290 
292  return Position - RHS.Position;
293 }
294 
297  I.Path = Path;
298  I.Position = Path.size();
299  I.S = style;
300  ++I;
301  return I;
302 }
303 
306  I.Path = Path;
307  I.Component = Path.substr(0, 0);
308  I.Position = 0;
309  return I;
310 }
311 
312 reverse_iterator &reverse_iterator::operator++() {
313  size_t root_dir_pos = root_dir_start(Path, S);
314 
315  // Skip separators unless it's the root directory.
316  size_t end_pos = Position;
317  while (end_pos > 0 && (end_pos - 1) != root_dir_pos &&
318  is_separator(Path[end_pos - 1], S))
319  --end_pos;
320 
321  // Treat trailing '/' as a '.', unless it is the root dir.
322  if (Position == Path.size() && !Path.empty() &&
323  is_separator(Path.back(), S) &&
324  (root_dir_pos == StringRef::npos || end_pos - 1 > root_dir_pos)) {
325  --Position;
326  Component = ".";
327  return *this;
328  }
329 
330  // Find next separator.
331  size_t start_pos = filename_pos(Path.substr(0, end_pos), S);
332  Component = Path.slice(start_pos, end_pos);
333  Position = start_pos;
334  return *this;
335 }
336 
338  return Path.begin() == RHS.Path.begin() && Component == RHS.Component &&
339  Position == RHS.Position;
340 }
341 
343  return Position - RHS.Position;
344 }
345 
347  const_iterator b = begin(path, style), pos = b, e = end(path);
348  if (b != e) {
349  bool has_net =
350  b->size() > 2 && is_separator((*b)[0], style) && (*b)[1] == (*b)[0];
351  bool has_drive = (real_style(style) == Style::windows) && b->endswith(":");
352 
353  if (has_net || has_drive) {
354  if ((++pos != e) && is_separator((*pos)[0], style)) {
355  // {C:/,//net/}, so get the first two components.
356  return path.substr(0, b->size() + pos->size());
357  }
358  // just {C:,//net}, return the first component.
359  return *b;
360  }
361 
362  // POSIX style root directory.
363  if (is_separator((*b)[0], style)) {
364  return *b;
365  }
366  }
367 
368  return StringRef();
369 }
370 
372  const_iterator b = begin(path, style), e = end(path);
373  if (b != e) {
374  bool has_net =
375  b->size() > 2 && is_separator((*b)[0], style) && (*b)[1] == (*b)[0];
376  bool has_drive = (real_style(style) == Style::windows) && b->endswith(":");
377 
378  if (has_net || has_drive) {
379  // just {C:,//net}, return the first component.
380  return *b;
381  }
382  }
383 
384  // No path or no name.
385  return StringRef();
386 }
387 
389  const_iterator b = begin(path, style), pos = b, e = end(path);
390  if (b != e) {
391  bool has_net =
392  b->size() > 2 && is_separator((*b)[0], style) && (*b)[1] == (*b)[0];
393  bool has_drive = (real_style(style) == Style::windows) && b->endswith(":");
394 
395  if ((has_net || has_drive) &&
396  // {C:,//net}, skip to the next component.
397  (++pos != e) && is_separator((*pos)[0], style)) {
398  return *pos;
399  }
400 
401  // POSIX style root directory.
402  if (!has_net && is_separator((*b)[0], style)) {
403  return *b;
404  }
405  }
406 
407  // No path or no root.
408  return StringRef();
409 }
410 
412  StringRef root = root_path(path, style);
413  return path.substr(root.size());
414 }
415 
416 void append(SmallVectorImpl<char> &path, Style style, const Twine &a,
417  const Twine &b, const Twine &c, const Twine &d) {
418  SmallString<32> a_storage;
419  SmallString<32> b_storage;
420  SmallString<32> c_storage;
421  SmallString<32> d_storage;
422 
423  SmallVector<StringRef, 4> components;
424  if (!a.isTriviallyEmpty()) components.push_back(a.toStringRef(a_storage));
425  if (!b.isTriviallyEmpty()) components.push_back(b.toStringRef(b_storage));
426  if (!c.isTriviallyEmpty()) components.push_back(c.toStringRef(c_storage));
427  if (!d.isTriviallyEmpty()) components.push_back(d.toStringRef(d_storage));
428 
429  for (auto &component : components) {
430  bool path_has_sep =
431  !path.empty() && is_separator(path[path.size() - 1], style);
432  if (path_has_sep) {
433  // Strip separators from beginning of component.
434  size_t loc = component.find_first_not_of(separators(style));
435  StringRef c = component.substr(loc);
436 
437  // Append it.
438  path.append(c.begin(), c.end());
439  continue;
440  }
441 
442  bool component_has_sep =
443  !component.empty() && is_separator(component[0], style);
444  if (!component_has_sep &&
445  !(path.empty() || has_root_name(component, style))) {
446  // Add a separator.
447  path.push_back(preferred_separator(style));
448  }
449 
450  path.append(component.begin(), component.end());
451  }
452 }
453 
454 void append(SmallVectorImpl<char> &path, const Twine &a, const Twine &b,
455  const Twine &c, const Twine &d) {
456  append(path, Style::native, a, b, c, d);
457 }
458 
460  const_iterator end, Style style) {
461  for (; begin != end; ++begin)
462  path::append(path, style, *begin);
463 }
464 
466  size_t end_pos = parent_path_end(path, style);
467  if (end_pos == StringRef::npos)
468  return StringRef();
469  return path.substr(0, end_pos);
470 }
471 
473  size_t end_pos = parent_path_end(StringRef(path.begin(), path.size()), style);
474  if (end_pos != StringRef::npos)
475  path.set_size(end_pos);
476 }
477 
479  Style style) {
480  StringRef p(path.begin(), path.size());
481  SmallString<32> ext_storage;
482  StringRef ext = extension.toStringRef(ext_storage);
483 
484  // Erase existing extension.
485  size_t pos = p.find_last_of('.');
486  if (pos != StringRef::npos && pos >= filename_pos(p, style))
487  path.set_size(pos);
488 
489  // Append '.' if needed.
490  if (ext.size() > 0 && ext[0] != '.')
491  path.push_back('.');
492 
493  // Append extension.
494  path.append(ext.begin(), ext.end());
495 }
496 
498  Style style = Style::native) {
499  // Windows prefix matching : case and separator insensitive
500  if (real_style(style) == Style::windows) {
501  if (Path.size() < Prefix.size())
502  return false;
503  for (size_t I = 0, E = Prefix.size(); I != E; ++I) {
504  bool SepPath = is_separator(Path[I], style);
505  bool SepPrefix = is_separator(Prefix[I], style);
506  if (SepPath != SepPrefix)
507  return false;
508  if (!SepPath && toLower(Path[I]) != toLower(Prefix[I]))
509  return false;
510  }
511  return true;
512  }
513  return Path.startswith(Prefix);
514 }
515 
517  StringRef NewPrefix, Style style) {
518  if (OldPrefix.empty() && NewPrefix.empty())
519  return false;
520 
521  StringRef OrigPath(Path.begin(), Path.size());
522  if (!starts_with(OrigPath, OldPrefix, style))
523  return false;
524 
525  // If prefixes have the same size we can simply copy the new one over.
526  if (OldPrefix.size() == NewPrefix.size()) {
527  llvm::copy(NewPrefix, Path.begin());
528  return true;
529  }
530 
531  StringRef RelPath = OrigPath.substr(OldPrefix.size());
532  SmallString<256> NewPath;
533  (Twine(NewPrefix) + RelPath).toVector(NewPath);
534  Path.swap(NewPath);
535  return true;
536 }
537 
538 void native(const Twine &path, SmallVectorImpl<char> &result, Style style) {
539  assert((!path.isSingleStringRef() ||
540  path.getSingleStringRef().data() != result.data()) &&
541  "path and result are not allowed to overlap!");
542  // Clear result.
543  result.clear();
544  path.toVector(result);
545  native(result, style);
546 }
547 
548 void native(SmallVectorImpl<char> &Path, Style style) {
549  if (Path.empty())
550  return;
551  if (real_style(style) == Style::windows) {
552  std::replace(Path.begin(), Path.end(), '/', '\\');
553  if (Path[0] == '~' && (Path.size() == 1 || is_separator(Path[1], style))) {
554  SmallString<128> PathHome;
555  home_directory(PathHome);
556  PathHome.append(Path.begin() + 1, Path.end());
557  Path = PathHome;
558  }
559  } else {
560  for (auto PI = Path.begin(), PE = Path.end(); PI < PE; ++PI)
561  if (*PI == '\\')
562  *PI = '/';
563  }
564 }
565 
566 std::string convert_to_slash(StringRef path, Style style) {
567  if (real_style(style) != Style::windows)
568  return std::string(path);
569 
570  std::string s = path.str();
571  std::replace(s.begin(), s.end(), '\\', '/');
572  return s;
573 }
574 
575 StringRef filename(StringRef path, Style style) { return *rbegin(path, style); }
576 
578  StringRef fname = filename(path, style);
579  size_t pos = fname.find_last_of('.');
580  if (pos == StringRef::npos)
581  return fname;
582  if ((fname.size() == 1 && fname == ".") ||
583  (fname.size() == 2 && fname == ".."))
584  return fname;
585  return fname.substr(0, pos);
586 }
587 
589  StringRef fname = filename(path, style);
590  size_t pos = fname.find_last_of('.');
591  if (pos == StringRef::npos)
592  return StringRef();
593  if ((fname.size() == 1 && fname == ".") ||
594  (fname.size() == 2 && fname == ".."))
595  return StringRef();
596  return fname.substr(pos);
597 }
598 
599 bool is_separator(char value, Style style) {
600  if (value == '/')
601  return true;
602  if (real_style(style) == Style::windows)
603  return value == '\\';
604  return false;
605 }
606 
608  if (real_style(style) == Style::windows)
609  return "\\";
610  return "/";
611 }
612 
613 bool has_root_name(const Twine &path, Style style) {
614  SmallString<128> path_storage;
615  StringRef p = path.toStringRef(path_storage);
616 
617  return !root_name(p, style).empty();
618 }
619 
620 bool has_root_directory(const Twine &path, Style style) {
621  SmallString<128> path_storage;
622  StringRef p = path.toStringRef(path_storage);
623 
624  return !root_directory(p, style).empty();
625 }
626 
627 bool has_root_path(const Twine &path, Style style) {
628  SmallString<128> path_storage;
629  StringRef p = path.toStringRef(path_storage);
630 
631  return !root_path(p, style).empty();
632 }
633 
634 bool has_relative_path(const Twine &path, Style style) {
635  SmallString<128> path_storage;
636  StringRef p = path.toStringRef(path_storage);
637 
638  return !relative_path(p, style).empty();
639 }
640 
641 bool has_filename(const Twine &path, Style style) {
642  SmallString<128> path_storage;
643  StringRef p = path.toStringRef(path_storage);
644 
645  return !filename(p, style).empty();
646 }
647 
648 bool has_parent_path(const Twine &path, Style style) {
649  SmallString<128> path_storage;
650  StringRef p = path.toStringRef(path_storage);
651 
652  return !parent_path(p, style).empty();
653 }
654 
655 bool has_stem(const Twine &path, Style style) {
656  SmallString<128> path_storage;
657  StringRef p = path.toStringRef(path_storage);
658 
659  return !stem(p, style).empty();
660 }
661 
662 bool has_extension(const Twine &path, Style style) {
663  SmallString<128> path_storage;
664  StringRef p = path.toStringRef(path_storage);
665 
666  return !extension(p, style).empty();
667 }
668 
669 bool is_absolute(const Twine &path, Style style) {
670  SmallString<128> path_storage;
671  StringRef p = path.toStringRef(path_storage);
672 
673  bool rootDir = has_root_directory(p, style);
674  bool rootName =
675  (real_style(style) != Style::windows) || has_root_name(p, style);
676 
677  return rootDir && rootName;
678 }
679 
680 bool is_absolute_gnu(const Twine &path, Style style) {
681  SmallString<128> path_storage;
682  StringRef p = path.toStringRef(path_storage);
683 
684  // Handle '/' which is absolute for both Windows and POSIX systems.
685  // Handle '\\' on Windows.
686  if (!p.empty() && is_separator(p.front(), style))
687  return true;
688 
689  if (real_style(style) == Style::windows) {
690  // Handle drive letter pattern (a character followed by ':') on Windows.
691  if (p.size() >= 2 && (p[0] && p[1] == ':'))
692  return true;
693  }
694 
695  return false;
696 }
697 
698 bool is_relative(const Twine &path, Style style) {
699  return !is_absolute(path, style);
700 }
701 
703  // Remove leading "./" (or ".//" or "././" etc.)
704  while (Path.size() > 2 && Path[0] == '.' && is_separator(Path[1], style)) {
705  Path = Path.substr(2);
706  while (Path.size() > 0 && is_separator(Path[0], style))
707  Path = Path.substr(1);
708  }
709  return Path;
710 }
711 
712 // Remove path traversal components ("." and "..") when possible, and
713 // canonicalize slashes.
714 bool remove_dots(SmallVectorImpl<char> &the_path, bool remove_dot_dot,
715  Style style) {
716  style = real_style(style);
717  StringRef remaining(the_path.data(), the_path.size());
718  bool needs_change = false;
719  SmallVector<StringRef, 16> components;
720 
721  // Consume the root path, if present.
722  StringRef root = path::root_path(remaining, style);
723  bool absolute = !root.empty();
724  if (absolute)
725  remaining = remaining.drop_front(root.size());
726 
727  // Loop over path components manually. This makes it easier to detect
728  // non-preferred slashes and double separators that must be canonicalized.
729  while (!remaining.empty()) {
730  size_t next_slash = remaining.find_first_of(separators(style));
731  if (next_slash == StringRef::npos)
732  next_slash = remaining.size();
733  StringRef component = remaining.take_front(next_slash);
734  remaining = remaining.drop_front(next_slash);
735 
736  // Eat the slash, and check if it is the preferred separator.
737  if (!remaining.empty()) {
738  needs_change |= remaining.front() != preferred_separator(style);
739  remaining = remaining.drop_front();
740  // The path needs to be rewritten if it has a trailing slash.
741  // FIXME: This is emergent behavior that could be removed.
742  needs_change |= remaining.empty();
743  }
744 
745  // Check for path traversal components or double separators.
746  if (component.empty() || component == ".") {
747  needs_change = true;
748  } else if (remove_dot_dot && component == "..") {
749  needs_change = true;
750  // Do not allow ".." to remove the root component. If this is the
751  // beginning of a relative path, keep the ".." component.
752  if (!components.empty() && components.back() != "..") {
753  components.pop_back();
754  } else if (!absolute) {
755  components.push_back(component);
756  }
757  } else {
758  components.push_back(component);
759  }
760  }
761 
762  // Avoid rewriting the path unless we have to.
763  if (!needs_change)
764  return false;
765 
766  SmallString<256> buffer = root;
767  if (!components.empty()) {
768  buffer += components[0];
769  for (StringRef C : makeArrayRef(components).drop_front()) {
770  buffer += preferred_separator(style);
771  buffer += C;
772  }
773  }
774  the_path.swap(buffer);
775  return true;
776 }
777 
778 } // end namespace path
779 
780 namespace fs {
781 
782 std::error_code getUniqueID(const Twine Path, UniqueID &Result) {
784  std::error_code EC = status(Path, Status);
785  if (EC)
786  return EC;
787  Result = Status.getUniqueID();
788  return std::error_code();
789 }
790 
792  bool MakeAbsolute) {
793  SmallString<128> ModelStorage;
794  Model.toVector(ModelStorage);
795 
796  if (MakeAbsolute) {
797  // Make model absolute by prepending a temp directory if it's not already.
798  if (!sys::path::is_absolute(Twine(ModelStorage))) {
799  SmallString<128> TDir;
801  sys::path::append(TDir, Twine(ModelStorage));
802  ModelStorage.swap(TDir);
803  }
804  }
805 
806  ResultPath = ModelStorage;
807  ResultPath.push_back(0);
808  ResultPath.pop_back();
809 
810  // Replace '%' with random chars.
811  for (unsigned i = 0, e = ModelStorage.size(); i != e; ++i) {
812  if (ModelStorage[i] == '%')
813  ResultPath[i] = "0123456789abcdef"[sys::Process::GetRandomNumber() & 15];
814  }
815 }
816 
817 std::error_code createUniqueFile(const Twine &Model, int &ResultFd,
818  SmallVectorImpl<char> &ResultPath,
819  OpenFlags Flags, unsigned Mode) {
820  return createUniqueEntity(Model, ResultFd, ResultPath, false, FS_File, Flags,
821  Mode);
822 }
823 
824 std::error_code createUniqueFile(const Twine &Model,
825  SmallVectorImpl<char> &ResultPath,
826  unsigned Mode) {
827  int FD;
828  auto EC = createUniqueFile(Model, FD, ResultPath, OF_None, Mode);
829  if (EC)
830  return EC;
831  // FD is only needed to avoid race conditions. Close it right away.
832  close(FD);
833  return EC;
834 }
835 
836 static std::error_code
837 createTemporaryFile(const Twine &Model, int &ResultFD,
840  SmallString<128> Storage;
841  StringRef P = Model.toNullTerminatedStringRef(Storage);
842  assert(P.find_first_of(separators(Style::native)) == StringRef::npos &&
843  "Model must be a simple filename.");
844  // Use P.begin() so that createUniqueEntity doesn't need to recreate Storage.
845  return createUniqueEntity(P.begin(), ResultFD, ResultPath, true, Type, Flags,
847 }
848 
849 static std::error_code
850 createTemporaryFile(const Twine &Prefix, StringRef Suffix, int &ResultFD,
853  const char *Middle = Suffix.empty() ? "-%%%%%%" : "-%%%%%%.";
854  return createTemporaryFile(Prefix + Middle + Suffix, ResultFD, ResultPath,
855  Type, Flags);
856 }
857 
858 std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix,
859  int &ResultFD,
860  SmallVectorImpl<char> &ResultPath,
861  sys::fs::OpenFlags Flags) {
862  return createTemporaryFile(Prefix, Suffix, ResultFD, ResultPath, FS_File,
863  Flags);
864 }
865 
866 std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix,
867  SmallVectorImpl<char> &ResultPath,
868  sys::fs::OpenFlags Flags) {
869  int FD;
870  auto EC = createTemporaryFile(Prefix, Suffix, FD, ResultPath, Flags);
871  if (EC)
872  return EC;
873  // FD is only needed to avoid race conditions. Close it right away.
874  close(FD);
875  return EC;
876 }
877 
878 // This is a mkdtemp with a different pattern. We use createUniqueEntity mostly
879 // for consistency. We should try using mkdtemp.
880 std::error_code createUniqueDirectory(const Twine &Prefix,
881  SmallVectorImpl<char> &ResultPath) {
882  int Dummy;
883  return createUniqueEntity(Prefix + "-%%%%%%", Dummy, ResultPath, true,
884  FS_Dir);
885 }
886 
887 std::error_code
889  SmallVectorImpl<char> &ResultPath) {
890  int Dummy;
891  return createUniqueEntity(Model, Dummy, ResultPath, false, FS_Name);
892 }
893 
894 std::error_code
896  SmallVectorImpl<char> &ResultPath) {
897  int Dummy;
898  return createTemporaryFile(Prefix, Suffix, Dummy, ResultPath, FS_Name);
899 }
900 
901 void make_absolute(const Twine &current_directory,
902  SmallVectorImpl<char> &path) {
903  StringRef p(path.data(), path.size());
904 
905  bool rootDirectory = path::has_root_directory(p);
906  bool rootName = path::has_root_name(p);
907 
908  // Already absolute.
909  if ((rootName || real_style(Style::native) != Style::windows) &&
910  rootDirectory)
911  return;
912 
913  // All of the following conditions will need the current directory.
914  SmallString<128> current_dir;
915  current_directory.toVector(current_dir);
916 
917  // Relative path. Prepend the current directory.
918  if (!rootName && !rootDirectory) {
919  // Append path to the current directory.
920  path::append(current_dir, p);
921  // Set path to the result.
922  path.swap(current_dir);
923  return;
924  }
925 
926  if (!rootName && rootDirectory) {
927  StringRef cdrn = path::root_name(current_dir);
928  SmallString<128> curDirRootName(cdrn.begin(), cdrn.end());
929  path::append(curDirRootName, p);
930  // Set path to the result.
931  path.swap(curDirRootName);
932  return;
933  }
934 
935  if (rootName && !rootDirectory) {
936  StringRef pRootName = path::root_name(p);
937  StringRef bRootDirectory = path::root_directory(current_dir);
938  StringRef bRelativePath = path::relative_path(current_dir);
939  StringRef pRelativePath = path::relative_path(p);
940 
941  SmallString<128> res;
942  path::append(res, pRootName, bRootDirectory, bRelativePath, pRelativePath);
943  path.swap(res);
944  return;
945  }
946 
947  llvm_unreachable("All rootName and rootDirectory combinations should have "
948  "occurred above!");
949 }
950 
951 std::error_code make_absolute(SmallVectorImpl<char> &path) {
952  if (path::is_absolute(path))
953  return {};
954 
955  SmallString<128> current_dir;
956  if (std::error_code ec = current_path(current_dir))
957  return ec;
958 
959  make_absolute(current_dir, path);
960  return {};
961 }
962 
963 std::error_code create_directories(const Twine &Path, bool IgnoreExisting,
964  perms Perms) {
965  SmallString<128> PathStorage;
966  StringRef P = Path.toStringRef(PathStorage);
967 
968  // Be optimistic and try to create the directory
969  std::error_code EC = create_directory(P, IgnoreExisting, Perms);
970  // If we succeeded, or had any error other than the parent not existing, just
971  // return it.
973  return EC;
974 
975  // We failed because of a no_such_file_or_directory, try to create the
976  // parent.
977  StringRef Parent = path::parent_path(P);
978  if (Parent.empty())
979  return EC;
980 
981  if ((EC = create_directories(Parent, IgnoreExisting, Perms)))
982  return EC;
983 
984  return create_directory(P, IgnoreExisting, Perms);
985 }
986 
987 static std::error_code copy_file_internal(int ReadFD, int WriteFD) {
988  const size_t BufSize = 4096;
989  char *Buf = new char[BufSize];
990  int BytesRead = 0, BytesWritten = 0;
991  for (;;) {
992  BytesRead = read(ReadFD, Buf, BufSize);
993  if (BytesRead <= 0)
994  break;
995  while (BytesRead) {
996  BytesWritten = write(WriteFD, Buf, BytesRead);
997  if (BytesWritten < 0)
998  break;
999  BytesRead -= BytesWritten;
1000  }
1001  if (BytesWritten < 0)
1002  break;
1003  }
1004  delete[] Buf;
1005 
1006  if (BytesRead < 0 || BytesWritten < 0)
1007  return std::error_code(errno, std::generic_category());
1008  return std::error_code();
1009 }
1010 
1011 #ifndef __APPLE__
1012 std::error_code copy_file(const Twine &From, const Twine &To) {
1013  int ReadFD, WriteFD;
1014  if (std::error_code EC = openFileForRead(From, ReadFD, OF_None))
1015  return EC;
1016  if (std::error_code EC =
1017  openFileForWrite(To, WriteFD, CD_CreateAlways, OF_None)) {
1018  close(ReadFD);
1019  return EC;
1020  }
1021 
1022  std::error_code EC = copy_file_internal(ReadFD, WriteFD);
1023 
1024  close(ReadFD);
1025  close(WriteFD);
1026 
1027  return EC;
1028 }
1029 #endif
1030 
1031 std::error_code copy_file(const Twine &From, int ToFD) {
1032  int ReadFD;
1033  if (std::error_code EC = openFileForRead(From, ReadFD, OF_None))
1034  return EC;
1035 
1036  std::error_code EC = copy_file_internal(ReadFD, ToFD);
1037 
1038  close(ReadFD);
1039 
1040  return EC;
1041 }
1042 
1044  MD5 Hash;
1045 
1046  constexpr size_t BufSize = 4096;
1047  std::vector<uint8_t> Buf(BufSize);
1048  int BytesRead = 0;
1049  for (;;) {
1050  BytesRead = read(FD, Buf.data(), BufSize);
1051  if (BytesRead <= 0)
1052  break;
1053  Hash.update(makeArrayRef(Buf.data(), BytesRead));
1054  }
1055 
1056  if (BytesRead < 0)
1057  return std::error_code(errno, std::generic_category());
1058  MD5::MD5Result Result;
1059  Hash.final(Result);
1060  return Result;
1061 }
1062 
1064  int FD;
1065  if (auto EC = openFileForRead(Path, FD, OF_None))
1066  return EC;
1067 
1068  auto Result = md5_contents(FD);
1069  close(FD);
1070  return Result;
1071 }
1072 
1074  return status_known(status) && status.type() != file_type::file_not_found;
1075 }
1076 
1078  return s.type() != file_type::status_error;
1079 }
1080 
1081 file_type get_file_type(const Twine &Path, bool Follow) {
1082  file_status st;
1083  if (status(Path, st, Follow))
1084  return file_type::status_error;
1085  return st.type();
1086 }
1087 
1089  return status.type() == file_type::directory_file;
1090 }
1091 
1092 std::error_code is_directory(const Twine &path, bool &result) {
1093  file_status st;
1094  if (std::error_code ec = status(path, st))
1095  return ec;
1096  result = is_directory(st);
1097  return std::error_code();
1098 }
1099 
1101  return status.type() == file_type::regular_file;
1102 }
1103 
1104 std::error_code is_regular_file(const Twine &path, bool &result) {
1105  file_status st;
1106  if (std::error_code ec = status(path, st))
1107  return ec;
1108  result = is_regular_file(st);
1109  return std::error_code();
1110 }
1111 
1113  return status.type() == file_type::symlink_file;
1114 }
1115 
1116 std::error_code is_symlink_file(const Twine &path, bool &result) {
1117  file_status st;
1118  if (std::error_code ec = status(path, st, false))
1119  return ec;
1120  result = is_symlink_file(st);
1121  return std::error_code();
1122 }
1123 
1125  return exists(status) &&
1126  !is_regular_file(status) &&
1127  !is_directory(status);
1128 }
1129 
1130 std::error_code is_other(const Twine &Path, bool &Result) {
1131  file_status FileStatus;
1132  if (std::error_code EC = status(Path, FileStatus))
1133  return EC;
1134  Result = is_other(FileStatus);
1135  return std::error_code();
1136 }
1137 
1138 void directory_entry::replace_filename(const Twine &Filename, file_type Type,
1140  SmallString<128> PathStr = path::parent_path(Path);
1141  path::append(PathStr, Filename);
1142  this->Path = std::string(PathStr.str());
1143  this->Type = Type;
1144  this->Status = Status;
1145 }
1146 
1149  if (std::error_code EC = status(Path, Status))
1150  return EC;
1151 
1152  return Status.permissions();
1153 }
1154 
1156  assert(Mapping && "Mapping failed but used anyway!");
1157  return Size;
1158 }
1159 
1160 char *mapped_file_region::data() const {
1161  assert(Mapping && "Mapping failed but used anyway!");
1162  return reinterpret_cast<char *>(Mapping);
1163 }
1164 
1165 const char *mapped_file_region::const_data() const {
1166  assert(Mapping && "Mapping failed but used anyway!");
1167  return reinterpret_cast<const char *>(Mapping);
1168 }
1169 
1170 } // end namespace fs
1171 } // end namespace sys
1172 } // end namespace llvm
1173 
1174 // Include the truly platform-specific parts.
1175 #if defined(LLVM_ON_UNIX)
1176 #include "Unix/Path.inc"
1177 #endif
1178 #if defined(_WIN32)
1179 #include "Windows/Path.inc"
1180 #endif
1181 
1182 namespace llvm {
1183 namespace sys {
1184 namespace fs {
1185 TempFile::TempFile(StringRef Name, int FD)
1186  : TmpName(std::string(Name)), FD(FD) {}
1187 TempFile::TempFile(TempFile &&Other) { *this = std::move(Other); }
1189  TmpName = std::move(Other.TmpName);
1190  FD = Other.FD;
1191  Other.Done = true;
1192  Other.FD = -1;
1193  return *this;
1194 }
1195 
1197 
1199  Done = true;
1200  if (FD != -1 && close(FD) == -1) {
1201  std::error_code EC = std::error_code(errno, std::generic_category());
1202  return errorCodeToError(EC);
1203  }
1204  FD = -1;
1205 
1206 #ifdef _WIN32
1207  // On windows closing will remove the file.
1208  TmpName = "";
1209  return Error::success();
1210 #else
1211  // Always try to close and remove.
1212  std::error_code RemoveEC;
1213  if (!TmpName.empty()) {
1214  RemoveEC = fs::remove(TmpName);
1216  if (!RemoveEC)
1217  TmpName = "";
1218  }
1219  return errorCodeToError(RemoveEC);
1220 #endif
1221 }
1222 
1224  assert(!Done);
1225  Done = true;
1226  // Always try to close and rename.
1227 #ifdef _WIN32
1228  // If we can't cancel the delete don't rename.
1229  auto H = reinterpret_cast<HANDLE>(_get_osfhandle(FD));
1230  std::error_code RenameEC = setDeleteDisposition(H, false);
1231  if (!RenameEC) {
1232  RenameEC = rename_handle(H, Name);
1233  // If rename failed because it's cross-device, copy instead
1234  if (RenameEC ==
1235  std::error_code(ERROR_NOT_SAME_DEVICE, std::system_category())) {
1236  RenameEC = copy_file(TmpName, Name);
1237  setDeleteDisposition(H, true);
1238  }
1239  }
1240 
1241  // If we can't rename, discard the temporary file.
1242  if (RenameEC)
1243  setDeleteDisposition(H, true);
1244 #else
1245  std::error_code RenameEC = fs::rename(TmpName, Name);
1246  if (RenameEC) {
1247  // If we can't rename, try to copy to work around cross-device link issues.
1248  RenameEC = sys::fs::copy_file(TmpName, Name);
1249  // If we can't rename or copy, discard the temporary file.
1250  if (RenameEC)
1251  remove(TmpName);
1252  }
1254 #endif
1255 
1256  if (!RenameEC)
1257  TmpName = "";
1258 
1259  if (close(FD) == -1) {
1260  std::error_code EC(errno, std::generic_category());
1261  return errorCodeToError(EC);
1262  }
1263  FD = -1;
1264 
1265  return errorCodeToError(RenameEC);
1266 }
1267 
1269  assert(!Done);
1270  Done = true;
1271 
1272 #ifdef _WIN32
1273  auto H = reinterpret_cast<HANDLE>(_get_osfhandle(FD));
1274  if (std::error_code EC = setDeleteDisposition(H, false))
1275  return errorCodeToError(EC);
1276 #else
1278 #endif
1279 
1280  TmpName = "";
1281 
1282  if (close(FD) == -1) {
1283  std::error_code EC(errno, std::generic_category());
1284  return errorCodeToError(EC);
1285  }
1286  FD = -1;
1287 
1288  return Error::success();
1289 }
1290 
1292  OpenFlags ExtraFlags) {
1293  int FD;
1294  SmallString<128> ResultPath;
1295  if (std::error_code EC =
1296  createUniqueFile(Model, FD, ResultPath, OF_Delete | ExtraFlags, Mode))
1297  return errorCodeToError(EC);
1298 
1299  TempFile Ret(ResultPath, FD);
1300 #ifndef _WIN32
1301  if (sys::RemoveFileOnSignal(ResultPath)) {
1302  // Make sure we delete the file when RemoveFileOnSignal fails.
1303  consumeError(Ret.discard());
1304  std::error_code EC(errc::operation_not_permitted);
1305  return errorCodeToError(EC);
1306  }
1307 #endif
1308  return std::move(Ret);
1309 }
1310 } // namespace fs
1311 
1312 } // namespace sys
1313 } // namespace llvm
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::sys::fs::createUniquePath
void createUniquePath(const Twine &Model, SmallVectorImpl< char > &ResultPath, bool MakeAbsolute)
Create a potentially unique file name but does not create it.
Definition: Path.cpp:791
i
i
Definition: README.txt:29
llvm::StringRef::startswith
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:286
llvm::sys::fs::openFileForWrite
std::error_code openFileForWrite(const Twine &Name, int &ResultFD, CreationDisposition Disp=CD_CreateAlways, OpenFlags Flags=OF_None, unsigned Mode=0666)
Opens the file with the given name in a write-only or read-write mode, returning its open file descri...
Definition: FileSystem.h:1040
llvm::sys::path::starts_with
static bool starts_with(StringRef Path, StringRef Prefix, Style style=Style::native)
Definition: Path.cpp:497
Signals.h
llvm::sys::fs::basic_file_status
Represents the result of a call to directory_iterator::status().
Definition: FileSystem.h:137
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::sys::path::replace_path_prefix
bool replace_path_prefix(SmallVectorImpl< char > &Path, StringRef OldPrefix, StringRef NewPrefix, Style style=Style::native)
Replace matching path prefix with another path.
Definition: Path.cpp:516
llvm::StringRef::empty
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:153
llvm::sys::fs::current_path
std::error_code current_path(SmallVectorImpl< char > &result)
Get the current path.
llvm::sys::path::home_directory
bool home_directory(SmallVectorImpl< char > &result)
Get the user's home directory.
llvm::sys::path::extension
StringRef extension(StringRef path, Style style=Style::native)
Get extension.
Definition: Path.cpp:588
llvm::MD5::update
void update(ArrayRef< uint8_t > Data)
Updates the hash for the byte stream provided.
Definition: MD5.cpp:190
llvm::sys::fs::createTemporaryFile
static std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix, int &ResultFD, llvm::SmallVectorImpl< char > &ResultPath, FSEntity Type, sys::fs::OpenFlags Flags=sys::fs::OF_None)
Definition: Path.cpp:850
FileSystem.h
llvm::sys::fs::OF_None
@ OF_None
Definition: FileSystem.h:757
llvm::Twine::getSingleStringRef
StringRef getSingleStringRef() const
This returns the twine as a single StringRef.
Definition: Twine.h:459
llvm::sys::path::rbegin
reverse_iterator rbegin(StringRef path, Style style=Style::native)
Get reverse begin iterator over path.
Definition: Path.cpp:295
llvm::cl::Prefix
@ Prefix
Definition: CommandLine.h:164
llvm::sys::fs::TempFile::TmpName
std::string TmpName
Definition: FileSystem.h:863
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::sys::path::remove_leading_dotslash
StringRef remove_leading_dotslash(StringRef path, Style style=Style::native)
Remove redundant leading "./" pieces and consecutive separators.
Definition: Path.cpp:702
llvm::StringRef::npos
static constexpr size_t npos
Definition: StringRef.h:60
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
Path.h
llvm::sys::path::is_absolute
bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
Definition: Path.cpp:669
llvm::sys::path::convert_to_slash
std::string convert_to_slash(StringRef path, Style style=Style::native)
Replaces backslashes with slashes if Windows.
Definition: Path.cpp:566
ErrorHandling.h
llvm::sys::path::reverse_iterator
Reverse path iterator.
Definition: Path.h:78
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
llvm::sys::fs::getUniqueID
std::error_code getUniqueID(const Twine Path, UniqueID &Result)
Definition: Path.cpp:782
llvm::sys::fs::getPotentiallyUniqueTempFileName
std::error_code getPotentiallyUniqueTempFileName(const Twine &Prefix, StringRef Suffix, SmallVectorImpl< char > &ResultPath)
Get a unique temporary file name, not currently exisiting in the filesystem.
Definition: Path.cpp:895
llvm::sys::fs::createUniqueFile
std::error_code createUniqueFile(const Twine &Model, int &ResultFD, SmallVectorImpl< char > &ResultPath, OpenFlags Flags=OF_None, unsigned Mode=all_read|all_write)
Create a uniquely named file.
Definition: Path.cpp:817
Errc.h
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::sys::path::end
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:233
llvm::sys::path::begin
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:224
llvm::copy
OutputIt copy(R &&Range, OutputIt Out)
Definition: STLExtras.h:1598
llvm::errc::no_such_file_or_directory
@ no_such_file_or_directory
llvm::sys::fs::access
std::error_code access(const Twine &Path, AccessMode Mode)
Can the file be accessed?
llvm::MipsISD::Ret
@ Ret
Definition: MipsISelLowering.h:116
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::sys::fs::is_regular_file
bool is_regular_file(const basic_file_status &status)
Does status represent a regular file?
Definition: Path.cpp:1100
Path.inc
replace
static void replace(Module &M, GlobalVariable *Old, GlobalVariable *New)
Definition: ConstantMerge.cpp:116
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1035
p
the resulting code requires compare and branches when and if * p
Definition: README.txt:396
llvm::sys::fs::TempFile::discard
Error discard()
Definition: Path.cpp:1198
llvm::errc::permission_denied
@ permission_denied
llvm::sys::fs::AccessMode::Exist
@ Exist
a
=0.0 ? 0.0 :(a > 0.0 ? 1.0 :-1.0) a
Definition: README.txt:489
result
It looks like we only need to define PPCfmarto for these because according to these instructions perform RTO on fma s result
Definition: README_P9.txt:256
llvm::Reloc::Model
Model
Definition: CodeGen.h:22
llvm::sys::path::append
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Definition: Path.cpp:454
llvm::StringRef::substr
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:611
llvm::support::endian
Definition: Endian.h:42
Process.h
llvm::MD5::final
void final(MD5Result &Result)
Finishes off the hash and puts the result in result.
Definition: MD5.cpp:235
llvm::StringRef::find_last_of
LLVM_NODISCARD size_t find_last_of(char C, size_t From=npos) const
Find the last character in the string that is C, or npos if not found.
Definition: StringRef.h:436
ptrdiff_t
llvm::StringRef::take_front
LLVM_NODISCARD StringRef take_front(size_t N=1) const
Return a StringRef equal to 'this' but with only the first N elements remaining.
Definition: StringRef.h:620
llvm::sys::path::has_extension
bool has_extension(const Twine &path, Style style=Style::native)
Has extension?
Definition: Path.cpp:662
llvm::sys::Process::GetRandomNumber
static unsigned GetRandomNumber()
Get the result of a process wide random number generator.
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::SmallVectorImpl::append
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:648
llvm::sys::path::has_parent_path
bool has_parent_path(const Twine &path, Style style=Style::native)
Has parent path?
Definition: Path.cpp:648
llvm::sys::fs::TempFile::operator=
TempFile & operator=(TempFile &&Other)
Definition: Path.cpp:1188
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::errorCodeToError
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition: Error.cpp:87
llvm::sys::fs::createUniqueDirectory
std::error_code createUniqueDirectory(const Twine &Prefix, SmallVectorImpl< char > &ResultPath)
Definition: Path.cpp:880
llvm::sys::path::root_path
StringRef root_path(StringRef path, Style style=Style::native)
Get root path.
Definition: Path.cpp:346
b
the resulting code requires compare and branches when and if the revised code is with conditional branches instead of More there is a byte word extend before each where there should be only and the condition codes are not remembered when the same two values are compared twice More LSR enhancements i8 and i32 load store addressing modes are identical int b
Definition: README.txt:418
llvm::sys::path::has_stem
bool has_stem(const Twine &path, Style style=Style::native)
Has stem?
Definition: Path.cpp:655
llvm::sys::fs::create_directories
std::error_code create_directories(const Twine &path, bool IgnoreExisting=true, perms Perms=owner_all|group_all)
Create all the non-existent directories in path.
Definition: Path.cpp:963
llvm::operator-
APInt operator-(APInt)
Definition: APInt.h:2107
llvm::sys::fs::get_file_type
file_type get_file_type(const Twine &Path, bool Follow=true)
Does status represent a directory?
Definition: Path.cpp:1081
llvm::sys::path::Style
Style
Definition: Path.h:28
llvm::sys::fs::file_type
file_type
An enumeration for the file system's view of the type.
Definition: FileSystem.h:66
c
the resulting code requires compare and branches when and if the revised code is with conditional branches instead of More there is a byte word extend before each where there should be only and the condition codes are not remembered when the same two values are compared twice More LSR enhancements i8 and i32 load store addressing modes are identical int int c
Definition: README.txt:418
llvm::StringRef::str
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:245
llvm::sys::fs::openFileForReadWrite
std::error_code openFileForReadWrite(const Twine &Name, int &ResultFD, CreationDisposition Disp, OpenFlags Flags, unsigned Mode=0666)
Opens the file with the given name in a write-only or read-write mode, returning its open file descri...
Definition: FileSystem.h:1081
llvm::errc::file_exists
@ file_exists
llvm::SmallString< 32 >
llvm::support::endian::write
void write(void *memory, value_type value, endianness endian)
Write a value to memory with a particular endianness.
Definition: Endian.h:97
llvm::SmallString::append
void append(StringRef RHS)
Append from a StringRef.
Definition: SmallString.h:67
FS_Name
@ FS_Name
Definition: Path.cpp:164
llvm::sys::fs::UniqueID
Definition: UniqueID.h:23
llvm::sys::fs::owner_write
@ owner_write
Definition: FileSystem.h:89
llvm::sys::fs::is_other
bool is_other(const basic_file_status &status)
Does this status represent something that exists but is not a directory or regular file?
Definition: Path.cpp:1124
llvm::sys::fs::file_status
Represents the result of a call to sys::fs::status().
Definition: FileSystem.h:226
llvm::sys::path::remove_dots
bool remove_dots(SmallVectorImpl< char > &path, bool remove_dot_dot=false, Style style=Style::native)
In-place remove any '.
Definition: Path.cpp:714
llvm::Twine::isSingleStringRef
bool isSingleStringRef() const
Return true if this twine can be dynamically accessed as a single StringRef value with getSingleStrin...
Definition: Twine.h:427
llvm::sys::fs::exists
bool exists(const basic_file_status &status)
Does file exist?
Definition: Path.cpp:1073
llvm::sys::fs::getPotentiallyUniqueFileName
std::error_code getPotentiallyUniqueFileName(const Twine &Model, SmallVectorImpl< char > &ResultPath)
Get a unique name, not currently exisiting in the filesystem.
Definition: Path.cpp:888
FSEntity
FSEntity
Definition: Path.cpp:161
llvm::sys::path::get_separator
StringRef get_separator(Style style=Style::native)
Return the preferred separator for this platform.
Definition: Path.cpp:607
llvm::StringRef::end
iterator end() const
Definition: StringRef.h:130
llvm::sys::path::root_directory
StringRef root_directory(StringRef path, Style style=Style::native)
Get root directory.
Definition: Path.cpp:388
llvm::sys::path::replace_extension
void replace_extension(SmallVectorImpl< char > &path, const Twine &extension, Style style=Style::native)
Replace the file extension of path with extension.
Definition: Path.cpp:478
s
multiplies can be turned into SHL s
Definition: README.txt:370
llvm::sys::fs::OF_Delete
@ OF_Delete
Delete the file on close. Only makes a difference on windows.
Definition: FileSystem.h:776
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::MD5
Definition: MD5.h:41
llvm::Twine::toVector
void toVector(SmallVectorImpl< char > &Out) const
Append the concatenated string into the given SmallString or SmallVector.
Definition: Twine.cpp:32
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:57
llvm::StringRef::front
LLVM_NODISCARD char front() const
front - Get the first character in the string.
Definition: StringRef.h:161
I
#define I(x, y, z)
Definition: MD5.cpp:59
size
i< reg-> size
Definition: README.txt:166
ArrayRef.h
llvm::sys::fs::status_known
bool status_known(const basic_file_status &s)
Is status available?
Definition: Path.cpp:1077
llvm::HexStyle::Style
Style
Definition: MCInstPrinter.h:32
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::sys::path::parent_path
StringRef parent_path(StringRef path, Style style=Style::native)
Get parent path.
Definition: Path.cpp:465
FS_File
@ FS_File
Definition: Path.cpp:163
llvm::sys::fs::is_symlink_file
bool is_symlink_file(const basic_file_status &status)
Does status represent a symlink file?
Definition: Path.cpp:1112
Mode
SI Whole Quad Mode
Definition: SIWholeQuadMode.cpp:262
llvm::sys::fs::make_absolute
void make_absolute(const Twine &current_directory, SmallVectorImpl< char > &path)
Make path an absolute path.
Definition: Path.cpp:901
llvm::sys::fs::create_directory
std::error_code create_directory(const Twine &path, bool IgnoreExisting=true, perms Perms=owner_all|group_all)
Create the directory in path.
llvm::sys::fs::CD_CreateAlways
@ CD_CreateAlways
CD_CreateAlways - When opening a file:
Definition: FileSystem.h:733
llvm::sys::fs::basic_file_status::type
file_type type() const
Definition: FileSystem.h:184
Status
Definition: SIModeRegister.cpp:28
llvm::sys::path::has_filename
bool has_filename(const Twine &path, Style style=Style::native)
Has filename?
Definition: Path.cpp:641
llvm::sys::path::has_relative_path
bool has_relative_path(const Twine &path, Style style=Style::native)
Has relative path?
Definition: Path.cpp:634
llvm::sys::fs::remove
std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
llvm::NVPTXISD::Dummy
@ Dummy
Definition: NVPTXISelLowering.h:60
llvm::sys::fs::TempFile::keep
Error keep()
Definition: Path.cpp:1268
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
llvm::sys::fs::getPermissions
ErrorOr< perms > getPermissions(const Twine &Path)
Get file permissions.
Definition: Path.cpp:1147
Path.inc
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::sys::fs::rename
std::error_code rename(const Twine &from, const Twine &to)
Rename from to to.
FS_Dir
@ FS_Dir
Definition: Path.cpp:162
llvm::sys::path::const_iterator
Path iterator.
Definition: Path.h:52
llvm::MD5::MD5Result
Definition: MD5.h:55
operator==
bool operator==(const StringView &LHS, const StringView &RHS)
Definition: StringView.h:112
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::sys::path::root_name
StringRef root_name(StringRef path, Style style=Style::native)
Get root name.
Definition: Path.cpp:371
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
std
Definition: BitVector.h:838
llvm::SmallVectorImpl::swap
void swap(SmallVectorImpl &RHS)
Definition: SmallVector.h:936
H
#define H(x, y, z)
Definition: MD5.cpp:58
llvm::StringRef::drop_front
LLVM_NODISCARD StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
Definition: StringRef.h:653
llvm::support::endian::read
value_type read(const void *memory, endianness endian)
Read a value of a particular endianness from memory.
Definition: Endian.h:63
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::sys::fs::owner_read
@ owner_read
Definition: FileSystem.h:88
llvm::sys::fs::OpenFlags
OpenFlags
Definition: FileSystem.h:756
llvm::sys::path::has_root_name
bool has_root_name(const Twine &path, Style style=Style::native)
Has root name?
Definition: Path.cpp:613
llvm::sys::path::system_temp_directory
void system_temp_directory(bool erasedOnReboot, SmallVectorImpl< char > &result)
Get the typical temporary directory for the system, e.g., "/var/tmp" or "C:/TEMP".
llvm::sys::fs::is_directory
bool is_directory(const basic_file_status &status)
Does status represent a directory?
Definition: Path.cpp:1088
llvm::SmallString::str
StringRef str() const
Explicit conversion to StringRef.
Definition: SmallString.h:259
llvm::sys::fs::TempFile::~TempFile
~TempFile()
Definition: Path.cpp:1196
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:476
llvm::sys::path::has_root_path
bool has_root_path(const Twine &path, Style style=Style::native)
Has root path?
Definition: Path.cpp:627
llvm::sys::DontRemoveFileOnSignal
void DontRemoveFileOnSignal(StringRef Filename)
This function removes a file from the list of files to be removed on signal delivery.
llvm::sys::path::is_absolute_gnu
bool is_absolute_gnu(const Twine &path, Style style=Style::native)
Is path absolute using GNU rules?
Definition: Path.cpp:680
llvm::sys::path::is_separator
bool is_separator(char value, Style style=Style::native)
Check whether the given char is a path separator on the host OS.
Definition: Path.cpp:599
llvm::sys::fs::md5_contents
ErrorOr< MD5::MD5Result > md5_contents(int FD)
Compute an MD5 hash of a file's contents.
Definition: Path.cpp:1043
llvm::sys::fs::perms
perms
Definition: FileSystem.h:86
llvm::sys::path::filename
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
Definition: Path.cpp:575
llvm::sys::fs::status
std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
llvm::ErrorOr
Represents either an error or a value T.
Definition: ErrorOr.h:56
llvm::support::native
@ native
Definition: Endian.h:27
llvm::sys::path::remove_filename
void remove_filename(SmallVectorImpl< char > &path, Style style=Style::native)
Remove the last component from path unless it is the root dir.
Definition: Path.cpp:472
llvm::StringRef::data
const LLVM_NODISCARD char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:149
llvm::SmallVectorImpl< char >
llvm::sys::path::rend
reverse_iterator rend(StringRef path)
Get reverse end iterator over path.
Definition: Path.cpp:304
llvm::errc::operation_not_permitted
@ operation_not_permitted
llvm::sys::path::has_root_directory
bool has_root_directory(const Twine &path, Style style=Style::native)
Has root directory?
Definition: Path.cpp:620
llvm::Twine::toStringRef
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
Definition: Twine.h:477
llvm::sys::fs::CD_CreateNew
@ CD_CreateNew
CD_CreateNew - When opening a file:
Definition: FileSystem.h:738
llvm::StringRef::find_first_of
LLVM_NODISCARD size_t find_first_of(char C, size_t From=0) const
Find the first character in the string that is C, or npos if not found.
Definition: StringRef.h:410
createUniqueEntity
static std::error_code createUniqueEntity(const Twine &Model, int &ResultFD, SmallVectorImpl< char > &ResultPath, bool MakeAbsolute, FSEntity Type, sys::fs::OpenFlags Flags=sys::fs::OF_None, unsigned Mode=0)
Definition: Path.cpp:168
llvm::sys::fs::TempFile
Represents a temporary file.
Definition: FileSystem.h:849
From
BlockVerifier::State From
Definition: BlockVerifier.cpp:55
llvm::sys::fs::TempFile::create
static Expected< TempFile > create(const Twine &Model, unsigned Mode=all_read|all_write, OpenFlags ExtraFlags=OF_None)
This creates a temporary file with createUniqueFile and schedules it for deletion with sys::RemoveFil...
Definition: Path.cpp:1291
llvm::sys::path::relative_path
StringRef relative_path(StringRef path, Style style=Style::native)
Get relative path.
Definition: Path.cpp:411
llvm::sys::fs::copy_file_internal
static std::error_code copy_file_internal(int ReadFD, int WriteFD)
Definition: Path.cpp:987
d
the resulting code requires compare and branches when and if the revised code is with conditional branches instead of More there is a byte word extend before each where there should be only and the condition codes are not remembered when the same two values are compared twice More LSR enhancements i8 and i32 load store addressing modes are identical int int int d
Definition: README.txt:418
llvm::StringRef::size
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:157
Endian.h
llvm::sys::fs::TempFile::FD
int FD
Definition: FileSystem.h:866
llvm::StringRef::begin
iterator begin() const
Definition: StringRef.h:128
llvm::sys::RemoveFileOnSignal
bool RemoveFileOnSignal(StringRef Filename, std::string *ErrMsg=nullptr)
This function registers signal handlers to ensure that if a signal gets delivered that the named file...
llvm::sys::path::is_relative
bool is_relative(const Twine &path, Style style=Style::native)
Is path relative?
Definition: Path.cpp:698
llvm::sys::fs::copy_file
std::error_code copy_file(const Twine &From, const Twine &To)
Copy the contents of From to To.
Definition: Path.cpp:1012
llvm::sys::path::stem
StringRef stem(StringRef path, Style style=Style::native)
Get stem.
Definition: Path.cpp:577
llvm::sys::fs::openFileForRead
std::error_code openFileForRead(const Twine &Name, int &ResultFD, OpenFlags Flags=OF_None, SmallVectorImpl< char > *RealPath=nullptr)
Opens the file with the given name in a read-only mode, returning its open file descriptor.
SpecialSubKind::string
@ string
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1172