• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 *mRSObjectSlotsMetadata;
59 
60   RSObjectRefCount mRefCount;
61 
62   RSCheckAST mASTChecker;
63 
64   void AnnotateFunction(clang::FunctionDecl *FD);
65 
66   void dumpExportVarInfo(llvm::Module *M);
67   void dumpExportFunctionInfo(llvm::Module *M);
68   void dumpExportForEachInfo(llvm::Module *M);
69   void dumpExportTypeInfo(llvm::Module *M);
70 
71  protected:
getTargetAPI()72   virtual unsigned int getTargetAPI() const {
73     return mContext->getTargetAPI();
74   }
75 
76   virtual bool HandleTopLevelDecl(clang::DeclGroupRef D);
77 
78   virtual void HandleTranslationUnitPre(clang::ASTContext &C);
79 
80   virtual void HandleTranslationUnitPost(llvm::Module *M);
81 
82  public:
83   RSBackend(RSContext *Context,
84             clang::DiagnosticsEngine *DiagEngine,
85             const clang::CodeGenOptions &CodeGenOpts,
86             const clang::TargetOptions &TargetOpts,
87             PragmaList *Pragmas,
88             llvm::raw_ostream *OS,
89             Slang::OutputType OT,
90             clang::SourceManager &SourceMgr,
91             bool AllowRSPrefix,
92             bool IsFilterscript);
93 
94   virtual ~RSBackend();
95 };
96 }  // namespace slang
97 
98 #endif  // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_BACKEND_H_  NOLINT
99