slang_rs_export_type.h revision cec9b65aa890dea58e39951900ae13efb8d11703
1c383a500aa59423264811be3874461bf8adbfea0Zonr Chang/* 2d5a84f6d49d64738e4bb7c9dea7242e48acad959Stephen Hines * Copyright 2010-2012, The Android Open Source Project 3c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * 4c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * Licensed under the Apache License, Version 2.0 (the "License"); 5c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * you may not use this file except in compliance with the License. 6c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * You may obtain a copy of the License at 7c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * 8c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * http://www.apache.org/licenses/LICENSE-2.0 9c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * 10c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * Unless required by applicable law or agreed to in writing, software 11c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * distributed under the License is distributed on an "AS IS" BASIS, 12c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * See the License for the specific language governing permissions and 14c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * limitations under the License. 15c383a500aa59423264811be3874461bf8adbfea0Zonr Chang */ 16c383a500aa59423264811be3874461bf8adbfea0Zonr Chang 17e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_TYPE_H_ // NOLINT 18e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_TYPE_H_ 19462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 209ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#include <list> 21e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include <set> 229ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#include <string> 23a6b54146b93eec68f6daa4b1877639cdc34801dcStephen Hines#include <sstream> 249ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 25e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "clang/AST/Decl.h" 26e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "clang/AST/Type.h" 27a41ce1d98094da84643995d40d71c529905123fcZonr Chang 286315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#include "llvm/ADT/SmallPtrSet.h" 29e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "llvm/ADT/StringMap.h" 30e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "llvm/ADT/StringRef.h" 316315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr 32e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "llvm/Support/ManagedStatic.h" 336315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr 34a41ce1d98094da84643995d40d71c529905123fcZonr Chang#include "slang_rs_exportable.h" 35a41ce1d98094da84643995d40d71c529905123fcZonr Chang 369ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#define GET_CANONICAL_TYPE(T) \ 372e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang (((T) == NULL) ? NULL : (T)->getCanonicalTypeInternal().getTypePtr()) 389ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#define UNSAFE_CAST_TYPE(TT, T) \ 392e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang static_cast<TT*>(T->getCanonicalTypeInternal().getTypePtr()) 409ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#define GET_EXT_VECTOR_ELEMENT_TYPE(T) \ 412e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang (((T) == NULL) ? NULL : \ 422e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang GET_CANONICAL_TYPE((T)->getElementType().getTypePtr())) 439ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#define GET_POINTEE_TYPE(T) \ 442e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang (((T) == NULL) ? NULL : \ 452e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang GET_CANONICAL_TYPE((T)->getPointeeType().getTypePtr())) 462e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang#define GET_CONSTANT_ARRAY_ELEMENT_TYPE(T) \ 472e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang (((T) == NULL) ? NULL : \ 482e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang GET_CANONICAL_TYPE((T)->getElementType().getTypePtr())) 490da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang#define DUMMY_RS_TYPE_NAME_PREFIX "<" 500da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang#define DUMMY_RS_TYPE_NAME_POSTFIX ">" 512e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang#define DUMMY_TYPE_NAME_FOR_RS_CONSTANT_ARRAY_TYPE \ 52ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray DUMMY_RS_TYPE_NAME_PREFIX "ConstantArray" DUMMY_RS_TYPE_NAME_POSTFIX 53462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 54462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaonamespace llvm { 556315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr class Type; 569ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao} // namespace llvm 57462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 58462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaonamespace slang { 59462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 60cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouilletclass RSContext; 61cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet 62cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet// Broad grouping of the data types 63cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouilletenum DataTypeCategory { 64cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet PrimitiveDataType, 65cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet MatrixDataType, 66cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet ObjectDataType 67cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet}; 68cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet 69cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet// From graphics/java/android/renderscript/Element.java: Element.DataType 70cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet/* NOTE: The values of the enums are found compiled in the bit code (i.e. as 71cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet * values, not symbolic. When adding new types, you must add them to the end. 72cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet * If removing types, you can't re-use the integer value. 73cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet * 74cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet * TODO: but if you do this, you won't be able to keep using First* & Last* 75cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet * for validation. 76cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet * 77cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet * IMPORTANT: This enum should correspond one-for-one to the entries found in the 78cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet * gReflectionsTypes table (except for the two negative numbers). Don't edit one without 79cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet * the other. 80cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet */ 81cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouilletenum DataType { 82cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeIsStruct = -2, 83cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeUnknown = -1, 84462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 85cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeFloat16 = 0, 86cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeFloat32 = 1, 87cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeFloat64 = 2, 88cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeSigned8 = 3, 89cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeSigned16 = 4, 90cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeSigned32 = 5, 91cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeSigned64 = 6, 92cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeUnsigned8 = 7, 93cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeUnsigned16 = 8, 94cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeUnsigned32 = 9, 95cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeUnsigned64 = 10, 96cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeBoolean = 11, 97cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeUnsigned565 = 12, 98cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeUnsigned5551 = 13, 99cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeUnsigned4444 = 14, 100cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet 101cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeRSMatrix2x2 = 15, 102cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeRSMatrix3x3 = 16, 103cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeRSMatrix4x4 = 17, 104cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet 105cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeRSElement = 18, 106cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeRSType = 19, 107cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeRSAllocation = 20, 108cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeRSSampler = 21, 109cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeRSScript = 22, 110cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeRSMesh = 23, 111cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeRSPath = 24, 112cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeRSProgramFragment = 25, 113cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeRSProgramVertex = 26, 114cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeRSProgramRaster = 27, 115cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeRSProgramStore = 28, 116cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeRSFont = 29, 117cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet 118cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet // This should always be last and correspond to the size of the gReflectionTypes table. 119cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet DataTypeMax 120cec9b65aa890dea58e39951900ae13efb8d11703Jean-Luc Brouillet}; 121474655a402e70cb329e1bcd4ebbe00bdc5be4206Jean-Luc Brouillet 122fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hinestypedef struct { 123474655a402e70cb329e1bcd4ebbe00bdc5be4206Jean-Luc Brouillet DataTypeCategory category; 124fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines const char * rs_type; 125fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines const char * rs_short_type; 126fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines uint32_t size_in_bits; 127fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines const char * c_name; 128fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines const char * java_name; 129fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines const char * rs_c_vector_prefix; 130fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines const char * rs_java_vector_prefix; 131fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines bool java_promotion; 132fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines} RSReflectionType; 133fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines 1341b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams 1351b6a0883cd6984e11e59b0c847fb334df1f41afcJason Samstypedef struct RSReflectionTypeData_rec { 1361b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams const RSReflectionType *type; 1371b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams uint32_t vecSize; 1381b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams bool isPointer; 1391b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams uint32_t arraySize; 1401b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams 1411b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams // Subelements 1421b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams //std::vector<const struct RSReflectionTypeData_rec *> fields; 1431b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams //std::vector< std::string > fieldNames; 1441b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams //std::vector< uint32_t> fieldOffsetBytes; 1451b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams} RSReflectionTypeData; 1461b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams 1471b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams 148a41ce1d98094da84643995d40d71c529905123fcZonr Changclass RSExportType : public RSExportable { 1499ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao friend class RSExportElement; 1509ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public: 1519ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao typedef enum { 1529ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao ExportClassPrimitive, 1539ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao ExportClassPointer, 1549ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao ExportClassVector, 15592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang ExportClassMatrix, 1562e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang ExportClassConstantArray, 1579ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao ExportClassRecord 1589ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } ExportClass; 159462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 1601b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams void convertToRTD(RSReflectionTypeData *rtd) const; 1611b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams 1629ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private: 1636b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang ExportClass mClass; 1649ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao std::string mName; 1659ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 1669ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // Cache the result after calling convertToLLVMType() at the first time 1677c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao mutable llvm::Type *mLLVMType; 1689ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 1699ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao protected: 1706b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang RSExportType(RSContext *Context, 1716b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang ExportClass Class, 1726b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang const llvm::StringRef &Name); 1739ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 1749ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // Let's make it private since there're some prerequisites to call this 1759ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // function. 1769ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // 177e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines // @T was normalized by calling RSExportType::NormalizeType(). 1786315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr // @TypeName was retrieve from RSExportType::GetTypeName() before calling 1796315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr // this. 1809ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // 1819ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static RSExportType *Create(RSContext *Context, 1829ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const clang::Type *T, 1836315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr const llvm::StringRef &TypeName); 1849ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 1859ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static llvm::StringRef GetTypeName(const clang::Type *T); 1869ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 1879ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // This function convert the RSExportType to LLVM type. Actually, it should be 1889ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // "convert Clang type to LLVM type." However, clang doesn't make this API 1899ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // (lib/CodeGen/CodeGenTypes.h) public, we need to do by ourselves. 1909ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // 1919ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // Once we can get LLVM type, we can use LLVM to get alignment information, 1929ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // allocation size of a given type and structure layout that LLVM used 1939ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // (all of these information are target dependent) without dealing with these 1949ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // by ourselves. 1957c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao virtual llvm::Type *convertToLLVMType() const = 0; 196e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines // Record type may recursively reference its type definition. We need a 1973cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang // temporary type setup before the type construction gets done. 1987c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao inline void setAbstractLLVMType(llvm::Type *LLVMType) const { 1993cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang mLLVMType = LLVMType; 2003cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang } 2019ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 202a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang virtual ~RSExportType(); 203ecddee364d731c09c77b4c3fa647fa4f50e26756Stephen Hines 2049ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public: 205e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines // This function additionally verifies that the Type T is exportable. 206e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines // If it is not, this function returns false. Otherwise it returns true. 207e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines static bool NormalizeType(const clang::Type *&T, 208e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines llvm::StringRef &TypeName, 20948d893dc7794b3cfb74f35955ca763ee4170f9adStephen Hines RSContext *Context, 2105bfec8dd08b3bde9ba3b331e2115210b0e910eaeStephen Hines const clang::VarDecl *VD); 21178e69cb06b9b0683b2ac9dcafde87b867690ef2fStephen Hines 21211274a7324b478ec13e1d10a1b81350b34a65ab1Stephen Hines // This function checks whether the specified type can be handled by RS/FS. 21311274a7324b478ec13e1d10a1b81350b34a65ab1Stephen Hines // If it cannot, this function returns false. Otherwise it returns true. 21411274a7324b478ec13e1d10a1b81350b34a65ab1Stephen Hines // Filterscript has additional restrictions on supported types. 215d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet static bool ValidateType(slang::RSContext *Context, clang::ASTContext &C, 216d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet clang::QualType QT, clang::NamedDecl *ND, 217d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet clang::SourceLocation Loc, unsigned int TargetAPI, 218d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet bool IsFilterscript); 21911274a7324b478ec13e1d10a1b81350b34a65ab1Stephen Hines 22078e69cb06b9b0683b2ac9dcafde87b867690ef2fStephen Hines // This function ensures that the VarDecl can be properly handled by RS. 22178e69cb06b9b0683b2ac9dcafde87b867690ef2fStephen Hines // If it cannot, this function returns false. Otherwise it returns true. 22211274a7324b478ec13e1d10a1b81350b34a65ab1Stephen Hines // Filterscript has additional restrictions on supported types. 223d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet static bool ValidateVarDecl(slang::RSContext *Context, clang::VarDecl *VD, 224d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet unsigned int TargetAPI, bool IsFilterscript); 22578e69cb06b9b0683b2ac9dcafde87b867690ef2fStephen Hines 2269ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // @T may not be normalized 2279ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static RSExportType *Create(RSContext *Context, const clang::Type *T); 2289ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static RSExportType *CreateFromDecl(RSContext *Context, 2299ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const clang::VarDecl *VD); 2309ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 2319ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static const clang::Type *GetTypeOfDecl(const clang::DeclaratorDecl *DD); 2329ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 2336b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang inline ExportClass getClass() const { return mClass; } 2349ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 2350d26cef64debfaa6862a27587c1fd0d30baa3b1dStephen Hines virtual unsigned getSize() const { return 1; } 2360d26cef64debfaa6862a27587c1fd0d30baa3b1dStephen Hines 2377c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao inline llvm::Type *getLLVMType() const { 2389ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao if (mLLVMType == NULL) 2399ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao mLLVMType = convertToLLVMType(); 2409ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return mLLVMType; 2419ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 242462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 2439ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // Return the number of bits necessary to hold the specified RSExportType 2449ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static size_t GetTypeStoreSize(const RSExportType *ET); 245462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 2469ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // The size of allocation of specified RSExportType (alignment considered) 2479ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static size_t GetTypeAllocSize(const RSExportType *ET); 248462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 249641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang inline const std::string &getName() const { return mName; } 250641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang 251a6b54146b93eec68f6daa4b1877639cdc34801dcStephen Hines virtual std::string getElementName() const { 252a6b54146b93eec68f6daa4b1877639cdc34801dcStephen Hines // Base case is actually an invalid C/Java identifier. 253a6b54146b93eec68f6daa4b1877639cdc34801dcStephen Hines return "@@INVALID@@"; 254a6b54146b93eec68f6daa4b1877639cdc34801dcStephen Hines } 255a6b54146b93eec68f6daa4b1877639cdc34801dcStephen Hines 2563cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang virtual bool keep(); 257641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang virtual bool equals(const RSExportable *E) const; 2589ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao}; // RSExportType 259462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 2609ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao// Primitive types 261462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportPrimitiveType : public RSExportType { 2629ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao friend class RSExportType; 2639ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao friend class RSExportElement; 2649ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private: 265a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang // NOTE: There's no any instance of RSExportPrimitiveType which mType 266a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang // is of the value DataTypeRSMatrix*. DataTypeRSMatrix* enumeration here is 267a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang // only for RSExportPrimitiveType::GetRSObjectType to *recognize* the struct 268a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang // rs_matrix{2x2, 3x3, 4x4}. These matrix type are represented as 269a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang // RSExportMatrixType. 2709ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao DataType mType; 2719ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao bool mNormalized; 2729ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 273b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang typedef llvm::StringMap<DataType> RSSpecificTypeMapTy; 274b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang static llvm::ManagedStatic<RSSpecificTypeMapTy> RSSpecificTypeMap; 2759ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 2769ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static llvm::Type *RSObjectLLVMType; 2779ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 2789ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static const size_t SizeOfDataTypeInBits[]; 279e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines // @T was normalized by calling RSExportType::NormalizeType() before calling 2809ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // this. 2819ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // @TypeName was retrieved from RSExportType::GetTypeName() before calling 2829ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // this 2839ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static RSExportPrimitiveType *Create(RSContext *Context, 2849ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const clang::Type *T, 2859ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const llvm::StringRef &TypeName, 2869ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao bool Normalized = false); 2879ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 2889ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao protected: 2899ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao RSExportPrimitiveType(RSContext *Context, 2906b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang // for derived class to set their type class 2916b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang ExportClass Class, 2929ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const llvm::StringRef &Name, 2939ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao DataType DT, 2946315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr bool Normalized) 2956b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang : RSExportType(Context, Class, Name), 2966315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr mType(DT), 2976315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr mNormalized(Normalized) { 2989ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return; 2999ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 3009ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 3017c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao virtual llvm::Type *convertToLLVMType() const; 3022ef9bc0cfbca2152d972c0975005f8c897c2a42cStephen Hines 3032ef9bc0cfbca2152d972c0975005f8c897c2a42cStephen Hines static DataType GetDataType(RSContext *Context, const clang::Type *T); 3042ef9bc0cfbca2152d972c0975005f8c897c2a42cStephen Hines 3059ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public: 306dd6206bb61bf8df2ed6b643abe8a29c48a315685Stephen Hines // T is normalized by calling RSExportType::NormalizeType() before 307dd6206bb61bf8df2ed6b643abe8a29c48a315685Stephen Hines // calling this 308dd6206bb61bf8df2ed6b643abe8a29c48a315685Stephen Hines static bool IsPrimitiveType(const clang::Type *T); 309dd6206bb61bf8df2ed6b643abe8a29c48a315685Stephen Hines 3109ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // @T may not be normalized 3119ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static RSExportPrimitiveType *Create(RSContext *Context, 3122b8fb64be3047df940a219872b331eb11de2758dStephen Hines const clang::Type *T); 313462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 314b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang static DataType GetRSSpecificType(const llvm::StringRef &TypeName); 315b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang static DataType GetRSSpecificType(const clang::Type *T); 316b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang 317b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang static bool IsRSMatrixType(DataType DT); 318b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang static bool IsRSObjectType(DataType DT); 319f2174cfd6a556b51aadf2b8765e50df080e8f18eStephen Hines static bool IsRSObjectType(const clang::Type *T) { 320f2174cfd6a556b51aadf2b8765e50df080e8f18eStephen Hines return IsRSObjectType(GetRSSpecificType(T)); 321f2174cfd6a556b51aadf2b8765e50df080e8f18eStephen Hines } 322462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 323feaca06fcb0772e9e972a0d61b17259fc5124d50Stephen Hines // Determines whether T is [an array of] struct that contains at least one 324feaca06fcb0772e9e972a0d61b17259fc5124d50Stephen Hines // RS object type within it. 325feaca06fcb0772e9e972a0d61b17259fc5124d50Stephen Hines static bool IsStructureTypeWithRSObject(const clang::Type *T); 326feaca06fcb0772e9e972a0d61b17259fc5124d50Stephen Hines 3279ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static size_t GetSizeInBits(const RSExportPrimitiveType *EPT); 328462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 3299ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline DataType getType() const { return mType; } 3309ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline bool isRSObjectType() const { 331474655a402e70cb329e1bcd4ebbe00bdc5be4206Jean-Luc Brouillet return IsRSObjectType(mType); 3329ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 333641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang 334641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang virtual bool equals(const RSExportable *E) const; 335fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines 336fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines static RSReflectionType *getRSReflectionType(DataType DT); 337fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines static RSReflectionType *getRSReflectionType( 338fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines const RSExportPrimitiveType *EPT) { 339fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines return getRSReflectionType(EPT->getType()); 340fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines } 341a6b54146b93eec68f6daa4b1877639cdc34801dcStephen Hines 3421f6c331d622ac645ab68a016aa4c577998547373Stephen Hines virtual unsigned getSize() const { return (GetSizeInBits(this) >> 3); } 3431f6c331d622ac645ab68a016aa4c577998547373Stephen Hines 344a6b54146b93eec68f6daa4b1877639cdc34801dcStephen Hines std::string getElementName() const { 345a6b54146b93eec68f6daa4b1877639cdc34801dcStephen Hines return getRSReflectionType(this)->rs_short_type; 346a6b54146b93eec68f6daa4b1877639cdc34801dcStephen Hines } 3479ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao}; // RSExportPrimitiveType 348462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 349462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 350462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportPointerType : public RSExportType { 3519ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao friend class RSExportType; 3529ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao friend class RSExportFunc; 3539ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private: 3549ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const RSExportType *mPointeeType; 3559ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 3569ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao RSExportPointerType(RSContext *Context, 3579ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const llvm::StringRef &Name, 3586315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr const RSExportType *PointeeType) 3596b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang : RSExportType(Context, ExportClassPointer, Name), 3606315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr mPointeeType(PointeeType) { 3619ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return; 3629ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 3639ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 364e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines // @PT was normalized by calling RSExportType::NormalizeType() before calling 3659ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // this. 3669ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static RSExportPointerType *Create(RSContext *Context, 3679ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const clang::PointerType *PT, 3689ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const llvm::StringRef &TypeName); 3699ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 3707c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao virtual llvm::Type *convertToLLVMType() const; 371ecddee364d731c09c77b4c3fa647fa4f50e26756Stephen Hines 3729ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public: 3733cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang virtual bool keep(); 374641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang 3759ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline const RSExportType *getPointeeType() const { return mPointeeType; } 376641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang 377641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang virtual bool equals(const RSExportable *E) const; 3789ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao}; // RSExportPointerType 379462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 380462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 381462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportVectorType : public RSExportPrimitiveType { 3829ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao friend class RSExportType; 3839ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao friend class RSExportElement; 3849ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private: 38592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang unsigned mNumElement; // number of element 3869ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 3879ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao RSExportVectorType(RSContext *Context, 3889ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const llvm::StringRef &Name, 3899ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao DataType DT, 3909ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao bool Normalized, 39192b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang unsigned NumElement) 3926b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang : RSExportPrimitiveType(Context, ExportClassVector, Name, 3932b8fb64be3047df940a219872b331eb11de2758dStephen Hines DT, Normalized), 3946315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr mNumElement(NumElement) { 3959ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return; 3969ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 3979ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 398e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines // @EVT was normalized by calling RSExportType::NormalizeType() before 3999ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // calling this. 4009ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static RSExportVectorType *Create(RSContext *Context, 4019ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const clang::ExtVectorType *EVT, 4029ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const llvm::StringRef &TypeName, 4039ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao bool Normalized = false); 4049ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 4057c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao virtual llvm::Type *convertToLLVMType() const; 406ecddee364d731c09c77b4c3fa647fa4f50e26756Stephen Hines 4079ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public: 4089ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static llvm::StringRef GetTypeName(const clang::ExtVectorType *EVT); 409462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 41092b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang inline unsigned getNumElement() const { return mNumElement; } 411641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang 412a6b54146b93eec68f6daa4b1877639cdc34801dcStephen Hines std::string getElementName() const { 413a6b54146b93eec68f6daa4b1877639cdc34801dcStephen Hines std::stringstream Name; 414a6b54146b93eec68f6daa4b1877639cdc34801dcStephen Hines Name << RSExportPrimitiveType::getRSReflectionType(this)->rs_short_type 415a6b54146b93eec68f6daa4b1877639cdc34801dcStephen Hines << "_" << getNumElement(); 416a6b54146b93eec68f6daa4b1877639cdc34801dcStephen Hines return Name.str(); 417a6b54146b93eec68f6daa4b1877639cdc34801dcStephen Hines } 418a6b54146b93eec68f6daa4b1877639cdc34801dcStephen Hines 419641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang virtual bool equals(const RSExportable *E) const; 42092b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang}; 42192b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang 42292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// Only *square* *float* matrix is supported by now. 42392b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// 42492b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// struct rs_matrix{2x2,3x3,4x4, ..., NxN} should be defined as the following 42592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// form *exactly*: 42692b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// typedef struct { 42792b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// float m[{NxN}]; 42892b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// } rs_matrixNxN; 42992b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// 43092b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// where mDim will be N. 43192b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Changclass RSExportMatrixType : public RSExportType { 43292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang friend class RSExportType; 43392b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang private: 4342e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang unsigned mDim; // dimension 43592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang 43692b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang RSExportMatrixType(RSContext *Context, 43792b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang const llvm::StringRef &Name, 43892b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang unsigned Dim) 4396b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang : RSExportType(Context, ExportClassMatrix, Name), 44092b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang mDim(Dim) { 44192b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang return; 44292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang } 44392b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang 4447c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao virtual llvm::Type *convertToLLVMType() const; 445ecddee364d731c09c77b4c3fa647fa4f50e26756Stephen Hines 44692b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang public: 447e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines // @RT was normalized by calling RSExportType::NormalizeType() before 44892b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang // calling this. 44992b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang static RSExportMatrixType *Create(RSContext *Context, 45092b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang const clang::RecordType *RT, 45192b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang const llvm::StringRef &TypeName, 45292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang unsigned Dim); 45392b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang 45492b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang inline unsigned getDim() const { return mDim; } 455641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang 456641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang virtual bool equals(const RSExportable *E) const; 457462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao}; 458462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 4592e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Changclass RSExportConstantArrayType : public RSExportType { 4602e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang friend class RSExportType; 4612e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang private: 4622e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang const RSExportType *mElementType; // Array element type 4632e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang unsigned mSize; // Array size 4642e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang 4652e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang RSExportConstantArrayType(RSContext *Context, 4662e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang const RSExportType *ElementType, 4672e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang unsigned Size) 4682e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang : RSExportType(Context, 4696b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang ExportClassConstantArray, 4702e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang DUMMY_TYPE_NAME_FOR_RS_CONSTANT_ARRAY_TYPE), 4712e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang mElementType(ElementType), 4722e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang mSize(Size) { 4732e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang return; 4742e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang } 4752e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang 476e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines // @CAT was normalized by calling RSExportType::NormalizeType() before 4772e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang // calling this. 4782e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang static RSExportConstantArrayType *Create(RSContext *Context, 4792e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang const clang::ConstantArrayType *CAT); 4802e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang 4817c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao virtual llvm::Type *convertToLLVMType() const; 482ecddee364d731c09c77b4c3fa647fa4f50e26756Stephen Hines 4832e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang public: 4840d26cef64debfaa6862a27587c1fd0d30baa3b1dStephen Hines virtual unsigned getSize() const { return mSize; } 4852e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang inline const RSExportType *getElementType() const { return mElementType; } 486641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang 487a6b54146b93eec68f6daa4b1877639cdc34801dcStephen Hines std::string getElementName() const { 488a6b54146b93eec68f6daa4b1877639cdc34801dcStephen Hines return mElementType->getElementName(); 489a6b54146b93eec68f6daa4b1877639cdc34801dcStephen Hines } 490a6b54146b93eec68f6daa4b1877639cdc34801dcStephen Hines 4913cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang virtual bool keep(); 492641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang virtual bool equals(const RSExportable *E) const; 4932e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang}; 4942e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang 495462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportRecordType : public RSExportType { 4969ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao friend class RSExportType; 4979ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public: 4989ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao class Field { 4999ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private: 5009ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const RSExportType *mType; 5019ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // Field name 5029ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao std::string mName; 5039ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // Link to the struct that contain this field 5049ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const RSExportRecordType *mParent; 5050da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang // Offset in the container 5060da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang size_t mOffset; 5079ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 5089ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public: 5099ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao Field(const RSExportType *T, 5109ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const llvm::StringRef &Name, 5119ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const RSExportRecordType *Parent, 5120da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang size_t Offset) 5136315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr : mType(T), 5146315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr mName(Name.data(), Name.size()), 5156315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr mParent(Parent), 5160da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang mOffset(Offset) { 5179ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return; 518462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao } 519462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 5209ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline const RSExportRecordType *getParent() const { return mParent; } 5219ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline const RSExportType *getType() const { return mType; } 5229ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline const std::string &getName() const { return mName; } 5230da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang inline size_t getOffsetInParent() const { return mOffset; } 5249ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao }; 525462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 5269ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao typedef std::list<const Field*>::const_iterator const_field_iterator; 527462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 5289ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline const_field_iterator fields_begin() const { 5299ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return this->mFields.begin(); 5309ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 5319ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline const_field_iterator fields_end() const { 5329ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return this->mFields.end(); 5339ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 5349ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 5359ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private: 5369ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao std::list<const Field*> mFields; 5379ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao bool mIsPacked; 5389ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // Artificial export struct type is not exported by user (and thus it won't 5399ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // get reflected) 5409ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao bool mIsArtificial; 5410da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang size_t mAllocSize; 5429ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 5439ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao RSExportRecordType(RSContext *Context, 5449ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const llvm::StringRef &Name, 5459ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao bool IsPacked, 5460da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang bool IsArtificial, 5470da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang size_t AllocSize) 5486b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang : RSExportType(Context, ExportClassRecord, Name), 5496315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr mIsPacked(IsPacked), 5500da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang mIsArtificial(IsArtificial), 5510da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang mAllocSize(AllocSize) { 5529ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return; 5539ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 5549ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 555e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines // @RT was normalized by calling RSExportType::NormalizeType() before calling 5569ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // this. 5579ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // @TypeName was retrieved from RSExportType::GetTypeName() before calling 5589ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // this. 5599ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static RSExportRecordType *Create(RSContext *Context, 5609ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const clang::RecordType *RT, 5619ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const llvm::StringRef &TypeName, 5629ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao bool mIsArtificial = false); 5639ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 5647c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao virtual llvm::Type *convertToLLVMType() const; 565ecddee364d731c09c77b4c3fa647fa4f50e26756Stephen Hines 5669ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public: 5670da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang inline const std::list<const Field*>& getFields() const { return mFields; } 5689ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline bool isPacked() const { return mIsPacked; } 5699ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline bool isArtificial() const { return mIsArtificial; } 5700da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang inline size_t getAllocSize() const { return mAllocSize; } 5719ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 572a6b54146b93eec68f6daa4b1877639cdc34801dcStephen Hines virtual std::string getElementName() const { 573a6b54146b93eec68f6daa4b1877639cdc34801dcStephen Hines return "ScriptField_" + getName(); 574a6b54146b93eec68f6daa4b1877639cdc34801dcStephen Hines } 575a6b54146b93eec68f6daa4b1877639cdc34801dcStephen Hines 5763cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang virtual bool keep(); 577641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang virtual bool equals(const RSExportable *E) const; 578641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang 5799ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao ~RSExportRecordType() { 5809ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao for (std::list<const Field*>::iterator I = mFields.begin(), 5819ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao E = mFields.end(); 5829ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao I != E; 5839ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao I++) 5849ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao if (*I != NULL) 5859ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao delete *I; 5869ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return; 5879ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 5889ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao}; // RSExportRecordType 5899ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 5909ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao} // namespace slang 5919ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 592e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_TYPE_H_ NOLINT 593