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