Esempio n. 1
0
int Slang::compile() {
  if (mDiagnostics->hasErrorOccurred())
    return 1;
  if (mOS.get() == NULL)
    return 1;

  // Here is per-compilation needed initialization
  createPreprocessor();
  createASTContext();

  mBackend.reset(createBackend(CodeGenOpts, &mOS->os(), mOT));

  // Inform the diagnostic client we are processing a source file
  mDiagClient->BeginSourceFile(LangOpts, mPP.get());

  // The core of the slang compiler
  ParseAST(*mPP, mBackend.get(), *mASTContext);

  // Inform the diagnostic client we are done with previous source file
  mDiagClient->EndSourceFile();

  // Declare success if no error
  if (!mDiagnostics->hasErrorOccurred())
    mOS->keep();

  // The compilation ended, clear
  mBackend.reset();
  mASTContext.reset();
  mPP.reset();
  mOS.reset();

  return mDiagnostics->hasErrorOccurred() ? 1 : 0;
}
void WebCLValidatorAction::ExecuteAction()
{
    // We will get assertions if sema_ isn't wrapped here.
    llvm::OwningPtr<clang::Sema> sema(sema_);
    ParseAST(*sema.get());
    validatedSource_ = consumer_->getTransformedSource();
    kernels_ = consumer_->getKernels();
}
void WebCLMatcher2Action::ExecuteAction()
{
    clang::CompilerInstance &instance = getCompilerInstance();

    WebCLRenamedStructRelocator renamedStructRelocator(instance, *rewriter_);

    renamedStructRelocator.prepare(finder_);
    ParseAST(instance.getPreprocessor(), consumer_, instance.getASTContext());
    clang::tooling::Replacements &renamedStructRelocations =
        renamedStructRelocator.complete();

    if (!clang::tooling::applyAllReplacements(renamedStructRelocations, *rewriter_)) {
        reporter_->fatal("Can't relocate renamed structures.");
        return;
    }

    if (!printer_->print(*out_, "// WebCL Validator: matching stage 2.\n")) {
        reporter_->fatal("Can't print second matcher stage output.");
        return;
    }
}
void WebCLMatcher1Action::ExecuteAction()
{
    clang::CompilerInstance &instance = getCompilerInstance();

    WebCLNamelessStructRenamer namelessStructRenamer(instance, cfg_);

    namelessStructRenamer.prepare(finder_);
    ParseAST(instance.getPreprocessor(), consumer_, instance.getASTContext());
    clang::tooling::Replacements &namelessStructRenamings =
        namelessStructRenamer.complete();

    if (!checkIdentifiers())
        return;

    if (!clang::tooling::applyAllReplacements(namelessStructRenamings, *rewriter_)) {
        reporter_->fatal("Can't apply rename nameless structures.");
        return;
    }

    if (!printer_->print(*out_, "// WebCL Validator: matching stage 1.\n")) {
        reporter_->fatal("Can't print first matcher stage output.");
        return;
    }
}
void WebCLFindUsedExtensionsAction::ExecuteAction()
{
    clang::CompilerInstance &instance = getCompilerInstance();

    ParseAST(instance.getPreprocessor(), consumer_, instance.getASTContext());
}
Esempio n. 6
0
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));*/


    const TargetInfo &targetInfo = *pTargetInfo;

    IdentifierTable identifierTable(langOptions);
    SelectorTable selectorTable;

    Builtin::Context builtinContext(targetInfo);
    ASTContext astContext(
        langOptions,
        sourceManager,
        targetInfo,
        identifierTable,
        selectorTable,
        builtinContext,
        0 /* size_reserve*/);
    // ASTConsumer astConsumer;
    MyASTConsumer astConsumer;
    astConsumer.sourceManager = &sourceManager;
    astConsumer.html = new ClangDocHTML;
    astConsumer.html->astConsumer = &astConsumer;
    preprocessor.addPPCallbacks(astConsumer.html);
    preprocessor.AddCommentHandler(astConsumer.html);

    Sema sema(
        preprocessor,
        astContext,
        astConsumer);
    sema.Initialize();

    //MySemanticAnalisys mySema( preprocessor, astContext, astConsumer);

    //Parser parser( preprocessor, sema);
    //parser.ParseTranslationUnit();
    astConsumer.preprocessor = &sema.PP;
    ParseAST(preprocessor, &astConsumer, astContext);
    return 0;
}