1 /* 2 * Copyright 2012, The Android Open Source Project 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_REFLECTION_CPP_H_ // NOLINT 18 #define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_REFLECTION_CPP_H_ 19 20 #include "slang_rs_reflection_base.h" 21 22 namespace slang { 23 24 class RSReflectionCpp : public RSReflectionBase { 25 public: 26 explicit RSReflectionCpp(const RSContext *); 27 virtual ~RSReflectionCpp(); 28 29 bool reflect(const std::string &OutputPathBase, 30 const std::string &InputFileName, 31 const std::string &OutputBCFileName); 32 33 34 private: 35 unsigned int mNextExportVarSlot; 36 unsigned int mNextExportFuncSlot; 37 unsigned int mNextExportForEachSlot; 38 clear()39 inline void clear() { 40 mNextExportVarSlot = 0; 41 mNextExportFuncSlot = 0; 42 mNextExportForEachSlot = 0; 43 } 44 getNextExportVarSlot()45 inline unsigned int getNextExportVarSlot() { 46 return mNextExportVarSlot++; 47 } 48 getNextExportFuncSlot()49 inline unsigned int getNextExportFuncSlot() { 50 return mNextExportFuncSlot++; 51 } 52 getNextExportForEachSlot()53 inline unsigned int getNextExportForEachSlot() { 54 return mNextExportForEachSlot++; 55 } 56 57 bool makeHeader(const std::string &baseClass); 58 bool makeImpl(const std::string &baseClass); 59 void makeFunctionSignature(std::stringstream &ss, bool isDefinition, 60 const RSExportFunc *ef); 61 bool writeBC(); 62 63 bool startScriptHeader(); 64 65 // Produce an argument string of the form "T1 t, T2 u, T3 v". 66 void makeArgs(std::stringstream &ss, const ArgTy& Args); 67 68 // Write out code for an export variable. 69 void genExportVariable(const RSExportVar *EV); 70 71 void genPrimitiveTypeExportVariable(const RSExportVar *EV); 72 void genPointerTypeExportVariable(const RSExportVar *EV); 73 void genVectorTypeExportVariable(const RSExportVar *EV); 74 void genMatrixTypeExportVariable(const RSExportVar *EV); 75 void genConstantArrayTypeExportVariable(const RSExportVar *EV); 76 void genRecordTypeExportVariable(const RSExportVar *EV); 77 78 // Write out a local FieldPacker (if necessary). 79 bool genCreateFieldPacker(const RSExportType *T, 80 const char *FieldPackerName); 81 82 // Populate (write) the FieldPacker with add() operations. 83 void genPackVarOfType(const RSExportType *ET, 84 const char *VarName, 85 const char *FieldPackerName); 86 }; // class RSReflectionCpp 87 88 } // namespace slang 89 90 #endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_REFLECTION_CPP_H_ NOLINT 91