blob: 0dc70e613edad704b0398f7df617a96ac62adf26 [file] [log] [blame]
Zonr Changc383a502010-10-12 01:52:08 +08001/*
Stephen Hines7b51b552012-02-16 00:12:38 -08002 * Copyright 2010-2012, The Android Open Source Project
Zonr Changc383a502010-10-12 01:52:08 +08003 *
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
Stephen Hinese639eb52010-11-08 19:27:20 -080017#ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_BACKEND_H_ // NOLINT
18#define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_BACKEND_H_
Shih-wei Liao462aefd2010-06-04 15:32:04 -070019
zonr6315f762010-10-05 15:35:14 +080020#include "slang_backend.h"
21#include "slang_pragma_recorder.h"
Stephen Hines4b32ffd2010-11-05 18:47:11 -070022#include "slang_rs_object_ref_count.h"
Shih-wei Liao462aefd2010-06-04 15:32:04 -070023
Shih-wei Liao462aefd2010-06-04 15:32:04 -070024namespace llvm {
zonr6315f762010-10-05 15:35:14 +080025 class NamedMDNode;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070026}
Shih-wei Liao462aefd2010-06-04 15:32:04 -070027
28namespace clang {
zonr6315f762010-10-05 15:35:14 +080029 class ASTConsumer;
Logan Chien9207a2e2011-10-21 15:39:28 +080030 class DiagnosticsEngine;
zonr6315f762010-10-05 15:35:14 +080031 class TargetOptions;
zonr6315f762010-10-05 15:35:14 +080032 class CodeGenerator;
33 class ASTContext;
34 class DeclGroupRef;
Stephen Hinescfae0f32010-11-01 18:57:31 -070035 class FunctionDecl;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070036}
Shih-wei Liao462aefd2010-06-04 15:32:04 -070037
38namespace slang {
39
Shih-wei Liao462aefd2010-06-04 15:32:04 -070040class RSContext;
41
42class RSBackend : public Backend {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070043 private:
44 RSContext *mContext;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070045
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080046 clang::SourceManager &mSourceMgr;
47
48 bool mAllowRSPrefix;
49
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070050 llvm::NamedMDNode *mExportVarMetadata;
51 llvm::NamedMDNode *mExportFuncMetadata;
Stephen Hines7b51b552012-02-16 00:12:38 -080052 llvm::NamedMDNode *mExportForEachNameMetadata;
53 llvm::NamedMDNode *mExportForEachSignatureMetadata;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070054 llvm::NamedMDNode *mExportTypeMetadata;
55 llvm::NamedMDNode *mExportElementMetadata;
Stephen Hinesb3a12fe2011-01-26 20:16:38 -080056 llvm::NamedMDNode *mRSObjectSlotsMetadata;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070057
Stephen Hines4b32ffd2010-11-05 18:47:11 -070058 RSObjectRefCount mRefCount;
59
Stephen Hinescfae0f32010-11-01 18:57:31 -070060 void AnnotateFunction(clang::FunctionDecl *FD);
61
Zonr Chang68fc02c2010-10-13 19:09:19 +080062 protected:
Stephen Hines4cc499d2011-08-24 19:06:17 -070063 virtual unsigned int getTargetAPI() const {
64 return mContext->getTargetAPI();
65 }
66
Logan Chienfa6ef562011-11-25 13:50:02 +080067 virtual bool HandleTopLevelDecl(clang::DeclGroupRef D);
Zonr Chang68fc02c2010-10-13 19:09:19 +080068
Stephen Hinesc97a3332010-11-30 15:31:08 -080069 virtual void HandleTranslationUnitPre(clang::ASTContext &C);
Stephen Hinesfcda2352010-10-19 16:49:32 -070070
Zonr Chang68fc02c2010-10-13 19:09:19 +080071 virtual void HandleTranslationUnitPost(llvm::Module *M);
Shih-wei Liao462aefd2010-06-04 15:32:04 -070072
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070073 public:
74 RSBackend(RSContext *Context,
Logan Chien9207a2e2011-10-21 15:39:28 +080075 clang::DiagnosticsEngine *DiagEngine,
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070076 const clang::CodeGenOptions &CodeGenOpts,
77 const clang::TargetOptions &TargetOpts,
Stephen Hines3fd0a942011-01-18 12:27:39 -080078 PragmaList *Pragmas,
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070079 llvm::raw_ostream *OS,
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080080 Slang::OutputType OT,
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070081 clang::SourceManager &SourceMgr,
Stephen Hines4a4bf922011-08-18 17:20:33 -070082 bool AllowRSPrefix);
Shih-wei Liao462aefd2010-06-04 15:32:04 -070083
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070084 virtual ~RSBackend();
85};
Stephen Hinese67239d2012-02-24 15:08:36 -080086} // namespace slang
Shih-wei Liao462aefd2010-06-04 15:32:04 -070087
Stephen Hinese639eb52010-11-08 19:27:20 -080088#endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_BACKEND_H_ NOLINT