slang_rs_export_type.h revision a65ec168e41e3ee9c6e8ac04cde694bbbfc2590a
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
53462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaonamespace llvm {
546315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  class Type;
559ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao}   // namespace llvm
56462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
57462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaonamespace slang {
58462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
596315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  class RSContext;
60462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
61a41ce1d98094da84643995d40d71c529905123fcZonr Changclass RSExportType : public RSExportable {
629ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportElement;
639ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
649ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef enum {
659ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    ExportClassPrimitive,
669ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    ExportClassPointer,
679ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    ExportClassVector,
6892b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang    ExportClassMatrix,
692e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang    ExportClassConstantArray,
709ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    ExportClassRecord
719ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  } ExportClass;
72462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
739ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private:
746b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang  ExportClass mClass;
759ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  std::string mName;
769ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
779ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Cache the result after calling convertToLLVMType() at the first time
789ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  mutable const llvm::Type *mLLVMType;
799ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
809ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao protected:
816b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang  RSExportType(RSContext *Context,
826b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang               ExportClass Class,
836b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang               const llvm::StringRef &Name);
849ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
859ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Let's make it private since there're some prerequisites to call this
869ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // function.
879ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  //
889ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @T was normalized by calling RSExportType::TypeExportable().
896315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  // @TypeName was retrieve from RSExportType::GetTypeName() before calling
906315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  //           this.
919ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  //
929ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportType *Create(RSContext *Context,
939ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                              const clang::Type *T,
946315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr                              const llvm::StringRef &TypeName);
959ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
969ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static llvm::StringRef GetTypeName(const clang::Type *T);
979ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Return the type that can be used to create RSExportType, will always return
989ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // the canonical type
999ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static const clang::Type
1006315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  *TypeExportable(const clang::Type *T,
1019ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                  // Contain the checked type for recursion
1029ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                  llvm::SmallPtrSet<const clang::Type*, 8> &SPS);
1039ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1049ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // This function convert the RSExportType to LLVM type. Actually, it should be
1059ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // "convert Clang type to LLVM type." However, clang doesn't make this API
1069ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // (lib/CodeGen/CodeGenTypes.h) public, we need to do by ourselves.
1079ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  //
1089ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Once we can get LLVM type, we can use LLVM to get alignment information,
1099ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // allocation size of a given type and structure layout that LLVM used
1109ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // (all of these information are target dependent) without dealing with these
1119ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // by ourselves.
1129ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  virtual const llvm::Type *convertToLLVMType() const = 0;
1139ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1146315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  virtual ~RSExportType() {}
1159ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
1169ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static bool NormalizeType(const clang::Type *&T, llvm::StringRef &TypeName);
1179ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @T may not be normalized
1189ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportType *Create(RSContext *Context, const clang::Type *T);
1199ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportType *CreateFromDecl(RSContext *Context,
1209ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                      const clang::VarDecl *VD);
1219ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1229ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static const clang::Type *GetTypeOfDecl(const clang::DeclaratorDecl *DD);
1239ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1246b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang  inline ExportClass getClass() const { return mClass; }
1259ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1269ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline const llvm::Type *getLLVMType() const {
1279ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    if (mLLVMType == NULL)
1289ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao      mLLVMType = convertToLLVMType();
1299ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return mLLVMType;
1309ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
131462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
1329ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Return the number of bits necessary to hold the specified RSExportType
1339ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static size_t GetTypeStoreSize(const RSExportType *ET);
134462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
1359ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // The size of allocation of specified RSExportType (alignment considered)
1369ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static size_t GetTypeAllocSize(const RSExportType *ET);
1379ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static unsigned char GetTypeAlignment(const RSExportType *ET);
138462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
139641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  inline const std::string &getName() const { return mName; }
140641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang
141641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  virtual void keep();
142641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  virtual bool equals(const RSExportable *E) const;
1439ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao};  // RSExportType
144462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
1459ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao// Primitive types
146462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportPrimitiveType : public RSExportType {
1479ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportType;
1489ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportElement;
1499ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
1509ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // From graphics/java/android/renderscript/Element.java: Element.DataType
1519ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef enum {
1529ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    DataTypeUnknown = -1,
1539ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
154a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang#define ENUM_RS_DATA_TYPE(type, cname, bits)  \
155a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang    DataType ## type,
156a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang#include "RSDataTypeEnums.inc"
157a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang#undef ENUM_RS_DATA_TYPE
1589ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1599ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    DataTypeMax
1609ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  } DataType;
1619ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1629ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // From graphics/java/android/renderscript/Element.java: Element.DataKind
1639ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef enum {
164a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang    DataKindUnknown = -1
165a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang#define ENUM_RS_DATA_KIND(kind) \
166a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang    , DataKind ## kind
167a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang#include "RSDataKindEnums.inc"
168a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang#undef ENUM_RS_DATA_KIND
1699ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  } DataKind;
170462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
1719ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private:
172a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang  // NOTE: There's no any instance of RSExportPrimitiveType which mType
173a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang  // is of the value DataTypeRSMatrix*. DataTypeRSMatrix* enumeration here is
174a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang  // only for RSExportPrimitiveType::GetRSObjectType to *recognize* the struct
175a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang  // rs_matrix{2x2, 3x3, 4x4}. These matrix type are represented as
176a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang  // RSExportMatrixType.
1779ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  DataType mType;
1789ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  DataKind mKind;
1799ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  bool mNormalized;
1809ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1819ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef llvm::StringMap<DataType> RSObjectTypeMapTy;
182a41ce1d98094da84643995d40d71c529905123fcZonr Chang  static llvm::ManagedStatic<RSObjectTypeMapTy> RSObjectTypeMap;
1839ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1849ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static llvm::Type *RSObjectLLVMType;
1859ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1869ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static const size_t SizeOfDataTypeInBits[];
1879ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @T was normalized by calling RSExportType::TypeExportable() before calling
1889ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // this.
1899ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @TypeName was retrieved from RSExportType::GetTypeName() before calling
1909ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // this
1919ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportPrimitiveType *Create(RSContext *Context,
1929ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                       const clang::Type *T,
1939ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                       const llvm::StringRef &TypeName,
1949ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                       DataKind DK = DataKindUser,
1959ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                       bool Normalized = false);
1969ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1979ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao protected:
1989ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // T is normalized by calling RSExportType::TypeExportable() before
1999ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // calling this
2009ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static bool IsPrimitiveType(const clang::Type *T);
2019ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2029ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static DataType GetDataType(const clang::Type *T);
2039ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2049ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  RSExportPrimitiveType(RSContext *Context,
2056b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang                        // for derived class to set their type class
2066b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang                        ExportClass Class,
2079ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                        const llvm::StringRef &Name,
2089ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                        DataType DT,
2099ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                        DataKind DK,
2106315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr                        bool Normalized)
2116b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang      : RSExportType(Context, Class, Name),
2126315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mType(DT),
2136315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mKind(DK),
2146315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mNormalized(Normalized) {
2159ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return;
2169ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
2179ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2189ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  virtual const llvm::Type *convertToLLVMType() const;
2199ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
2209ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @T may not be normalized
2219ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportPrimitiveType *Create(RSContext *Context,
2229ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                       const clang::Type *T,
2239ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                       DataKind DK = DataKindUser);
224462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
2259ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static DataType GetRSObjectType(const llvm::StringRef &TypeName);
2269ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static DataType GetRSObjectType(const clang::Type *T);
227462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
2289ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static size_t GetSizeInBits(const RSExportPrimitiveType *EPT);
229462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
2309ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline DataType getType() const { return mType; }
2319ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline DataKind getKind() const { return mKind; }
2329ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline bool isRSObjectType() const {
2339ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return ((mType >= DataTypeRSElement) && (mType < DataTypeMax));
2349ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
235641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang
236641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  virtual bool equals(const RSExportable *E) const;
2379ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao};  // RSExportPrimitiveType
238462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
239462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
240462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportPointerType : public RSExportType {
2419ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportType;
2429ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportFunc;
2439ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private:
2449ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  const RSExportType *mPointeeType;
2459ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2469ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  RSExportPointerType(RSContext *Context,
2479ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                      const llvm::StringRef &Name,
2486315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr                      const RSExportType *PointeeType)
2496b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang      : RSExportType(Context, ExportClassPointer, Name),
2506315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mPointeeType(PointeeType) {
2519ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return;
2529ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
2539ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2549ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @PT was normalized by calling RSExportType::TypeExportable() before calling
2559ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // this.
2569ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportPointerType *Create(RSContext *Context,
2579ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                     const clang::PointerType *PT,
2589ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                     const llvm::StringRef &TypeName);
2599ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2609ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  virtual const llvm::Type *convertToLLVMType() const;
2619ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
2629ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static const clang::Type *IntegerType;
263462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
264641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  virtual void keep();
265641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang
2669ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline const RSExportType *getPointeeType() const { return mPointeeType; }
267641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang
268641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  virtual bool equals(const RSExportable *E) const;
2699ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao};  // RSExportPointerType
270462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
271462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
272462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportVectorType : public RSExportPrimitiveType {
2739ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportType;
2749ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportElement;
2759ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private:
27692b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  unsigned mNumElement;   // number of element
2779ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2789ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  RSExportVectorType(RSContext *Context,
2799ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     const llvm::StringRef &Name,
2809ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     DataType DT,
2819ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     DataKind DK,
2829ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     bool Normalized,
28392b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                     unsigned NumElement)
2846b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang      : RSExportPrimitiveType(Context, ExportClassVector, Name,
2856b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang                              DT, DK, Normalized),
2866315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mNumElement(NumElement) {
2879ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return;
2889ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
2899ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2909ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @EVT was normalized by calling RSExportType::TypeExportable() before
2919ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // calling this.
2929ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportVectorType *Create(RSContext *Context,
2939ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    const clang::ExtVectorType *EVT,
2949ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    const llvm::StringRef &TypeName,
2959ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    DataKind DK = DataKindUser,
2969ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    bool Normalized = false);
2979ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2989ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  virtual const llvm::Type *convertToLLVMType() const;
2999ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
3009ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static llvm::StringRef GetTypeName(const clang::ExtVectorType *EVT);
301462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
30292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  inline unsigned getNumElement() const { return mNumElement; }
303641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang
304641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  virtual bool equals(const RSExportable *E) const;
30592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang};
30692b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang
30792b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// Only *square* *float* matrix is supported by now.
30892b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//
30992b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// struct rs_matrix{2x2,3x3,4x4, ..., NxN} should be defined as the following
31092b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// form *exactly*:
31192b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//  typedef struct {
31292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//    float m[{NxN}];
31392b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//  } rs_matrixNxN;
31492b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//
31592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//  where mDim will be N.
31692b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Changclass RSExportMatrixType : public RSExportType {
31792b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  friend class RSExportType;
31892b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang private:
3192e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  unsigned mDim;  // dimension
32092b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang
32192b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  RSExportMatrixType(RSContext *Context,
32292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                     const llvm::StringRef &Name,
32392b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                     unsigned Dim)
3246b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang    : RSExportType(Context, ExportClassMatrix, Name),
32592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang      mDim(Dim) {
32692b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang    return;
32792b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  }
32892b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang
32992b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  virtual const llvm::Type *convertToLLVMType() const;
33092b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang public:
33192b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  // @RT was normalized by calling RSExportType::TypeExportable() before
33292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  // calling this.
33392b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  static RSExportMatrixType *Create(RSContext *Context,
33492b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                                    const clang::RecordType *RT,
33592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                                    const llvm::StringRef &TypeName,
33692b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                                    unsigned Dim);
33792b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang
33892b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  inline unsigned getDim() const { return mDim; }
339641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang
340641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  virtual bool equals(const RSExportable *E) const;
341462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao};
342462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
3432e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Changclass RSExportConstantArrayType : public RSExportType {
3442e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  friend class RSExportType;
3452e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang private:
3462e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  const RSExportType *mElementType;  // Array element type
3472e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  unsigned mSize;  // Array size
3482e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang
3492e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  RSExportConstantArrayType(RSContext *Context,
3502e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang                            const RSExportType *ElementType,
3512e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang                            unsigned Size)
3522e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang    : RSExportType(Context,
3536b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang                   ExportClassConstantArray,
3542e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang                   DUMMY_TYPE_NAME_FOR_RS_CONSTANT_ARRAY_TYPE),
3552e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang      mElementType(ElementType),
3562e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang      mSize(Size) {
3572e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang    return;
3582e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  }
3592e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang
3602e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  // @CAT was normalized by calling RSExportType::TypeExportable() before
3612e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  // calling this.
3622e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  static RSExportConstantArrayType *Create(RSContext *Context,
3632e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang                                           const clang::ConstantArrayType *CAT);
3642e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang
3652e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  virtual const llvm::Type *convertToLLVMType() const;
3662e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang public:
3672e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  inline unsigned getSize() const { return mSize; }
3682e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  inline const RSExportType *getElementType() const { return mElementType; }
369641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang
370641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  virtual void keep();
371641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  virtual bool equals(const RSExportable *E) const;
3722e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang};
3732e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang
374462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportRecordType : public RSExportType {
3759ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportType;
3769ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
3779ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  class Field {
3789ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao   private:
3799ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    const RSExportType *mType;
3809ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    // Field name
3819ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    std::string mName;
3829ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    // Link to the struct that contain this field
3839ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    const RSExportRecordType *mParent;
3840da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang    // Offset in the container
3850da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang    size_t mOffset;
3869ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
3879ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao   public:
3889ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    Field(const RSExportType *T,
3899ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao          const llvm::StringRef &Name,
3909ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao          const RSExportRecordType *Parent,
3910da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang          size_t Offset)
3926315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        : mType(T),
3936315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr          mName(Name.data(), Name.size()),
3946315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr          mParent(Parent),
3950da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang          mOffset(Offset) {
3969ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao      return;
397462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao    }
398462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
3999ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    inline const RSExportRecordType *getParent() const { return mParent; }
4009ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    inline const RSExportType *getType() const { return mType; }
4019ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    inline const std::string &getName() const { return mName; }
4020da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang    inline size_t getOffsetInParent() const { return mOffset; }
4039ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  };
404462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
4059ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef std::list<const Field*>::const_iterator const_field_iterator;
406462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
4079ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline const_field_iterator fields_begin() const {
4089ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return this->mFields.begin();
4099ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
4109ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline const_field_iterator fields_end() const {
4119ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return this->mFields.end();
4129ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
4139ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
4149ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private:
4159ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  std::list<const Field*> mFields;
4169ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  bool mIsPacked;
4179ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Artificial export struct type is not exported by user (and thus it won't
4189ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // get reflected)
4199ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  bool mIsArtificial;
4200da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang  size_t mAllocSize;
4219ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
4229ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  RSExportRecordType(RSContext *Context,
4239ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     const llvm::StringRef &Name,
4249ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     bool IsPacked,
4250da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang                     bool IsArtificial,
4260da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang                     size_t AllocSize)
4276b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang      : RSExportType(Context, ExportClassRecord, Name),
4286315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mIsPacked(IsPacked),
4290da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang        mIsArtificial(IsArtificial),
4300da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang        mAllocSize(AllocSize) {
4319ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return;
4329ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
4339ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
4349ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @RT was normalized by calling RSExportType::TypeExportable() before calling
4359ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // this.
4369ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @TypeName was retrieved from RSExportType::GetTypeName() before calling
4379ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // this.
4389ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportRecordType *Create(RSContext *Context,
4399ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    const clang::RecordType *RT,
4409ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    const llvm::StringRef &TypeName,
4419ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    bool mIsArtificial = false);
4429ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
4439ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  virtual const llvm::Type *convertToLLVMType() const;
4449ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
4450da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang  inline const std::list<const Field*>& getFields() const { return mFields; }
4469ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline bool isPacked() const { return mIsPacked; }
4479ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline bool isArtificial() const { return mIsArtificial; }
4480da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang  inline size_t getAllocSize() const { return mAllocSize; }
4499ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
450641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  virtual void keep();
451641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  virtual bool equals(const RSExportable *E) const;
452641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang
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