slang_rs_export_type.h revision a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8fa
1c383a500aa59423264811be3874461bf8adbfea0Zonr Chang/* 2c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * Copyright 2010, 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 176315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#ifndef _SLANG_COMPILER_RS_EXPORT_TYPE_H 186315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#define _SLANG_COMPILER_RS_EXPORT_TYPE_H 19462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 209ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#include <set> 219ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#include <list> 229ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#include <string> 239ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 24a41ce1d98094da84643995d40d71c529905123fcZonr Chang#include "llvm/Support/ManagedStatic.h" 25a41ce1d98094da84643995d40d71c529905123fcZonr Chang 266315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#include "llvm/ADT/StringRef.h" 276315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#include "llvm/ADT/StringMap.h" 286315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#include "llvm/ADT/SmallPtrSet.h" 296315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr 306315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#include "clang/AST/Type.h" 316315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#include "clang/AST/Decl.h" 326315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr 33a41ce1d98094da84643995d40d71c529905123fcZonr Chang#include "slang_rs_exportable.h" 34a41ce1d98094da84643995d40d71c529905123fcZonr Chang 359ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#define GET_CANONICAL_TYPE(T) \ 362e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang (((T) == NULL) ? NULL : (T)->getCanonicalTypeInternal().getTypePtr()) 379ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#define UNSAFE_CAST_TYPE(TT, T) \ 382e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang static_cast<TT*>(T->getCanonicalTypeInternal().getTypePtr()) 399ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#define GET_EXT_VECTOR_ELEMENT_TYPE(T) \ 402e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang (((T) == NULL) ? NULL : \ 412e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang GET_CANONICAL_TYPE((T)->getElementType().getTypePtr())) 429ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#define GET_POINTEE_TYPE(T) \ 432e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang (((T) == NULL) ? NULL : \ 442e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang GET_CANONICAL_TYPE((T)->getPointeeType().getTypePtr())) 452e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang#define GET_CONSTANT_ARRAY_ELEMENT_TYPE(T) \ 462e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang (((T) == NULL) ? NULL : \ 472e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang GET_CANONICAL_TYPE((T)->getElementType().getTypePtr())) 480da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang#define DUMMY_RS_TYPE_NAME_PREFIX "<" 490da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang#define DUMMY_RS_TYPE_NAME_POSTFIX ">" 502e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang#define DUMMY_TYPE_NAME_FOR_RS_CONSTANT_ARRAY_TYPE \ 512e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang DUMMY_RS_TYPE_NAME_PREFIX"ConstantArray"DUMMY_RS_TYPE_NAME_POSTFIX 52462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 53a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Changunion RSType; 54a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang 55462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaonamespace llvm { 566315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr class Type; 579ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao} // namespace llvm 58462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 59462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaonamespace slang { 60462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 616315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr class RSContext; 62462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 63a41ce1d98094da84643995d40d71c529905123fcZonr Changclass RSExportType : public RSExportable { 649ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao friend class RSExportElement; 659ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public: 669ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao typedef enum { 679ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao ExportClassPrimitive, 689ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao ExportClassPointer, 699ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao ExportClassVector, 7092b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang ExportClassMatrix, 712e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang ExportClassConstantArray, 729ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao ExportClassRecord 739ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } ExportClass; 74462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 759ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private: 766b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang ExportClass mClass; 779ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao std::string mName; 789ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 799ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // Cache the result after calling convertToLLVMType() at the first time 809ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao mutable const llvm::Type *mLLVMType; 81a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang // Cache the result after calling convertToSpecType() at the first time 82a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang mutable union RSType *mSpecType; 839ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 849ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao protected: 856b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang RSExportType(RSContext *Context, 866b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang ExportClass Class, 876b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang const llvm::StringRef &Name); 889ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 899ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // Let's make it private since there're some prerequisites to call this 909ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // function. 919ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // 929ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // @T was normalized by calling RSExportType::TypeExportable(). 936315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr // @TypeName was retrieve from RSExportType::GetTypeName() before calling 946315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr // this. 959ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // 969ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static RSExportType *Create(RSContext *Context, 979ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const clang::Type *T, 986315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr const llvm::StringRef &TypeName); 999ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 1009ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static llvm::StringRef GetTypeName(const clang::Type *T); 1019ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // Return the type that can be used to create RSExportType, will always return 1029ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // the canonical type 1039ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static const clang::Type 1046315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr *TypeExportable(const clang::Type *T, 1059ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // Contain the checked type for recursion 1069ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao llvm::SmallPtrSet<const clang::Type*, 8> &SPS); 1079ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 1089ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // This function convert the RSExportType to LLVM type. Actually, it should be 1099ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // "convert Clang type to LLVM type." However, clang doesn't make this API 1109ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // (lib/CodeGen/CodeGenTypes.h) public, we need to do by ourselves. 1119ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // 1129ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // Once we can get LLVM type, we can use LLVM to get alignment information, 1139ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // allocation size of a given type and structure layout that LLVM used 1149ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // (all of these information are target dependent) without dealing with these 1159ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // by ourselves. 1169ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao virtual const llvm::Type *convertToLLVMType() const = 0; 1173cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang // Record type may recursively referece its type definition. We need a 1183cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang // temporary type setup before the type construction gets done. 1193cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang inline void setAbstractLLVMType(const llvm::Type *LLVMType) const { 1203cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang mLLVMType = LLVMType; 1213cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang } 1229ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 123a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang virtual union RSType *convertToSpecType() const = 0; 124a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang inline void setSpecTypeTemporarily(union RSType *SpecType) const { 125a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang mSpecType = SpecType; 126a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang } 127a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang 128a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang virtual ~RSExportType(); 1299ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public: 1309ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static bool NormalizeType(const clang::Type *&T, llvm::StringRef &TypeName); 1319ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // @T may not be normalized 1329ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static RSExportType *Create(RSContext *Context, const clang::Type *T); 1339ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static RSExportType *CreateFromDecl(RSContext *Context, 1349ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const clang::VarDecl *VD); 1359ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 1369ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static const clang::Type *GetTypeOfDecl(const clang::DeclaratorDecl *DD); 1379ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 1386b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang inline ExportClass getClass() const { return mClass; } 1399ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 1409ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline const llvm::Type *getLLVMType() const { 1419ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao if (mLLVMType == NULL) 1429ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao mLLVMType = convertToLLVMType(); 1439ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return mLLVMType; 1449ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 145462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 146a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang inline const union RSType *getSpecType() const { 147a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang if (mSpecType == NULL) 148a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang mSpecType = convertToSpecType(); 149a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang return mSpecType; 150a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang } 151a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang 1529ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // Return the number of bits necessary to hold the specified RSExportType 1539ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static size_t GetTypeStoreSize(const RSExportType *ET); 154462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 1559ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // The size of allocation of specified RSExportType (alignment considered) 1569ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static size_t GetTypeAllocSize(const RSExportType *ET); 157462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 158641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang inline const std::string &getName() const { return mName; } 159641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang 1603cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang virtual bool keep(); 161641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang virtual bool equals(const RSExportable *E) const; 1629ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao}; // RSExportType 163462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 1649ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao// Primitive types 165462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportPrimitiveType : public RSExportType { 1669ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao friend class RSExportType; 1679ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao friend class RSExportElement; 1689ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public: 1699ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // From graphics/java/android/renderscript/Element.java: Element.DataType 1709ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao typedef enum { 1719ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao DataTypeUnknown = -1, 1729ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 173a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang#define ENUM_RS_DATA_TYPE(type, cname, bits) \ 174a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang DataType ## type, 175a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang#include "RSDataTypeEnums.inc" 1769ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 1779ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao DataTypeMax 1789ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } DataType; 1799ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 1809ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // From graphics/java/android/renderscript/Element.java: Element.DataKind 1819ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao typedef enum { 182a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang DataKindUnknown = -1 183a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang#define ENUM_RS_DATA_KIND(kind) \ 184a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang , DataKind ## kind 185a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang#include "RSDataKindEnums.inc" 1869ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } DataKind; 187462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 1889ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private: 189a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang // NOTE: There's no any instance of RSExportPrimitiveType which mType 190a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang // is of the value DataTypeRSMatrix*. DataTypeRSMatrix* enumeration here is 191a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang // only for RSExportPrimitiveType::GetRSObjectType to *recognize* the struct 192a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang // rs_matrix{2x2, 3x3, 4x4}. These matrix type are represented as 193a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang // RSExportMatrixType. 1949ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao DataType mType; 1959ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao DataKind mKind; 1969ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao bool mNormalized; 1979ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 1989ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao typedef llvm::StringMap<DataType> RSObjectTypeMapTy; 199a41ce1d98094da84643995d40d71c529905123fcZonr Chang static llvm::ManagedStatic<RSObjectTypeMapTy> RSObjectTypeMap; 2009ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 2019ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static llvm::Type *RSObjectLLVMType; 2029ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 2039ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static const size_t SizeOfDataTypeInBits[]; 2049ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // @T was normalized by calling RSExportType::TypeExportable() before calling 2059ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // this. 2069ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // @TypeName was retrieved from RSExportType::GetTypeName() before calling 2079ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // this 2089ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static RSExportPrimitiveType *Create(RSContext *Context, 2099ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const clang::Type *T, 2109ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const llvm::StringRef &TypeName, 2119ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao DataKind DK = DataKindUser, 2129ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao bool Normalized = false); 2139ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 2149ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao protected: 2159ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // T is normalized by calling RSExportType::TypeExportable() before 2169ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // calling this 2179ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static bool IsPrimitiveType(const clang::Type *T); 2189ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 2199ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static DataType GetDataType(const clang::Type *T); 2209ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 2219ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao RSExportPrimitiveType(RSContext *Context, 2226b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang // for derived class to set their type class 2236b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang ExportClass Class, 2249ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const llvm::StringRef &Name, 2259ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao DataType DT, 2269ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao DataKind DK, 2276315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr bool Normalized) 2286b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang : RSExportType(Context, Class, Name), 2296315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr mType(DT), 2306315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr mKind(DK), 2316315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr mNormalized(Normalized) { 2329ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return; 2339ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 2349ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 2359ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao virtual const llvm::Type *convertToLLVMType() const; 236a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang virtual union RSType *convertToSpecType() const; 2379ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public: 2389ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // @T may not be normalized 2399ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static RSExportPrimitiveType *Create(RSContext *Context, 2409ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const clang::Type *T, 2419ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao DataKind DK = DataKindUser); 242462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 2439ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static DataType GetRSObjectType(const llvm::StringRef &TypeName); 2449ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static DataType GetRSObjectType(const clang::Type *T); 245462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 2469ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static size_t GetSizeInBits(const RSExportPrimitiveType *EPT); 247462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 2489ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline DataType getType() const { return mType; } 2499ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline DataKind getKind() const { return mKind; } 2509ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline bool isRSObjectType() const { 2519ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return ((mType >= DataTypeRSElement) && (mType < DataTypeMax)); 2529ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 253641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang 254641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang virtual bool equals(const RSExportable *E) const; 2559ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao}; // RSExportPrimitiveType 256462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 257462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 258462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportPointerType : public RSExportType { 2599ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao friend class RSExportType; 2609ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao friend class RSExportFunc; 2619ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private: 2629ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const RSExportType *mPointeeType; 2639ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 2649ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao RSExportPointerType(RSContext *Context, 2659ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const llvm::StringRef &Name, 2666315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr const RSExportType *PointeeType) 2676b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang : RSExportType(Context, ExportClassPointer, Name), 2686315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr mPointeeType(PointeeType) { 2699ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return; 2709ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 2719ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 2729ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // @PT was normalized by calling RSExportType::TypeExportable() before calling 2739ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // this. 2749ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static RSExportPointerType *Create(RSContext *Context, 2759ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const clang::PointerType *PT, 2769ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const llvm::StringRef &TypeName); 2779ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 2789ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao virtual const llvm::Type *convertToLLVMType() const; 279a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang virtual union RSType *convertToSpecType() const; 2809ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public: 2819ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static const clang::Type *IntegerType; 282462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 2833cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang virtual bool keep(); 284641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang 2859ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline const RSExportType *getPointeeType() const { return mPointeeType; } 286641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang 287641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang virtual bool equals(const RSExportable *E) const; 2889ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao}; // RSExportPointerType 289462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 290462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 291462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportVectorType : public RSExportPrimitiveType { 2929ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao friend class RSExportType; 2939ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao friend class RSExportElement; 2949ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private: 29592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang unsigned mNumElement; // number of element 2969ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 2979ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao RSExportVectorType(RSContext *Context, 2989ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const llvm::StringRef &Name, 2999ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao DataType DT, 3009ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao DataKind DK, 3019ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao bool Normalized, 30292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang unsigned NumElement) 3036b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang : RSExportPrimitiveType(Context, ExportClassVector, Name, 3046b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang DT, DK, Normalized), 3056315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr mNumElement(NumElement) { 3069ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return; 3079ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 3089ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 3099ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // @EVT was normalized by calling RSExportType::TypeExportable() before 3109ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // calling this. 3119ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static RSExportVectorType *Create(RSContext *Context, 3129ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const clang::ExtVectorType *EVT, 3139ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const llvm::StringRef &TypeName, 3149ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao DataKind DK = DataKindUser, 3159ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao bool Normalized = false); 3169ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 3179ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao virtual const llvm::Type *convertToLLVMType() const; 318a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang virtual union RSType *convertToSpecType() const; 3199ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public: 3209ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static llvm::StringRef GetTypeName(const clang::ExtVectorType *EVT); 321462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 32292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang inline unsigned getNumElement() const { return mNumElement; } 323641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang 324641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang virtual bool equals(const RSExportable *E) const; 32592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang}; 32692b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang 32792b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// Only *square* *float* matrix is supported by now. 32892b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// 32992b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// struct rs_matrix{2x2,3x3,4x4, ..., NxN} should be defined as the following 33092b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// form *exactly*: 33192b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// typedef struct { 33292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// float m[{NxN}]; 33392b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// } rs_matrixNxN; 33492b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// 33592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// where mDim will be N. 33692b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Changclass RSExportMatrixType : public RSExportType { 33792b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang friend class RSExportType; 33892b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang private: 3392e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang unsigned mDim; // dimension 34092b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang 34192b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang RSExportMatrixType(RSContext *Context, 34292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang const llvm::StringRef &Name, 34392b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang unsigned Dim) 3446b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang : RSExportType(Context, ExportClassMatrix, Name), 34592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang mDim(Dim) { 34692b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang return; 34792b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang } 34892b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang 34992b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang virtual const llvm::Type *convertToLLVMType() const; 350a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang virtual union RSType *convertToSpecType() const; 35192b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang public: 35292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang // @RT was normalized by calling RSExportType::TypeExportable() before 35392b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang // calling this. 35492b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang static RSExportMatrixType *Create(RSContext *Context, 35592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang const clang::RecordType *RT, 35692b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang const llvm::StringRef &TypeName, 35792b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang unsigned Dim); 35892b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang 35992b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang inline unsigned getDim() const { return mDim; } 360641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang 361641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang virtual bool equals(const RSExportable *E) const; 362462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao}; 363462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 3642e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Changclass RSExportConstantArrayType : public RSExportType { 3652e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang friend class RSExportType; 3662e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang private: 3672e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang const RSExportType *mElementType; // Array element type 3682e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang unsigned mSize; // Array size 3692e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang 3702e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang RSExportConstantArrayType(RSContext *Context, 3712e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang const RSExportType *ElementType, 3722e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang unsigned Size) 3732e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang : RSExportType(Context, 3746b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang ExportClassConstantArray, 3752e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang DUMMY_TYPE_NAME_FOR_RS_CONSTANT_ARRAY_TYPE), 3762e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang mElementType(ElementType), 3772e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang mSize(Size) { 3782e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang return; 3792e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang } 3802e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang 3812e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang // @CAT was normalized by calling RSExportType::TypeExportable() before 3822e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang // calling this. 3832e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang static RSExportConstantArrayType *Create(RSContext *Context, 3842e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang const clang::ConstantArrayType *CAT); 3852e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang 3862e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang virtual const llvm::Type *convertToLLVMType() const; 387a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang virtual union RSType *convertToSpecType() const; 3882e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang public: 3892e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang inline unsigned getSize() const { return mSize; } 3902e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang inline const RSExportType *getElementType() const { return mElementType; } 391641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang 3923cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang virtual bool keep(); 393641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang virtual bool equals(const RSExportable *E) const; 3942e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang}; 3952e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang 396462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportRecordType : public RSExportType { 3979ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao friend class RSExportType; 3989ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public: 3999ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao class Field { 4009ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private: 4019ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const RSExportType *mType; 4029ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // Field name 4039ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao std::string mName; 4049ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // Link to the struct that contain this field 4059ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const RSExportRecordType *mParent; 4060da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang // Offset in the container 4070da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang size_t mOffset; 4089ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 4099ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public: 4109ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao Field(const RSExportType *T, 4119ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const llvm::StringRef &Name, 4129ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const RSExportRecordType *Parent, 4130da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang size_t Offset) 4146315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr : mType(T), 4156315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr mName(Name.data(), Name.size()), 4166315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr mParent(Parent), 4170da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang mOffset(Offset) { 4189ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return; 419462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao } 420462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 4219ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline const RSExportRecordType *getParent() const { return mParent; } 4229ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline const RSExportType *getType() const { return mType; } 4239ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline const std::string &getName() const { return mName; } 4240da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang inline size_t getOffsetInParent() const { return mOffset; } 4259ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao }; 426462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 4279ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao typedef std::list<const Field*>::const_iterator const_field_iterator; 428462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 4299ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline const_field_iterator fields_begin() const { 4309ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return this->mFields.begin(); 4319ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 4329ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline const_field_iterator fields_end() const { 4339ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return this->mFields.end(); 4349ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 4359ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 4369ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private: 4379ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao std::list<const Field*> mFields; 4389ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao bool mIsPacked; 4399ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // Artificial export struct type is not exported by user (and thus it won't 4409ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // get reflected) 4419ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao bool mIsArtificial; 4420da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang size_t mAllocSize; 4439ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 4449ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao RSExportRecordType(RSContext *Context, 4459ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const llvm::StringRef &Name, 4469ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao bool IsPacked, 4470da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang bool IsArtificial, 4480da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang size_t AllocSize) 4496b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang : RSExportType(Context, ExportClassRecord, Name), 4506315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr mIsPacked(IsPacked), 4510da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang mIsArtificial(IsArtificial), 4520da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang mAllocSize(AllocSize) { 4539ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return; 4549ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 4559ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 4569ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // @RT was normalized by calling RSExportType::TypeExportable() before calling 4579ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // this. 4589ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // @TypeName was retrieved from RSExportType::GetTypeName() before calling 4599ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // this. 4609ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao static RSExportRecordType *Create(RSContext *Context, 4619ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const clang::RecordType *RT, 4629ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const llvm::StringRef &TypeName, 4639ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao bool mIsArtificial = false); 4649ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 4659ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao virtual const llvm::Type *convertToLLVMType() const; 466a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang virtual union RSType *convertToSpecType() const; 4679ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public: 4680da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang inline const std::list<const Field*>& getFields() const { return mFields; } 4699ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline bool isPacked() const { return mIsPacked; } 4709ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline bool isArtificial() const { return mIsArtificial; } 4710da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang inline size_t getAllocSize() const { return mAllocSize; } 4729ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 4733cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang virtual bool keep(); 474641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang virtual bool equals(const RSExportable *E) const; 475641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang 4769ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao ~RSExportRecordType() { 4779ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao for (std::list<const Field*>::iterator I = mFields.begin(), 4789ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao E = mFields.end(); 4799ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao I != E; 4809ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao I++) 4819ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao if (*I != NULL) 4829ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao delete *I; 4839ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return; 4849ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 4859ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao}; // RSExportRecordType 4869ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 4879ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao} // namespace slang 4889ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 4896315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#endif // _SLANG_COMPILER_RS_EXPORT_TYPE_H 490