blob: a8fef0e951a8000d940be421dc0b0024cedca00b [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 Hines11274a72012-09-26 19:14:20 -070022#include "slang_rs_check_ast.h"
Stephen Hines4b32ffd2010-11-05 18:47:11 -070023#include "slang_rs_object_ref_count.h"
Shih-wei Liao462aefd2010-06-04 15:32:04 -070024
Shih-wei Liao462aefd2010-06-04 15:32:04 -070025namespace llvm {
zonr6315f762010-10-05 15:35:14 +080026 class NamedMDNode;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070027}
Shih-wei Liao462aefd2010-06-04 15:32:04 -070028
29namespace clang {
zonr6315f762010-10-05 15:35:14 +080030 class ASTConsumer;
Logan Chien9207a2e2011-10-21 15:39:28 +080031 class DiagnosticsEngine;
zonr6315f762010-10-05 15:35:14 +080032 class TargetOptions;
zonr6315f762010-10-05 15:35:14 +080033 class CodeGenerator;
34 class ASTContext;
35 class DeclGroupRef;
Stephen Hinescfae0f32010-11-01 18:57:31 -070036 class FunctionDecl;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070037}
Shih-wei Liao462aefd2010-06-04 15:32:04 -070038
39namespace slang {
40
Shih-wei Liao462aefd2010-06-04 15:32:04 -070041class RSContext;
42
43class RSBackend : public Backend {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070044 private:
45 RSContext *mContext;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070046
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080047 clang::SourceManager &mSourceMgr;
48
49 bool mAllowRSPrefix;
50
Stephen Hines11274a72012-09-26 19:14:20 -070051 bool mIsFilterscript;
52
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070053 llvm::NamedMDNode *mExportVarMetadata;
54 llvm::NamedMDNode *mExportFuncMetadata;
Stephen Hines7b51b552012-02-16 00:12:38 -080055 llvm::NamedMDNode *mExportForEachNameMetadata;
56 llvm::NamedMDNode *mExportForEachSignatureMetadata;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070057 llvm::NamedMDNode *mExportTypeMetadata;
Stephen Hinesb3a12fe2011-01-26 20:16:38 -080058 llvm::NamedMDNode *mRSObjectSlotsMetadata;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070059
Stephen Hines4b32ffd2010-11-05 18:47:11 -070060 RSObjectRefCount mRefCount;
61
Stephen Hines11274a72012-09-26 19:14:20 -070062 RSCheckAST mASTChecker;
63
Stephen Hinescfae0f32010-11-01 18:57:31 -070064 void AnnotateFunction(clang::FunctionDecl *FD);
65
Tobias Grosserd460f622013-07-23 10:37:23 -070066 void dumpExportVarInfo(llvm::Module *M);
67 void dumpExportFunctionInfo(llvm::Module *M);
68 void dumpExportForEachInfo(llvm::Module *M);
69 void dumpExportTypeInfo(llvm::Module *M);
70
Zonr Chang68fc02c2010-10-13 19:09:19 +080071 protected:
Chris Wailesc9454af2014-06-13 17:25:40 -070072 virtual unsigned int getTargetAPI() const {
Stephen Hines4cc499d2011-08-24 19:06:17 -070073 return mContext->getTargetAPI();
74 }
75
Logan Chienfa6ef562011-11-25 13:50:02 +080076 virtual bool HandleTopLevelDecl(clang::DeclGroupRef D);
Zonr Chang68fc02c2010-10-13 19:09:19 +080077
Stephen Hinesc97a3332010-11-30 15:31:08 -080078 virtual void HandleTranslationUnitPre(clang::ASTContext &C);
Stephen Hinesfcda2352010-10-19 16:49:32 -070079
Zonr Chang68fc02c2010-10-13 19:09:19 +080080 virtual void HandleTranslationUnitPost(llvm::Module *M);
Shih-wei Liao462aefd2010-06-04 15:32:04 -070081
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070082 public:
83 RSBackend(RSContext *Context,
Logan Chien9207a2e2011-10-21 15:39:28 +080084 clang::DiagnosticsEngine *DiagEngine,
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070085 const clang::CodeGenOptions &CodeGenOpts,
86 const clang::TargetOptions &TargetOpts,
Stephen Hines3fd0a942011-01-18 12:27:39 -080087 PragmaList *Pragmas,
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070088 llvm::raw_ostream *OS,
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080089 Slang::OutputType OT,
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070090 clang::SourceManager &SourceMgr,
Stephen Hines11274a72012-09-26 19:14:20 -070091 bool AllowRSPrefix,
92 bool IsFilterscript);
Shih-wei Liao462aefd2010-06-04 15:32:04 -070093
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070094 virtual ~RSBackend();
95};
Stephen Hinese67239d2012-02-24 15:08:36 -080096} // namespace slang
Shih-wei Liao462aefd2010-06-04 15:32:04 -070097
Stephen Hinese639eb52010-11-08 19:27:20 -080098#endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_BACKEND_H_ NOLINT