本文整理汇总了C++中SourceManager::createMainFileID方法的典型用法代码示例。如果您正苦于以下问题:C++ SourceManager::createMainFileID方法的具体用法?C++ SourceManager::createMainFileID怎么用?C++ SourceManager::createMainFileID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SourceManager
的用法示例。
在下文中一共展示了SourceManager::createMainFileID方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InitializeSourceManager
bool CompilerInstance::InitializeSourceManager(StringRef InputFile,
SrcMgr::CharacteristicKind Kind,
DiagnosticsEngine &Diags,
FileManager &FileMgr,
SourceManager &SourceMgr,
const FrontendOptions &Opts) {
// Figure out where to get and map in the main file.
if (InputFile != "-") {
const FileEntry *File = FileMgr.getFile(InputFile);
if (!File) {
Diags.Report(diag::err_fe_error_reading) << InputFile;
return false;
}
SourceMgr.createMainFileID(File, Kind);
} else {
OwningPtr<llvm::MemoryBuffer> SB;
if (llvm::MemoryBuffer::getSTDIN(SB)) {
// FIXME: Give ec.message() in this diag.
Diags.Report(diag::err_fe_error_reading_stdin);
return false;
}
const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(),
SB->getBufferSize(), 0);
SourceMgr.createMainFileID(File, Kind);
SourceMgr.overrideFileContents(File, SB.take());
}
assert(!SourceMgr.getMainFileID().isInvalid() &&
"Couldn't establish MainFileID!");
return true;
}
示例2: InitializeSourceManager
bool CompilerInstance::InitializeSourceManager(llvm::StringRef InputFile,
Diagnostic &Diags,
FileManager &FileMgr,
SourceManager &SourceMgr,
const FrontendOptions &Opts) {
// Figure out where to get and map in the main file, unless it's already
// been created (e.g., by a precompiled preamble).
if (!SourceMgr.getMainFileID().isInvalid()) {
// Do nothing: the main file has already been set.
} else if (InputFile != "-") {
const FileEntry *File = FileMgr.getFile(InputFile);
if (!File) {
Diags.Report(diag::err_fe_error_reading) << InputFile;
return false;
}
SourceMgr.createMainFileID(File);
} else {
llvm::OwningPtr<llvm::MemoryBuffer> SB;
if (llvm::MemoryBuffer::getSTDIN(SB)) {
// FIXME: Give ec.message() in this diag.
Diags.Report(diag::err_fe_error_reading_stdin);
return false;
}
const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(),
SB->getBufferSize(), 0);
SourceMgr.createMainFileID(File);
SourceMgr.overrideFileContents(File, SB.take());
}
assert(!SourceMgr.getMainFileID().isInvalid() &&
"Couldn't establish MainFileID!");
return true;
}
示例3: InitializeSourceManager
bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input,
DiagnosticsEngine &Diags,
FileManager &FileMgr,
SourceManager &SourceMgr,
const FrontendOptions &Opts) {
SrcMgr::CharacteristicKind
Kind = Input.isSystem() ? SrcMgr::C_System : SrcMgr::C_User;
if (Input.isBuffer()) {
SourceMgr.createMainFileIDForMemBuffer(Input.getBuffer(), Kind);
assert(!SourceMgr.getMainFileID().isInvalid() &&
"Couldn't establish MainFileID!");
return true;
}
StringRef InputFile = Input.getFile();
// Figure out where to get and map in the main file.
if (InputFile != "-") {
const FileEntry *File = FileMgr.getFile(InputFile);
if (!File) {
Diags.Report(diag::err_fe_error_reading) << InputFile;
return false;
}
// The natural SourceManager infrastructure can't currently handle named
// pipes, but we would at least like to accept them for the main
// file. Detect them here, read them with the more generic MemoryBuffer
// function, and simply override their contents as we do for STDIN.
if (File->isNamedPipe()) {
OwningPtr<llvm::MemoryBuffer> MB;
if (llvm::error_code ec = llvm::MemoryBuffer::getFile(InputFile, MB)) {
Diags.Report(diag::err_cannot_open_file) << InputFile << ec.message();
return false;
}
// Create a new virtual file that will have the correct size.
File = FileMgr.getVirtualFile(InputFile, MB->getBufferSize(), 0);
SourceMgr.overrideFileContents(File, MB.take());
}
SourceMgr.createMainFileID(File, Kind);
} else {
OwningPtr<llvm::MemoryBuffer> SB;
if (llvm::MemoryBuffer::getSTDIN(SB)) {
// FIXME: Give ec.message() in this diag.
Diags.Report(diag::err_fe_error_reading_stdin);
return false;
}
const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(),
SB->getBufferSize(), 0);
SourceMgr.createMainFileID(File, Kind);
SourceMgr.overrideFileContents(File, SB.take());
}
assert(!SourceMgr.getMainFileID().isInvalid() &&
"Couldn't establish MainFileID!");
return true;
}
示例4: InitializeSourceManager
bool CompilerInstance::InitializeSourceManager(llvm::StringRef InputFile,
Diagnostic &Diags,
FileManager &FileMgr,
SourceManager &SourceMgr,
const FrontendOptions &Opts) {
// Figure out where to get and map in the main file.
if (Opts.EmptyInputOnly) {
const char *EmptyStr = "";
llvm::MemoryBuffer *SB =
llvm::MemoryBuffer::getMemBuffer(EmptyStr, EmptyStr, "<empty input>");
SourceMgr.createMainFileIDForMemBuffer(SB);
} else if (InputFile != "-") {
const FileEntry *File = FileMgr.getFile(InputFile);
if (File) SourceMgr.createMainFileID(File, SourceLocation());
if (SourceMgr.getMainFileID().isInvalid()) {
Diags.Report(diag::err_fe_error_reading) << InputFile;
return false;
}
} else {
llvm::MemoryBuffer *SB = llvm::MemoryBuffer::getSTDIN();
SourceMgr.createMainFileIDForMemBuffer(SB);
if (SourceMgr.getMainFileID().isInvalid()) {
Diags.Report(diag::err_fe_error_reading_stdin);
return false;
}
}
return true;
}
示例5: testClang
void testClang()
{
return; //maks:teste
std::string InFile = "E:/GAMEDEVELOPMENT/output/dots.c";
// Create a file manager object to provide access to and cache the filesystem.
FileManager FileMgr;
char *PredefineBuffer = "";
ASTConsumer *consumer = new ASTDumper();
// Create the diagnostic client for reporting errors or for
// implementing -verify.
DiagnosticClient* TextDiagClient = 0;
TextDiagClient = new TextDiagnosticPrinter();
llvm::OwningPtr<DiagnosticClient> DiagClient(TextDiagClient);
Diagnostic Diags(DiagClient.get());
LangOptions LangInfo;
SourceManager SourceMgr;
HeaderSearch HeaderInfo(FileMgr);
TargetInfo *Target;
std::string Triple = CreateTargetTriple();
//llvm::OwningPtr<TargetInfo> Target(TargetInfo::CreateTargetInfo(Triple));
Target = TargetInfo::CreateTargetInfo(Triple);
// Set up the preprocessor with these options.
Preprocessor PP(Diags, LangInfo, *Target, SourceMgr, HeaderInfo);
PP.setPredefines(PredefineBuffer);
const FileEntry *File = FileMgr.getFile(InFile);
if (File) SourceMgr.createMainFileID(File, SourceLocation());
ParseAST(PP, consumer, false);
}
示例6: createCI
//.........这里部分代码省略.........
if (CI->getLangOpts().CPlusPlus11 == 1) {
// http://llvm.org/bugs/show_bug.cgi?id=13530
CI->getInvocation().getPreprocessorOpts()
.addMacroDef("__CLING__CXX11");
}
if (CI->getDiagnostics().hasErrorOccurred()) {
delete CI;
CI = 0;
return 0;
}
}
CI->setTarget(TargetInfo::CreateTargetInfo(CI->getDiagnostics(),
&Invocation->getTargetOpts()));
if (!CI->hasTarget()) {
delete CI;
CI = 0;
return 0;
}
CI->getTarget().setForcedLangOptions(CI->getLangOpts());
SetClingTargetLangOpts(CI->getLangOpts(), CI->getTarget());
if (CI->getTarget().getTriple().getOS() == llvm::Triple::Cygwin) {
// clang "forgets" the basic arch part needed by winnt.h:
if (CI->getTarget().getTriple().getArch() == llvm::Triple::x86) {
CI->getInvocation().getPreprocessorOpts().addMacroDef("_X86_=1");
} else if (CI->getTarget().getTriple().getArch()
== llvm::Triple::x86_64) {
CI->getInvocation().getPreprocessorOpts().addMacroDef("__x86_64=1");
} else {
llvm::errs() << "Warning: unhandled target architecture "
<< CI->getTarget().getTriple().getArchName() << '\n';
}
}
// Set up source and file managers
CI->createFileManager();
SourceManager* SM = new SourceManager(CI->getDiagnostics(),
CI->getFileManager(),
/*UserFilesAreVolatile*/ true);
CI->setSourceManager(SM); // FIXME: SM leaks.
// Set up the memory buffer
if (buffer)
CI->getSourceManager().createMainFileIDForMemBuffer(buffer);
else {
// As main file we want
// * a virtual file that is claiming to be huge
// * with an empty memory buffer attached (to bring the content)
SourceManager& SM = CI->getSourceManager();
FileManager& FM = SM.getFileManager();
// Build the virtual file
const char* Filename = "InteractiveInputLineIncluder.h";
const std::string& CGOptsMainFileName
= CI->getInvocation().getCodeGenOpts().MainFileName;
if (!CGOptsMainFileName.empty())
Filename = CGOptsMainFileName.c_str();
const FileEntry* FE
= FM.getVirtualFile(Filename, 1U << 15U, time(0));
FileID MainFileID = SM.createMainFileID(FE, SrcMgr::C_User);
const SrcMgr::SLocEntry& MainFileSLocE = SM.getSLocEntry(MainFileID);
const SrcMgr::ContentCache* MainFileCC
= MainFileSLocE.getFile().getContentCache();
llvm::MemoryBuffer* MainFileMB
= llvm::MemoryBuffer::getMemBuffer("/*CLING MAIN FILE*/\n");
const_cast<SrcMgr::ContentCache*>(MainFileCC)->setBuffer(MainFileMB);
}
// Set up the preprocessor
CI->createPreprocessor();
Preprocessor& PP = CI->getPreprocessor();
PP.getBuiltinInfo().InitializeBuiltins(PP.getIdentifierTable(),
PP.getLangOpts());
// Set up the ASTContext
ASTContext *Ctx = new ASTContext(CI->getLangOpts(),
PP.getSourceManager(), &CI->getTarget(),
PP.getIdentifierTable(),
PP.getSelectorTable(), PP.getBuiltinInfo(),
/*size_reserve*/0, /*DelayInit*/false);
CI->setASTContext(Ctx);
// Set up the ASTConsumers
CI->setASTConsumer(new DeclCollector());
// Set up Sema
CodeCompleteConsumer* CCC = 0;
CI->createSema(TU_Complete, CCC);
// Set CodeGen options
// CI->getCodeGenOpts().DebugInfo = 1; // want debug info
// CI->getCodeGenOpts().EmitDeclMetadata = 1; // For unloading, for later
CI->getCodeGenOpts().OptimizationLevel = 0; // see pure SSA, that comes out
CI->getCodeGenOpts().CXXCtorDtorAliases = 0; // aliasing the complete
// ctor to the base ctor causes
// the JIT to crash
// When asserts are on, TURN ON not compare the VerifyModule
assert(CI->getCodeGenOpts().VerifyModule = 1);
return CI;
}
示例7: assembler
static int
do_assemble(SourceManager& source_mgr, DiagnosticsEngine& diags)
{
// Apply warning settings
ApplyWarningSettings(diags);
// Determine objfmt_bits based on -32 and -64 options
std::string objfmt_bits = GetBitsSetting();
FileManager& file_mgr = source_mgr.getFileManager();
Assembler assembler("x86", YGAS_OBJFMT_BASE + objfmt_bits, diags,
dump_object);
HeaderSearch headers(file_mgr);
if (diags.hasFatalErrorOccurred())
return EXIT_FAILURE;
// Set object filename if specified.
if (!obj_filename.empty())
assembler.setObjectFilename(obj_filename);
// Set parser.
assembler.setParser("gas", diags);
if (diags.hasFatalErrorOccurred())
return EXIT_FAILURE;
// Set debug format to dwarf2pass if it's legal for this object format.
if (assembler.isOkDebugFormat("dwarf2pass"))
{
assembler.setDebugFormat("dwarf2pass", diags);
if (diags.hasFatalErrorOccurred())
return EXIT_FAILURE;
}
// open the input file or STDIN (for filename of "-")
if (in_filename == "-")
{
OwningPtr<MemoryBuffer> my_stdin;
if (llvm::error_code err = MemoryBuffer::getSTDIN(my_stdin))
{
diags.Report(SourceLocation(), diag::fatal_file_open)
<< in_filename << err.message();
return EXIT_FAILURE;
}
source_mgr.createMainFileIDForMemBuffer(my_stdin.take());
}
else
{
const FileEntry* in = file_mgr.getFile(in_filename);
if (!in)
{
diags.Report(SourceLocation(), diag::fatal_file_open)
<< in_filename;
return EXIT_FAILURE;
}
source_mgr.createMainFileID(in);
}
// Initialize the object.
if (!assembler.InitObject(source_mgr, diags))
return EXIT_FAILURE;
// Configure object per command line parameters.
ConfigureObject(*assembler.getObject());
// Predefine symbols.
for (std::vector<std::string>::const_iterator i=defsym.begin(),
end=defsym.end(); i != end; ++i)
{
StringRef str(*i);
size_t equalpos = str.find('=');
if (equalpos == StringRef::npos)
{
diags.Report(diag::fatal_bad_defsym) << str;
continue;
}
StringRef name = str.slice(0, equalpos);
StringRef vstr = str.slice(equalpos+1, StringRef::npos);
IntNum value;
if (!vstr.empty())
{
// determine radix
unsigned int radix;
if (vstr[0] == '0' && vstr.size() > 1 &&
(vstr[1] == 'x' || vstr[1] == 'X'))
{
vstr = vstr.substr(2);
radix = 16;
}
else if (vstr[0] == '0')
{
vstr = vstr.substr(1);
radix = 8;
}
else
radix = 10;
// check validity
//.........这里部分代码省略.........