1c383a500aa59423264811be3874461bf8adbfea0Zonr Chang/*
27b51b55e4467605a599e868a0dde7cb95c5ab76eStephen Hines * Copyright 2010-2012, The Android Open Source Project
3c383a500aa59423264811be3874461bf8adbfea0Zonr Chang *
4c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * Licensed under the Apache License, Version 2.0 (the "License");
5c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * you may not use this file except in compliance with the License.
6c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * You may obtain a copy of the License at
7c383a500aa59423264811be3874461bf8adbfea0Zonr Chang *
8c383a500aa59423264811be3874461bf8adbfea0Zonr Chang *     http://www.apache.org/licenses/LICENSE-2.0
9c383a500aa59423264811be3874461bf8adbfea0Zonr Chang *
10c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * Unless required by applicable law or agreed to in writing, software
11c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * distributed under the License is distributed on an "AS IS" BASIS,
12c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * See the License for the specific language governing permissions and
14c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * limitations under the License.
15c383a500aa59423264811be3874461bf8adbfea0Zonr Chang */
16c383a500aa59423264811be3874461bf8adbfea0Zonr Chang
17e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_BACKEND_H_  // NOLINT
18e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_BACKEND_H_
19462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
206315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#include "slang_backend.h"
216315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#include "slang_pragma_recorder.h"
2211274a7324b478ec13e1d10a1b81350b34a65ab1Stephen Hines#include "slang_rs_check_ast.h"
234b32ffdfc1ac766f8932e7effbcdf7484e804a8eStephen Hines#include "slang_rs_object_ref_count.h"
24462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
25462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaonamespace llvm {
266315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  class NamedMDNode;
279ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao}
28462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
29462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaonamespace clang {
306315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  class ASTConsumer;
319207a2e495c8363606861e4f034504ec5c153dabLogan Chien  class DiagnosticsEngine;
326315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  class TargetOptions;
336315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  class CodeGenerator;
346315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  class ASTContext;
356315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  class DeclGroupRef;
36cfae0f350e4e0d8f7b4c71780b3f74f58fa23afbStephen Hines  class FunctionDecl;
379ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao}
38462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
39462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaonamespace slang {
40462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
41462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSContext;
42462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
43462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSBackend : public Backend {
449ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private:
459ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  RSContext *mContext;
46462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
473a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang  clang::SourceManager &mSourceMgr;
483a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang
493a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang  bool mAllowRSPrefix;
503a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang
5111274a7324b478ec13e1d10a1b81350b34a65ab1Stephen Hines  bool mIsFilterscript;
5211274a7324b478ec13e1d10a1b81350b34a65ab1Stephen Hines
539ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  llvm::NamedMDNode *mExportVarMetadata;
549ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  llvm::NamedMDNode *mExportFuncMetadata;
557b51b55e4467605a599e868a0dde7cb95c5ab76eStephen Hines  llvm::NamedMDNode *mExportForEachNameMetadata;
567b51b55e4467605a599e868a0dde7cb95c5ab76eStephen Hines  llvm::NamedMDNode *mExportForEachSignatureMetadata;
579ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  llvm::NamedMDNode *mExportTypeMetadata;
58b3a12fe7c18a06f99201dc491a932a90ab7d975cStephen Hines  llvm::NamedMDNode *mRSObjectSlotsMetadata;
59462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
604b32ffdfc1ac766f8932e7effbcdf7484e804a8eStephen Hines  RSObjectRefCount mRefCount;
614b32ffdfc1ac766f8932e7effbcdf7484e804a8eStephen Hines
6211274a7324b478ec13e1d10a1b81350b34a65ab1Stephen Hines  RSCheckAST mASTChecker;
6311274a7324b478ec13e1d10a1b81350b34a65ab1Stephen Hines
64cfae0f350e4e0d8f7b4c71780b3f74f58fa23afbStephen Hines  void AnnotateFunction(clang::FunctionDecl *FD);
65cfae0f350e4e0d8f7b4c71780b3f74f58fa23afbStephen Hines
66d460f623328e2b4ebd05bb93910edb471e6e91d6Tobias Grosser  void dumpExportVarInfo(llvm::Module *M);
67d460f623328e2b4ebd05bb93910edb471e6e91d6Tobias Grosser  void dumpExportFunctionInfo(llvm::Module *M);
68d460f623328e2b4ebd05bb93910edb471e6e91d6Tobias Grosser  void dumpExportForEachInfo(llvm::Module *M);
69d460f623328e2b4ebd05bb93910edb471e6e91d6Tobias Grosser  void dumpExportTypeInfo(llvm::Module *M);
70d460f623328e2b4ebd05bb93910edb471e6e91d6Tobias Grosser
7168fc02ca4a7235e2981be5eee4ad968a9d3928c0Zonr Chang protected:
72c9454afec1649846512993d0ef65a9f868976bb4Chris Wailes  virtual unsigned int getTargetAPI() const {
734cc499d6e5ec602309501873449c938af61170b2Stephen Hines    return mContext->getTargetAPI();
744cc499d6e5ec602309501873449c938af61170b2Stephen Hines  }
754cc499d6e5ec602309501873449c938af61170b2Stephen Hines
76fa6ef56a6ca3dc3061218a75a7e68e5357fcb82cLogan Chien  virtual bool HandleTopLevelDecl(clang::DeclGroupRef D);
7768fc02ca4a7235e2981be5eee4ad968a9d3928c0Zonr Chang
78c97a333bc84ce8c28c96d07734cbded75c914639Stephen Hines  virtual void HandleTranslationUnitPre(clang::ASTContext &C);
79fcda2352b9e140529f8f3c89f05b10a70c0048b2Stephen Hines
8068fc02ca4a7235e2981be5eee4ad968a9d3928c0Zonr Chang  virtual void HandleTranslationUnitPost(llvm::Module *M);
81462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
829ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
839ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  RSBackend(RSContext *Context,
849207a2e495c8363606861e4f034504ec5c153dabLogan Chien            clang::DiagnosticsEngine *DiagEngine,
859ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao            const clang::CodeGenOptions &CodeGenOpts,
869ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao            const clang::TargetOptions &TargetOpts,
873fd0a94a5cf1656569b1aea07043cc63939dcb46Stephen Hines            PragmaList *Pragmas,
889ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao            llvm::raw_ostream *OS,
893a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang            Slang::OutputType OT,
909ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao            clang::SourceManager &SourceMgr,
9111274a7324b478ec13e1d10a1b81350b34a65ab1Stephen Hines            bool AllowRSPrefix,
9211274a7324b478ec13e1d10a1b81350b34a65ab1Stephen Hines            bool IsFilterscript);
93462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
949ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  virtual ~RSBackend();
959ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao};
96e67239de8d94975e7e2216ee6860ae2e6cb8b15aStephen Hines}  // namespace slang
97462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
98e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#endif  // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_BACKEND_H_  NOLINT
99