Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 1 | /* |
Stephen Hines | 9999ec3 | 2012-02-10 18:22:14 -0800 | [diff] [blame] | 2 | * Copyright 2011-2012, The Android Open Source Project |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 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_EXPORT_FOREACH_H_ // NOLINT |
| 18 | #define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_FOREACH_H_ |
| 19 | |
| 20 | #include "llvm/ADT/StringRef.h" |
| 21 | #include "llvm/Support/raw_ostream.h" |
| 22 | |
| 23 | #include "clang/AST/Decl.h" |
| 24 | |
| 25 | #include "slang_assert.h" |
| 26 | #include "slang_rs_context.h" |
| 27 | #include "slang_rs_exportable.h" |
| 28 | #include "slang_rs_export_type.h" |
| 29 | |
| 30 | namespace clang { |
| 31 | class FunctionDecl; |
| 32 | } // namespace clang |
| 33 | |
| 34 | namespace slang { |
| 35 | |
| 36 | // Base class for reflecting control-side forEach (currently for root() |
| 37 | // functions that fit appropriate criteria) |
| 38 | class RSExportForEach : public RSExportable { |
| 39 | private: |
| 40 | std::string mName; |
| 41 | RSExportRecordType *mParamPacketType; |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 42 | RSExportType *mInType; |
| 43 | RSExportType *mOutType; |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 44 | size_t numParams; |
| 45 | |
Stephen Hines | 7b51b55 | 2012-02-16 00:12:38 -0800 | [diff] [blame] | 46 | unsigned int mSignatureMetadata; |
Stephen Hines | 4ccf75e | 2011-08-16 18:21:01 -0700 | [diff] [blame] | 47 | |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 48 | const clang::ParmVarDecl *mIn; |
| 49 | const clang::ParmVarDecl *mOut; |
| 50 | const clang::ParmVarDecl *mUsrData; |
| 51 | const clang::ParmVarDecl *mX; |
| 52 | const clang::ParmVarDecl *mY; |
| 53 | const clang::ParmVarDecl *mZ; |
| 54 | const clang::ParmVarDecl *mAr; |
| 55 | |
Stephen Hines | c17e198 | 2012-02-22 12:30:45 -0800 | [diff] [blame] | 56 | bool mDummyRoot; |
| 57 | |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 58 | // TODO(all): Add support for LOD/face when we have them |
Stephen Hines | c17e198 | 2012-02-22 12:30:45 -0800 | [diff] [blame] | 59 | RSExportForEach(RSContext *Context, const llvm::StringRef &Name) |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 60 | : RSExportable(Context, RSExportable::EX_FOREACH), |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 61 | mName(Name.data(), Name.size()), mParamPacketType(NULL), mInType(NULL), |
Stephen Hines | 7b51b55 | 2012-02-16 00:12:38 -0800 | [diff] [blame] | 62 | mOutType(NULL), numParams(0), mSignatureMetadata(0), |
Stephen Hines | 4ccf75e | 2011-08-16 18:21:01 -0700 | [diff] [blame] | 63 | mIn(NULL), mOut(NULL), mUsrData(NULL), |
Stephen Hines | c17e198 | 2012-02-22 12:30:45 -0800 | [diff] [blame] | 64 | mX(NULL), mY(NULL), mZ(NULL), mAr(NULL), mDummyRoot(false) { |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 65 | return; |
| 66 | } |
| 67 | |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 68 | bool validateAndConstructParams(RSContext *Context, |
| 69 | const clang::FunctionDecl *FD); |
| 70 | |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 71 | public: |
| 72 | static RSExportForEach *Create(RSContext *Context, |
| 73 | const clang::FunctionDecl *FD); |
| 74 | |
Stephen Hines | c17e198 | 2012-02-22 12:30:45 -0800 | [diff] [blame] | 75 | static RSExportForEach *CreateDummyRoot(RSContext *Context); |
| 76 | |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 77 | inline const std::string &getName() const { |
| 78 | return mName; |
| 79 | } |
| 80 | |
| 81 | inline size_t getNumParameters() const { |
| 82 | return numParams; |
| 83 | } |
| 84 | |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 85 | inline bool hasIn() const { |
| 86 | return (mIn != NULL); |
| 87 | } |
| 88 | |
| 89 | inline bool hasOut() const { |
| 90 | return (mOut != NULL); |
| 91 | } |
| 92 | |
| 93 | inline bool hasUsrData() const { |
| 94 | return (mUsrData != NULL); |
| 95 | } |
| 96 | |
| 97 | inline const RSExportType *getInType() const { |
| 98 | return mInType; |
| 99 | } |
| 100 | |
| 101 | inline const RSExportType *getOutType() const { |
| 102 | return mOutType; |
| 103 | } |
| 104 | |
| 105 | inline const RSExportRecordType *getParamPacketType() const { |
| 106 | return mParamPacketType; |
| 107 | } |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 108 | |
Stephen Hines | 7b51b55 | 2012-02-16 00:12:38 -0800 | [diff] [blame] | 109 | inline unsigned int getSignatureMetadata() const { |
| 110 | return mSignatureMetadata; |
Stephen Hines | 4ccf75e | 2011-08-16 18:21:01 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Stephen Hines | c17e198 | 2012-02-22 12:30:45 -0800 | [diff] [blame] | 113 | inline bool isDummyRoot() const { |
| 114 | return mDummyRoot; |
| 115 | } |
| 116 | |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 117 | typedef RSExportRecordType::const_field_iterator const_param_iterator; |
| 118 | |
| 119 | inline const_param_iterator params_begin() const { |
| 120 | slangAssert((mParamPacketType != NULL) && |
| 121 | "Get parameter from export foreach having no parameter!"); |
| 122 | return mParamPacketType->fields_begin(); |
| 123 | } |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 124 | |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 125 | inline const_param_iterator params_end() const { |
| 126 | slangAssert((mParamPacketType != NULL) && |
| 127 | "Get parameter from export foreach having no parameter!"); |
| 128 | return mParamPacketType->fields_end(); |
| 129 | } |
| 130 | |
| 131 | inline static bool isInitRSFunc(const clang::FunctionDecl *FD) { |
| 132 | if (!FD) { |
| 133 | return false; |
| 134 | } |
| 135 | const llvm::StringRef Name = FD->getName(); |
| 136 | static llvm::StringRef FuncInit("init"); |
| 137 | return Name.equals(FuncInit); |
| 138 | } |
| 139 | |
| 140 | inline static bool isRootRSFunc(const clang::FunctionDecl *FD) { |
| 141 | if (!FD) { |
| 142 | return false; |
| 143 | } |
| 144 | const llvm::StringRef Name = FD->getName(); |
| 145 | static llvm::StringRef FuncRoot("root"); |
| 146 | return Name.equals(FuncRoot); |
| 147 | } |
| 148 | |
Stephen Hines | 688e64b | 2011-08-23 16:01:25 -0700 | [diff] [blame] | 149 | inline static bool isDtorRSFunc(const clang::FunctionDecl *FD) { |
| 150 | if (!FD) { |
| 151 | return false; |
| 152 | } |
| 153 | const llvm::StringRef Name = FD->getName(); |
| 154 | static llvm::StringRef FuncDtor(".rs.dtor"); |
| 155 | return Name.equals(FuncDtor); |
| 156 | } |
| 157 | |
Stephen Hines | 9999ec3 | 2012-02-10 18:22:14 -0800 | [diff] [blame] | 158 | static bool isGraphicsRootRSFunc(int targetAPI, |
| 159 | const clang::FunctionDecl *FD); |
| 160 | |
Stephen Hines | f736d5a | 2011-10-26 16:18:14 -0700 | [diff] [blame] | 161 | static bool isRSForEachFunc(int targetAPI, const clang::FunctionDecl *FD); |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 162 | |
Stephen Hines | 9999ec3 | 2012-02-10 18:22:14 -0800 | [diff] [blame] | 163 | inline static bool isSpecialRSFunc(int targetAPI, |
| 164 | const clang::FunctionDecl *FD) { |
| 165 | return isGraphicsRootRSFunc(targetAPI, FD) || isInitRSFunc(FD) || |
| 166 | isDtorRSFunc(FD); |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Stephen Hines | f736d5a | 2011-10-26 16:18:14 -0700 | [diff] [blame] | 169 | static bool validateSpecialFuncDecl(int targetAPI, |
Stephen Hines | fbfd7f5 | 2011-10-27 16:09:01 -0700 | [diff] [blame] | 170 | clang::DiagnosticsEngine *DiagEngine, |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 171 | const clang::FunctionDecl *FD); |
| 172 | }; // RSExportForEach |
| 173 | |
| 174 | } // namespace slang |
| 175 | |
| 176 | #endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_FOREACH_H_ NOLINT |