zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 1 | #ifndef _SLANG_COMPILER_RS_EXPORT_TYPE_H |
| 2 | #define _SLANG_COMPILER_RS_EXPORT_TYPE_H |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 3 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 4 | #include <set> |
| 5 | #include <list> |
| 6 | #include <string> |
| 7 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 8 | #include "llvm/ADT/StringRef.h" |
| 9 | #include "llvm/ADT/StringMap.h" |
| 10 | #include "llvm/ADT/SmallPtrSet.h" |
| 11 | |
| 12 | #include "clang/AST/Type.h" |
| 13 | #include "clang/AST/Decl.h" |
| 14 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 15 | #define GET_CANONICAL_TYPE(T) \ |
Zonr Chang | 2e1dba6 | 2010-10-05 22:20:11 +0800 | [diff] [blame] | 16 | (((T) == NULL) ? NULL : (T)->getCanonicalTypeInternal().getTypePtr()) |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 17 | #define UNSAFE_CAST_TYPE(TT, T) \ |
Zonr Chang | 2e1dba6 | 2010-10-05 22:20:11 +0800 | [diff] [blame] | 18 | static_cast<TT*>(T->getCanonicalTypeInternal().getTypePtr()) |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 19 | #define GET_EXT_VECTOR_ELEMENT_TYPE(T) \ |
Zonr Chang | 2e1dba6 | 2010-10-05 22:20:11 +0800 | [diff] [blame] | 20 | (((T) == NULL) ? NULL : \ |
| 21 | GET_CANONICAL_TYPE((T)->getElementType().getTypePtr())) |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 22 | #define GET_POINTEE_TYPE(T) \ |
Zonr Chang | 2e1dba6 | 2010-10-05 22:20:11 +0800 | [diff] [blame] | 23 | (((T) == NULL) ? NULL : \ |
| 24 | GET_CANONICAL_TYPE((T)->getPointeeType().getTypePtr())) |
| 25 | #define GET_CONSTANT_ARRAY_ELEMENT_TYPE(T) \ |
| 26 | (((T) == NULL) ? NULL : \ |
| 27 | GET_CANONICAL_TYPE((T)->getElementType().getTypePtr())) |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 28 | #define DUMMY_RS_TYPE_NAME_PREFIX "<" |
| 29 | #define DUMMY_RS_TYPE_NAME_POSTFIX ">" |
Zonr Chang | 2e1dba6 | 2010-10-05 22:20:11 +0800 | [diff] [blame] | 30 | #define DUMMY_TYPE_NAME_FOR_RS_CONSTANT_ARRAY_TYPE \ |
| 31 | DUMMY_RS_TYPE_NAME_PREFIX"ConstantArray"DUMMY_RS_TYPE_NAME_POSTFIX |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 32 | |
| 33 | namespace llvm { |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 34 | class Type; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 35 | } // namespace llvm |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 36 | |
| 37 | namespace slang { |
| 38 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 39 | class RSContext; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 40 | |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 41 | class RSExportType { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 42 | friend class RSExportElement; |
| 43 | public: |
| 44 | typedef enum { |
| 45 | ExportClassPrimitive, |
| 46 | ExportClassPointer, |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 47 | ExportClassVector, |
Zonr Chang | 92b344a | 2010-10-05 20:39:03 +0800 | [diff] [blame] | 48 | ExportClassMatrix, |
Zonr Chang | 2e1dba6 | 2010-10-05 22:20:11 +0800 | [diff] [blame] | 49 | ExportClassConstantArray, |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 50 | ExportClassRecord |
| 51 | } ExportClass; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 52 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 53 | private: |
| 54 | RSContext *mContext; |
Zonr Chang | 6b6320a | 2010-10-05 22:42:01 +0800 | [diff] [blame^] | 55 | ExportClass mClass; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 56 | std::string mName; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 57 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 58 | // Cache the result after calling convertToLLVMType() at the first time |
| 59 | mutable const llvm::Type *mLLVMType; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 60 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 61 | protected: |
Zonr Chang | 6b6320a | 2010-10-05 22:42:01 +0800 | [diff] [blame^] | 62 | RSExportType(RSContext *Context, |
| 63 | ExportClass Class, |
| 64 | const llvm::StringRef &Name); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 65 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 66 | // Let's make it private since there're some prerequisites to call this |
| 67 | // function. |
| 68 | // |
| 69 | // @T was normalized by calling RSExportType::TypeExportable(). |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 70 | // @TypeName was retrieve from RSExportType::GetTypeName() before calling |
| 71 | // this. |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 72 | // |
| 73 | static RSExportType *Create(RSContext *Context, |
| 74 | const clang::Type *T, |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 75 | const llvm::StringRef &TypeName); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 76 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 77 | static llvm::StringRef GetTypeName(const clang::Type *T); |
| 78 | // Return the type that can be used to create RSExportType, will always return |
| 79 | // the canonical type |
| 80 | static const clang::Type |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 81 | *TypeExportable(const clang::Type *T, |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 82 | // Contain the checked type for recursion |
| 83 | llvm::SmallPtrSet<const clang::Type*, 8> &SPS); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 84 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 85 | // This function convert the RSExportType to LLVM type. Actually, it should be |
| 86 | // "convert Clang type to LLVM type." However, clang doesn't make this API |
| 87 | // (lib/CodeGen/CodeGenTypes.h) public, we need to do by ourselves. |
| 88 | // |
| 89 | // Once we can get LLVM type, we can use LLVM to get alignment information, |
| 90 | // allocation size of a given type and structure layout that LLVM used |
| 91 | // (all of these information are target dependent) without dealing with these |
| 92 | // by ourselves. |
| 93 | virtual const llvm::Type *convertToLLVMType() const = 0; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 94 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 95 | virtual ~RSExportType() {} |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 96 | public: |
| 97 | static bool NormalizeType(const clang::Type *&T, llvm::StringRef &TypeName); |
| 98 | // @T may not be normalized |
| 99 | static RSExportType *Create(RSContext *Context, const clang::Type *T); |
| 100 | static RSExportType *CreateFromDecl(RSContext *Context, |
| 101 | const clang::VarDecl *VD); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 102 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 103 | static const clang::Type *GetTypeOfDecl(const clang::DeclaratorDecl *DD); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 104 | |
Zonr Chang | 6b6320a | 2010-10-05 22:42:01 +0800 | [diff] [blame^] | 105 | inline ExportClass getClass() const { return mClass; } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 106 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 107 | inline const llvm::Type *getLLVMType() const { |
| 108 | if (mLLVMType == NULL) |
| 109 | mLLVMType = convertToLLVMType(); |
| 110 | return mLLVMType; |
| 111 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 112 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 113 | // Return the number of bits necessary to hold the specified RSExportType |
| 114 | static size_t GetTypeStoreSize(const RSExportType *ET); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 115 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 116 | // The size of allocation of specified RSExportType (alignment considered) |
| 117 | static size_t GetTypeAllocSize(const RSExportType *ET); |
| 118 | static unsigned char GetTypeAlignment(const RSExportType *ET); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 119 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 120 | const std::string &getName() const { return mName; } |
| 121 | inline RSContext *getRSContext() const { return mContext; } |
| 122 | }; // RSExportType |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 123 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 124 | // Primitive types |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 125 | class RSExportPrimitiveType : public RSExportType { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 126 | friend class RSExportType; |
| 127 | friend class RSExportElement; |
| 128 | public: |
| 129 | // From graphics/java/android/renderscript/Element.java: Element.DataType |
| 130 | typedef enum { |
| 131 | DataTypeUnknown = -1, |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 132 | |
Shih-wei Liao | 91a3783 | 2010-10-03 19:11:51 -0700 | [diff] [blame] | 133 | DataTypeFloat16 = 0, |
| 134 | DataTypeFloat32, |
| 135 | DataTypeFloat64, |
| 136 | DataTypeSigned8, |
| 137 | DataTypeSigned16, |
| 138 | DataTypeSigned32, |
| 139 | DataTypeSigned64, |
| 140 | DataTypeUnsigned8, |
| 141 | DataTypeUnsigned16, |
| 142 | DataTypeUnsigned32, |
| 143 | DataTypeUnSigned64, |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 144 | |
Shih-wei Liao | 91a3783 | 2010-10-03 19:11:51 -0700 | [diff] [blame] | 145 | DataTypeBoolean, |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 146 | |
Shih-wei Liao | 91a3783 | 2010-10-03 19:11:51 -0700 | [diff] [blame] | 147 | DataTypeUnsigned565, |
| 148 | DataTypeUnsigned5551, |
| 149 | DataTypeUnsigned4444, |
Shih-wei Liao | dd35e49 | 2010-06-21 14:42:40 -0700 | [diff] [blame] | 150 | |
Zonr Chang | 92b344a | 2010-10-05 20:39:03 +0800 | [diff] [blame] | 151 | // Actually, there's no any instance of RSExportPrimitiveType which mType |
| 152 | // is of the value DataTypeRSMatrix*. DataTypeRSMatrix* enumeration here is |
| 153 | // only for RSExportPrimitiveType::GetRSObjectType to *recognize* the struct |
| 154 | // rs_matrix{2x2, 3x3, 4x4}. These matrix type are represented as |
| 155 | // RSExportMatrixType. |
Shih-wei Liao | 91a3783 | 2010-10-03 19:11:51 -0700 | [diff] [blame] | 156 | DataTypeRSMatrix2x2, |
| 157 | DataTypeRSMatrix3x3, |
| 158 | DataTypeRSMatrix4x4, |
| 159 | |
| 160 | DataTypeRSElement, |
| 161 | DataTypeRSType, |
| 162 | DataTypeRSAllocation, |
| 163 | DataTypeRSSampler, |
| 164 | DataTypeRSScript, |
| 165 | DataTypeRSMesh, |
| 166 | DataTypeRSProgramFragment, |
| 167 | DataTypeRSProgramVertex, |
| 168 | DataTypeRSProgramRaster, |
| 169 | DataTypeRSProgramStore, |
| 170 | DataTypeRSFont, |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 171 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 172 | DataTypeMax |
| 173 | } DataType; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 174 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 175 | // From graphics/java/android/renderscript/Element.java: Element.DataKind |
| 176 | typedef enum { |
Shih-wei Liao | 91a3783 | 2010-10-03 19:11:51 -0700 | [diff] [blame] | 177 | DataKindUser, |
| 178 | DataKindPixelL, |
| 179 | DataKindPixelA, |
| 180 | DataKindPixelLA, |
| 181 | DataKindPixelRGB, |
| 182 | DataKindPixelRGBA |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 183 | } DataKind; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 184 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 185 | private: |
| 186 | DataType mType; |
| 187 | DataKind mKind; |
| 188 | bool mNormalized; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 189 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 190 | typedef llvm::StringMap<DataType> RSObjectTypeMapTy; |
| 191 | static RSObjectTypeMapTy *RSObjectTypeMap; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 192 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 193 | static llvm::Type *RSObjectLLVMType; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 194 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 195 | static const size_t SizeOfDataTypeInBits[]; |
| 196 | // @T was normalized by calling RSExportType::TypeExportable() before calling |
| 197 | // this. |
| 198 | // @TypeName was retrieved from RSExportType::GetTypeName() before calling |
| 199 | // this |
| 200 | static RSExportPrimitiveType *Create(RSContext *Context, |
| 201 | const clang::Type *T, |
| 202 | const llvm::StringRef &TypeName, |
| 203 | DataKind DK = DataKindUser, |
| 204 | bool Normalized = false); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 205 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 206 | protected: |
| 207 | // T is normalized by calling RSExportType::TypeExportable() before |
| 208 | // calling this |
| 209 | static bool IsPrimitiveType(const clang::Type *T); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 210 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 211 | static DataType GetDataType(const clang::Type *T); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 212 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 213 | RSExportPrimitiveType(RSContext *Context, |
Zonr Chang | 6b6320a | 2010-10-05 22:42:01 +0800 | [diff] [blame^] | 214 | // for derived class to set their type class |
| 215 | ExportClass Class, |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 216 | const llvm::StringRef &Name, |
| 217 | DataType DT, |
| 218 | DataKind DK, |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 219 | bool Normalized) |
Zonr Chang | 6b6320a | 2010-10-05 22:42:01 +0800 | [diff] [blame^] | 220 | : RSExportType(Context, Class, Name), |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 221 | mType(DT), |
| 222 | mKind(DK), |
| 223 | mNormalized(Normalized) { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 224 | return; |
| 225 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 226 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 227 | virtual const llvm::Type *convertToLLVMType() const; |
| 228 | public: |
| 229 | // @T may not be normalized |
| 230 | static RSExportPrimitiveType *Create(RSContext *Context, |
| 231 | const clang::Type *T, |
| 232 | DataKind DK = DataKindUser); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 233 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 234 | static DataType GetRSObjectType(const llvm::StringRef &TypeName); |
| 235 | static DataType GetRSObjectType(const clang::Type *T); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 236 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 237 | static size_t GetSizeInBits(const RSExportPrimitiveType *EPT); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 238 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 239 | inline DataType getType() const { return mType; } |
| 240 | inline DataKind getKind() const { return mKind; } |
| 241 | inline bool isRSObjectType() const { |
| 242 | return ((mType >= DataTypeRSElement) && (mType < DataTypeMax)); |
| 243 | } |
| 244 | }; // RSExportPrimitiveType |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 245 | |
| 246 | |
| 247 | class RSExportPointerType : public RSExportType { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 248 | friend class RSExportType; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 249 | friend class RSExportFunc; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 250 | private: |
| 251 | const RSExportType *mPointeeType; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 252 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 253 | RSExportPointerType(RSContext *Context, |
| 254 | const llvm::StringRef &Name, |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 255 | const RSExportType *PointeeType) |
Zonr Chang | 6b6320a | 2010-10-05 22:42:01 +0800 | [diff] [blame^] | 256 | : RSExportType(Context, ExportClassPointer, Name), |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 257 | mPointeeType(PointeeType) { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 258 | return; |
| 259 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 260 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 261 | // @PT was normalized by calling RSExportType::TypeExportable() before calling |
| 262 | // this. |
| 263 | static RSExportPointerType *Create(RSContext *Context, |
| 264 | const clang::PointerType *PT, |
| 265 | const llvm::StringRef &TypeName); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 266 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 267 | virtual const llvm::Type *convertToLLVMType() const; |
| 268 | public: |
| 269 | static const clang::Type *IntegerType; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 270 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 271 | inline const RSExportType *getPointeeType() const { return mPointeeType; } |
| 272 | }; // RSExportPointerType |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 273 | |
| 274 | |
| 275 | class RSExportVectorType : public RSExportPrimitiveType { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 276 | friend class RSExportType; |
| 277 | friend class RSExportElement; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 278 | private: |
Zonr Chang | 92b344a | 2010-10-05 20:39:03 +0800 | [diff] [blame] | 279 | unsigned mNumElement; // number of element |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 280 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 281 | RSExportVectorType(RSContext *Context, |
| 282 | const llvm::StringRef &Name, |
| 283 | DataType DT, |
| 284 | DataKind DK, |
| 285 | bool Normalized, |
Zonr Chang | 92b344a | 2010-10-05 20:39:03 +0800 | [diff] [blame] | 286 | unsigned NumElement) |
Zonr Chang | 6b6320a | 2010-10-05 22:42:01 +0800 | [diff] [blame^] | 287 | : RSExportPrimitiveType(Context, ExportClassVector, Name, |
| 288 | DT, DK, Normalized), |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 289 | mNumElement(NumElement) { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 290 | return; |
| 291 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 292 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 293 | // @EVT was normalized by calling RSExportType::TypeExportable() before |
| 294 | // calling this. |
| 295 | static RSExportVectorType *Create(RSContext *Context, |
| 296 | const clang::ExtVectorType *EVT, |
| 297 | const llvm::StringRef &TypeName, |
| 298 | DataKind DK = DataKindUser, |
| 299 | bool Normalized = false); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 300 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 301 | static const char *VectorTypeNameStore[][3]; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 302 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 303 | virtual const llvm::Type *convertToLLVMType() const; |
| 304 | public: |
| 305 | static llvm::StringRef GetTypeName(const clang::ExtVectorType *EVT); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 306 | |
Zonr Chang | 92b344a | 2010-10-05 20:39:03 +0800 | [diff] [blame] | 307 | inline unsigned getNumElement() const { return mNumElement; } |
| 308 | }; |
| 309 | |
| 310 | // Only *square* *float* matrix is supported by now. |
| 311 | // |
| 312 | // struct rs_matrix{2x2,3x3,4x4, ..., NxN} should be defined as the following |
| 313 | // form *exactly*: |
| 314 | // typedef struct { |
| 315 | // float m[{NxN}]; |
| 316 | // } rs_matrixNxN; |
| 317 | // |
| 318 | // where mDim will be N. |
| 319 | class RSExportMatrixType : public RSExportType { |
| 320 | friend class RSExportType; |
| 321 | private: |
Zonr Chang | 2e1dba6 | 2010-10-05 22:20:11 +0800 | [diff] [blame] | 322 | unsigned mDim; // dimension |
Zonr Chang | 92b344a | 2010-10-05 20:39:03 +0800 | [diff] [blame] | 323 | |
| 324 | RSExportMatrixType(RSContext *Context, |
| 325 | const llvm::StringRef &Name, |
| 326 | unsigned Dim) |
Zonr Chang | 6b6320a | 2010-10-05 22:42:01 +0800 | [diff] [blame^] | 327 | : RSExportType(Context, ExportClassMatrix, Name), |
Zonr Chang | 92b344a | 2010-10-05 20:39:03 +0800 | [diff] [blame] | 328 | mDim(Dim) { |
| 329 | return; |
| 330 | } |
| 331 | |
| 332 | virtual const llvm::Type *convertToLLVMType() const; |
| 333 | public: |
Zonr Chang | 92b344a | 2010-10-05 20:39:03 +0800 | [diff] [blame] | 334 | // @RT was normalized by calling RSExportType::TypeExportable() before |
| 335 | // calling this. |
| 336 | static RSExportMatrixType *Create(RSContext *Context, |
| 337 | const clang::RecordType *RT, |
| 338 | const llvm::StringRef &TypeName, |
| 339 | unsigned Dim); |
| 340 | |
| 341 | inline unsigned getDim() const { return mDim; } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 342 | }; |
| 343 | |
Zonr Chang | 2e1dba6 | 2010-10-05 22:20:11 +0800 | [diff] [blame] | 344 | class RSExportConstantArrayType : public RSExportType { |
| 345 | friend class RSExportType; |
| 346 | private: |
| 347 | const RSExportType *mElementType; // Array element type |
| 348 | unsigned mSize; // Array size |
| 349 | |
| 350 | RSExportConstantArrayType(RSContext *Context, |
| 351 | const RSExportType *ElementType, |
| 352 | unsigned Size) |
| 353 | : RSExportType(Context, |
Zonr Chang | 6b6320a | 2010-10-05 22:42:01 +0800 | [diff] [blame^] | 354 | ExportClassConstantArray, |
Zonr Chang | 2e1dba6 | 2010-10-05 22:20:11 +0800 | [diff] [blame] | 355 | DUMMY_TYPE_NAME_FOR_RS_CONSTANT_ARRAY_TYPE), |
| 356 | mElementType(ElementType), |
| 357 | mSize(Size) { |
| 358 | return; |
| 359 | } |
| 360 | |
| 361 | // @CAT was normalized by calling RSExportType::TypeExportable() before |
| 362 | // calling this. |
| 363 | static RSExportConstantArrayType *Create(RSContext *Context, |
| 364 | const clang::ConstantArrayType *CAT); |
| 365 | |
| 366 | virtual const llvm::Type *convertToLLVMType() const; |
| 367 | public: |
Zonr Chang | 2e1dba6 | 2010-10-05 22:20:11 +0800 | [diff] [blame] | 368 | inline unsigned getSize() const { return mSize; } |
| 369 | inline const RSExportType *getElementType() const { return mElementType; } |
| 370 | }; |
| 371 | |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 372 | class RSExportRecordType : public RSExportType { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 373 | friend class RSExportType; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 374 | public: |
| 375 | class Field { |
| 376 | private: |
| 377 | const RSExportType *mType; |
| 378 | // Field name |
| 379 | std::string mName; |
| 380 | // Link to the struct that contain this field |
| 381 | const RSExportRecordType *mParent; |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 382 | // Offset in the container |
| 383 | size_t mOffset; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 384 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 385 | public: |
| 386 | Field(const RSExportType *T, |
| 387 | const llvm::StringRef &Name, |
| 388 | const RSExportRecordType *Parent, |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 389 | size_t Offset) |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 390 | : mType(T), |
| 391 | mName(Name.data(), Name.size()), |
| 392 | mParent(Parent), |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 393 | mOffset(Offset) { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 394 | return; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 397 | inline const RSExportRecordType *getParent() const { return mParent; } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 398 | inline const RSExportType *getType() const { return mType; } |
| 399 | inline const std::string &getName() const { return mName; } |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 400 | inline size_t getOffsetInParent() const { return mOffset; } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 401 | }; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 402 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 403 | typedef std::list<const Field*>::const_iterator const_field_iterator; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 404 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 405 | inline const_field_iterator fields_begin() const { |
| 406 | return this->mFields.begin(); |
| 407 | } |
| 408 | inline const_field_iterator fields_end() const { |
| 409 | return this->mFields.end(); |
| 410 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 411 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 412 | private: |
| 413 | std::list<const Field*> mFields; |
| 414 | bool mIsPacked; |
| 415 | // Artificial export struct type is not exported by user (and thus it won't |
| 416 | // get reflected) |
| 417 | bool mIsArtificial; |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 418 | size_t mAllocSize; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 419 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 420 | RSExportRecordType(RSContext *Context, |
| 421 | const llvm::StringRef &Name, |
| 422 | bool IsPacked, |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 423 | bool IsArtificial, |
| 424 | size_t AllocSize) |
Zonr Chang | 6b6320a | 2010-10-05 22:42:01 +0800 | [diff] [blame^] | 425 | : RSExportType(Context, ExportClassRecord, Name), |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 426 | mIsPacked(IsPacked), |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 427 | mIsArtificial(IsArtificial), |
| 428 | mAllocSize(AllocSize) { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 429 | return; |
| 430 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 431 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 432 | // @RT was normalized by calling RSExportType::TypeExportable() before calling |
| 433 | // this. |
| 434 | // @TypeName was retrieved from RSExportType::GetTypeName() before calling |
| 435 | // this. |
| 436 | static RSExportRecordType *Create(RSContext *Context, |
| 437 | const clang::RecordType *RT, |
| 438 | const llvm::StringRef &TypeName, |
| 439 | bool mIsArtificial = false); |
| 440 | |
| 441 | virtual const llvm::Type *convertToLLVMType() const; |
| 442 | public: |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 443 | inline const std::list<const Field*>& getFields() const { return mFields; } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 444 | inline bool isPacked() const { return mIsPacked; } |
| 445 | inline bool isArtificial() const { return mIsArtificial; } |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 446 | inline size_t getAllocSize() const { return mAllocSize; } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 447 | |
| 448 | ~RSExportRecordType() { |
| 449 | for (std::list<const Field*>::iterator I = mFields.begin(), |
| 450 | E = mFields.end(); |
| 451 | I != E; |
| 452 | I++) |
| 453 | if (*I != NULL) |
| 454 | delete *I; |
| 455 | return; |
| 456 | } |
| 457 | }; // RSExportRecordType |
| 458 | |
| 459 | } // namespace slang |
| 460 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 461 | #endif // _SLANG_COMPILER_RS_EXPORT_TYPE_H |