slang_rs_export_type.h revision 2e1dba6c779a0ae55c76d36a3c03553e16725ab7
16315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#ifndef _SLANG_COMPILER_RS_EXPORT_TYPE_H
26315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#define _SLANG_COMPILER_RS_EXPORT_TYPE_H
3462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
49ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#include <set>
59ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#include <list>
69ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#include <string>
79ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
86315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#include "llvm/ADT/StringRef.h"
96315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#include "llvm/ADT/StringMap.h"
106315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#include "llvm/ADT/SmallPtrSet.h"
116315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr
126315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#include "clang/AST/Type.h"
136315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#include "clang/AST/Decl.h"
146315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr
159ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#define GET_CANONICAL_TYPE(T) \
162e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang    (((T) == NULL) ? NULL : (T)->getCanonicalTypeInternal().getTypePtr())
179ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#define UNSAFE_CAST_TYPE(TT, T) \
182e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang    static_cast<TT*>(T->getCanonicalTypeInternal().getTypePtr())
199ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#define GET_EXT_VECTOR_ELEMENT_TYPE(T) \
202e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang    (((T) == NULL) ? NULL : \
212e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang                     GET_CANONICAL_TYPE((T)->getElementType().getTypePtr()))
229ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#define GET_POINTEE_TYPE(T) \
232e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang    (((T) == NULL) ? NULL : \
242e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang                     GET_CANONICAL_TYPE((T)->getPointeeType().getTypePtr()))
252e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang#define GET_CONSTANT_ARRAY_ELEMENT_TYPE(T)  \
262e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang    (((T) == NULL) ? NULL : \
272e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang                     GET_CANONICAL_TYPE((T)->getElementType().getTypePtr()))
280da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang#define DUMMY_RS_TYPE_NAME_PREFIX   "<"
290da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang#define DUMMY_RS_TYPE_NAME_POSTFIX  ">"
302e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang#define DUMMY_TYPE_NAME_FOR_RS_CONSTANT_ARRAY_TYPE  \
312e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang    DUMMY_RS_TYPE_NAME_PREFIX"ConstantArray"DUMMY_RS_TYPE_NAME_POSTFIX
32462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
33462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaonamespace llvm {
346315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  class Type;
359ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao}   // namespace llvm
36462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
37462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaonamespace slang {
38462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
396315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  class RSContext;
40462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
41462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportType {
429ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportElement;
439ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
449ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef enum {
459ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    ExportClassPrimitive,
469ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    ExportClassPointer,
479ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    ExportClassVector,
4892b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang    ExportClassMatrix,
492e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang    ExportClassConstantArray,
509ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    ExportClassRecord
519ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  } ExportClass;
52462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
539ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private:
549ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  RSContext *mContext;
559ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  std::string mName;
569ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
579ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Cache the result after calling convertToLLVMType() at the first time
589ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  mutable const llvm::Type *mLLVMType;
599ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
609ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao protected:
619ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  RSExportType(RSContext *Context, const llvm::StringRef &Name);
629ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
639ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Let's make it private since there're some prerequisites to call this
649ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // function.
659ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  //
669ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @T was normalized by calling RSExportType::TypeExportable().
676315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  // @TypeName was retrieve from RSExportType::GetTypeName() before calling
686315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  //           this.
699ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  //
709ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportType *Create(RSContext *Context,
719ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                              const clang::Type *T,
726315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr                              const llvm::StringRef &TypeName);
739ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
749ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static llvm::StringRef GetTypeName(const clang::Type *T);
759ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Return the type that can be used to create RSExportType, will always return
769ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // the canonical type
779ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static const clang::Type
786315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  *TypeExportable(const clang::Type *T,
799ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                  // Contain the checked type for recursion
809ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                  llvm::SmallPtrSet<const clang::Type*, 8> &SPS);
819ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
829ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // This function convert the RSExportType to LLVM type. Actually, it should be
839ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // "convert Clang type to LLVM type." However, clang doesn't make this API
849ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // (lib/CodeGen/CodeGenTypes.h) public, we need to do by ourselves.
859ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  //
869ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Once we can get LLVM type, we can use LLVM to get alignment information,
879ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // allocation size of a given type and structure layout that LLVM used
889ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // (all of these information are target dependent) without dealing with these
899ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // by ourselves.
909ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  virtual const llvm::Type *convertToLLVMType() const = 0;
919ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
926315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  virtual ~RSExportType() {}
939ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
949ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static bool NormalizeType(const clang::Type *&T, llvm::StringRef &TypeName);
959ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @T may not be normalized
969ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportType *Create(RSContext *Context, const clang::Type *T);
979ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportType *CreateFromDecl(RSContext *Context,
989ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                      const clang::VarDecl *VD);
999ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1009ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static const clang::Type *GetTypeOfDecl(const clang::DeclaratorDecl *DD);
1019ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1029ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  virtual ExportClass getClass() const = 0;
1039ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1049ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline const llvm::Type *getLLVMType() const {
1059ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    if (mLLVMType == NULL)
1069ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao      mLLVMType = convertToLLVMType();
1079ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return mLLVMType;
1089ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
109462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
1109ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Return the number of bits necessary to hold the specified RSExportType
1119ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static size_t GetTypeStoreSize(const RSExportType *ET);
112462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
1139ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // The size of allocation of specified RSExportType (alignment considered)
1149ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static size_t GetTypeAllocSize(const RSExportType *ET);
1159ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static unsigned char GetTypeAlignment(const RSExportType *ET);
116462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
1179ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  const std::string &getName() const { return mName; }
1189ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline RSContext *getRSContext() const { return mContext; }
1199ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao};  // RSExportType
120462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
1219ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao// Primitive types
122462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportPrimitiveType : public RSExportType {
1239ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportType;
1249ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportElement;
1259ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
1269ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // From graphics/java/android/renderscript/Element.java: Element.DataType
1279ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef enum {
1289ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    DataTypeUnknown = -1,
1299ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
13091a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeFloat16 = 0,
13191a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeFloat32,
13291a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeFloat64,
13391a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeSigned8,
13491a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeSigned16,
13591a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeSigned32,
13691a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeSigned64,
13791a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeUnsigned8,
13891a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeUnsigned16,
13991a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeUnsigned32,
14091a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeUnSigned64,
14191a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao
14291a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeBoolean,
14391a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao
14491a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeUnsigned565,
14591a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeUnsigned5551,
14691a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeUnsigned4444,
14791a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao
14892b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang    // Actually, there's no any instance of RSExportPrimitiveType which mType
14992b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang    // is of the value DataTypeRSMatrix*. DataTypeRSMatrix* enumeration here is
15092b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang    // only for RSExportPrimitiveType::GetRSObjectType to *recognize* the struct
15192b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang    // rs_matrix{2x2, 3x3, 4x4}. These matrix type are represented as
15292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang    // RSExportMatrixType.
15391a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeRSMatrix2x2,
15491a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeRSMatrix3x3,
15591a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeRSMatrix4x4,
15691a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao
15791a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeRSElement,
15891a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeRSType,
15991a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeRSAllocation,
16091a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeRSSampler,
16191a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeRSScript,
16291a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeRSMesh,
16391a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeRSProgramFragment,
16491a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeRSProgramVertex,
16591a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeRSProgramRaster,
16691a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeRSProgramStore,
16791a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeRSFont,
1689ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1699ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    DataTypeMax
1709ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  } DataType;
1719ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1729ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // From graphics/java/android/renderscript/Element.java: Element.DataKind
1739ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef enum {
17491a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataKindUser,
17591a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataKindPixelL,
17691a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataKindPixelA,
17791a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataKindPixelLA,
17891a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataKindPixelRGB,
17991a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataKindPixelRGBA
1809ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  } DataKind;
181462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
1829ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private:
1839ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  DataType mType;
1849ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  DataKind mKind;
1859ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  bool mNormalized;
1869ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1879ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef llvm::StringMap<DataType> RSObjectTypeMapTy;
1889ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSObjectTypeMapTy *RSObjectTypeMap;
1899ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1909ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static llvm::Type *RSObjectLLVMType;
1919ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1929ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static const size_t SizeOfDataTypeInBits[];
1939ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @T was normalized by calling RSExportType::TypeExportable() before calling
1949ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // this.
1959ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @TypeName was retrieved from RSExportType::GetTypeName() before calling
1969ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // this
1979ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportPrimitiveType *Create(RSContext *Context,
1989ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                       const clang::Type *T,
1999ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                       const llvm::StringRef &TypeName,
2009ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                       DataKind DK = DataKindUser,
2019ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                       bool Normalized = false);
2029ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2039ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao protected:
2049ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // T is normalized by calling RSExportType::TypeExportable() before
2059ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // calling this
2069ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static bool IsPrimitiveType(const clang::Type *T);
2079ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2089ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static DataType GetDataType(const clang::Type *T);
2099ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2109ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  RSExportPrimitiveType(RSContext *Context,
2119ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                        const llvm::StringRef &Name,
2129ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                        DataType DT,
2139ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                        DataKind DK,
2146315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr                        bool Normalized)
2156315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr      : RSExportType(Context, Name),
2166315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mType(DT),
2176315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mKind(DK),
2186315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mNormalized(Normalized) {
2199ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return;
2209ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
2219ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2229ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  virtual const llvm::Type *convertToLLVMType() const;
2239ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
2249ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @T may not be normalized
2259ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportPrimitiveType *Create(RSContext *Context,
2269ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                       const clang::Type *T,
2279ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                       DataKind DK = DataKindUser);
228462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
2299ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static DataType GetRSObjectType(const llvm::StringRef &TypeName);
2309ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static DataType GetRSObjectType(const clang::Type *T);
231462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
2329ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static size_t GetSizeInBits(const RSExportPrimitiveType *EPT);
233462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
2349ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  virtual ExportClass getClass() const;
235462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
2369ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline DataType getType() const { return mType; }
2379ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline DataKind getKind() const { return mKind; }
2389ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline bool isRSObjectType() const {
2399ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return ((mType >= DataTypeRSElement) && (mType < DataTypeMax));
2409ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
2419ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao};  // RSExportPrimitiveType
242462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
243462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
244462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportPointerType : public RSExportType {
2459ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportType;
2469ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportFunc;
2479ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private:
2489ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  const RSExportType *mPointeeType;
2499ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2509ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  RSExportPointerType(RSContext *Context,
2519ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                      const llvm::StringRef &Name,
2526315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr                      const RSExportType *PointeeType)
2536315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr      : RSExportType(Context, Name),
2546315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mPointeeType(PointeeType) {
2559ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return;
2569ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
2579ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2589ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @PT was normalized by calling RSExportType::TypeExportable() before calling
2599ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // this.
2609ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportPointerType *Create(RSContext *Context,
2619ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                     const clang::PointerType *PT,
2629ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                     const llvm::StringRef &TypeName);
2639ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2649ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  virtual const llvm::Type *convertToLLVMType() const;
2659ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
2669ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static const clang::Type *IntegerType;
267462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
2689ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  virtual ExportClass getClass() const;
269462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
2709ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline const RSExportType *getPointeeType() const { return mPointeeType; }
2719ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao};  // RSExportPointerType
272462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
273462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
274462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportVectorType : public RSExportPrimitiveType {
2759ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportType;
2769ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportElement;
2779ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private:
27892b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  unsigned mNumElement;   // number of element
2799ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2809ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  RSExportVectorType(RSContext *Context,
2819ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     const llvm::StringRef &Name,
2829ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     DataType DT,
2839ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     DataKind DK,
2849ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     bool Normalized,
28592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                     unsigned NumElement)
2866315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr      : RSExportPrimitiveType(Context, Name, DT, DK, Normalized),
2876315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mNumElement(NumElement) {
2889ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return;
2899ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
2909ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2919ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @EVT was normalized by calling RSExportType::TypeExportable() before
2929ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // calling this.
2939ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportVectorType *Create(RSContext *Context,
2949ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    const clang::ExtVectorType *EVT,
2959ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    const llvm::StringRef &TypeName,
2969ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    DataKind DK = DataKindUser,
2979ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    bool Normalized = false);
2989ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2999ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static const char *VectorTypeNameStore[][3];
3009ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
3019ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  virtual const llvm::Type *convertToLLVMType() const;
3029ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
3039ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static llvm::StringRef GetTypeName(const clang::ExtVectorType *EVT);
304462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
3059ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  virtual ExportClass getClass() const;
306462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
30792b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  inline unsigned getNumElement() const { return mNumElement; }
30892b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang};
30992b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang
31092b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// Only *square* *float* matrix is supported by now.
31192b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//
31292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// struct rs_matrix{2x2,3x3,4x4, ..., NxN} should be defined as the following
31392b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// form *exactly*:
31492b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//  typedef struct {
31592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//    float m[{NxN}];
31692b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//  } rs_matrixNxN;
31792b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//
31892b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//  where mDim will be N.
31992b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Changclass RSExportMatrixType : public RSExportType {
32092b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  friend class RSExportType;
32192b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang private:
3222e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  unsigned mDim;  // dimension
32392b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang
32492b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  RSExportMatrixType(RSContext *Context,
32592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                     const llvm::StringRef &Name,
32692b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                     unsigned Dim)
32792b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang    : RSExportType(Context, Name),
32892b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang      mDim(Dim) {
32992b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang    return;
33092b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  }
33192b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang
33292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  virtual const llvm::Type *convertToLLVMType() const;
33392b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang public:
33492b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  virtual ExportClass getClass() const;
33592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang
33692b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  // @RT was normalized by calling RSExportType::TypeExportable() before
33792b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  // calling this.
33892b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  static RSExportMatrixType *Create(RSContext *Context,
33992b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                                    const clang::RecordType *RT,
34092b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                                    const llvm::StringRef &TypeName,
34192b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                                    unsigned Dim);
34292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang
34392b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  inline unsigned getDim() const { return mDim; }
344462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao};
345462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
3462e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Changclass RSExportConstantArrayType : public RSExportType {
3472e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  friend class RSExportType;
3482e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang private:
3492e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  const RSExportType *mElementType;  // Array element type
3502e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  unsigned mSize;  // Array size
3512e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang
3522e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  RSExportConstantArrayType(RSContext *Context,
3532e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang                            const RSExportType *ElementType,
3542e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang                            unsigned Size)
3552e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang    : RSExportType(Context,
3562e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang                   DUMMY_TYPE_NAME_FOR_RS_CONSTANT_ARRAY_TYPE),
3572e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang      mElementType(ElementType),
3582e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang      mSize(Size) {
3592e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang    return;
3602e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  }
3612e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang
3622e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  // @CAT was normalized by calling RSExportType::TypeExportable() before
3632e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  // calling this.
3642e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  static RSExportConstantArrayType *Create(RSContext *Context,
3652e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang                                           const clang::ConstantArrayType *CAT);
3662e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang
3672e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  virtual const llvm::Type *convertToLLVMType() const;
3682e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang public:
3692e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  virtual ExportClass getClass() const;
3702e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang
3712e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  inline unsigned getSize() const { return mSize; }
3722e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  inline const RSExportType *getElementType() const { return mElementType; }
3732e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang};
3742e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang
375462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportRecordType : public RSExportType {
3769ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportType;
3779ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
3789ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  class Field {
3799ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao   private:
3809ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    const RSExportType *mType;
3819ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    // Field name
3829ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    std::string mName;
3839ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    // Link to the struct that contain this field
3849ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    const RSExportRecordType *mParent;
3850da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang    // Offset in the container
3860da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang    size_t mOffset;
3879ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
3889ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao   public:
3899ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    Field(const RSExportType *T,
3909ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao          const llvm::StringRef &Name,
3919ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao          const RSExportRecordType *Parent,
3920da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang          size_t Offset)
3936315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        : mType(T),
3946315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr          mName(Name.data(), Name.size()),
3956315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr          mParent(Parent),
3960da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang          mOffset(Offset) {
3979ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao      return;
398462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao    }
399462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
4009ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    inline const RSExportRecordType *getParent() const { return mParent; }
4019ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    inline const RSExportType *getType() const { return mType; }
4029ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    inline const std::string &getName() const { return mName; }
4030da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang    inline size_t getOffsetInParent() const { return mOffset; }
4049ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  };
405462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
4069ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef std::list<const Field*>::const_iterator const_field_iterator;
407462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
4089ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline const_field_iterator fields_begin() const {
4099ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return this->mFields.begin();
4109ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
4119ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline const_field_iterator fields_end() const {
4129ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return this->mFields.end();
4139ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
4149ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
4159ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private:
4169ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  std::list<const Field*> mFields;
4179ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  bool mIsPacked;
4189ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Artificial export struct type is not exported by user (and thus it won't
4199ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // get reflected)
4209ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  bool mIsArtificial;
4210da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang  size_t mAllocSize;
4229ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
4239ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  RSExportRecordType(RSContext *Context,
4249ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     const llvm::StringRef &Name,
4259ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     bool IsPacked,
4260da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang                     bool IsArtificial,
4270da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang                     size_t AllocSize)
4286315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr      : RSExportType(Context, Name),
4296315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mIsPacked(IsPacked),
4300da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang        mIsArtificial(IsArtificial),
4310da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang        mAllocSize(AllocSize) {
4329ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return;
4339ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
4349ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
4359ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @RT was normalized by calling RSExportType::TypeExportable() before calling
4369ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // this.
4379ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @TypeName was retrieved from RSExportType::GetTypeName() before calling
4389ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // this.
4399ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportRecordType *Create(RSContext *Context,
4409ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    const clang::RecordType *RT,
4419ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    const llvm::StringRef &TypeName,
4429ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    bool mIsArtificial = false);
4439ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
4449ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  virtual const llvm::Type *convertToLLVMType() const;
4459ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
4469ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  virtual ExportClass getClass() const;
4479ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
4480da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang  inline const std::list<const Field*>& getFields() const { return mFields; }
4499ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline bool isPacked() const { return mIsPacked; }
4509ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline bool isArtificial() const { return mIsArtificial; }
4510da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang  inline size_t getAllocSize() const { return mAllocSize; }
4529ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
4539ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  ~RSExportRecordType() {
4549ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    for (std::list<const Field*>::iterator I = mFields.begin(),
4559ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao             E = mFields.end();
4569ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao         I != E;
4579ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao         I++)
4589ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao      if (*I != NULL)
4599ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao        delete *I;
4609ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return;
4619ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
4629ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao};  // RSExportRecordType
4639ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
4649ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao}   // namespace slang
4659ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
4666315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#endif  // _SLANG_COMPILER_RS_EXPORT_TYPE_H
467