本文整理汇总了C++中TargetInfo::getTriple方法的典型用法代码示例。如果您正苦于以下问题:C++ TargetInfo::getTriple方法的具体用法?C++ TargetInfo::getTriple怎么用?C++ TargetInfo::getTriple使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TargetInfo
的用法示例。
在下文中一共展示了TargetInfo::getTriple方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TextDiagnosticPrinter
void c2ffi::init_ci(config &c, clang::CompilerInstance &ci) {
using clang::DiagnosticOptions;
using clang::TextDiagnosticPrinter;
using clang::TargetOptions;
using clang::TargetInfo;
DiagnosticOptions *dopt = new DiagnosticOptions;
TextDiagnosticPrinter *tpd =
new TextDiagnosticPrinter(llvm::errs(), dopt, false);
ci.createDiagnostics(tpd);
std::shared_ptr<TargetOptions> pto =
std::shared_ptr<TargetOptions>(new TargetOptions());
if(c.arch == "")
pto->Triple = llvm::sys::getDefaultTargetTriple();
else
pto->Triple = c.arch;
TargetInfo *pti = TargetInfo::CreateTargetInfo(ci.getDiagnostics(), pto);
clang::LangOptions &lo = ci.getLangOpts();
switch(pti->getTriple().getEnvironment()) {
case llvm::Triple::EnvironmentType::GNU:
lo.GNUMode = 1;
break;
case llvm::Triple::EnvironmentType::MSVC:
lo.MSVCCompat = 1;
lo.MicrosoftExt = 1;
break;
default:
std::cerr << "c2ffi warning: Unhandled environment: '"
<< pti->getTriple().getEnvironmentName().str()
<< "' for triple '" << c.arch
<< "'" << std::endl;
}
ci.getInvocation().setLangDefaults(lo, c.kind, c.std);
ci.setTarget(pti);
ci.createFileManager();
ci.createSourceManager(ci.getFileManager());
ci.createPreprocessor(clang::TU_Complete);
ci.getPreprocessorOpts().UsePredefines = false;
ci.getPreprocessorOutputOpts().ShowCPP = c.preprocess_only;
ci.getPreprocessor().setPreprocessedOutput(c.preprocess_only);
}
示例2: SetClingTargetLangOpts
void CIFactory::SetClingTargetLangOpts(LangOptions& Opts,
const TargetInfo& Target) {
if (Target.getTriple().getOS() == llvm::Triple::Win32) {
Opts.MicrosoftExt = 1;
Opts.MSCVersion = 1300;
// Should fix http://llvm.org/bugs/show_bug.cgi?id=10528
Opts.DelayedTemplateParsing = 1;
} else {
Opts.MicrosoftExt = 0;
}
}
示例3: InitializePredefinedMacros
//.........这里部分代码省略.........
if (LangOpts.NoInlineDefine)
Builder.defineMacro("__NO_INLINE__");
if (unsigned PICLevel = LangOpts.PICLevel) {
Builder.defineMacro("__PIC__", Twine(PICLevel));
Builder.defineMacro("__pic__", Twine(PICLevel));
}
if (unsigned PIELevel = LangOpts.PIELevel) {
Builder.defineMacro("__PIE__", Twine(PIELevel));
Builder.defineMacro("__pie__", Twine(PIELevel));
}
// Macros to control C99 numerics and <float.h>
Builder.defineMacro("__FLT_EVAL_METHOD__", Twine(TI.getFloatEvalMethod()));
Builder.defineMacro("__FLT_RADIX__", "2");
Builder.defineMacro("__DECIMAL_DIG__", "__LDBL_DECIMAL_DIG__");
if (LangOpts.getStackProtector() == LangOptions::SSPOn)
Builder.defineMacro("__SSP__");
else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
Builder.defineMacro("__SSP_STRONG__", "2");
else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
Builder.defineMacro("__SSP_ALL__", "3");
// Define a macro that exists only when using the static analyzer.
if (FEOpts.ProgramAction == frontend::RunAnalysis)
Builder.defineMacro("__clang_analyzer__");
if (LangOpts.FastRelaxedMath)
Builder.defineMacro("__FAST_RELAXED_MATH__");
if (FEOpts.ProgramAction == frontend::RewriteObjC ||
LangOpts.getGC() != LangOptions::NonGC) {
Builder.defineMacro("__weak", "__attribute__((objc_gc(weak)))");
Builder.defineMacro("__strong", "__attribute__((objc_gc(strong)))");
Builder.defineMacro("__autoreleasing", "");
Builder.defineMacro("__unsafe_unretained", "");
} else if (LangOpts.ObjC1) {
Builder.defineMacro("__weak", "__attribute__((objc_ownership(weak)))");
Builder.defineMacro("__strong", "__attribute__((objc_ownership(strong)))");
Builder.defineMacro("__autoreleasing",
"__attribute__((objc_ownership(autoreleasing)))");
Builder.defineMacro("__unsafe_unretained",
"__attribute__((objc_ownership(none)))");
}
// On Darwin, there are __double_underscored variants of the type
// nullability qualifiers.
if (TI.getTriple().isOSDarwin()) {
Builder.defineMacro("__nonnull", "_Nonnull");
Builder.defineMacro("__null_unspecified", "_Null_unspecified");
Builder.defineMacro("__nullable", "_Nullable");
}
// OpenMP definition
// OpenMP 2.2:
// In implementations that support a preprocessor, the _OPENMP
// macro name is defined to have the decimal value yyyymm where
// yyyy and mm are the year and the month designations of the
// version of the OpenMP API that the implementation support.
switch (LangOpts.OpenMP) {
case 0:
break;
case 40:
Builder.defineMacro("_OPENMP", "201307");
break;
case 45:
Builder.defineMacro("_OPENMP", "201511");
break;
default:
// Default version is OpenMP 3.1
Builder.defineMacro("_OPENMP", "201107");
break;
}
// CUDA device path compilaton
if (LangOpts.CUDAIsDevice) {
// The CUDA_ARCH value is set for the GPU target specified in the NVPTX
// backend's target defines.
Builder.defineMacro("__CUDA_ARCH__");
}
// We need to communicate this to our CUDA header wrapper, which in turn
// informs the proper CUDA headers of this choice.
if (LangOpts.CUDADeviceApproxTranscendentals || LangOpts.FastMath) {
Builder.defineMacro("__CLANG_CUDA_APPROX_TRANSCENDENTALS__");
}
// OpenCL definitions.
if (LangOpts.OpenCL) {
#define OPENCLEXT(Ext) \
if (TI.getSupportedOpenCLOpts().is_##Ext##_supported( \
LangOpts.OpenCLVersion)) \
Builder.defineMacro(#Ext);
#include "clang/Basic/OpenCLExtensions.def"
}
// Get other target #defines.
TI.getTargetDefines(LangOpts, Builder);
}
示例4: hasValidLengthModifier
bool FormatSpecifier::hasValidLengthModifier(const TargetInfo &Target) const {
switch (LM.getKind()) {
case LengthModifier::None:
return true;
// Handle most integer flags
case LengthModifier::AsShort:
if (Target.getTriple().isOSMSVCRT()) {
switch (CS.getKind()) {
case ConversionSpecifier::cArg:
case ConversionSpecifier::CArg:
case ConversionSpecifier::sArg:
case ConversionSpecifier::SArg:
case ConversionSpecifier::ZArg:
return true;
default:
break;
}
}
// Fall through.
case LengthModifier::AsChar:
case LengthModifier::AsLongLong:
case LengthModifier::AsQuad:
case LengthModifier::AsIntMax:
case LengthModifier::AsSizeT:
case LengthModifier::AsPtrDiff:
switch (CS.getKind()) {
case ConversionSpecifier::dArg:
case ConversionSpecifier::DArg:
case ConversionSpecifier::iArg:
case ConversionSpecifier::oArg:
case ConversionSpecifier::OArg:
case ConversionSpecifier::uArg:
case ConversionSpecifier::UArg:
case ConversionSpecifier::xArg:
case ConversionSpecifier::XArg:
case ConversionSpecifier::nArg:
return true;
case ConversionSpecifier::FreeBSDrArg:
case ConversionSpecifier::FreeBSDyArg:
return Target.getTriple().isOSFreeBSD();
default:
return false;
}
// Handle 'l' flag
case LengthModifier::AsLong: // or AsWideChar
switch (CS.getKind()) {
case ConversionSpecifier::dArg:
case ConversionSpecifier::DArg:
case ConversionSpecifier::iArg:
case ConversionSpecifier::oArg:
case ConversionSpecifier::OArg:
case ConversionSpecifier::uArg:
case ConversionSpecifier::UArg:
case ConversionSpecifier::xArg:
case ConversionSpecifier::XArg:
case ConversionSpecifier::aArg:
case ConversionSpecifier::AArg:
case ConversionSpecifier::fArg:
case ConversionSpecifier::FArg:
case ConversionSpecifier::eArg:
case ConversionSpecifier::EArg:
case ConversionSpecifier::gArg:
case ConversionSpecifier::GArg:
case ConversionSpecifier::nArg:
case ConversionSpecifier::cArg:
case ConversionSpecifier::sArg:
case ConversionSpecifier::ScanListArg:
case ConversionSpecifier::ZArg:
return true;
case ConversionSpecifier::FreeBSDrArg:
case ConversionSpecifier::FreeBSDyArg:
return Target.getTriple().isOSFreeBSD();
default:
return false;
}
case LengthModifier::AsLongDouble:
switch (CS.getKind()) {
case ConversionSpecifier::aArg:
case ConversionSpecifier::AArg:
case ConversionSpecifier::fArg:
case ConversionSpecifier::FArg:
case ConversionSpecifier::eArg:
case ConversionSpecifier::EArg:
case ConversionSpecifier::gArg:
case ConversionSpecifier::GArg:
return true;
// GNU libc extension.
case ConversionSpecifier::dArg:
case ConversionSpecifier::iArg:
case ConversionSpecifier::oArg:
case ConversionSpecifier::uArg:
case ConversionSpecifier::xArg:
case ConversionSpecifier::XArg:
return !Target.getTriple().isOSDarwin() &&
!Target.getTriple().isOSWindows();
default:
return false;
//.........这里部分代码省略.........
示例5: ParsePrintfSpecifier
//.........这里部分代码省略.........
ConversionSpecifier::Kind k = ConversionSpecifier::InvalidSpecifier;
switch (*conversionPosition) {
default:
break;
// C99: 7.19.6.1 (section 8).
case '%': k = ConversionSpecifier::PercentArg; break;
case 'A': k = ConversionSpecifier::AArg; break;
case 'E': k = ConversionSpecifier::EArg; break;
case 'F': k = ConversionSpecifier::FArg; break;
case 'G': k = ConversionSpecifier::GArg; break;
case 'X': k = ConversionSpecifier::XArg; break;
case 'a': k = ConversionSpecifier::aArg; break;
case 'c': k = ConversionSpecifier::cArg; break;
case 'd': k = ConversionSpecifier::dArg; break;
case 'e': k = ConversionSpecifier::eArg; break;
case 'f': k = ConversionSpecifier::fArg; break;
case 'g': k = ConversionSpecifier::gArg; break;
case 'i': k = ConversionSpecifier::iArg; break;
case 'n': k = ConversionSpecifier::nArg; break;
case 'o': k = ConversionSpecifier::oArg; break;
case 'p': k = ConversionSpecifier::pArg; break;
case 's': k = ConversionSpecifier::sArg; break;
case 'u': k = ConversionSpecifier::uArg; break;
case 'x': k = ConversionSpecifier::xArg; break;
// POSIX specific.
case 'C': k = ConversionSpecifier::CArg; break;
case 'S': k = ConversionSpecifier::SArg; break;
// Apple extension for os_log
case 'P':
k = ConversionSpecifier::PArg;
break;
// Objective-C.
case '@': k = ConversionSpecifier::ObjCObjArg; break;
// Glibc specific.
case 'm': k = ConversionSpecifier::PrintErrno; break;
// FreeBSD kernel specific.
case 'b':
if (isFreeBSDKPrintf)
k = ConversionSpecifier::FreeBSDbArg; // int followed by char *
break;
case 'r':
if (isFreeBSDKPrintf)
k = ConversionSpecifier::FreeBSDrArg; // int
break;
case 'y':
if (isFreeBSDKPrintf)
k = ConversionSpecifier::FreeBSDyArg; // int
break;
// Apple-specific.
case 'D':
if (isFreeBSDKPrintf)
k = ConversionSpecifier::FreeBSDDArg; // void * followed by char *
else if (Target.getTriple().isOSDarwin())
k = ConversionSpecifier::DArg;
break;
case 'O':
if (Target.getTriple().isOSDarwin())
k = ConversionSpecifier::OArg;
break;
case 'U':
if (Target.getTriple().isOSDarwin())
k = ConversionSpecifier::UArg;
break;
// MS specific.
case 'Z':
if (Target.getTriple().isOSMSVCRT())
k = ConversionSpecifier::ZArg;
}
// Check to see if we used the Objective-C modifier flags with
// a conversion specifier other than '@'.
if (k != ConversionSpecifier::ObjCObjArg &&
k != ConversionSpecifier::InvalidSpecifier &&
ObjCModifierFlagsStart) {
H.HandleObjCFlagsWithNonObjCConversion(ObjCModifierFlagsStart,
ObjCModifierFlagsEnd + 1,
conversionPosition);
return true;
}
PrintfConversionSpecifier CS(conversionPosition, k);
FS.setConversionSpecifier(CS);
if (CS.consumesDataArgument() && !FS.usesPositionalArg())
FS.setArgIndex(argIndex++);
// FreeBSD kernel specific.
if (k == ConversionSpecifier::FreeBSDbArg ||
k == ConversionSpecifier::FreeBSDDArg)
argIndex++;
if (k == ConversionSpecifier::InvalidSpecifier) {
unsigned Len = I - Start;
if (ParseUTF8InvalidSpecifier(Start, E, Len)) {
CS.setEndScanList(Start + Len);
FS.setConversionSpecifier(CS);
}
// Assume the conversion takes one argument.
return !H.HandleInvalidPrintfConversionSpecifier(FS, Start, Len);
}
return PrintfSpecifierResult(Start, FS);
}
示例6: ParsePrintfSpecifier
//.........这里部分代码省略.........
if (ParseFieldWidth(H, FS, Start, I, E,
FS.usesPositionalArg() ? 0 : &argIndex))
return true;
if (I == E) {
// No more characters left?
H.HandleIncompleteSpecifier(Start, E - Start);
return true;
}
// Look for the precision (if any).
if (*I == '.') {
++I;
if (I == E) {
H.HandleIncompleteSpecifier(Start, E - Start);
return true;
}
if (ParsePrecision(H, FS, Start, I, E,
FS.usesPositionalArg() ? 0 : &argIndex))
return true;
if (I == E) {
// No more characters left?
H.HandleIncompleteSpecifier(Start, E - Start);
return true;
}
}
// Look for the length modifier.
if (ParseLengthModifier(FS, I, E, LO) && I == E) {
// No more characters left?
H.HandleIncompleteSpecifier(Start, E - Start);
return true;
}
if (*I == '\0') {
// Detect spurious null characters, which are likely errors.
H.HandleNullChar(I);
return true;
}
// Finally, look for the conversion specifier.
const char *conversionPosition = I++;
ConversionSpecifier::Kind k = ConversionSpecifier::InvalidSpecifier;
switch (*conversionPosition) {
default:
break;
// C99: 7.19.6.1 (section 8).
case '%': k = ConversionSpecifier::PercentArg; break;
case 'A': k = ConversionSpecifier::AArg; break;
case 'E': k = ConversionSpecifier::EArg; break;
case 'F': k = ConversionSpecifier::FArg; break;
case 'G': k = ConversionSpecifier::GArg; break;
case 'X': k = ConversionSpecifier::XArg; break;
case 'a': k = ConversionSpecifier::aArg; break;
case 'c': k = ConversionSpecifier::cArg; break;
case 'd': k = ConversionSpecifier::dArg; break;
case 'e': k = ConversionSpecifier::eArg; break;
case 'f': k = ConversionSpecifier::fArg; break;
case 'g': k = ConversionSpecifier::gArg; break;
case 'i': k = ConversionSpecifier::iArg; break;
case 'n': k = ConversionSpecifier::nArg; break;
case 'o': k = ConversionSpecifier::oArg; break;
case 'p': k = ConversionSpecifier::pArg; break;
case 's': k = ConversionSpecifier::sArg; break;
case 'u': k = ConversionSpecifier::uArg; break;
case 'x': k = ConversionSpecifier::xArg; break;
// POSIX specific.
case 'C': k = ConversionSpecifier::CArg; break;
case 'S': k = ConversionSpecifier::SArg; break;
// Objective-C.
case '@': k = ConversionSpecifier::ObjCObjArg; break;
// Glibc specific.
case 'm': k = ConversionSpecifier::PrintErrno; break;
// Apple-specific
case 'D':
if (Target.getTriple().isOSDarwin())
k = ConversionSpecifier::DArg;
break;
case 'O':
if (Target.getTriple().isOSDarwin())
k = ConversionSpecifier::OArg;
break;
case 'U':
if (Target.getTriple().isOSDarwin())
k = ConversionSpecifier::UArg;
break;
}
PrintfConversionSpecifier CS(conversionPosition, k);
FS.setConversionSpecifier(CS);
if (CS.consumesDataArgument() && !FS.usesPositionalArg())
FS.setArgIndex(argIndex++);
if (k == ConversionSpecifier::InvalidSpecifier) {
// Assume the conversion takes one argument.
return !H.HandleInvalidPrintfConversionSpecifier(FS, Start, I - Start);
}
return PrintfSpecifierResult(Start, FS);
}
示例7: ParseScanfSpecifier
//.........这里部分代码省略.........
}
// Look for '*' flag if it is present.
if (*I == '*') {
FS.setSuppressAssignment(I);
if (++I == E) {
H.HandleIncompleteSpecifier(Start, E - Start);
return true;
}
}
// Look for the field width (if any). Unlike printf, this is either
// a fixed integer or isn't present.
const OptionalAmount &Amt = lfort::analyze_format_string::ParseAmount(I, E);
if (Amt.getHowSpecified() != OptionalAmount::NotSpecified) {
assert(Amt.getHowSpecified() == OptionalAmount::Constant);
FS.setFieldWidth(Amt);
if (I == E) {
// No more characters left?
H.HandleIncompleteSpecifier(Start, E - Start);
return true;
}
}
// Look for the length modifier.
if (ParseLengthModifier(FS, I, E, LO, /*scanf=*/true) && I == E) {
// No more characters left?
H.HandleIncompleteSpecifier(Start, E - Start);
return true;
}
// Detect spurious null characters, which are likely errors.
if (*I == '\0') {
H.HandleNullChar(I);
return true;
}
// Finally, look for the conversion specifier.
const char *conversionPosition = I++;
ScanfConversionSpecifier::Kind k = ScanfConversionSpecifier::InvalidSpecifier;
switch (*conversionPosition) {
default:
break;
case '%': k = ConversionSpecifier::PercentArg; break;
case 'A': k = ConversionSpecifier::AArg; break;
case 'E': k = ConversionSpecifier::EArg; break;
case 'F': k = ConversionSpecifier::FArg; break;
case 'G': k = ConversionSpecifier::GArg; break;
case 'X': k = ConversionSpecifier::XArg; break;
case 'a': k = ConversionSpecifier::aArg; break;
case 'd': k = ConversionSpecifier::dArg; break;
case 'e': k = ConversionSpecifier::eArg; break;
case 'f': k = ConversionSpecifier::fArg; break;
case 'g': k = ConversionSpecifier::gArg; break;
case 'i': k = ConversionSpecifier::iArg; break;
case 'n': k = ConversionSpecifier::nArg; break;
case 'c': k = ConversionSpecifier::cArg; break;
case 'C': k = ConversionSpecifier::CArg; break;
case 'S': k = ConversionSpecifier::SArg; break;
case '[': k = ConversionSpecifier::ScanListArg; break;
case 'u': k = ConversionSpecifier::uArg; break;
case 'x': k = ConversionSpecifier::xArg; break;
case 'o': k = ConversionSpecifier::oArg; break;
case 's': k = ConversionSpecifier::sArg; break;
case 'p': k = ConversionSpecifier::pArg; break;
// Apple extensions
// Apple-specific
case 'D':
if (Target.getTriple().isOSDarwin())
k = ConversionSpecifier::DArg;
break;
case 'O':
if (Target.getTriple().isOSDarwin())
k = ConversionSpecifier::OArg;
break;
case 'U':
if (Target.getTriple().isOSDarwin())
k = ConversionSpecifier::UArg;
break;
}
ScanfConversionSpecifier CS(conversionPosition, k);
if (k == ScanfConversionSpecifier::ScanListArg) {
if (ParseScanList(H, CS, I, E))
return true;
}
FS.setConversionSpecifier(CS);
if (CS.consumesDataArgument() && !FS.getSuppressAssignment()
&& !FS.usesPositionalArg())
FS.setArgIndex(argIndex++);
// FIXME: '%' and '*' doesn't make sense. Issue a warning.
// FIXME: 'ConsumedSoFar' and '*' doesn't make sense.
if (k == ScanfConversionSpecifier::InvalidSpecifier) {
// Assume the conversion takes one argument.
return !H.HandleInvalidScanfConversionSpecifier(FS, Beg, I - Beg);
}
return ScanfSpecifierResult(Start, FS);
}
示例8: ParsePrintfSpecifier
//.........这里部分代码省略.........
ConversionSpecifier::Kind k = ConversionSpecifier::InvalidSpecifier;
switch (*conversionPosition) {
default:
break;
// C99: 7.19.6.1 (section 8).
case '%': k = ConversionSpecifier::PercentArg; break;
case 'A': k = ConversionSpecifier::AArg; break;
case 'E': k = ConversionSpecifier::EArg; break;
case 'F': k = ConversionSpecifier::FArg; break;
case 'G': k = ConversionSpecifier::GArg; break;
case 'X': k = ConversionSpecifier::XArg; break;
case 'a': k = ConversionSpecifier::aArg; break;
case 'c': k = ConversionSpecifier::cArg; break;
case 'd': k = ConversionSpecifier::dArg; break;
case 'e': k = ConversionSpecifier::eArg; break;
case 'f': k = ConversionSpecifier::fArg; break;
case 'g': k = ConversionSpecifier::gArg; break;
case 'i': k = ConversionSpecifier::iArg; break;
case 'n': k = ConversionSpecifier::nArg; break;
case 'o': k = ConversionSpecifier::oArg; break;
case 'p': k = ConversionSpecifier::pArg; break;
case 's': k = ConversionSpecifier::sArg; break;
case 'u': k = ConversionSpecifier::uArg; break;
case 'x': k = ConversionSpecifier::xArg; break;
// POSIX specific.
case 'C': k = ConversionSpecifier::CArg; break;
case 'S': k = ConversionSpecifier::SArg; break;
// Apple extension for os_log
case 'P':
k = ConversionSpecifier::PArg;
break;
// Objective-C.
case '@': k = ConversionSpecifier::ObjCObjArg; break;
// Glibc specific.
case 'm': k = ConversionSpecifier::PrintErrno; break;
// FreeBSD kernel specific.
case 'b':
if (isFreeBSDKPrintf)
k = ConversionSpecifier::FreeBSDbArg; // int followed by char *
break;
case 'r':
if (isFreeBSDKPrintf)
k = ConversionSpecifier::FreeBSDrArg; // int
break;
case 'y':
if (isFreeBSDKPrintf)
k = ConversionSpecifier::FreeBSDyArg; // int
break;
// Apple-specific.
case 'D':
if (isFreeBSDKPrintf)
k = ConversionSpecifier::FreeBSDDArg; // void * followed by char *
else if (Target.getTriple().isOSDarwin())
k = ConversionSpecifier::DArg;
break;
case 'O':
if (Target.getTriple().isOSDarwin())
k = ConversionSpecifier::OArg;
break;
case 'U':
if (Target.getTriple().isOSDarwin())
k = ConversionSpecifier::UArg;
break;
// MS specific.
case 'Z':
if (Target.getTriple().isOSMSVCRT())
k = ConversionSpecifier::ZArg;
}
// Check to see if we used the Objective-C modifier flags with
// a conversion specifier other than '@'.
if (k != ConversionSpecifier::ObjCObjArg &&
k != ConversionSpecifier::InvalidSpecifier &&
ObjCModifierFlagsStart) {
H.HandleObjCFlagsWithNonObjCConversion(ObjCModifierFlagsStart,
ObjCModifierFlagsEnd + 1,
conversionPosition);
return true;
}
PrintfConversionSpecifier CS(conversionPosition, k);
FS.setConversionSpecifier(CS);
if (CS.consumesDataArgument() && !FS.usesPositionalArg())
FS.setArgIndex(argIndex++);
// FreeBSD kernel specific.
if (k == ConversionSpecifier::FreeBSDbArg ||
k == ConversionSpecifier::FreeBSDDArg)
argIndex++;
if (k == ConversionSpecifier::InvalidSpecifier) {
unsigned Len = I - Start;
if (ParseUTF8InvalidSpecifier(Start, E, Len)) {
CS.setEndScanList(Start + Len);
FS.setConversionSpecifier(CS);
}
// Assume the conversion takes one argument.
return !H.HandleInvalidPrintfConversionSpecifier(FS, Start, Len);
}
return PrintfSpecifierResult(Start, FS);
}
示例9: main
int main(int argc, const char **argv, char * const *envp)
{
// Path
void *MainAddr = (void*) (intptr_t) GetExecutablePath;
llvm::sys::Path Path = GetExecutablePath(argv[0]);
// DiagnosticOptions
DiagnosticOptions diagnosticOptions;
// DiagnosticClient
TextDiagnosticPrinter *DiagClient = new TextDiagnosticPrinter(llvm::outs(), diagnosticOptions);
// Diagnostic
llvm::IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
Diagnostic diagnostic(DiagID, DiagClient);
//DiagnosticOptions DiagOpts;
//llvm::IntrusiveRefCntPtr<Diagnostic> diagnostic = CompilerInstance::createDiagnostics(DiagOpts, argc, argv);
// LangOptions
LangOptions langOptions;
langOptions.CPlusPlus = 1;
langOptions.CPlusPlus0x = 1;
langOptions.Microsoft = 1;
langOptions.Bool = 1;
langOptions.Exceptions = 1;
langOptions.CXXExceptions = 1;
langOptions.EmitAllDecls = 1;
// FileManager
FileSystemOptions fileSystemOptions;
FileManager fileManager(fileSystemOptions);
// SourceManager
SourceManager sourceManager(diagnostic, fileManager);
// HeadderSearch
HeaderSearch headerSearch(fileManager);
// TargetOptions
TargetOptions targetOptions;
targetOptions.Triple = llvm::sys::getHostTriple();
// TargetInfo
TargetInfo *pTargetInfo =
TargetInfo::CreateTargetInfo(
diagnostic,
targetOptions);
// HeaderSearchOptions
HeaderSearchOptions headerSearchOptions;
ApplyHeaderSearchOptions(
headerSearch,
headerSearchOptions,
langOptions,
pTargetInfo->getTriple());
// Preprocessor
Preprocessor preprocessor(
diagnostic,
langOptions,
*pTargetInfo,
sourceManager,
headerSearch);
// PreprocessorOptions
PreprocessorOptions preprocessorOptions;
preprocessorOptions.DetailedRecord = true;
preprocessor.createPreprocessingRecord();
// FrontendOptions
FrontendOptions frontendOptions;
// InitializePreprocessor
InitializePreprocessor(
preprocessor,
preprocessorOptions,
headerSearchOptions,
frontendOptions);
//preprocessor.SetCommentRetentionState(true, true);
// Tutorial
const FileEntry *pFile = fileManager.getFile(
"test.cpp",
true);
sourceManager.createMainFileID(pFile);
/*preprocessor.EnterMainSourceFile();
Token Tok;
do {
preprocessor.Lex(Tok); // read one token
//if (context.diags.hasErrorOccurred()) // stop lexing/pp on error
// break;
preprocessor.DumpToken(Tok); // outputs to cerr
std::cerr << std::endl;
} while (Tok.isNot(tok::eof));*/
//.........这里部分代码省略.........
示例10: main
int main()
{
//string a;
//raw_string_ostream ost(a);
const DiagnosticOptions diagOptions;
TextDiagnosticPrinter *tdp =
new TextDiagnosticPrinter(outs(), diagOptions, true);//, dops);
LangOptions lang;
DiagnosticIDs *diagID;
const llvm::IntrusiveRefCntPtr< DiagnosticIDs > Diags;
Diagnostic diag(Diags, tdp, false);
FileSystemOptions fsOptions;
FileManager fm(fsOptions);
SourceManager sm(diag, fm);
//tut3
HeaderSearchOptions HSOpts;
HSOpts.AddPath("/usr/include/linux/", frontend::System, false, false, true); // for stddef.h
HSOpts.AddPath("/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/", frontend::System, false, false, true); // for stdarg.h
HeaderSearch headers(fm);
TargetOptions tarOptions;
tarOptions.Triple = LLVM_HOSTTRIPLE;
TargetInfo *ti = TargetInfo::CreateTargetInfo(diag, tarOptions);
//tut3
ApplyHeaderSearchOptions( headers, HSOpts, lang, ti->getTriple());
Preprocessor pp(diag, lang, *ti, sm, headers);
//tut2---------------------------------------------------------------
const FileEntry *file = fm.getFile("input01.c");
sm.createMainFileID(file);
pp.EnterMainSourceFile();
Token Tok;
do {
pp.Lex(Tok);
if(diag.hasErrorOccurred())
break;
pp.DumpToken(Tok);
std::cerr << std::endl;
} while(Tok.isNot(tok::eof));
//end of tut2---------------------------------------------------------------
//tut4---------------------------------------------------------------
IdentifierTable tab(lang);
SelectorTable sels;
Builtin::Context builtins(*ti);
unsigned size = 0;
ASTContext ctxt(lang, sm, *ti, tab, sels, builtins, size);
ASTConsumer consumer;
CodeCompleteConsumer *codeCompleter;
MySemaAction sema(pp, ctxt, consumer, false, codeCompleter);
Parser p(pp, sema);
p.ParseTranslationUnit();
tab.PrintStats();
//end of tut4---------------------------------------------------------------
//DeclSpec DS;
//Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
//sema.ActOnDeclarator(p.getCurScope(), DeclaratorInfo);
return 0;
}