slang_rs_backend.h revision e3cb21bc8654181da174ac441acec7726b5a78ec
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_object_ref_count.h"
23
24namespace llvm {
25  class NamedMDNode;
26}
27
28namespace clang {
29  class ASTConsumer;
30  class DiagnosticsEngine;
31  class TargetOptions;
32  class CodeGenerator;
33  class ASTContext;
34  class DeclGroupRef;
35  class FunctionDecl;
36}
37
38namespace slang {
39
40class RSContext;
41
42class RSBackend : public Backend {
43 private:
44  RSContext *mContext;
45
46  clang::SourceManager &mSourceMgr;
47
48  bool mAllowRSPrefix;
49
50  llvm::NamedMDNode *mExportVarMetadata;
51  llvm::NamedMDNode *mExportFuncMetadata;
52  llvm::NamedMDNode *mExportForEachNameMetadata;
53  llvm::NamedMDNode *mExportForEachSignatureMetadata;
54  llvm::NamedMDNode *mExportTypeMetadata;
55  llvm::NamedMDNode *mExportElementMetadata;
56  llvm::NamedMDNode *mRSObjectSlotsMetadata;
57  llvm::NamedMDNode *mRSOptimizationMetadata;
58
59  RSObjectRefCount mRefCount;
60
61  void AnnotateFunction(clang::FunctionDecl *FD);
62
63 protected:
64  virtual unsigned int getTargetAPI() const {
65    return mContext->getTargetAPI();
66  }
67
68  virtual bool HandleTopLevelDecl(clang::DeclGroupRef D);
69
70  virtual void HandleTranslationUnitPre(clang::ASTContext &C);
71
72  virtual void HandleTranslationUnitPost(llvm::Module *M);
73
74 public:
75  RSBackend(RSContext *Context,
76            clang::DiagnosticsEngine *DiagEngine,
77            const clang::CodeGenOptions &CodeGenOpts,
78            const clang::TargetOptions &TargetOpts,
79            PragmaList *Pragmas,
80            llvm::raw_ostream *OS,
81            Slang::OutputType OT,
82            clang::SourceManager &SourceMgr,
83            bool AllowRSPrefix);
84
85  virtual ~RSBackend();
86};
87}  // namespace slang
88
89#endif  // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_BACKEND_H_  NOLINT
90