LLVM 19.0.0git
Go to the documentation of this file.
1//===- Utils.h --------------------------------------------------*- C++ -*-===//
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
13#include "llvm/ADT/Twine.h"
14#include "llvm/Support/Error.h"
16#include "llvm/Support/Path.h"
18namespace llvm {
19namespace dwarf_linker {
21/// This function calls \p Iteration() until it returns false.
22/// If number of iterations exceeds \p MaxCounter then an Error is returned.
23/// This function should be used for loops which assumed to have number of
24/// iterations significantly smaller than \p MaxCounter to avoid infinite
25/// looping in error cases.
27 size_t MaxCounter = 100000) {
28 size_t iterationsCounter = 0;
29 while (iterationsCounter++ < MaxCounter) {
30 Expected<bool> IterationResultOrError = Iteration();
31 if (!IterationResultOrError)
32 return IterationResultOrError.takeError();
33 if (!IterationResultOrError.get())
34 return Error::success();
35 }
36 return createStringError(std::errc::invalid_argument, "Infinite recursion");
39/// Make a best effort to guess the
40/// Xcode.app/Contents/Developer/Toolchains/ path from an SDK path.
42 SmallString<128> Result;
43 // Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
45 if (sys::path::filename(Base) != "SDKs")
46 return Result;
48 Result = Base;
49 Result += "/Toolchains";
50 return Result;
53inline bool isPathAbsoluteOnWindowsOrPosix(const Twine &Path) {
54 // Debug info can contain paths from any OS, not necessarily
55 // an OS we're currently running on. Moreover different compilation units can
56 // be compiled on different operating systems and linked together later.
61} // end of namespace dwarf_linker
62} // end of namespace llvm
This file defines the SmallString class.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:334
Tagged union holding either a T or a Error.
Definition: Error.h:474
Error takeError()
Take ownership of the stored error.
Definition: Error.h:601
reference get()
Returns a reference to the stored T value.
Definition: Error.h:571
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
An efficient, type-erasing, non-owning reference to a callable.
Error finiteLoop(function_ref< Expected< bool >()> Iteration, size_t MaxCounter=100000)
This function calls Iteration() until it returns false.
Definition: Utils.h:26
bool isPathAbsoluteOnWindowsOrPosix(const Twine &Path)
Definition: Utils.h:53
SmallString< 128 > guessToolchainBaseDir(StringRef SysRoot)
Make a best effort to guess the Xcode.app/Contents/Developer/Toolchains/ path from an SDK path.
Definition: Utils.h:41
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
Definition: Path.cpp:578
StringRef parent_path(StringRef path, Style style=Style::native)
Get parent path.
Definition: Path.cpp:468
bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
Definition: Path.cpp:672
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1258