1 /* 2 * Copyright 2010-2012, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_BACKEND_H_ // NOLINT 18 #define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_BACKEND_H_ 19 20 #include "slang_backend.h" 21 #include "slang_pragma_recorder.h" 22 #include "slang_rs_check_ast.h" 23 #include "slang_rs_object_ref_count.h" 24 25 namespace llvm { 26 class NamedMDNode; 27 } 28 29 namespace clang { 30 class ASTConsumer; 31 class DiagnosticsEngine; 32 class TargetOptions; 33 class CodeGenerator; 34 class ASTContext; 35 class DeclGroupRef; 36 class FunctionDecl; 37 } 38 39 namespace slang { 40 41 class RSContext; 42 43 class RSBackend : public Backend { 44 private: 45 RSContext *mContext; 46 47 clang::SourceManager &mSourceMgr; 48 49 bool mAllowRSPrefix; 50 51 bool mIsFilterscript; 52 53 llvm::NamedMDNode *mExportVarMetadata; 54 llvm::NamedMDNode *mExportFuncMetadata; 55 llvm::NamedMDNode *mExportForEachNameMetadata; 56 llvm::NamedMDNode *mExportForEachSignatureMetadata; 57 llvm::NamedMDNode *mExportTypeMetadata; 58 llvm::NamedMDNode *mExportElementMetadata; 59 llvm::NamedMDNode *mRSObjectSlotsMetadata; 60 61 RSObjectRefCount mRefCount; 62 63 RSCheckAST mASTChecker; 64 65 void AnnotateFunction(clang::FunctionDecl *FD); 66 67 void dumpExportVarInfo(llvm::Module *M); 68 void dumpExportFunctionInfo(llvm::Module *M); 69 void dumpExportForEachInfo(llvm::Module *M); 70 void dumpExportTypeInfo(llvm::Module *M); 71 72 protected: getTargetAPI()73 virtual unsigned int getTargetAPI() const { 74 return mContext->getTargetAPI(); 75 } 76 77 virtual bool HandleTopLevelDecl(clang::DeclGroupRef D); 78 79 virtual void HandleTranslationUnitPre(clang::ASTContext &C); 80 81 virtual void HandleTranslationUnitPost(llvm::Module *M); 82 83 public: 84 RSBackend(RSContext *Context, 85 clang::DiagnosticsEngine *DiagEngine, 86 const clang::CodeGenOptions &CodeGenOpts, 87 const clang::TargetOptions &TargetOpts, 88 PragmaList *Pragmas, 89 llvm::raw_ostream *OS, 90 Slang::OutputType OT, 91 clang::SourceManager &SourceMgr, 92 bool AllowRSPrefix, 93 bool IsFilterscript); 94 95 virtual ~RSBackend(); 96 }; 97 } // namespace slang 98 99 #endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_BACKEND_H_ NOLINT 100