slang_rs_reflection_cpp.h revision 2ce118e843fcbd53488b503933136bb4fdbdfbc1
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#include <set> 23#include <string> 24 25#define RS_EXPORT_VAR_PREFIX "mExportVar_" 26 27namespace slang { 28 29class RSReflectionCpp : public RSReflectionBase { 30public: 31 explicit RSReflectionCpp(const RSContext *); 32 virtual ~RSReflectionCpp(); 33 34 bool reflect(const std::string &OutputPathBase, 35 const std::string &InputFileName, 36 const std::string &OutputBCFileName); 37 38private: 39 unsigned int mNextExportVarSlot; 40 unsigned int mNextExportFuncSlot; 41 unsigned int mNextExportForEachSlot; 42 43 inline void clear() { 44 mNextExportVarSlot = 0; 45 mNextExportFuncSlot = 0; 46 mNextExportForEachSlot = 0; 47 mTypesToCheck.clear(); 48 } 49 50 inline unsigned int getNextExportVarSlot() { return mNextExportVarSlot++; } 51 52 inline unsigned int getNextExportFuncSlot() { return mNextExportFuncSlot++; } 53 54 inline unsigned int getNextExportForEachSlot() { 55 return mNextExportForEachSlot++; 56 } 57 58 bool makeHeader(const std::string &baseClass); 59 bool makeImpl(const std::string &baseClass); 60 void makeFunctionSignature(std::stringstream &ss, bool isDefinition, 61 const RSExportFunc *ef); 62 bool writeBC(); 63 64 bool startScriptHeader(); 65 66 // Write out code for an export variable initialization. 67 void genInitExportVariable(const RSExportType *ET, const std::string &VarName, 68 const clang::APValue &Val); 69 void genZeroInitExportVariable(const std::string &VarName); 70 void genInitBoolExportVariable(const std::string &VarName, 71 const clang::APValue &Val); 72 void genInitPrimitiveExportVariable(const std::string &VarName, 73 const clang::APValue &Val); 74 75 // Produce an argument string of the form "T1 t, T2 u, T3 v". 76 void makeArgs(std::stringstream &ss, const ArgTy &Args); 77 78 // Write out code for an export variable. 79 void genExportVariable(const RSExportVar *EV); 80 81 void genPrimitiveTypeExportVariable(const RSExportVar *EV); 82 void genPointerTypeExportVariable(const RSExportVar *EV); 83 void genVectorTypeExportVariable(const RSExportVar *EV); 84 void genMatrixTypeExportVariable(const RSExportVar *EV); 85 void genConstantArrayTypeExportVariable(const RSExportVar *EV); 86 void genRecordTypeExportVariable(const RSExportVar *EV); 87 88 // Write out a local FieldPacker (if necessary). 89 bool genCreateFieldPacker(const RSExportType *T, const char *FieldPackerName); 90 91 // Populate (write) the FieldPacker with add() operations. 92 void genPackVarOfType(const RSExportType *ET, const char *VarName, 93 const char *FieldPackerName); 94 95 // Generate a runtime type check for VarName. 96 void genTypeCheck(const RSExportType *ET, const char *VarName); 97 98 // Generate a type instance for a given forEach argument type. 99 void genTypeInstanceFromPointer(const RSExportType *ET); 100 void genTypeInstance(const RSExportType *ET); 101 102}; // class RSReflectionCpp 103 104} // namespace slang 105 106#endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_REFLECTION_CPP_H_ NOLINT 107