slang_rs_export_type.h revision c383a500aa59423264811be3874461bf8adbfea0
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:
749ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  RSContext *mContext;
756b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang  ExportClass mClass;
769ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  std::string mName;
779ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
789ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Cache the result after calling convertToLLVMType() at the first time
799ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  mutable const llvm::Type *mLLVMType;
809ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
819ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao protected:
826b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang  RSExportType(RSContext *Context,
836b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang               ExportClass Class,
846b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang               const llvm::StringRef &Name);
859ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
869ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Let's make it private since there're some prerequisites to call this
879ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // function.
889ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  //
899ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @T was normalized by calling RSExportType::TypeExportable().
906315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  // @TypeName was retrieve from RSExportType::GetTypeName() before calling
916315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  //           this.
929ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  //
939ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportType *Create(RSContext *Context,
949ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                              const clang::Type *T,
956315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr                              const llvm::StringRef &TypeName);
969ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
979ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static llvm::StringRef GetTypeName(const clang::Type *T);
989ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Return the type that can be used to create RSExportType, will always return
999ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // the canonical type
1009ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static const clang::Type
1016315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  *TypeExportable(const clang::Type *T,
1029ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                  // Contain the checked type for recursion
1039ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                  llvm::SmallPtrSet<const clang::Type*, 8> &SPS);
1049ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1059ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // This function convert the RSExportType to LLVM type. Actually, it should be
1069ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // "convert Clang type to LLVM type." However, clang doesn't make this API
1079ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // (lib/CodeGen/CodeGenTypes.h) public, we need to do by ourselves.
1089ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  //
1099ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Once we can get LLVM type, we can use LLVM to get alignment information,
1109ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // allocation size of a given type and structure layout that LLVM used
1119ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // (all of these information are target dependent) without dealing with these
1129ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // by ourselves.
1139ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  virtual const llvm::Type *convertToLLVMType() const = 0;
1149ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1156315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  virtual ~RSExportType() {}
1169ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
1179ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static bool NormalizeType(const clang::Type *&T, llvm::StringRef &TypeName);
1189ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @T may not be normalized
1199ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportType *Create(RSContext *Context, const clang::Type *T);
1209ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportType *CreateFromDecl(RSContext *Context,
1219ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                      const clang::VarDecl *VD);
1229ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1239ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static const clang::Type *GetTypeOfDecl(const clang::DeclaratorDecl *DD);
1249ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1256b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang  inline ExportClass getClass() const { return mClass; }
1269ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1279ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline const llvm::Type *getLLVMType() const {
1289ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    if (mLLVMType == NULL)
1299ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao      mLLVMType = convertToLLVMType();
1309ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return mLLVMType;
1319ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
132462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
1339ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Return the number of bits necessary to hold the specified RSExportType
1349ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static size_t GetTypeStoreSize(const RSExportType *ET);
135462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
1369ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // The size of allocation of specified RSExportType (alignment considered)
1379ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static size_t GetTypeAllocSize(const RSExportType *ET);
1389ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static unsigned char GetTypeAlignment(const RSExportType *ET);
139462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
1409ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  const std::string &getName() const { return mName; }
1419ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline RSContext *getRSContext() const { return mContext; }
1429ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao};  // RSExportType
143462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
1449ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao// Primitive types
145462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportPrimitiveType : public RSExportType {
1469ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportType;
1479ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportElement;
1489ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
1499ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // From graphics/java/android/renderscript/Element.java: Element.DataType
1509ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef enum {
1519ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    DataTypeUnknown = -1,
1529ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
15391a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeFloat16 = 0,
15491a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeFloat32,
15591a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeFloat64,
15691a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeSigned8,
15791a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeSigned16,
15891a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeSigned32,
15991a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeSigned64,
16091a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeUnsigned8,
16191a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeUnsigned16,
16291a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeUnsigned32,
163a5d2c232d56b04292cb51c8fb343aef990f7970fStephen Hines    DataTypeUnsigned64,
16491a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao
16591a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeBoolean,
16691a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao
16791a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeUnsigned565,
16891a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeUnsigned5551,
16991a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeUnsigned4444,
17091a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao
17192b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang    // Actually, there's no any instance of RSExportPrimitiveType which mType
17292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang    // is of the value DataTypeRSMatrix*. DataTypeRSMatrix* enumeration here is
17392b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang    // only for RSExportPrimitiveType::GetRSObjectType to *recognize* the struct
17492b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang    // rs_matrix{2x2, 3x3, 4x4}. These matrix type are represented as
17592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang    // RSExportMatrixType.
17691a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeRSMatrix2x2,
17791a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeRSMatrix3x3,
17891a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeRSMatrix4x4,
17991a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao
18091a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeRSElement,
18191a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeRSType,
18291a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeRSAllocation,
18391a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeRSSampler,
18491a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeRSScript,
18591a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeRSMesh,
18691a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeRSProgramFragment,
18791a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeRSProgramVertex,
18891a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeRSProgramRaster,
18991a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeRSProgramStore,
19091a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataTypeRSFont,
1919ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1929ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    DataTypeMax
1939ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  } DataType;
1949ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1959ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // From graphics/java/android/renderscript/Element.java: Element.DataKind
1969ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef enum {
19791a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataKindUser,
19891a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataKindPixelL,
19991a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataKindPixelA,
20091a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataKindPixelLA,
20191a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataKindPixelRGB,
20291a3783ce1f4eb9ad6e9c1ecdbd27f3d6dc58634Shih-wei Liao    DataKindPixelRGBA
2039ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  } DataKind;
204462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
2059ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private:
2069ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  DataType mType;
2079ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  DataKind mKind;
2089ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  bool mNormalized;
2099ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2109ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef llvm::StringMap<DataType> RSObjectTypeMapTy;
211a41ce1d98094da84643995d40d71c529905123fcZonr Chang  static llvm::ManagedStatic<RSObjectTypeMapTy> RSObjectTypeMap;
2129ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2139ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static llvm::Type *RSObjectLLVMType;
2149ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2159ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static const size_t SizeOfDataTypeInBits[];
2169ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @T was normalized by calling RSExportType::TypeExportable() before calling
2179ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // this.
2189ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @TypeName was retrieved from RSExportType::GetTypeName() before calling
2199ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // this
2209ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportPrimitiveType *Create(RSContext *Context,
2219ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                       const clang::Type *T,
2229ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                       const llvm::StringRef &TypeName,
2239ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                       DataKind DK = DataKindUser,
2249ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                       bool Normalized = false);
2259ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2269ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao protected:
2279ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // T is normalized by calling RSExportType::TypeExportable() before
2289ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // calling this
2299ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static bool IsPrimitiveType(const clang::Type *T);
2309ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2319ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static DataType GetDataType(const clang::Type *T);
2329ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2339ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  RSExportPrimitiveType(RSContext *Context,
2346b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang                        // for derived class to set their type class
2356b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang                        ExportClass Class,
2369ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                        const llvm::StringRef &Name,
2379ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                        DataType DT,
2389ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                        DataKind DK,
2396315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr                        bool Normalized)
2406b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang      : RSExportType(Context, Class, Name),
2416315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mType(DT),
2426315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mKind(DK),
2436315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mNormalized(Normalized) {
2449ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return;
2459ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
2469ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2479ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  virtual const llvm::Type *convertToLLVMType() const;
2489ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
2499ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @T may not be normalized
2509ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportPrimitiveType *Create(RSContext *Context,
2519ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                       const clang::Type *T,
2529ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                       DataKind DK = DataKindUser);
253462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
2549ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static DataType GetRSObjectType(const llvm::StringRef &TypeName);
2559ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static DataType GetRSObjectType(const clang::Type *T);
256462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
2579ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static size_t GetSizeInBits(const RSExportPrimitiveType *EPT);
258462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
2599ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline DataType getType() const { return mType; }
2609ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline DataKind getKind() const { return mKind; }
2619ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline bool isRSObjectType() const {
2629ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return ((mType >= DataTypeRSElement) && (mType < DataTypeMax));
2639ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
2649ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao};  // RSExportPrimitiveType
265462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
266462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
267462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportPointerType : public RSExportType {
2689ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportType;
2699ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportFunc;
2709ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private:
2719ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  const RSExportType *mPointeeType;
2729ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2739ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  RSExportPointerType(RSContext *Context,
2749ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                      const llvm::StringRef &Name,
2756315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr                      const RSExportType *PointeeType)
2766b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang      : RSExportType(Context, ExportClassPointer, Name),
2776315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mPointeeType(PointeeType) {
2789ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return;
2799ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
2809ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2819ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @PT was normalized by calling RSExportType::TypeExportable() before calling
2829ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // this.
2839ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportPointerType *Create(RSContext *Context,
2849ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                     const clang::PointerType *PT,
2859ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                     const llvm::StringRef &TypeName);
2869ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2879ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  virtual const llvm::Type *convertToLLVMType() const;
2889ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
2899ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static const clang::Type *IntegerType;
290462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
2919ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline const RSExportType *getPointeeType() const { return mPointeeType; }
2929ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao};  // RSExportPointerType
293462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
294462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
295462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportVectorType : public RSExportPrimitiveType {
2969ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportType;
2979ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportElement;
2989ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private:
29992b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  unsigned mNumElement;   // number of element
3009ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
3019ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  RSExportVectorType(RSContext *Context,
3029ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     const llvm::StringRef &Name,
3039ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     DataType DT,
3049ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     DataKind DK,
3059ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     bool Normalized,
30692b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                     unsigned NumElement)
3076b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang      : RSExportPrimitiveType(Context, ExportClassVector, Name,
3086b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang                              DT, DK, Normalized),
3096315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mNumElement(NumElement) {
3109ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return;
3119ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
3129ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
3139ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @EVT was normalized by calling RSExportType::TypeExportable() before
3149ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // calling this.
3159ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportVectorType *Create(RSContext *Context,
3169ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    const clang::ExtVectorType *EVT,
3179ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    const llvm::StringRef &TypeName,
3189ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    DataKind DK = DataKindUser,
3199ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    bool Normalized = false);
3209ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
3219ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static const char *VectorTypeNameStore[][3];
3229ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
3239ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  virtual const llvm::Type *convertToLLVMType() const;
3249ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
3259ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static llvm::StringRef GetTypeName(const clang::ExtVectorType *EVT);
326462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
32792b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  inline unsigned getNumElement() const { return mNumElement; }
32892b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang};
32992b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang
33092b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// Only *square* *float* matrix is supported by now.
33192b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//
33292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// struct rs_matrix{2x2,3x3,4x4, ..., NxN} should be defined as the following
33392b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// form *exactly*:
33492b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//  typedef struct {
33592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//    float m[{NxN}];
33692b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//  } rs_matrixNxN;
33792b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//
33892b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//  where mDim will be N.
33992b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Changclass RSExportMatrixType : public RSExportType {
34092b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  friend class RSExportType;
34192b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang private:
3422e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  unsigned mDim;  // dimension
34392b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang
34492b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  RSExportMatrixType(RSContext *Context,
34592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                     const llvm::StringRef &Name,
34692b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                     unsigned Dim)
3476b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang    : RSExportType(Context, ExportClassMatrix, Name),
34892b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang      mDim(Dim) {
34992b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang    return;
35092b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  }
35192b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang
35292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  virtual const llvm::Type *convertToLLVMType() const;
35392b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang public:
35492b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  // @RT was normalized by calling RSExportType::TypeExportable() before
35592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  // calling this.
35692b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  static RSExportMatrixType *Create(RSContext *Context,
35792b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                                    const clang::RecordType *RT,
35892b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                                    const llvm::StringRef &TypeName,
35992b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                                    unsigned Dim);
36092b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang
36192b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  inline unsigned getDim() const { return mDim; }
362462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao};
363462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
3642e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Changclass RSExportConstantArrayType : public RSExportType {
3652e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  friend class RSExportType;
3662e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang private:
3672e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  const RSExportType *mElementType;  // Array element type
3682e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  unsigned mSize;  // Array size
3692e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang
3702e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  RSExportConstantArrayType(RSContext *Context,
3712e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang                            const RSExportType *ElementType,
3722e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang                            unsigned Size)
3732e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang    : RSExportType(Context,
3746b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang                   ExportClassConstantArray,
3752e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang                   DUMMY_TYPE_NAME_FOR_RS_CONSTANT_ARRAY_TYPE),
3762e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang      mElementType(ElementType),
3772e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang      mSize(Size) {
3782e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang    return;
3792e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  }
3802e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang
3812e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  // @CAT was normalized by calling RSExportType::TypeExportable() before
3822e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  // calling this.
3832e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  static RSExportConstantArrayType *Create(RSContext *Context,
3842e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang                                           const clang::ConstantArrayType *CAT);
3852e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang
3862e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  virtual const llvm::Type *convertToLLVMType() const;
3872e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang public:
3882e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  inline unsigned getSize() const { return mSize; }
3892e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  inline const RSExportType *getElementType() const { return mElementType; }
3902e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang};
3912e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang
392462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportRecordType : public RSExportType {
3939ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportType;
3949ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
3959ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  class Field {
3969ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao   private:
3979ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    const RSExportType *mType;
3989ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    // Field name
3999ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    std::string mName;
4009ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    // Link to the struct that contain this field
4019ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    const RSExportRecordType *mParent;
4020da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang    // Offset in the container
4030da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang    size_t mOffset;
4049ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
4059ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao   public:
4069ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    Field(const RSExportType *T,
4079ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao          const llvm::StringRef &Name,
4089ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao          const RSExportRecordType *Parent,
4090da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang          size_t Offset)
4106315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        : mType(T),
4116315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr          mName(Name.data(), Name.size()),
4126315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr          mParent(Parent),
4130da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang          mOffset(Offset) {
4149ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao      return;
415462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao    }
416462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
4179ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    inline const RSExportRecordType *getParent() const { return mParent; }
4189ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    inline const RSExportType *getType() const { return mType; }
4199ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    inline const std::string &getName() const { return mName; }
4200da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang    inline size_t getOffsetInParent() const { return mOffset; }
4219ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  };
422462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
4239ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef std::list<const Field*>::const_iterator const_field_iterator;
424462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
4259ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline const_field_iterator fields_begin() const {
4269ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return this->mFields.begin();
4279ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
4289ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline const_field_iterator fields_end() const {
4299ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return this->mFields.end();
4309ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
4319ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
4329ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private:
4339ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  std::list<const Field*> mFields;
4349ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  bool mIsPacked;
4359ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Artificial export struct type is not exported by user (and thus it won't
4369ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // get reflected)
4379ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  bool mIsArtificial;
4380da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang  size_t mAllocSize;
4399ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
4409ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  RSExportRecordType(RSContext *Context,
4419ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     const llvm::StringRef &Name,
4429ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     bool IsPacked,
4430da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang                     bool IsArtificial,
4440da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang                     size_t AllocSize)
4456b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang      : RSExportType(Context, ExportClassRecord, Name),
4466315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mIsPacked(IsPacked),
4470da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang        mIsArtificial(IsArtificial),
4480da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang        mAllocSize(AllocSize) {
4499ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return;
4509ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
4519ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
4529ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @RT was normalized by calling RSExportType::TypeExportable() before calling
4539ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // this.
4549ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @TypeName was retrieved from RSExportType::GetTypeName() before calling
4559ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // this.
4569ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportRecordType *Create(RSContext *Context,
4579ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    const clang::RecordType *RT,
4589ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    const llvm::StringRef &TypeName,
4599ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    bool mIsArtificial = false);
4609ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
4619ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  virtual const llvm::Type *convertToLLVMType() const;
4629ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
4630da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang  inline const std::list<const Field*>& getFields() const { return mFields; }
4649ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline bool isPacked() const { return mIsPacked; }
4659ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline bool isArtificial() const { return mIsArtificial; }
4660da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang  inline size_t getAllocSize() const { return mAllocSize; }
4679ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
4689ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  ~RSExportRecordType() {
4699ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    for (std::list<const Field*>::iterator I = mFields.begin(),
4709ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao             E = mFields.end();
4719ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao         I != E;
4729ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao         I++)
4739ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao      if (*I != NULL)
4749ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao        delete *I;
4759ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return;
4769ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
4779ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao};  // RSExportRecordType
4789ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
4799ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao}   // namespace slang
4809ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
4816315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#endif  // _SLANG_COMPILER_RS_EXPORT_TYPE_H
482