Zonr Chang | c383a50 | 2010-10-12 01:52:08 +0800 | [diff] [blame] | 1 | /* |
Stephen Hines | 0a813a3 | 2012-08-03 16:52:40 -0700 | [diff] [blame] | 2 | * Copyright 2010-2012, The Android Open Source Project |
Zonr Chang | c383a50 | 2010-10-12 01:52:08 +0800 | [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 | |
Jean-Luc Brouillet | 2ce118e | 2014-05-27 17:41:22 -0700 | [diff] [blame] | 17 | #ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_REFLECTION_H_ // NOLINT |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 18 | #define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_REFLECTION_H_ |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 19 | |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 20 | #include <fstream> |
| 21 | #include <iostream> |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 22 | #include <map> |
Stephen Hines | 48b72bf | 2011-06-10 15:37:27 -0700 | [diff] [blame] | 23 | #include <set> |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 24 | #include <string> |
| 25 | #include <vector> |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 26 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 27 | #include "llvm/ADT/StringExtras.h" |
| 28 | |
Stephen Hines | 6e6578a | 2011-02-07 18:05:48 -0800 | [diff] [blame] | 29 | #include "slang_assert.h" |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 30 | #include "slang_rs_export_type.h" |
Jean-Luc Brouillet | f33e156 | 2014-06-03 17:55:57 -0700 | [diff] [blame] | 31 | #include "slang_rs_reflect_utils.h" |
David Gross | d80e58b | 2017-07-24 11:41:12 -0700 | [diff] [blame] | 32 | #include "slang_rs_reflection_state.h" |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 33 | |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 34 | namespace slang { |
| 35 | |
Jean-Luc Brouillet | 2ce118e | 2014-05-27 17:41:22 -0700 | [diff] [blame] | 36 | class RSContext; |
| 37 | class RSExportVar; |
| 38 | class RSExportFunc; |
| 39 | class RSExportForEach; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 40 | |
Jean-Luc Brouillet | 602def7 | 2014-05-27 16:11:37 -0700 | [diff] [blame] | 41 | class RSReflectionJava { |
Jean-Luc Brouillet | 2ce118e | 2014-05-27 17:41:22 -0700 | [diff] [blame] | 42 | private: |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 43 | const RSContext *mRSContext; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 44 | |
David Gross | d80e58b | 2017-07-24 11:41:12 -0700 | [diff] [blame] | 45 | ReflectionState *mState; |
| 46 | |
| 47 | // If we're in the "collecting" state (according to mState), we |
| 48 | // don't actually generate code, but we do want to keep track of |
| 49 | // some information about what we WOULD generate. |
| 50 | const bool mCollecting; |
| 51 | |
Jean-Luc Brouillet | 59f22c3 | 2014-06-04 14:53:48 -0700 | [diff] [blame] | 52 | // The name of the Java package name we're creating this file for, |
| 53 | // e.g. com.example.android.rs.flashlight |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 54 | std::string mPackageName; |
Jean-Luc Brouillet | 59f22c3 | 2014-06-04 14:53:48 -0700 | [diff] [blame] | 55 | // The name of the Java Renderscript package we'll be using, |
| 56 | // e.g. android.renderscript |
| 57 | // e.g. android.support.v8.renderscript |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 58 | std::string mRSPackageName; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 59 | |
Jean-Luc Brouillet | 59f22c3 | 2014-06-04 14:53:48 -0700 | [diff] [blame] | 60 | // The directory under which we'll create the Java files, in appropriate subdirectories, |
| 61 | // e.g. /tmp/myout |
| 62 | std::string mOutputBaseDirectory; |
| 63 | // The output directory for the specfied package (mPackageName), |
| 64 | // e.g. /tmp/myout/com/example/android/rs/flashlight/ |
| 65 | // TODO This includes the terminating separator. Needed? |
| 66 | std::string mOutputDirectory; |
| 67 | |
| 68 | // The full path of the .rs file that we are reflecting. |
| 69 | std::string mRSSourceFileName; |
| 70 | // The full path where the generated bit code can be read. |
| 71 | std::string mBitCodeFileName; |
| 72 | |
| 73 | // The name of the resource we pass to the RenderScript constructor |
| 74 | // e.g. flashlight |
| 75 | std::string mResourceId; |
| 76 | // The name of the Java class we are generating for this script. |
| 77 | // e.g. ScriptC_flashlight |
| 78 | std::string mScriptClassName; |
| 79 | |
Jean-Luc Brouillet | 59f22c3 | 2014-06-04 14:53:48 -0700 | [diff] [blame] | 80 | // This is set by startClass() and will change for the multiple classes generated. |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 81 | std::string mClassName; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 82 | |
Tim Murray | 3a38b74 | 2014-07-02 10:41:08 -0700 | [diff] [blame] | 83 | // This is the token used for determining the size of a given ScriptField.Item. |
| 84 | std::string mItemSizeof; |
| 85 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 86 | bool mEmbedBitcodeInJava; |
Stephen Hines | 44d495d | 2014-05-22 19:42:55 -0700 | [diff] [blame] | 87 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 88 | int mNextExportVarSlot; |
| 89 | int mNextExportFuncSlot; |
| 90 | int mNextExportForEachSlot; |
Matt Wala | 7682b66 | 2015-07-30 15:53:47 -0700 | [diff] [blame] | 91 | int mNextExportReduceSlot; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 92 | |
Jean-Luc Brouillet | f33e156 | 2014-06-03 17:55:57 -0700 | [diff] [blame] | 93 | GeneratedFile mOut; |
| 94 | |
Jean-Luc Brouillet | 59f22c3 | 2014-06-04 14:53:48 -0700 | [diff] [blame] | 95 | std::string mLastError; |
| 96 | std::vector<std::string> *mGeneratedFileNames; |
| 97 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 98 | // A mapping from a field in a record type to its index in the rsType |
| 99 | // instance. Only used when generates TypeClass (ScriptField_*). |
David Gross | d80e58b | 2017-07-24 11:41:12 -0700 | [diff] [blame] | 100 | // |
| 101 | // .first = field index |
| 102 | // .second = when compiling for both 32-bit and 64-bit (RSCCOptions::mEmit3264), |
| 103 | // and we are reflecting 64-bit code, this is field index for 32-bit; |
| 104 | // otherwise, it is undefined |
| 105 | typedef std::map<const RSExportRecordType::Field *, std::pair<unsigned,unsigned> > FieldIndexMapTy; |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 106 | FieldIndexMapTy mFieldIndexMap; |
| 107 | // Field index of current processing TypeClass. |
David Gross | d80e58b | 2017-07-24 11:41:12 -0700 | [diff] [blame] | 108 | unsigned mFieldIndex; // corresponds to FieldIndexMapTy::mapped_type.first |
| 109 | unsigned mField32Index; // corresponds to FieldIndexMapTy::mapped_type.second |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 110 | |
Jean-Luc Brouillet | 59f22c3 | 2014-06-04 14:53:48 -0700 | [diff] [blame] | 111 | inline void setError(const std::string &Error) { mLastError = Error; } |
| 112 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 113 | inline void clear() { |
| 114 | mClassName = ""; |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 115 | mNextExportVarSlot = 0; |
| 116 | mNextExportFuncSlot = 0; |
| 117 | mNextExportForEachSlot = 0; |
Matt Wala | 7682b66 | 2015-07-30 15:53:47 -0700 | [diff] [blame] | 118 | mNextExportReduceSlot = 0; |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 119 | } |
Shih-wei Liao | 9c631ff | 2010-09-17 11:57:29 -0700 | [diff] [blame] | 120 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 121 | public: |
| 122 | typedef enum { |
| 123 | AM_Public, |
| 124 | AM_Protected, |
| 125 | AM_Private, |
| 126 | AM_PublicSynchronized |
| 127 | } AccessModifier; |
Zonr Chang | 8c6d9b2 | 2010-10-07 18:01:19 +0800 | [diff] [blame] | 128 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 129 | // Generated RS Elements for type-checking code. |
| 130 | std::set<std::string> mTypesToCheck; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 131 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 132 | // Generated FieldPackers for unsigned setters/validation. |
| 133 | std::set<std::string> mFieldPackerTypes; |
Stephen Hines | 48b72bf | 2011-06-10 15:37:27 -0700 | [diff] [blame] | 134 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 135 | bool addTypeNameForElement(const std::string &TypeName); |
| 136 | bool addTypeNameForFieldPacker(const std::string &TypeName); |
Stephen Hines | 1f6c331 | 2012-07-03 17:23:33 -0700 | [diff] [blame] | 137 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 138 | static const char *AccessModifierStr(AccessModifier AM); |
Stephen Hines | 1f6c331 | 2012-07-03 17:23:33 -0700 | [diff] [blame] | 139 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 140 | inline bool getEmbedBitcodeInJava() const { return mEmbedBitcodeInJava; } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 141 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 142 | inline int getNextExportVarSlot() { return mNextExportVarSlot++; } |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 143 | inline int getNextExportFuncSlot() { return mNextExportFuncSlot++; } |
| 144 | inline int getNextExportForEachSlot() { return mNextExportForEachSlot++; } |
Matt Wala | 7682b66 | 2015-07-30 15:53:47 -0700 | [diff] [blame] | 145 | inline int getNextExportReduceSlot() { return mNextExportReduceSlot++; } |
Stephen Hines | 44d495d | 2014-05-22 19:42:55 -0700 | [diff] [blame] | 146 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 147 | bool startClass(AccessModifier AM, bool IsStatic, |
| 148 | const std::string &ClassName, const char *SuperClassName, |
| 149 | std::string &ErrorMsg); |
| 150 | void endClass(); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 151 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 152 | void startFunction(AccessModifier AM, bool IsStatic, const char *ReturnType, |
| 153 | const std::string &FunctionName, int Argc, ...); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 154 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 155 | typedef std::vector<std::pair<std::string, std::string>> ArgTy; |
| 156 | void startFunction(AccessModifier AM, bool IsStatic, const char *ReturnType, |
| 157 | const std::string &FunctionName, const ArgTy &Args); |
| 158 | void endFunction(); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 159 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 160 | inline const std::string &getPackageName() const { return mPackageName; } |
| 161 | inline const std::string &getRSPackageName() const { return mRSPackageName; } |
| 162 | inline const std::string &getClassName() const { return mClassName; } |
| 163 | inline const std::string &getResourceId() const { return mResourceId; } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 164 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 165 | void startTypeClass(const std::string &ClassName); |
| 166 | void endTypeClass(); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 167 | |
David Gross | d80e58b | 2017-07-24 11:41:12 -0700 | [diff] [blame] | 168 | enum { FieldIndex = 0x1, Field32Index = 0x2 }; // bitmask |
| 169 | inline void incFieldIndex(unsigned Which) { |
| 170 | slangAssert(!(Which & ~(FieldIndex | Field32Index))); |
| 171 | if (Which & FieldIndex ) mFieldIndex++; |
| 172 | if (Which & Field32Index) mField32Index++; |
| 173 | } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 174 | |
David Gross | d80e58b | 2017-07-24 11:41:12 -0700 | [diff] [blame] | 175 | inline void resetFieldIndex() { mFieldIndex = mField32Index = 0; } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 176 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 177 | inline void addFieldIndexMapping(const RSExportRecordType::Field *F) { |
| 178 | slangAssert((mFieldIndexMap.find(F) == mFieldIndexMap.end()) && |
| 179 | "Nested structure never occurs in C language."); |
David Gross | d80e58b | 2017-07-24 11:41:12 -0700 | [diff] [blame] | 180 | mFieldIndexMap.insert(std::make_pair(F, std::make_pair(mFieldIndex, mField32Index))); |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 181 | } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 182 | |
David Gross | d80e58b | 2017-07-24 11:41:12 -0700 | [diff] [blame] | 183 | inline std::pair<unsigned, unsigned> getFieldIndex(const RSExportRecordType::Field *F) const { |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 184 | FieldIndexMapTy::const_iterator I = mFieldIndexMap.find(F); |
| 185 | slangAssert((I != mFieldIndexMap.end()) && |
| 186 | "Requesting field is out of scope."); |
| 187 | return I->second; |
| 188 | } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 189 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 190 | inline void clearFieldIndexMap() { mFieldIndexMap.clear(); } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 191 | |
David Gross | 47cf31e | 2017-05-31 15:17:00 -0700 | [diff] [blame] | 192 | enum { |
| 193 | TypeNameWithConstantArrayBrackets = 0x01, |
| 194 | TypeNameWithRecordElementName = 0x02, |
David Gross | d80e58b | 2017-07-24 11:41:12 -0700 | [diff] [blame] | 195 | |
| 196 | // Three major flavors of types: |
| 197 | // - Java |
| 198 | // - C |
| 199 | // - PseudoC -- Identical to C for all types supported by C; |
| 200 | // for other types, uses a simplified C-like syntax |
| 201 | TypeNameC = 0x04, |
| 202 | TypeNamePseudoC = 0x08, |
| 203 | |
David Gross | 47cf31e | 2017-05-31 15:17:00 -0700 | [diff] [blame] | 204 | TypeNameDefault = TypeNameWithConstantArrayBrackets|TypeNameWithRecordElementName |
| 205 | }; |
| 206 | static std::string GetTypeName(const RSExportType *ET, unsigned Style = TypeNameDefault); |
| 207 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 208 | private: |
David Gross | 1c6bf88 | 2016-06-02 14:46:55 -0700 | [diff] [blame] | 209 | static bool exportableReduce(const RSExportType *ResultType); |
David Gross | 277fd5e | 2016-01-14 12:19:56 -0800 | [diff] [blame] | 210 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 211 | bool genScriptClass(const std::string &ClassName, std::string &ErrorMsg); |
| 212 | void genScriptClassConstructor(); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 213 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 214 | void genInitBoolExportVariable(const std::string &VarName, |
| 215 | const clang::APValue &Val); |
| 216 | void genInitPrimitiveExportVariable(const std::string &VarName, |
| 217 | const clang::APValue &Val); |
| 218 | void genInitExportVariable(const RSExportType *ET, const std::string &VarName, |
| 219 | const clang::APValue &Val); |
Jean-Luc Brouillet | efcff10 | 2014-06-03 16:13:51 -0700 | [diff] [blame] | 220 | void genInitValue(const clang::APValue &Val, bool asBool); |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 221 | void genExportVariable(const RSExportVar *EV); |
| 222 | void genPrimitiveTypeExportVariable(const RSExportVar *EV); |
| 223 | void genPointerTypeExportVariable(const RSExportVar *EV); |
| 224 | void genVectorTypeExportVariable(const RSExportVar *EV); |
| 225 | void genMatrixTypeExportVariable(const RSExportVar *EV); |
David Gross | d80e58b | 2017-07-24 11:41:12 -0700 | [diff] [blame] | 226 | void genConstantArrayTypeExportVariable(const RSExportVar *EV, ReflectionState::Val32 AllocSize32); |
| 227 | void genRecordTypeExportVariable(const RSExportVar *EV, ReflectionState::Val32 AllocSize32); |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 228 | void genPrivateExportVariable(const std::string &TypeName, |
Stephen Hines | 0d26cef | 2012-05-01 19:23:01 -0700 | [diff] [blame] | 229 | const std::string &VarName); |
David Gross | d80e58b | 2017-07-24 11:41:12 -0700 | [diff] [blame] | 230 | void genSetExportVariable(const std::string &TypeName, const RSExportVar *EV, unsigned Dimension, |
| 231 | ReflectionState::Val32 AllocSize32 = ReflectionState::NoVal32()); |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 232 | void genGetExportVariable(const std::string &TypeName, |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 233 | const std::string &VarName); |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 234 | void genGetFieldID(const std::string &VarName); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 235 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 236 | void genExportFunction(const RSExportFunc *EF); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 237 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 238 | void genExportForEach(const RSExportForEach *EF); |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 239 | |
Matt Wala | 7682b66 | 2015-07-30 15:53:47 -0700 | [diff] [blame] | 240 | void genExportReduce(const RSExportReduce *ER); |
David Gross | 1c6bf88 | 2016-06-02 14:46:55 -0700 | [diff] [blame] | 241 | void genExportReduceAllocationVariant(const RSExportReduce *ER); |
| 242 | void genExportReduceArrayVariant(const RSExportReduce *ER); |
| 243 | void genExportReduceResultType(const RSExportType *ResultType); |
David Gross | 277fd5e | 2016-01-14 12:19:56 -0800 | [diff] [blame] | 244 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 245 | void genTypeCheck(const RSExportType *ET, const char *VarName); |
Stephen Hines | 48b72bf | 2011-06-10 15:37:27 -0700 | [diff] [blame] | 246 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 247 | void genTypeInstanceFromPointer(const RSExportType *ET); |
Stephen Hines | a6b5414 | 2012-04-09 18:25:08 -0700 | [diff] [blame] | 248 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 249 | void genTypeInstance(const RSExportType *ET); |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 250 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 251 | void genFieldPackerInstance(const RSExportType *ET); |
Stephen Hines | 1f6c331 | 2012-07-03 17:23:33 -0700 | [diff] [blame] | 252 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 253 | bool genTypeClass(const RSExportRecordType *ERT, std::string &ErrorMsg); |
| 254 | void genTypeItemClass(const RSExportRecordType *ERT); |
| 255 | void genTypeClassConstructor(const RSExportRecordType *ERT); |
| 256 | void genTypeClassCopyToArray(const RSExportRecordType *ERT); |
| 257 | void genTypeClassCopyToArrayLocal(const RSExportRecordType *ERT); |
| 258 | void genTypeClassItemSetter(const RSExportRecordType *ERT); |
| 259 | void genTypeClassItemGetter(const RSExportRecordType *ERT); |
| 260 | void genTypeClassComponentSetter(const RSExportRecordType *ERT); |
| 261 | void genTypeClassComponentGetter(const RSExportRecordType *ERT); |
| 262 | void genTypeClassCopyAll(const RSExportRecordType *ERT); |
| 263 | void genTypeClassResize(); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 264 | |
David Gross | d80e58b | 2017-07-24 11:41:12 -0700 | [diff] [blame] | 265 | // emits an expression that evaluates to true on a 64-bit target and |
| 266 | // false on a 32-bit target |
| 267 | void genCheck64Bit(bool Parens); |
| 268 | |
| 269 | // emits a fragment of the class definition needed to set up for |
| 270 | // genCheck64Bit() |
| 271 | void genCompute64Bit(); |
| 272 | |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 273 | void genBuildElement(const char *ElementBuilderName, |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 274 | const RSExportRecordType *ERT, |
Jean-Luc Brouillet | 2ce118e | 2014-05-27 17:41:22 -0700 | [diff] [blame] | 275 | const char *RenderScriptVar, bool IsInline); |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 276 | void genAddElementToElementBuilder(const RSExportType *ERT, |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 277 | const std::string &VarName, |
| 278 | const char *ElementBuilderName, |
Zonr Chang | 89273bd | 2010-10-14 20:57:38 +0800 | [diff] [blame] | 279 | const char *RenderScriptVar, |
| 280 | unsigned ArraySize); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 281 | |
David Gross | d80e58b | 2017-07-24 11:41:12 -0700 | [diff] [blame] | 282 | bool genCreateFieldPacker(const RSExportType *T, const char *FieldPackerName, |
| 283 | ReflectionState::Val32 AllocSize32); |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 284 | void genPackVarOfType(const RSExportType *T, const char *VarName, |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 285 | const char *FieldPackerName); |
Jean-Luc Brouillet | 2e205d0 | 2014-06-02 21:06:52 -0700 | [diff] [blame] | 286 | void genAllocateVarOfType(const RSExportType *T, const std::string &VarName); |
| 287 | void genNewItemBufferIfNull(const char *Index); |
| 288 | void genNewItemBufferPackerIfNull(); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 289 | |
Chih-Hung Hsieh | e2ead84 | 2016-08-12 15:57:25 -0700 | [diff] [blame] | 290 | void genPairwiseDimCheck(const std::string &name0, const std::string &name1); |
Matt Wala | 7682b66 | 2015-07-30 15:53:47 -0700 | [diff] [blame] | 291 | void genVectorLengthCompatibilityCheck(const std::string &ArrayName, unsigned VecSize); |
David Gross | 277fd5e | 2016-01-14 12:19:56 -0800 | [diff] [blame] | 292 | void genNullArrayCheck(const std::string &ArrayName); |
Chris Wailes | c9454af | 2014-06-13 17:25:40 -0700 | [diff] [blame] | 293 | |
David Gross | d80e58b | 2017-07-24 11:41:12 -0700 | [diff] [blame] | 294 | // NOTE |
| 295 | // |
| 296 | // If there's a nonempty Prefix, then: |
| 297 | // - If there's a nonzero value to emit, then emit the prefix followed by the value. |
| 298 | // - Otherwise, emit nothing. |
| 299 | // |
| 300 | // If there's an empty Prefix, then |
| 301 | // - Always emit a value, even if zero. |
| 302 | // |
| 303 | void genConditionalVal(const std::string &Prefix, bool Parens, |
| 304 | size_t Val, ReflectionState::Val32 Val32); |
| 305 | |
Jean-Luc Brouillet | 2ce118e | 2014-05-27 17:41:22 -0700 | [diff] [blame] | 306 | public: |
Jean-Luc Brouillet | 59f22c3 | 2014-06-04 14:53:48 -0700 | [diff] [blame] | 307 | RSReflectionJava(const RSContext *Context, |
| 308 | std::vector<std::string> *GeneratedFileNames, |
| 309 | const std::string &OutputBaseDirectory, |
| 310 | const std::string &RSSourceFilename, |
| 311 | const std::string &BitCodeFileName, |
David Gross | d80e58b | 2017-07-24 11:41:12 -0700 | [diff] [blame] | 312 | bool EmbedBitcodeInJava, |
| 313 | ReflectionState *RState); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 314 | |
Jean-Luc Brouillet | 59f22c3 | 2014-06-04 14:53:48 -0700 | [diff] [blame] | 315 | bool reflect(); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 316 | |
| 317 | inline const char *getLastError() const { |
| 318 | if (mLastError.empty()) |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 319 | return nullptr; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 320 | else |
| 321 | return mLastError.c_str(); |
| 322 | } |
Jean-Luc Brouillet | 2ce118e | 2014-05-27 17:41:22 -0700 | [diff] [blame] | 323 | }; // class RSReflectionJava |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 324 | |
Jean-Luc Brouillet | 2ce118e | 2014-05-27 17:41:22 -0700 | [diff] [blame] | 325 | } // namespace slang |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 326 | |
Jean-Luc Brouillet | 2ce118e | 2014-05-27 17:41:22 -0700 | [diff] [blame] | 327 | #endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_REFLECTION_H_ NOLINT |