diff options
author | Logan Chien <loganchien@google.com> | 2011-10-21 15:39:28 +0800 |
---|---|---|
committer | Logan Chien <loganchien@google.com> | 2011-10-22 12:01:41 +0800 |
commit | 9207a2e495c8363606861e4f034504ec5c153dab (patch) | |
tree | 55f8301585245ad07adb89f63bd27082c5c0aeba | |
parent | 18ca8cfc2b9e60e4aa4b4269e2b02c5f6f245822 (diff) | |
download | android_frameworks_compile_slang-9207a2e495c8363606861e4f034504ec5c153dab.tar.gz android_frameworks_compile_slang-9207a2e495c8363606861e4f034504ec5c153dab.tar.bz2 android_frameworks_compile_slang-9207a2e495c8363606861e4f034504ec5c153dab.zip |
Apply changes to migrate to LLVM upstream Oct 20th 2011.
- StructType::isAnonymous is renamed to StructType::isLiteral.
- PassManagerBuilder has been moved from
llvm/Support/PassManagerBuilder.h to
llvm/Transforms/IPO/PassManagerBuilder.h
- Include llvm/Transforms/IPO.h for llvm::createInternalizePass.
- clang::DiagClient has be renamed to clang::DiagnosticConsumer.
Besides, we have to implement one additional pure virtual method
'clone' for create a clone of slang::DiagnosticBuffer.
- llvm::Linker::LinkModules comes with one additional parameter.
Passing llvm::Linker::DestroySource should be equivalent to
the old code we were using.
- slang::Slang is now derived from clang::ModuleLoader and implemented
loadModule pure virtual method (though we will always return NULL.)
- clang::Preprocessor is taking one additional parameter for
clang::ModuleLoader.
- clang::Diagnostic has been changed. A lot of the method has been
moved to clang::DiagnosticsEngine, and we can no longer 'Report' a
diagnostic from clang::Diagnostic. We have to use
clang::DiagnosticEngine instead.
- llvm::setCodeModel has been removed.
Change-Id: I1f2a4cbeaf61a8ed1d0d635a5a0e1baa90d99d07
-rw-r--r-- | Android.mk | 72 | ||||
-rw-r--r-- | BitWriter_2_9/BitcodeWriter.cpp | 2 | ||||
-rw-r--r-- | BitWriter_2_9/ValueEnumerator.cpp | 2 | ||||
-rw-r--r-- | llvm-rs-cc.cpp | 22 | ||||
-rw-r--r-- | llvm-rs-link.cpp | 8 | ||||
-rw-r--r-- | slang.cpp | 122 | ||||
-rw-r--r-- | slang.h | 110 | ||||
-rw-r--r-- | slang_backend.cpp | 29 | ||||
-rw-r--r-- | slang_backend.h | 4 | ||||
-rw-r--r-- | slang_diagnostic_buffer.cpp | 38 | ||||
-rw-r--r-- | slang_diagnostic_buffer.h | 21 | ||||
-rw-r--r-- | slang_rs.cpp | 47 | ||||
-rw-r--r-- | slang_rs_backend.cpp | 60 | ||||
-rw-r--r-- | slang_rs_backend.h | 4 | ||||
-rw-r--r-- | slang_rs_context.h | 2 | ||||
-rw-r--r-- | slang_rs_export_foreach.cpp | 132 | ||||
-rw-r--r-- | slang_rs_export_foreach.h | 2 | ||||
-rw-r--r-- | slang_rs_export_func.cpp | 14 | ||||
-rw-r--r-- | slang_rs_export_type.cpp | 219 | ||||
-rw-r--r-- | slang_rs_export_type.h | 2 | ||||
-rw-r--r-- | slang_rs_object_ref_count.cpp | 10 |
21 files changed, 487 insertions, 435 deletions
@@ -36,41 +36,41 @@ endif local_cflags_for_slang += -DRS_VERSION=$(RS_VERSION) static_libraries_needed_by_slang := \ - libLLVMLinker \ - libLLVMipo \ - libLLVMBitWriter \ - libLLVMBitWriter_2_9 \ - libLLVMBitReader \ - libLLVMARMCodeGen \ - libLLVMARMAsmPrinter \ - libLLVMARMInfo \ - libLLVMARMDesc \ - libLLVMX86CodeGen \ - libLLVMX86AsmPrinter \ - libLLVMX86Info \ - libLLVMX86Desc \ - libLLVMX86Utils \ - libLLVMAsmPrinter \ - libLLVMSelectionDAG \ - libLLVMCodeGen \ - libLLVMScalarOpts \ - libLLVMInstCombine \ - libLLVMTransformUtils \ - libLLVMInstrumentation \ - libLLVMipa \ - libLLVMAnalysis \ - libLLVMTarget \ - libLLVMMC \ - libLLVMMCParser \ - libLLVMCore \ - libclangParse \ - libclangSema \ - libclangAnalysis \ - libclangAST \ - libclangLex \ - libclangFrontend \ - libclangCodeGen \ - libclangBasic \ + libLLVMLinker \ + libLLVMipo \ + libLLVMBitWriter \ + libLLVMBitWriter_2_9 \ + libLLVMBitReader \ + libLLVMARMCodeGen \ + libLLVMARMAsmPrinter \ + libLLVMARMInfo \ + libLLVMARMDesc \ + libLLVMX86CodeGen \ + libLLVMX86Info \ + libLLVMX86Desc \ + libLLVMX86AsmPrinter \ + libLLVMX86Utils \ + libLLVMAsmPrinter \ + libLLVMSelectionDAG \ + libLLVMCodeGen \ + libLLVMScalarOpts \ + libLLVMInstCombine \ + libLLVMTransformUtils \ + libLLVMInstrumentation \ + libLLVMipa \ + libLLVMAnalysis \ + libLLVMTarget \ + libLLVMMC \ + libLLVMMCParser \ + libLLVMCore \ + libclangParse \ + libclangSema \ + libclangAnalysis \ + libclangCodeGen \ + libclangAST \ + libclangLex \ + libclangFrontend \ + libclangBasic \ libLLVMSupport # Static library libslang for host @@ -243,7 +243,7 @@ intermediates := $(call local-intermediates-dir) LOCAL_GENERATED_SOURCES += $(intermediates)/RSCCOptions.inc $(intermediates)/RSCCOptions.inc: $(LOCAL_PATH)/RSCCOptions.td $(CLANG_ROOT_PATH)/include/clang/Driver/OptParser.td $(TBLGEN) @echo "Building Renderscript compiler (llvm-rs-cc) Option tables with tblgen" - $(call transform-host-td-to-out,opt-parser-defs) + $(call transform-host-clang-td-to-out,opt-parser-defs) include frameworks/compile/slang/RSSpec.mk include $(CLANG_HOST_BUILD_MK) diff --git a/BitWriter_2_9/BitcodeWriter.cpp b/BitWriter_2_9/BitcodeWriter.cpp index 3eab55d..c4f8e75 100644 --- a/BitWriter_2_9/BitcodeWriter.cpp +++ b/BitWriter_2_9/BitcodeWriter.cpp @@ -181,7 +181,7 @@ static void WriteTypeSymbolTable(const ValueEnumerator &VE, switch (T->getTypeID()) { case Type::StructTyID: { StructType *ST = cast<StructType>(T); - if (ST->isAnonymous()) { + if (ST->isLiteral()) { // Skip anonymous struct definitions in type symbol table // FIXME(srhines) break; diff --git a/BitWriter_2_9/ValueEnumerator.cpp b/BitWriter_2_9/ValueEnumerator.cpp index db766b1..9ae9905 100644 --- a/BitWriter_2_9/ValueEnumerator.cpp +++ b/BitWriter_2_9/ValueEnumerator.cpp @@ -326,7 +326,7 @@ void ValueEnumerator::EnumerateType(Type *Ty) { // don't recursively visit it. This is safe because we allow forward // references of these in the bitcode reader. if (StructType *STy = dyn_cast<StructType>(Ty)) - if (!STy->isAnonymous()) + if (!STy->isLiteral()) *TypeID = ~0U; // Enumerate all of the subtypes before we enumerate this type. This ensures diff --git a/llvm-rs-cc.cpp b/llvm-rs-cc.cpp index 9d70439..176abe3 100644 --- a/llvm-rs-cc.cpp +++ b/llvm-rs-cc.cpp @@ -159,7 +159,7 @@ class RSCCOptions { static void ParseArguments(llvm::SmallVectorImpl<const char*> &ArgVector, llvm::SmallVectorImpl<const char*> &Inputs, RSCCOptions &Opts, - clang::Diagnostic &Diags) { + clang::DiagnosticsEngine &DiagEngine) { if (ArgVector.size() > 1) { const char **ArgBegin = ArgVector.data() + 1; const char **ArgEnd = ArgVector.data() + ArgVector.size(); @@ -170,13 +170,13 @@ static void ParseArguments(llvm::SmallVectorImpl<const char*> &ArgVector, // Check for missing argument error. if (MissingArgCount) - Diags.Report(clang::diag::err_drv_missing_argument) + DiagEngine.Report(clang::diag::err_drv_missing_argument) << Args->getArgString(MissingArgIndex) << MissingArgCount; // Issue errors on unknown arguments. for (arg_iterator it = Args->filtered_begin(OPT_UNKNOWN), ie = Args->filtered_end(); it != ie; ++it) - Diags.Report(clang::diag::err_drv_unknown_argument) + DiagEngine.Report(clang::diag::err_drv_unknown_argument) << (*it)->getAsString(*Args); for (ArgList::const_iterator it = Args->begin(), ie = Args->end(); @@ -235,7 +235,7 @@ static void ParseArguments(llvm::SmallVectorImpl<const char*> &ArgVector, if (Opts.mOutputDep && ((Opts.mOutputType != slang::Slang::OT_Bitcode) && (Opts.mOutputType != slang::Slang::OT_Dependency))) - Diags.Report(clang::diag::err_drv_argument_not_allowed_with) + DiagEngine.Report(clang::diag::err_drv_argument_not_allowed_with) << Args->getLastArg(OPT_M_Group)->getAsString(*Args) << Args->getLastArg(OPT_Output_Type_Group)->getAsString(*Args); @@ -253,7 +253,7 @@ static void ParseArguments(llvm::SmallVectorImpl<const char*> &ArgVector, else if (BitcodeStorageValue == "jc") Opts.mBitcodeStorage = slang::BCST_JAVA_CODE; else if (!BitcodeStorageValue.empty()) - Diags.Report(clang::diag::err_drv_invalid_value) + DiagEngine.Report(clang::diag::err_drv_invalid_value) << OptParser->getOptionName(OPT_bitcode_storage) << BitcodeStorageValue; @@ -267,7 +267,7 @@ static void ParseArguments(llvm::SmallVectorImpl<const char*> &ArgVector, Opts.mTargetAPI = Args->getLastArgIntValue(OPT_target_api, RS_VERSION, - Diags); + DiagEngine); } return; @@ -366,14 +366,16 @@ int main(int argc, const char **argv) { llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> DiagIDs( new clang::DiagnosticIDs()); - clang::Diagnostic Diags(DiagIDs, DiagClient, true); + clang::DiagnosticsEngine DiagEngine(DiagIDs, DiagClient, true); + + clang::Diagnostic Diags(&DiagEngine); slang::Slang::GlobalInitialization(); - ParseArguments(ArgVector, Inputs, Opts, Diags); + ParseArguments(ArgVector, Inputs, Opts, DiagEngine); // Exits when there's any error occurred during parsing the arguments - if (Diags.hasErrorOccurred()) + if (DiagEngine.hasErrorOccurred()) return 1; if (Opts.mShowHelp) { @@ -390,7 +392,7 @@ int main(int argc, const char **argv) { // No input file if (Inputs.empty()) { - Diags.Report(clang::diag::err_drv_no_input_files); + DiagEngine.Report(clang::diag::err_drv_no_input_files); return 1; } diff --git a/llvm-rs-link.cpp b/llvm-rs-link.cpp index 29b41ac..8dec206 100644 --- a/llvm-rs-link.cpp +++ b/llvm-rs-link.cpp @@ -31,11 +31,14 @@ #include "llvm/Support/CommandLine.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MemoryBuffer.h" -#include "llvm/Support/PassManagerBuilder.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Support/ToolOutputFile.h" #include "llvm/Support/system_error.h" +#include "llvm/PassManager.h" +#include "llvm/Transforms/IPO.h" +#include "llvm/Transforms/IPO/PassManagerBuilder.h" + #include "llvm/Target/TargetData.h" #include "slang_rs_metadata.h" @@ -201,7 +204,8 @@ Module *PerformLinking(const std::string &InputFile, if (Lib == NULL) return NULL; - if (llvm::Linker::LinkModules(Composite.get(), Lib, &Err)) { + if (llvm::Linker::LinkModules(Composite.get(), Lib, + llvm::Linker::DestroySource, &Err)) { errs() << "Failed to link `" << InputFile << "' with library bitcode `" << (*I)->getBufferIdentifier() << "' (" << Err << ")\n"; return NULL; @@ -59,10 +59,9 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ManagedStatic.h" -#include "llvm/Support/ToolOutputFile.h" #include "llvm/Support/Path.h" - -#include "llvm/Target/TargetSelect.h" +#include "llvm/Support/TargetSelect.h" +#include "llvm/Support/ToolOutputFile.h" #include "slang_assert.h" #include "slang_backend.h" @@ -81,7 +80,7 @@ struct ForceSlangLinking { // llvm-rs-link needs following functions existing in libslang. llvm::ParseBitcodeFile(NULL, llvm::getGlobalContext(), NULL); - llvm::Linker::LinkModules(NULL, NULL, NULL); + llvm::Linker::LinkModules(NULL, NULL, 0, NULL); // llvm-rs-cc need this. new clang::TextDiagnosticPrinter(llvm::errs(), @@ -114,12 +113,14 @@ clang::CodeGenOptions Slang::CodeGenOpts; // bcc.cpp) const llvm::StringRef Slang::PragmaMetadataName = "#pragma"; -static inline llvm::tool_output_file *OpenOutputFile(const char *OutputFile, - unsigned Flags, - std::string* Error, - clang::Diagnostic* Diag) { - slangAssert((OutputFile != NULL) && (Error != NULL) && (Diag != NULL) && - "Invalid parameter!"); +static inline llvm::tool_output_file * +OpenOutputFile(const char *OutputFile, + unsigned Flags, + std::string* Error, + clang::DiagnosticsEngine *DiagEngine) +{ + slangAssert((OutputFile != NULL) && (Error != NULL) && + (DiagEngine != NULL) && "Invalid parameter!"); if (SlangUtils::CreateDirectoryWithParents( llvm::sys::path::parent_path(OutputFile), Error)) { @@ -130,7 +131,8 @@ static inline llvm::tool_output_file *OpenOutputFile(const char *OutputFile, } // Report error here. - Diag->Report(clang::diag::err_fe_error_opening) << OutputFile << *Error; + DiagEngine->Report(clang::diag::err_fe_error_opening) + << OutputFile << *Error; return NULL; } @@ -159,22 +161,24 @@ void Slang::GlobalInitialization() { GlobalInitialized = true; } - - return; } void Slang::LLVMErrorHandler(void *UserData, const std::string &Message) { - clang::Diagnostic* Diags = static_cast<clang::Diagnostic*>(UserData); - Diags->Report(clang::diag::err_fe_error_backend) << Message; + clang::DiagnosticsEngine* DiagEngine = + static_cast<clang::DiagnosticsEngine *>(UserData); + + DiagEngine->Report(clang::diag::err_fe_error_backend) << Message; exit(1); } void Slang::createDiagnostic() { mDiagClient = new DiagnosticBuffer(); + mDiagIDs = new clang::DiagnosticIDs(); - mDiagnostics = new clang::Diagnostic(mDiagIDs, mDiagClient, true); + mDiagEngine = new clang::DiagnosticsEngine(mDiagIDs, mDiagClient, true); + mDiag.reset(new clang::Diagnostic(mDiagEngine.getPtr())); + initDiagnostic(); - return; } void Slang::createTarget(const std::string &Triple, const std::string &CPU, @@ -190,10 +194,8 @@ void Slang::createTarget(const std::string &Triple, const std::string &CPU, if (!Features.empty()) mTargetOpts.Features = Features; - mTarget.reset(clang::TargetInfo::CreateTargetInfo(*mDiagnostics, + mTarget.reset(clang::TargetInfo::CreateTargetInfo(*mDiagEngine, mTargetOpts)); - - return; } void Slang::createFileManager() { @@ -202,19 +204,19 @@ void Slang::createFileManager() { } void Slang::createSourceManager() { - mSourceMgr.reset(new clang::SourceManager(*mDiagnostics, *mFileMgr)); - return; + mSourceMgr.reset(new clang::SourceManager(*mDiagEngine, *mFileMgr)); } void Slang::createPreprocessor() { // Default only search header file in current dir - clang::HeaderSearch *HS = new clang::HeaderSearch(*mFileMgr); + clang::HeaderSearch *HeaderInfo = new clang::HeaderSearch(*mFileMgr); - mPP.reset(new clang::Preprocessor(*mDiagnostics, + mPP.reset(new clang::Preprocessor(*mDiagEngine, LangOpts, - *mTarget, + mTarget.get(), *mSourceMgr, - *HS, + *HeaderInfo, + *this, NULL, /* OwnsHeaderSearch = */true)); // Initialize the preprocessor @@ -232,42 +234,34 @@ void Slang::createPreprocessor() { } } - HS->SetSearchPaths(SearchList, - /* angledDirIdx = */1, - /* systemDixIdx = */1, - /* noCurDirSearch = */false); + HeaderInfo->SetSearchPaths(SearchList, + /* angledDirIdx = */1, + /* systemDixIdx = */1, + /* noCurDirSearch = */false); initPreprocessor(); - return; } void Slang::createASTContext() { mASTContext.reset(new clang::ASTContext(LangOpts, *mSourceMgr, - *mTarget, + mTarget.get(), mPP->getIdentifierTable(), mPP->getSelectorTable(), mPP->getBuiltinInfo(), /* size_reserve = */0)); initASTContext(); - return; } -clang::ASTConsumer -*Slang::createBackend(const clang::CodeGenOptions& CodeGenOpts, - llvm::raw_ostream *OS, - OutputType OT) { - return new Backend(mDiagnostics.getPtr(), - CodeGenOpts, - mTargetOpts, - &mPragmas, - OS, - OT); +clang::ASTConsumer * +Slang::createBackend(const clang::CodeGenOptions& CodeGenOpts, + llvm::raw_ostream *OS, OutputType OT) { + return new Backend(mDiagEngine.getPtr(), CodeGenOpts, mTargetOpts, + &mPragmas, OS, OT); } Slang::Slang() : mInitialized(false), mDiagClient(NULL), mOT(OT_Default) { GlobalInitialization(); - return; } void Slang::init(const std::string &Triple, const std::string &CPU, @@ -276,15 +270,21 @@ void Slang::init(const std::string &Triple, const std::string &CPU, return; createDiagnostic(); - llvm::install_fatal_error_handler(LLVMErrorHandler, mDiagnostics.getPtr()); + llvm::install_fatal_error_handler(LLVMErrorHandler, mDiagEngine.getPtr()); createTarget(Triple, CPU, Features); createFileManager(); createSourceManager(); mInitialized = true; +} - return; +clang::ModuleKey Slang::loadModule(clang::SourceLocation ImportLoc, + clang::IdentifierInfo &ModuleName, + clang::SourceLocation ModuleNameLoc) { + //FIXME: Don't we have to implement this? + slangAssert(0 && "Not implemented"); + return NULL; } bool Slang::setInputSource(llvm::StringRef InputFile, @@ -301,7 +301,7 @@ bool Slang::setInputSource(llvm::StringRef InputFile, mSourceMgr->createMainFileIDForMemBuffer(SB); if (mSourceMgr->getMainFileID().isInvalid()) { - mDiagnostics->Report(clang::diag::err_fe_error_reading) << InputFile; + mDiagEngine->Report(clang::diag::err_fe_error_reading) << InputFile; return false; } return true; @@ -317,7 +317,7 @@ bool Slang::setInputSource(llvm::StringRef InputFile) { mSourceMgr->createMainFileID(File); if (mSourceMgr->getMainFileID().isInvalid()) { - mDiagnostics->Report(clang::diag::err_fe_error_reading) << InputFile; + mDiagEngine->Report(clang::diag::err_fe_error_reading) << InputFile; return false; } @@ -333,7 +333,7 @@ bool Slang::setOutput(const char *OutputFile) { case OT_Dependency: case OT_Assembly: case OT_LLVMAssembly: { - OS = OpenOutputFile(OutputFile, 0, &Error, mDiagnostics.getPtr()); + OS = OpenOutputFile(OutputFile, 0, &Error, mDiagEngine.getPtr()); break; } case OT_Nothing: { @@ -341,10 +341,8 @@ bool Slang::setOutput(const char *OutputFile) { } case OT_Object: case OT_Bitcode: { - OS = OpenOutputFile(OutputFile, - llvm::raw_fd_ostream::F_Binary, - &Error, - mDiagnostics.getPtr()); + OS = OpenOutputFile(OutputFile, llvm::raw_fd_ostream::F_Binary, + &Error, mDiagEngine.getPtr()); break; } default: { @@ -366,7 +364,7 @@ bool Slang::setDepOutput(const char *OutputFile) { llvm::sys::Path OutputFilePath(OutputFile); std::string Error; - mDOS.reset(OpenOutputFile(OutputFile, 0, &Error, mDiagnostics.getPtr())); + mDOS.reset(OpenOutputFile(OutputFile, 0, &Error, mDiagEngine.getPtr())); if (!Error.empty() || (mDOS.get() == NULL)) return false; @@ -376,7 +374,7 @@ bool Slang::setDepOutput(const char *OutputFile) { } int Slang::generateDepFile() { - if (mDiagnostics->hasErrorOccurred()) + if (mDiagEngine->hasErrorOccurred()) return 1; if (mDOS.get() == NULL) return 1; @@ -412,18 +410,18 @@ int Slang::generateDepFile() { mPP->EndSourceFile(); // Declare success if no error - if (!mDiagnostics->hasErrorOccurred()) + if (!mDiagEngine->hasErrorOccurred()) mDOS->keep(); // Clean up after compilation mPP.reset(); mDOS.reset(); - return mDiagnostics->hasErrorOccurred() ? 1 : 0; + return mDiagEngine->hasErrorOccurred() ? 1 : 0; } int Slang::compile() { - if (mDiagnostics->hasErrorOccurred()) + if (mDiagEngine->hasErrorOccurred()) return 1; if (mOS.get() == NULL) return 1; @@ -444,7 +442,7 @@ int Slang::compile() { mDiagClient->EndSourceFile(); // Declare success if no error - if (!mDiagnostics->hasErrorOccurred()) + if (!mDiagEngine->hasErrorOccurred()) mOS->keep(); // The compilation ended, clear @@ -453,19 +451,17 @@ int Slang::compile() { mPP.reset(); mOS.reset(); - return mDiagnostics->hasErrorOccurred() ? 1 : 0; + return mDiagEngine->hasErrorOccurred() ? 1 : 0; } void Slang::reset() { llvm::errs() << mDiagClient->str(); - mDiagnostics->Reset(); + mDiagEngine->Reset(); mDiagClient->reset(); - return; } Slang::~Slang() { llvm::llvm_shutdown(); - return; } } // namespace slang @@ -22,6 +22,7 @@ #include <vector> #include "clang/Basic/TargetOptions.h" +#include "clang/Lex/ModuleLoader.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/ADT/OwningPtr.h" @@ -35,23 +36,24 @@ namespace llvm { } namespace clang { + class ASTConsumer; + class ASTContext; + class Backend; + class CodeGenOptions; class Diagnostic; + class DiagnosticsEngine; class FileManager; class FileSystemOptions; - class SourceManager; class LangOptions; class Preprocessor; - class TargetOptions; - class CodeGenOptions; - class ASTContext; - class ASTConsumer; - class Backend; + class SourceManager; class TargetInfo; + class TargetOptions; } namespace slang { -class Slang { +class Slang : public clang::ModuleLoader { static clang::LangOptions LangOpts; static clang::CodeGenOptions CodeGenOpts; @@ -60,7 +62,7 @@ class Slang { static void LLVMErrorHandler(void *UserData, const std::string &Message); public: - typedef enum { + enum OutputType { OT_Dependency, OT_Assembly, OT_LLVMAssembly, @@ -69,49 +71,60 @@ class Slang { OT_Object, OT_Default = OT_Bitcode - } OutputType; + }; private: bool mInitialized; - // The diagnostics engine instance (for status reporting during compilation) - llvm::IntrusiveRefCntPtr<clang::Diagnostic> mDiagnostics; - // The diagnostics id + // Diagnostics Mediator (An interface for both Producer and Consumer) + llvm::OwningPtr<clang::Diagnostic> mDiag; + + // Diagnostics ID llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> mDiagIDs; - // The clients of diagnostics engine. The ownership is taken by the - // mDiagnostics after creation. + + // Diagnostics Engine (Producer and Diagnostics Reporter) + llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine> mDiagEngine; + + // Diagnostics Consumer + // NOTE: The ownership is taken by mDiagEngine after creation. DiagnosticBuffer *mDiagClient; + void createDiagnostic(); + // The target being compiled for clang::TargetOptions mTargetOpts; llvm::OwningPtr<clang::TargetInfo> mTarget; - void createTarget(const std::string &Triple, const std::string &CPU, - const std::vector<std::string> &Features); + void createTarget(std::string const &Triple, std::string const &CPU, + std::vector<std::string> const &Features); - // Below is for parsing and code generation - // The file manager (for prepocessor doing the job such as header file search) + // File manager (for prepocessor doing the job such as header file search) llvm::OwningPtr<clang::FileManager> mFileMgr; llvm::OwningPtr<clang::FileSystemOptions> mFileSysOpt; void createFileManager(); - // The source manager (responsible for the source code handling) + + // Source manager (responsible for the source code handling) llvm::OwningPtr<clang::SourceManager> mSourceMgr; void createSourceManager(); - // The preprocessor (source code preprocessor) + + // Preprocessor (source code preprocessor) llvm::OwningPtr<clang::Preprocessor> mPP; void createPreprocessor(); - // The AST context (the context to hold long-lived AST nodes) + + // AST context (the context to hold long-lived AST nodes) llvm::OwningPtr<clang::ASTContext> mASTContext; void createASTContext(); - // The AST consumer, responsible for code generation + + // AST consumer, responsible for code generation llvm::OwningPtr<clang::ASTConsumer> mBackend; - // Input file name + + // File names std::string mInputFileName; std::string mOutputFileName; @@ -124,6 +137,7 @@ class Slang { // Output stream llvm::OwningPtr<llvm::tool_output_file> mOS; + // Dependency output stream llvm::OwningPtr<llvm::tool_output_file> mDOS; @@ -132,24 +146,24 @@ class Slang { protected: PragmaList mPragmas; - inline clang::Diagnostic &getDiagnostics() { return *mDiagnostics; } - inline const clang::TargetInfo &getTargetInfo() const { return *mTarget; } - inline clang::FileManager &getFileManager() { return *mFileMgr; } - inline clang::SourceManager &getSourceManager() { return *mSourceMgr; } - inline clang::Preprocessor &getPreprocessor() { return *mPP; } - inline clang::ASTContext &getASTContext() { return *mASTContext; } + clang::DiagnosticsEngine &getDiagnostics() { return *mDiagEngine; } + clang::TargetInfo const &getTargetInfo() const { return *mTarget; } + clang::FileManager &getFileManager() { return *mFileMgr; } + clang::SourceManager &getSourceManager() { return *mSourceMgr; } + clang::Preprocessor &getPreprocessor() { return *mPP; } + clang::ASTContext &getASTContext() { return *mASTContext; } - inline const clang::TargetOptions &getTargetOptions() const + inline clang::TargetOptions const &getTargetOptions() const { return mTargetOpts; } virtual void initDiagnostic() {} virtual void initPreprocessor() {} virtual void initASTContext() {} - virtual clang::ASTConsumer - *createBackend(const clang::CodeGenOptions& CodeGenOpts, - llvm::raw_ostream *OS, - OutputType OT); + virtual clang::ASTConsumer * + createBackend(const clang::CodeGenOptions& CodeGenOpts, + llvm::raw_ostream *OS, + OutputType OT); public: static const llvm::StringRef PragmaMetadataName; @@ -161,41 +175,49 @@ class Slang { void init(const std::string &Triple, const std::string &CPU, const std::vector<std::string> &Features); + virtual clang::ModuleKey loadModule(clang::SourceLocation ImportLoc, + clang::IdentifierInfo &ModuleName, + clang::SourceLocation ModuleNameLoc); + bool setInputSource(llvm::StringRef InputFile, const char *Text, size_t TextLength); bool setInputSource(llvm::StringRef InputFile); - inline const std::string &getInputFileName() const { return mInputFileName; } + std::string const &getInputFileName() const { return mInputFileName; } - inline void setIncludePaths(const std::vector<std::string> &IncludePaths) { + void setIncludePaths(const std::vector<std::string> &IncludePaths) { mIncludePaths = IncludePaths; } - inline void setOutputType(OutputType OT) { mOT = OT; } + void setOutputType(OutputType OT) { mOT = OT; } bool setOutput(const char *OutputFile); - inline const std::string &getOutputFileName() const { + + std::string const &getOutputFileName() const { return mOutputFileName; } bool setDepOutput(const char *OutputFile); - inline void setDepTargetBC(const char *TargetBCFile) { + + void setDepTargetBC(const char *TargetBCFile) { mDepTargetBCFileName = TargetBCFile; } - inline void setAdditionalDepTargets( - const std::vector<std::string> &AdditionalDepTargets) { + + void setAdditionalDepTargets( + std::vector<std::string> const &AdditionalDepTargets) { mAdditionalDepTargets = AdditionalDepTargets; } - inline void appendGeneratedFileName( - const std::string &GeneratedFileName) { + + void appendGeneratedFileName(std::string const &GeneratedFileName) { mGeneratedFileNames.push_back(GeneratedFileName); } int generateDepFile(); + int compile(); - inline const char *getErrorMessage() { return mDiagClient->str().c_str(); } + char const *getErrorMessage() { return mDiagClient->str().c_str(); } // Reset the slang compiler state such that it can be reused to compile // another file diff --git a/slang_backend.cpp b/slang_backend.cpp index 659d0ce..ca07a49 100644 --- a/slang_backend.cpp +++ b/slang_backend.cpp @@ -43,12 +43,12 @@ #include "llvm/Module.h" #include "llvm/Metadata.h" -#include "llvm/Support/PassManagerBuilder.h" +#include "llvm/Transforms/IPO/PassManagerBuilder.h" #include "llvm/Target/TargetData.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetOptions.h" -#include "llvm/Target/TargetRegistry.h" +#include "llvm/Support/TargetRegistry.h" #include "llvm/MC/SubtargetFeature.h" @@ -115,7 +115,7 @@ bool Backend::CreateCodeGenPasses() { const llvm::Target* TargetInfo = llvm::TargetRegistry::lookupTarget(Triple, Error); if (TargetInfo == NULL) { - mDiags.Report(clang::diag::err_fe_unable_to_create_target) << Error; + mDiagEngine.Report(clang::diag::err_fe_unable_to_create_target) << Error; return false; } @@ -135,15 +135,16 @@ bool Backend::CreateCodeGenPasses() { // need any relocation model. llvm::Reloc::Model RM = llvm::Reloc::Static; - // This is set for the linker (specify how large of the virtual addresses we // can access for all unknown symbols.) - if (mpModule->getPointerSize() == llvm::Module::Pointer32) - llvm::TargetMachine::setCodeModel(llvm::CodeModel::Small); - else + llvm::CodeModel::Model CM; + if (mpModule->getPointerSize() == llvm::Module::Pointer32) { + CM = llvm::CodeModel::Small; + } else { // The target may have pointer size greater than 32 (e.g. x86_64 // architecture) may need large data address model - llvm::TargetMachine::setCodeModel(llvm::CodeModel::Medium); + CM = llvm::CodeModel::Medium; + } // Setup feature string std::string FeaturesStr; @@ -158,8 +159,10 @@ bool Backend::CreateCodeGenPasses() { FeaturesStr = Features.getString(); } + llvm::TargetMachine *TM = - TargetInfo->createTargetMachine(Triple, mTargetOpts.CPU, FeaturesStr, RM); + TargetInfo->createTargetMachine(Triple, mTargetOpts.CPU, FeaturesStr, + RM, CM); // Register scheduler llvm::RegisterScheduler::setDefault(llvm::createDefaultScheduler); @@ -185,14 +188,14 @@ bool Backend::CreateCodeGenPasses() { } if (TM->addPassesToEmitFile(*mCodeGenPasses, FormattedOutStream, CGFT, OptLevel)) { - mDiags.Report(clang::diag::err_fe_unable_to_interface_with_target); + mDiagEngine.Report(clang::diag::err_fe_unable_to_interface_with_target); return false; } return true; } -Backend::Backend(clang::Diagnostic *Diags, +Backend::Backend(clang::DiagnosticsEngine *DiagEngine, const clang::CodeGenOptions &CodeGenOpts, const clang::TargetOptions &TargetOpts, PragmaList *Pragmas, @@ -209,11 +212,11 @@ Backend::Backend(clang::Diagnostic *Diags, mPerModulePasses(NULL), mCodeGenPasses(NULL), mLLVMContext(llvm::getGlobalContext()), - mDiags(*Diags), + mDiagEngine(*DiagEngine), mPragmas(Pragmas) { FormattedOutStream.setStream(*mpOS, llvm::formatted_raw_ostream::PRESERVE_STREAM); - mGen = CreateLLVMCodeGen(mDiags, "", mCodeGenOpts, mLLVMContext); + mGen = CreateLLVMCodeGen(mDiagEngine, "", mCodeGenOpts, mLLVMContext); return; } diff --git a/slang_backend.h b/slang_backend.h index 052be4b..c678574 100644 --- a/slang_backend.h +++ b/slang_backend.h @@ -77,7 +77,7 @@ class Backend : public clang::ASTConsumer { protected: llvm::LLVMContext &mLLVMContext; - clang::Diagnostic &mDiags; + clang::DiagnosticsEngine &mDiagEngine; PragmaList *mPragmas; @@ -99,7 +99,7 @@ class Backend : public clang::ASTConsumer { virtual void HandleTranslationUnitPost(llvm::Module *M) { return; } public: - Backend(clang::Diagnostic *Diags, + Backend(clang::DiagnosticsEngine *DiagEngine, const clang::CodeGenOptions &CodeGenOpts, const clang::TargetOptions &TargetOpts, PragmaList *Pragmas, diff --git a/slang_diagnostic_buffer.cpp b/slang_diagnostic_buffer.cpp index 6b70cfe..ed6f303 100644 --- a/slang_diagnostic_buffer.cpp +++ b/slang_diagnostic_buffer.cpp @@ -25,14 +25,23 @@ namespace slang { -DiagnosticBuffer::DiagnosticBuffer() : mSOS(NULL) { - mSOS = new llvm::raw_string_ostream(mDiags); - return; +DiagnosticBuffer::DiagnosticBuffer() +: mSOS(new llvm::raw_string_ostream(mDiags)) { } -void DiagnosticBuffer::HandleDiagnostic(clang::Diagnostic::Level DiagLevel, - const clang::DiagnosticInfo &Info) { - const clang::SourceLocation &SrcLoc = Info.getLocation(); +DiagnosticBuffer::DiagnosticBuffer(DiagnosticBuffer const &src) +: mDiags(src.mDiags), mSOS(new llvm::raw_string_ostream(mDiags)) { +} + +DiagnosticBuffer::~DiagnosticBuffer() { +} + +void DiagnosticBuffer::HandleDiagnostic( + clang::DiagnosticsEngine::Level DiagLevel, + clang::Diagnostic const &Info) { + + clang::SourceLocation const &SrcLoc = Info.getLocation(); + // 100 is enough for storing general diagnosis message llvm::SmallString<100> Buf; @@ -42,19 +51,19 @@ void DiagnosticBuffer::HandleDiagnostic(clang::Diagnostic::Level DiagLevel, } switch (DiagLevel) { - case clang::Diagnostic::Note: { + case clang::DiagnosticsEngine::Note: { (*mSOS) << "note: "; break; } - case clang::Diagnostic::Warning: { + case clang::DiagnosticsEngine::Warning: { (*mSOS) << "warning: "; break; } - case clang::Diagnostic::Error: { + case clang::DiagnosticsEngine::Error: { (*mSOS) << "error: "; break; } - case clang::Diagnostic::Fatal: { + case clang::DiagnosticsEngine::Fatal: { (*mSOS) << "fatal: "; break; } @@ -63,16 +72,13 @@ void DiagnosticBuffer::HandleDiagnostic(clang::Diagnostic::Level DiagLevel, } } - Info.FormatDiagnostic(Buf); (*mSOS) << Buf.str() << '\n'; - - return; } -DiagnosticBuffer::~DiagnosticBuffer() { - delete mSOS; - return; +clang::DiagnosticConsumer * +DiagnosticBuffer::clone(clang::DiagnosticsEngine &Diags) const { + return new DiagnosticBuffer(*this); } } // namespace slang diff --git a/slang_diagnostic_buffer.h b/slang_diagnostic_buffer.h index 3c4e1c7..e4eeaab 100644 --- a/slang_diagnostic_buffer.h +++ b/slang_diagnostic_buffer.h @@ -29,17 +29,24 @@ namespace llvm { namespace slang { -// The diagnostics client instance (for reading the processed diagnostics) -class DiagnosticBuffer : public clang::DiagnosticClient { +// The diagnostics consumer instance (for reading the processed diagnostics) +class DiagnosticBuffer : public clang::DiagnosticConsumer { private: std::string mDiags; - llvm::raw_string_ostream *mSOS; + llvm::OwningPtr<llvm::raw_string_ostream> mSOS; public: DiagnosticBuffer(); - virtual void HandleDiagnostic(clang::Diagnostic::Level DiagLevel, - const clang::DiagnosticInfo& Info); + DiagnosticBuffer(DiagnosticBuffer const &src); + + virtual ~DiagnosticBuffer(); + + virtual void HandleDiagnostic(clang::DiagnosticsEngine::Level DiagLevel, + const clang::Diagnostic& Info); + + virtual clang::DiagnosticConsumer * + clone(clang::DiagnosticsEngine &Diags) const; inline const std::string &str() const { mSOS->flush(); @@ -48,11 +55,9 @@ class DiagnosticBuffer : public clang::DiagnosticClient { inline void reset() { this->mSOS->str().clear(); - return; } - - virtual ~DiagnosticBuffer(); }; + } #endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_DIAGNOSTIC_BUFFER_H_ NOLINT diff --git a/slang_rs.cpp b/slang_rs.cpp index 1d9f42d..994139e 100644 --- a/slang_rs.cpp +++ b/slang_rs.cpp @@ -166,30 +166,33 @@ bool SlangRS::checkODR(const char *CurInputFile) { } void SlangRS::initDiagnostic() { - clang::Diagnostic &Diag = getDiagnostics(); - if (Diag.setDiagnosticGroupMapping("implicit-function-declaration", - clang::diag::MAP_ERROR)) - Diag.Report(clang::diag::warn_unknown_warning_option) - << "implicit-function-declaration"; + clang::DiagnosticsEngine &DiagEngine = getDiagnostics(); - Diag.setDiagnosticMapping( - clang::diag::ext_typecheck_convert_discards_qualifiers, - clang::diag::MAP_ERROR, - clang::SourceLocation()); + if (DiagEngine.setDiagnosticGroupMapping("implicit-function-declaration", + clang::diag::MAP_ERROR)) + DiagEngine.Report(clang::diag::warn_unknown_warning_option) + << "implicit-function-declaration"; + + DiagEngine.setDiagnosticMapping( + clang::diag::ext_typecheck_convert_discards_qualifiers, + clang::diag::MAP_ERROR, + clang::SourceLocation()); mDiagErrorInvalidOutputDepParameter = - Diag.getCustomDiagID(clang::Diagnostic::Error, - "invalid parameter for output dependencies files."); + DiagEngine.getCustomDiagID( + clang::DiagnosticsEngine::Error, + "invalid parameter for output dependencies files."); mDiagErrorODR = - Diag.getCustomDiagID(clang::Diagnostic::Error, - "type '%0' in different translation unit (%1 v.s. " - "%2) has incompatible type definition"); - - mDiagErrorTargetAPIRange = Diag.getCustomDiagID(clang::Diagnostic::Error, + DiagEngine.getCustomDiagID( + clang::DiagnosticsEngine::Error, + "type '%0' in different translation unit (%1 v.s. %2) " + "has incompatible type definition"); + + mDiagErrorTargetAPIRange = + DiagEngine.getCustomDiagID( + clang::DiagnosticsEngine::Error, "target API level '%0' is out of range ('%1' - '%2')"); - - return; } void SlangRS::initPreprocessor() { @@ -199,8 +202,6 @@ void SlangRS::initPreprocessor() { RSH << "#define RS_VERSION " << mTargetAPI << std::endl; RSH << "#include \"rs_core." RS_HEADER_SUFFIX "\"" << std::endl; PP.setPredefines(RSH.str()); - - return; } void SlangRS::initASTContext() { @@ -210,7 +211,6 @@ void SlangRS::initASTContext() { &mPragmas, mTargetAPI, &mGeneratedFileNames); - return; } clang::ASTConsumer @@ -250,9 +250,8 @@ bool SlangRS::IsFunctionInRSHeaderFile(const clang::FunctionDecl *FD, } } -SlangRS::SlangRS() : Slang(), mRSContext(NULL), mAllowRSPrefix(false), - mTargetAPI(0) { - return; +SlangRS::SlangRS() + : Slang(), mRSContext(NULL), mAllowRSPrefix(false), mTargetAPI(0) { } bool SlangRS::compile( diff --git a/slang_rs_backend.cpp b/slang_rs_backend.cpp index 0119cc9..d4a081b 100644 --- a/slang_rs_backend.cpp +++ b/slang_rs_backend.cpp @@ -43,7 +43,7 @@ namespace slang { RSBackend::RSBackend(RSContext *Context, - clang::Diagnostic *Diags, + clang::DiagnosticsEngine *DiagEngine, const clang::CodeGenOptions &CodeGenOpts, const clang::TargetOptions &TargetOpts, PragmaList *Pragmas, @@ -51,22 +51,16 @@ RSBackend::RSBackend(RSContext *Context, Slang::OutputType OT, clang::SourceManager &SourceMgr, bool AllowRSPrefix) - : Backend(Diags, - CodeGenOpts, - TargetOpts, - Pragmas, - OS, - OT), - mContext(Context), - mSourceMgr(SourceMgr), - mAllowRSPrefix(AllowRSPrefix), - mExportVarMetadata(NULL), - mExportFuncMetadata(NULL), - mExportForEachMetadata(NULL), - mExportTypeMetadata(NULL), - mRSObjectSlotsMetadata(NULL), - mRefCount(mContext->getASTContext()) { - return; + : Backend(DiagEngine, CodeGenOpts, TargetOpts, Pragmas, OS, OT), + mContext(Context), + mSourceMgr(SourceMgr), + mAllowRSPrefix(AllowRSPrefix), + mExportVarMetadata(NULL), + mExportFuncMetadata(NULL), + mExportForEachMetadata(NULL), + mExportTypeMetadata(NULL), + mRSObjectSlotsMetadata(NULL), + mRefCount(mContext->getASTContext()) { } // 1) Add zero initialization of local RS object types @@ -92,11 +86,12 @@ void RSBackend::HandleTopLevelDecl(clang::DeclGroupRef D) { if (!FD->getName().startswith("rs")) // Check prefix continue; if (!SlangRS::IsFunctionInRSHeaderFile(FD, mSourceMgr)) - mDiags.Report(clang::FullSourceLoc(FD->getLocation(), mSourceMgr), - mDiags.getCustomDiagID(clang::Diagnostic::Error, - "invalid function name prefix, " - "\"rs\" is reserved: '%0'")) - << FD->getName(); + mDiagEngine.Report( + clang::FullSourceLoc(FD->getLocation(), mSourceMgr), + mDiagEngine.getCustomDiagID(clang::DiagnosticsEngine::Error, + "invalid function name prefix, " + "\"rs\" is reserved: '%0'")) + << FD->getName(); } } @@ -162,11 +157,13 @@ void RSBackend::HandleTranslationUnitPre(clang::ASTContext &C) { int version = mContext->getVersion(); if (version == 0) { // Not setting a version is an error - mDiags.Report(mDiags.getCustomDiagID(clang::Diagnostic::Error, - "Missing pragma for version in source file")); + mDiagEngine.Report(mDiagEngine.getCustomDiagID( + clang::DiagnosticsEngine::Error, + "Missing pragma for version in source file")); } else if (version > 1) { - mDiags.Report(mDiags.getCustomDiagID(clang::Diagnostic::Error, - "Pragma for version in source file must be set to 1")); + mDiagEngine.Report(mDiagEngine.getCustomDiagID( + clang::DiagnosticsEngine::Error, + "Pragma for version in source file must be set to 1")); } // Create a static global destructor if necessary (to handle RS object @@ -370,12 +367,11 @@ void RSBackend::HandleTranslationUnitPost(llvm::Module *M) { // parameter .p for (size_t i = 0; i < EF->getNumParameters(); i++) { // getelementptr - Idx[1] = - llvm::ConstantInt::get( - llvm::Type::getInt32Ty(mLLVMContext), i); - llvm::Value *Ptr = IB->CreateInBoundsGEP(HelperFunctionParameter, - Idx, - Idx + 2); + Idx[1] = llvm::ConstantInt::get( + llvm::Type::getInt32Ty(mLLVMContext), i); + + llvm::Value *Ptr = + IB->CreateInBoundsGEP(HelperFunctionParameter, Idx); // load llvm::Value *V = IB->CreateLoad(Ptr); diff --git a/slang_rs_backend.h b/slang_rs_backend.h index 1395594..49d4f00 100644 --- a/slang_rs_backend.h +++ b/slang_rs_backend.h @@ -27,7 +27,7 @@ namespace llvm { namespace clang { class ASTConsumer; - class Diagnostic; + class DiagnosticsEngine; class TargetOptions; class CodeGenerator; class ASTContext; @@ -71,7 +71,7 @@ class RSBackend : public Backend { public: RSBackend(RSContext *Context, - clang::Diagnostic *Diags, + clang::DiagnosticsEngine *DiagEngine, const clang::CodeGenOptions &CodeGenOpts, const clang::TargetOptions &TargetOpts, PragmaList *Pragmas, diff --git a/slang_rs_context.h b/slang_rs_context.h index e447b24..030338b 100644 --- a/slang_rs_context.h +++ b/slang_rs_context.h @@ -112,7 +112,7 @@ class RSContext { inline const clang::SourceManager *getSourceManager() const { return &mPP.getSourceManager(); } - inline clang::Diagnostic *getDiagnostics() const { + inline clang::DiagnosticsEngine *getDiagnostics() const { return &mPP.getDiagnostics(); } inline unsigned int getTargetAPI() const { diff --git a/slang_rs_export_foreach.cpp b/slang_rs_export_foreach.cpp index faa5f17..e5d0176 100644 --- a/slang_rs_export_foreach.cpp +++ b/slang_rs_export_foreach.cpp @@ -34,15 +34,17 @@ namespace slang { namespace { -static void ReportNameError(clang::Diagnostic *Diags, - const clang::ParmVarDecl *PVD) { - slangAssert(Diags && PVD); - const clang::SourceManager &SM = Diags->getSourceManager(); - - Diags->Report(clang::FullSourceLoc(PVD->getLocation(), SM), - Diags->getCustomDiagID(clang::Diagnostic::Error, - "Duplicate parameter entry (by position/name): '%0'")) - << PVD->getName(); +static void ReportNameError(clang::DiagnosticsEngine *DiagEngine, + clang::ParmVarDecl const *PVD) { + slangAssert(DiagEngine && PVD); + const clang::SourceManager &SM = DiagEngine->getSourceManager(); + + DiagEngine->Report( + clang::FullSourceLoc(PVD->getLocation(), SM), + DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error, + "Duplicate parameter entry " + "(by position/name): '%0'")) + << PVD->getName(); return; } @@ -55,7 +57,7 @@ bool RSExportForEach::validateAndConstructParams( slangAssert(Context && FD); bool valid = true; clang::ASTContext &C = Context->getASTContext(); - clang::Diagnostic *Diags = Context->getDiagnostics(); + clang::DiagnosticsEngine *DiagEngine = Context->getDiagnostics(); if (!isRootRSFunc(FD)) { slangAssert(false && "must be called on compute root function!"); @@ -66,11 +68,11 @@ bool RSExportForEach::validateAndConstructParams( // Compute root functions are required to return a void type for now if (FD->getResultType().getCanonicalType() != C.VoidTy) { - Diags->Report( - clang::FullSourceLoc(FD->getLocation(), Diags->getSourceManager()), - Diags->getCustomDiagID(clang::Diagnostic::Error, - "compute root() is required to return a " - "void type")); + DiagEngine->Report( + clang::FullSourceLoc(FD->getLocation(), DiagEngine->getSourceManager()), + DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error, + "compute root() is required to return a " + "void type")); valid = false; } @@ -98,12 +100,12 @@ bool RSExportForEach::validateAndConstructParams( } if (!mIn && !mOut) { - Diags->Report( - clang::FullSourceLoc(FD->getLocation(), - Diags->getSourceManager()), - Diags->getCustomDiagID(clang::Diagnostic::Error, - "Compute root() must have at least one " - "parameter for in or out")); + DiagEngine->Report( + clang::FullSourceLoc(FD->getLocation(), + DiagEngine->getSourceManager()), + DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error, + "Compute root() must have at least one " + "parameter for in or out")); valid = false; } @@ -122,30 +124,30 @@ bool RSExportForEach::validateAndConstructParams( QT = PVD->getType().getCanonicalType(); if (QT.getUnqualifiedType() != C.UnsignedIntTy) { - Diags->Report( - clang::FullSourceLoc(PVD->getLocation(), - Diags->getSourceManager()), - Diags->getCustomDiagID(clang::Diagnostic::Error, - "Unexpected root() parameter '%0' " - "of type '%1'")) - << PVD->getName() << PVD->getType().getAsString(); + DiagEngine->Report( + clang::FullSourceLoc(PVD->getLocation(), + DiagEngine->getSourceManager()), + DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error, + "Unexpected root() parameter '%0' " + "of type '%1'")) + << PVD->getName() << PVD->getType().getAsString(); valid = false; } else { llvm::StringRef ParamName = PVD->getName(); if (ParamName.equals("x")) { if (mX) { - ReportNameError(Diags, PVD); + ReportNameError(DiagEngine, PVD); valid = false; } else if (mY) { // Can't go back to X after skipping Y - ReportNameError(Diags, PVD); + ReportNameError(DiagEngine, PVD); valid = false; } else { mX = PVD; } } else if (ParamName.equals("y")) { if (mY) { - ReportNameError(Diags, PVD); + ReportNameError(DiagEngine, PVD); valid = false; } else { mY = PVD; @@ -156,13 +158,13 @@ bool RSExportForEach::validateAndConstructParams( } else if (!mY) { mY = PVD; } else { - Diags->Report( - clang::FullSourceLoc(PVD->getLocation(), - Diags->getSourceManager()), - Diags->getCustomDiagID(clang::Diagnostic::Error, - "Unexpected root() parameter '%0' " - "of type '%1'")) - << PVD->getName() << PVD->getType().getAsString(); + DiagEngine->Report( + clang::FullSourceLoc(PVD->getLocation(), + DiagEngine->getSourceManager()), + DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error, + "Unexpected root() parameter '%0' " + "of type '%1'")) + << PVD->getName() << PVD->getType().getAsString(); valid = false; } } @@ -189,13 +191,13 @@ bool RSExportForEach::validateAndConstructParams( mMetadataEncoding != 0x07 && // In, Out, UsrData mMetadataEncoding != 0x03 && // In, Out mMetadataEncoding != 0x01) { // In - Diags->Report( - clang::FullSourceLoc(FD->getLocation(), - Diags->getSourceManager()), - Diags->getCustomDiagID(clang::Diagnostic::Error, - "Compute root() targeting SDK levels %0-%1 " - "may not skip parameters")) - << SLANG_MINIMUM_TARGET_API << (SLANG_ICS_TARGET_API-1); + DiagEngine->Report( + clang::FullSourceLoc(FD->getLocation(), + DiagEngine->getSourceManager()), + DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error, + "Compute root() targeting SDK levels " + "%0-%1 may not skip parameters")) + << SLANG_MINIMUM_TARGET_API << (SLANG_ICS_TARGET_API-1); valid = false; } } @@ -305,9 +307,10 @@ bool RSExportForEach::isRSForEachFunc(const clang::FunctionDecl *FD) { return true; } -bool RSExportForEach::validateSpecialFuncDecl(clang::Diagnostic *Diags, - const clang::FunctionDecl *FD) { - slangAssert(Diags && FD); +bool +RSExportForEach::validateSpecialFuncDecl(clang::DiagnosticsEngine *DiagEngine, + clang::FunctionDecl const *FD) { + slangAssert(DiagEngine && FD); bool valid = true; const clang::ASTContext &C = FD->getASTContext(); @@ -316,11 +319,12 @@ bool RSExportForEach::validateSpecialFuncDecl(clang::Diagnostic *Diags, if (numParams == 0) { // Graphics root function, so verify that it returns an int if (FD->getResultType().getCanonicalType() != C.IntTy) { - Diags->Report( - clang::FullSourceLoc(FD->getLocation(), Diags->getSourceManager()), - Diags->getCustomDiagID(clang::Diagnostic::Error, - "root(void) is required to return " - "an int for graphics usage")); + DiagEngine->Report( + clang::FullSourceLoc(FD->getLocation(), + DiagEngine->getSourceManager()), + DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error, + "root(void) is required to return " + "an int for graphics usage")); valid = false; } } else { @@ -329,20 +333,22 @@ bool RSExportForEach::validateSpecialFuncDecl(clang::Diagnostic *Diags, } } else if (isInitRSFunc(FD) || isDtorRSFunc(FD)) { if (FD->getNumParams() != 0) { - Diags->Report( - clang::FullSourceLoc(FD->getLocation(), Diags->getSourceManager()), - Diags->getCustomDiagID(clang::Diagnostic::Error, - "%0(void) is required to have no " - "parameters")) << FD->getName(); + DiagEngine->Report( + clang::FullSourceLoc(FD->getLocation(), + DiagEngine->getSourceManager()), + DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error, + "%0(void) is required to have no " + "parameters")) << FD->getName(); valid = false; } if (FD->getResultType().getCanonicalType() != C.VoidTy) { - Diags->Report( - clang::FullSourceLoc(FD->getLocation(), Diags->getSourceManager()), - Diags->getCustomDiagID(clang::Diagnostic::Error, - "%0(void) is required to have a void " - "return type")) << FD->getName(); + DiagEngine->Report( + clang::FullSourceLoc(FD->getLocation(), + DiagEngine->getSourceManager()), + DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error, + "%0(void) is required to have a void " + "return type")) << FD->getName(); valid = false; } } else { diff --git a/slang_rs_export_foreach.h b/slang_rs_export_foreach.h index 13fd3a7..0143110 100644 --- a/slang_rs_export_foreach.h +++ b/slang_rs_export_foreach.h @@ -154,7 +154,7 @@ class RSExportForEach : public RSExportable { return isRootRSFunc(FD) || isInitRSFunc(FD) || isDtorRSFunc(FD); } - static bool validateSpecialFuncDecl(clang::Diagnostic *Diags, + static bool validateSpecialFuncDecl(clang::DiagnosticsEngine *DiagEngine, const clang::FunctionDecl *FD); }; // RSExportForEach diff --git a/slang_rs_export_func.cpp b/slang_rs_export_func.cpp index 24370cd..6abae26 100644 --- a/slang_rs_export_func.cpp +++ b/slang_rs_export_func.cpp @@ -32,16 +32,16 @@ namespace slang { namespace { // Ensure that the exported function is actually valid -static bool ValidateFuncDecl(clang::Diagnostic *Diags, +static bool ValidateFuncDecl(clang::DiagnosticsEngine *DiagEngine, const clang::FunctionDecl *FD) { - slangAssert(Diags && FD); + slangAssert(DiagEngine && FD); const clang::ASTContext &C = FD->getASTContext(); if (FD->getResultType().getCanonicalType() != C.VoidTy) { - Diags->Report( - clang::FullSourceLoc(FD->getLocation(), Diags->getSourceManager()), - Diags->getCustomDiagID(clang::Diagnostic::Error, - "invokable non-static functions are required " - "to return void")); + DiagEngine->Report( + clang::FullSourceLoc(FD->getLocation(), DiagEngine->getSourceManager()), + DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error, + "invokable non-static functions are " + "required to return void")); return false; } return true; diff --git a/slang_rs_export_type.cpp b/slang_rs_export_type.cpp index a5f4b86..0c28e30 100644 --- a/slang_rs_export_type.cpp +++ b/slang_rs_export_type.cpp @@ -45,49 +45,49 @@ namespace { static const clang::Type *TypeExportableHelper( const clang::Type *T, llvm::SmallPtrSet<const clang::Type*, 8>& SPS, - clang::Diagnostic *Diags, + clang::DiagnosticsEngine *DiagEngine, const clang::VarDecl *VD, const clang::RecordDecl *TopLevelRecord); -static void ReportTypeError(clang::Diagnostic *Diags, +static void ReportTypeError(clang::DiagnosticsEngine *DiagEngine, const clang::VarDecl *VD, const clang::RecordDecl *TopLevelRecord, const char *Message) { - if (!Diags) { + if (!DiagEngine) { return; } - const clang::SourceManager &SM = Diags->getSourceManager(); + const clang::SourceManager &SM = DiagEngine->getSourceManager(); // Attempt to use the type declaration first (if we have one). // Fall back to the variable definition, if we are looking at something // like an array declaration that can't be exported. if (TopLevelRecord) { - Diags->Report(clang::FullSourceLoc(TopLevelRecord->getLocation(), SM), - Diags->getCustomDiagID(clang::Diagnostic::Error, Message)) - << TopLevelRecord->getName(); + DiagEngine->Report( + clang::FullSourceLoc(TopLevelRecord->getLocation(), SM), + DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error, Message)) + << TopLevelRecord->getName(); } else if (VD) { - Diags->Report(clang::FullSourceLoc(VD->getLocation(), SM), - Diags->getCustomDiagID(clang::Diagnostic::Error, Message)) - << VD->getName(); + DiagEngine->Report( + clang::FullSourceLoc(VD->getLocation(), SM), + DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error, Message)) + << VD->getName(); } else { slangAssert(false && "Variables should be validated before exporting"); } - - return; } static const clang::Type *ConstantArrayTypeExportableHelper( const clang::ConstantArrayType *CAT, llvm::SmallPtrSet<const clang::Type*, 8>& SPS, - clang::Diagnostic *Diags, + clang::DiagnosticsEngine *DiagEngine, const clang::VarDecl *VD, const clang::RecordDecl *TopLevelRecord) { // Check element type const clang::Type *ElementType = GET_CONSTANT_ARRAY_ELEMENT_TYPE(CAT); if (ElementType->isArrayType()) { - ReportTypeError(Diags, VD, TopLevelRecord, - "multidimensional arrays cannot be exported: '%0'"); + ReportTypeError(DiagEngine, VD, TopLevelRecord, + "multidimensional arrays cannot be exported: '%0'"); return NULL; } else if (ElementType->isExtVectorType()) { const clang::ExtVectorType *EVT = @@ -96,30 +96,32 @@ static const clang::Type *ConstantArrayTypeExportableHelper( const clang::Type *BaseElementType = GET_EXT_VECTOR_ELEMENT_TYPE(EVT); if (!RSExportPrimitiveType::IsPrimitiveType(BaseElementType)) { - ReportTypeError(Diags, VD, TopLevelRecord, - "vectors of non-primitive types cannot be exported: '%0'"); + ReportTypeError(DiagEngine, VD, TopLevelRecord, + "vectors of non-primitive types cannot be exported: '%0'"); return NULL; } if (numElements == 3 && CAT->getSize() != 1) { - ReportTypeError(Diags, VD, TopLevelRecord, - "arrays of width 3 vector types cannot be exported: '%0'"); + ReportTypeError(DiagEngine, VD, TopLevelRecord, + "arrays of width 3 vector types cannot be exported: '%0'"); return NULL; } } - if (TypeExportableHelper(ElementType, SPS, Diags, VD, TopLevelRecord) == NULL) + if (TypeExportableHelper(ElementType, SPS, DiagEngine, VD, + TopLevelRecord) == NULL) return NULL; else return CAT; } static const clang::Type *TypeExportableHelper( - const clang::Type *T, - llvm::SmallPtrSet<const clang::Type*, 8>& SPS, - clang::Diagnostic *Diags, - const clang::VarDecl *VD, - const clang::RecordDecl *TopLevelRecord) { + clang::Type const *T, + llvm::SmallPtrSet<clang::Type const *, 8> &SPS, + clang::DiagnosticsEngine *DiagEngine, + clang::VarDecl const *VD, + clang::RecordDecl const *TopLevelRecord) +{ // Normalize first if ((T = GET_CANONICAL_TYPE(T)) == NULL) return NULL; @@ -149,8 +151,8 @@ static const clang::Type *TypeExportableHelper( // Check internal struct if (T->isUnionType()) { - ReportTypeError(Diags, NULL, T->getAsUnionType()->getDecl(), - "unions cannot be exported: '%0'"); + ReportTypeError(DiagEngine, NULL, T->getAsUnionType()->getDecl(), + "unions cannot be exported: '%0'"); return NULL; } else if (!T->isStructureType()) { slangAssert(false && "Unknown type cannot be exported"); @@ -161,8 +163,8 @@ static const clang::Type *TypeExportableHelper( if (RD != NULL) { RD = RD->getDefinition(); if (RD == NULL) { - ReportTypeError(Diags, NULL, T->getAsStructureType()->getDecl(), - "struct is not defined in this module"); + ReportTypeError(DiagEngine, NULL, T->getAsStructureType()->getDecl(), + "struct is not defined in this module"); return NULL; } } @@ -171,8 +173,8 @@ static const clang::Type *TypeExportableHelper( TopLevelRecord = RD; } if (RD->getName().empty()) { - ReportTypeError(Diags, NULL, RD, - "anonymous structures cannot be exported"); + ReportTypeError(DiagEngine, NULL, RD, + "anonymous structures cannot be exported"); return NULL; } @@ -192,7 +194,7 @@ static const clang::Type *TypeExportableHelper( const clang::Type *FT = RSExportType::GetTypeOfDecl(FD); FT = GET_CANONICAL_TYPE(FT); - if (!TypeExportableHelper(FT, SPS, Diags, VD, TopLevelRecord)) { + if (!TypeExportableHelper(FT, SPS, DiagEngine, VD, TopLevelRecord)) { return NULL; } @@ -200,13 +202,15 @@ static const clang::Type *TypeExportableHelper( // // TODO(zonr/srhines): allow bit fields of size 8, 16, 32 if (FD->isBitField()) { - if (Diags) { - Diags->Report(clang::FullSourceLoc(FD->getLocation(), - Diags->getSourceManager()), - Diags->getCustomDiagID(clang::Diagnostic::Error, - "bit fields are not able to be exported: '%0.%1'")) - << RD->getName() - << FD->getName(); + if (DiagEngine) { + DiagEngine->Report( + clang::FullSourceLoc(FD->getLocation(), + DiagEngine->getSourceManager()), + DiagEngine->getCustomDiagID( + clang::DiagnosticsEngine::Error, + "bit fields are not able to be exported: '%0.%1'")) + << RD->getName() + << FD->getName(); } return NULL; } @@ -216,8 +220,8 @@ static const clang::Type *TypeExportableHelper( } case clang::Type::Pointer: { if (TopLevelRecord) { - ReportTypeError(Diags, NULL, TopLevelRecord, - "structures containing pointers cannot be exported: '%0'"); + ReportTypeError(DiagEngine, NULL, TopLevelRecord, + "structures containing pointers cannot be exported: '%0'"); return NULL; } @@ -230,7 +234,7 @@ static const clang::Type *TypeExportableHelper( // We don't support pointer with array-type pointee or unsupported pointee // type if (PointeeType->isArrayType() || - (TypeExportableHelper(PointeeType, SPS, Diags, VD, + (TypeExportableHelper(PointeeType, SPS, DiagEngine, VD, TopLevelRecord) == NULL)) return NULL; else @@ -247,7 +251,7 @@ static const clang::Type *TypeExportableHelper( const clang::Type *ElementType = GET_EXT_VECTOR_ELEMENT_TYPE(EVT); if ((ElementType->getTypeClass() != clang::Type::Builtin) || - (TypeExportableHelper(ElementType, SPS, Diags, VD, + (TypeExportableHelper(ElementType, SPS, DiagEngine, VD, TopLevelRecord) == NULL)) return NULL; else @@ -257,7 +261,7 @@ static const clang::Type *TypeExportableHelper( const clang::ConstantArrayType *CAT = UNSAFE_CAST_TYPE(const clang::ConstantArrayType, T); - return ConstantArrayTypeExportableHelper(CAT, SPS, Diags, VD, + return ConstantArrayTypeExportableHelper(CAT, SPS, DiagEngine, VD, TopLevelRecord); } default: { @@ -268,18 +272,18 @@ static const clang::Type *TypeExportableHelper( // Return the type that can be used to create RSExportType, will always return // the canonical type -// If the Type T is not exportable, this function returns NULL. Diags is +// If the Type T is not exportable, this function returns NULL. DiagEngine is // used to generate proper Clang diagnostic messages when a // non-exportable type is detected. TopLevelRecord is used to capture the // highest struct (in the case of a nested hierarchy) for detecting other // types that cannot be exported (mostly pointers within a struct). static const clang::Type *TypeExportable(const clang::Type *T, - clang::Diagnostic *Diags, + clang::DiagnosticsEngine *DiagEngine, const clang::VarDecl *VD) { llvm::SmallPtrSet<const clang::Type*, 8> SPS = llvm::SmallPtrSet<const clang::Type*, 8>(); - return TypeExportableHelper(T, SPS, Diags, VD, NULL); + return TypeExportableHelper(T, SPS, DiagEngine, VD, NULL); } static bool ValidateVarDeclHelper( @@ -391,25 +395,25 @@ static bool ValidateVarDeclHelper( /****************************** RSExportType ******************************/ bool RSExportType::NormalizeType(const clang::Type *&T, llvm::StringRef &TypeName, - clang::Diagnostic *Diags, + clang::DiagnosticsEngine *DiagEngine, const clang::VarDecl *VD) { - if ((T = TypeExportable(T, Diags, VD)) == NULL) { + if ((T = TypeExportable(T, DiagEngine, VD)) == NULL) { return false; } // Get type name TypeName = RSExportType::GetTypeName(T); if (TypeName.empty()) { - if (Diags) { + if (DiagEngine) { if (VD) { - Diags->Report(clang::FullSourceLoc(VD->getLocation(), - Diags->getSourceManager()), - Diags->getCustomDiagID(clang::Diagnostic::Error, - "anonymous types cannot " - "be exported")); + DiagEngine->Report( + clang::FullSourceLoc(VD->getLocation(), + DiagEngine->getSourceManager()), + DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error, + "anonymous types cannot be exported")); } else { - Diags->Report(Diags->getCustomDiagID(clang::Diagnostic::Error, - "anonymous types cannot " - "be exported")); + DiagEngine->Report( + DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error, + "anonymous types cannot be exported")); } } return false; @@ -607,10 +611,11 @@ RSExportType *RSExportType::Create(RSContext *Context, break; } default: { - clang::Diagnostic *Diags = Context->getDiagnostics(); - Diags->Report(Diags->getCustomDiagID(clang::Diagnostic::Error, - "unknown type cannot be exported: '%0'")) - << T->getTypeClassName(); + clang::DiagnosticsEngine *DiagEngine = Context->getDiagnostics(); + DiagEngine->Report( + DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error, + "unknown type cannot be exported: '%0'")) + << T->getTypeClassName(); break; } } @@ -817,10 +822,12 @@ RSExportPrimitiveType::GetDataType(RSContext *Context, const clang::Type *T) { // The size of type WChar depend on platform so we abandon the support // to them. default: { - clang::Diagnostic *Diags = Context->getDiagnostics(); - Diags->Report(Diags->getCustomDiagID(clang::Diagnostic::Error, - "built-in type cannot be exported: '%0'")) - << T->getTypeClassName(); + clang::DiagnosticsEngine *DiagEngine = Context->getDiagnostics(); + DiagEngine->Report( + DiagEngine->getCustomDiagID( + clang::DiagnosticsEngine::Error, + "built-in type cannot be exported: '%0'")) + << T->getTypeClassName(); break; } } @@ -831,9 +838,10 @@ RSExportPrimitiveType::GetDataType(RSContext *Context, const clang::Type *T) { return RSExportPrimitiveType::GetRSSpecificType(T); } default: { - clang::Diagnostic *Diags = Context->getDiagnostics(); - Diags->Report(Diags->getCustomDiagID(clang::Diagnostic::Error, - "primitive type cannot be exported: '%0'")) + clang::DiagnosticsEngine *DiagEngine = Context->getDiagnostics(); + DiagEngine->Report( + DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error, + "primitive type cannot be exported: '%0'")) << T->getTypeClassName(); break; } @@ -1088,14 +1096,15 @@ RSExportMatrixType *RSExportMatrixType::Create(RSContext *Context, const clang::RecordDecl* RD = RT->getDecl(); RD = RD->getDefinition(); if (RD != NULL) { - clang::Diagnostic *Diags = Context->getDiagnostics(); + clang::DiagnosticsEngine *DiagEngine = Context->getDiagnostics(); const clang::SourceManager *SM = Context->getSourceManager(); // Find definition, perform further examination if (RD->field_empty()) { - Diags->Report(clang::FullSourceLoc(RD->getLocation(), *SM), - Diags->getCustomDiagID(clang::Diagnostic::Error, - "invalid matrix struct: must have 1 field for saving " - "values: '%0'")) + DiagEngine->Report( + clang::FullSourceLoc(RD->getLocation(), *SM), + DiagEngine->getCustomDiagID( + clang::DiagnosticsEngine::Error, + "invalid matrix struct: must have 1 field for saving values: '%0'")) << RD->getName(); return NULL; } @@ -1104,11 +1113,12 @@ RSExportMatrixType *RSExportMatrixType::Create(RSContext *Context, const clang::FieldDecl *FD = *FIT; const clang::Type *FT = RSExportType::GetTypeOfDecl(FD); if ((FT == NULL) || (FT->getTypeClass() != clang::Type::ConstantArray)) { - Diags->Report(clang::FullSourceLoc(RD->getLocation(), *SM), - Diags->getCustomDiagID(clang::Diagnostic::Error, - "invalid matrix struct: first field should be an " - "array with constant size: '%0'")) - << RD->getName(); + DiagEngine->Report( + clang::FullSourceLoc(RD->getLocation(), *SM), + DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error, + "invalid matrix struct: first field should" + " be an array with constant size: '%0'")) + << RD->getName(); return NULL; } const clang::ConstantArrayType *CAT = @@ -1116,33 +1126,35 @@ RSExportMatrixType *RSExportMatrixType::Create(RSContext *Context, const clang::Type *ElementType = GET_CONSTANT_ARRAY_ELEMENT_TYPE(CAT); if ((ElementType == NULL) || (ElementType->getTypeClass() != clang::Type::Builtin) || - (static_cast<const clang::BuiltinType *>(ElementType)->getKind() - != clang::BuiltinType::Float)) { - Diags->Report(clang::FullSourceLoc(RD->getLocation(), *SM), - Diags->getCustomDiagID(clang::Diagnostic::Error, - "invalid matrix struct: first field should be a " - "float array: '%0'")) - << RD->getName(); + (static_cast<const clang::BuiltinType *>(ElementType)->getKind() != + clang::BuiltinType::Float)) { + DiagEngine->Report( + clang::FullSourceLoc(RD->getLocation(), *SM), + DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error, + "invalid matrix struct: first field " + "should be a float array: '%0'")) + << RD->getName(); return NULL; } if (CAT->getSize() != Dim * Dim) { - Diags->Report(clang::FullSourceLoc(RD->getLocation(), *SM), - Diags->getCustomDiagID(clang::Diagnostic::Error, - "invalid matrix struct: first field should be an " - "array with size %0: '%1'")) - << Dim * Dim - << RD->getName(); + DiagEngine->Report( + clang::FullSourceLoc(RD->getLocation(), *SM), + DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error, + "invalid matrix struct: first field " + "should be an array with size %0: '%1'")) + << (Dim * Dim) << (RD->getName()); return NULL; } FIT++; if (FIT != RD->field_end()) { - Diags->Report(clang::FullSourceLoc(RD->getLocation(), *SM), - Diags->getCustomDiagID(clang::Diagnostic::Error, - "invalid matrix struct: must have exactly 1 field: " - "'%0'")) - << RD->getName(); + DiagEngine->Report( + clang::FullSourceLoc(RD->getLocation(), *SM), + DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error, + "invalid matrix struct: must have " + "exactly 1 field: '%0'")) + << RD->getName(); return NULL; } } @@ -1270,7 +1282,7 @@ RSExportRecordType *RSExportRecordType::Create(RSContext *Context, FE = RD->field_end(); FI != FE; FI++, Index++) { - clang::Diagnostic *Diags = Context->getDiagnostics(); + clang::DiagnosticsEngine *DiagEngine = Context->getDiagnostics(); // FIXME: All fields should be primitive type slangAssert((*FI)->getKind() == clang::Decl::Field); @@ -1288,12 +1300,11 @@ RSExportRecordType *RSExportRecordType::Create(RSContext *Context, new Field(ET, FD->getName(), ERT, static_cast<size_t>(RL->getFieldOffset(Index) >> 3))); } else { - Diags->Report(clang::FullSourceLoc(RD->getLocation(), - Diags->getSourceManager()), - Diags->getCustomDiagID(clang::Diagnostic::Error, - "field type cannot be exported: '%0.%1'")) - << RD->getName() - << FD->getName(); + DiagEngine->Report( + clang::FullSourceLoc(RD->getLocation(), DiagEngine->getSourceManager()), + DiagEngine->getCustomDiagID(clang::DiagnosticsEngine::Error, + "field type cannot be exported: '%0.%1'")) + << RD->getName() << FD->getName(); return NULL; } } diff --git a/slang_rs_export_type.h b/slang_rs_export_type.h index 1834506..fcb2f1b 100644 --- a/slang_rs_export_type.h +++ b/slang_rs_export_type.h @@ -126,7 +126,7 @@ class RSExportType : public RSExportable { // If it is not, this function returns false. Otherwise it returns true. static bool NormalizeType(const clang::Type *&T, llvm::StringRef &TypeName, - clang::Diagnostic *Diags, + clang::DiagnosticsEngine *Diags, const clang::VarDecl *VD); // This function ensures that the VarDecl can be properly handled by RS. diff --git a/slang_rs_object_ref_count.cpp b/slang_rs_object_ref_count.cpp index 88ffc62..f4ce728 100644 --- a/slang_rs_object_ref_count.cpp +++ b/slang_rs_object_ref_count.cpp @@ -1061,10 +1061,12 @@ static clang::Stmt *CreateStructRSSetObject(clang::ASTContext &C, RSExportPrimitiveType::GetRSSpecificType(FT); if (IsArrayType) { - clang::Diagnostic &Diags = C.getDiagnostics(); - Diags.Report(clang::FullSourceLoc(Loc, C.getSourceManager()), - Diags.getCustomDiagID(clang::Diagnostic::Error, - "Arrays of RS object types within structures cannot be copied")); + clang::DiagnosticsEngine &DiagEngine = C.getDiagnostics(); + DiagEngine.Report( + clang::FullSourceLoc(Loc, C.getSourceManager()), + DiagEngine.getCustomDiagID( + clang::DiagnosticsEngine::Error, + "Arrays of RS object types within structures cannot be copied")); // TODO(srhines): Support setting arrays of RS objects // StmtArray[StmtCount++] = // CreateArrayRSSetObject(C, DstMember, SrcMember, StartLoc, Loc); |