1 //===--- OptionUtils.cpp - Utilities for command line arguments -----------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "clang/Basic/Diagnostic.h"
10 #include "clang/Basic/DiagnosticDriver.h"
11 #include "clang/Driver/OptionUtils.h"
12 #include "llvm/Option/ArgList.h"
14 using namespace clang
;
15 using namespace llvm::opt
;
18 template <typename IntTy
>
19 IntTy
getLastArgIntValueImpl(const ArgList
&Args
, OptSpecifier Id
,
20 IntTy Default
, DiagnosticsEngine
*Diags
,
23 if (Arg
*A
= Args
.getLastArg(Id
)) {
24 if (StringRef(A
->getValue()).getAsInteger(Base
, Res
)) {
26 Diags
->Report(diag::err_drv_invalid_int_value
)
27 << A
->getAsString(Args
) << A
->getValue();
36 int getLastArgIntValue(const ArgList
&Args
, OptSpecifier Id
, int Default
,
37 DiagnosticsEngine
*Diags
, unsigned Base
) {
38 return getLastArgIntValueImpl
<int>(Args
, Id
, Default
, Diags
, Base
);
41 uint64_t getLastArgUInt64Value(const ArgList
&Args
, OptSpecifier Id
,
42 uint64_t Default
, DiagnosticsEngine
*Diags
,
44 return getLastArgIntValueImpl
<uint64_t>(Args
, Id
, Default
, Diags
, Base
);