diff options
-rw-r--r-- | Android.mk | 22 | ||||
-rw-r--r-- | RSSpec.mk | 59 | ||||
-rw-r--r-- | slang_rs_export_element.cpp | 46 | ||||
-rw-r--r-- | slang_rs_export_type.cpp | 262 | ||||
-rw-r--r-- | slang_rs_export_type.h | 78 | ||||
-rw-r--r-- | slang_rs_metadata_spec_encoder.cpp | 31 | ||||
-rw-r--r-- | slang_rs_object_ref_count.cpp | 23 | ||||
-rw-r--r-- | slang_rs_object_ref_count.h | 14 | ||||
-rw-r--r-- | slang_rs_spec_table.cpp | 411 | ||||
-rw-r--r-- | slang_rs_type_spec.h | 111 |
10 files changed, 336 insertions, 721 deletions
@@ -113,20 +113,6 @@ LOCAL_SRC_FILES := slang-data.c include $(BUILD_HOST_EXECUTABLE) -# Executable rs-spec-gen for host -# ======================================================== -include $(CLEAR_VARS) - -LOCAL_MODULE := rs-spec-gen -LOCAL_MODULE_TAGS := optional - -LOCAL_MODULE_CLASS := EXECUTABLES - -LOCAL_SRC_FILES := \ - slang_rs_spec_table.cpp - -include $(BUILD_HOST_EXECUTABLE) - # ======================================================== include $(CLEAR_VARS) @@ -174,13 +160,6 @@ TBLGEN_TABLES := \ StmtNodes.inc \ RSCCOptions.inc -RS_SPEC_TABLES := \ - RSClangBuiltinEnums.inc \ - RSDataTypeEnums.inc \ - RSDataElementEnums.inc \ - RSMatrixTypeEnums.inc \ - RSObjectTypeEnums.inc - LOCAL_SRC_FILES := \ llvm-rs-cc.cpp \ slang_rs.cpp \ @@ -223,7 +202,6 @@ $(intermediates)/RSCCOptions.inc: $(LOCAL_PATH)/RSCCOptions.td $(LLVM_ROOT_PATH) @echo "Building Renderscript compiler (llvm-rs-cc) Option tables with tblgen" $(call transform-host-td-to-out,opt-parser-defs) -include frameworks/compile/slang/RSSpec.mk include $(CLANG_HOST_BUILD_MK) include $(CLANG_TBLGEN_RULES_MK) include $(BUILD_HOST_EXECUTABLE) diff --git a/RSSpec.mk b/RSSpec.mk deleted file mode 100644 index ba9c016..0000000 --- a/RSSpec.mk +++ /dev/null @@ -1,59 +0,0 @@ -# -# Copyright (C) 2010 The Android Open Source Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -LOCAL_PATH := $(call my-dir) -RS_SPEC_GEN := $(BUILD_OUT_EXECUTABLES)/rs-spec-gen$(BUILD_EXECUTABLE_SUFFIX) - -define generate-rs-spec-inc -@mkdir -p $(dir $@) -@echo "Host RSSpecGen: $(LOCAL_MODULE) (gen-$(1)) <= $<" -$(hide) $(RS_SPEC_GEN) \ - -gen-$(strip $(1)) \ - > $@ -endef - -ifneq ($(strip $(TBLGEN_TABLES)),) - -ifneq ($(findstring RSClangBuiltinEnums.inc,$(RS_SPEC_TABLES)),) -LOCAL_GENERATED_SOURCES += $(intermediates)/RSClangBuiltinEnums.inc -$(intermediates)/RSClangBuiltinEnums.inc: $(RS_SPEC_GEN) - $(call generate-rs-spec-inc,clang-builtin-enums) -endif - -ifneq ($(findstring RSDataTypeEnums.inc,$(RS_SPEC_TABLES)),) -LOCAL_GENERATED_SOURCES += $(intermediates)/RSDataTypeEnums.inc -$(intermediates)/RSDataTypeEnums.inc: $(RS_SPEC_GEN) - $(call generate-rs-spec-inc,rs-data-type-enums) -endif - -ifneq ($(findstring RSMatrixTypeEnums.inc,$(RS_SPEC_TABLES)),) -LOCAL_GENERATED_SOURCES += $(intermediates)/RSMatrixTypeEnums.inc -$(intermediates)/RSMatrixTypeEnums.inc: $(RS_SPEC_GEN) - $(call generate-rs-spec-inc,rs-matrix-type-enums) -endif - -ifneq ($(findstring RSObjectTypeEnums.inc,$(RS_SPEC_TABLES)),) -LOCAL_GENERATED_SOURCES += $(intermediates)/RSObjectTypeEnums.inc -$(intermediates)/RSObjectTypeEnums.inc: $(RS_SPEC_GEN) - $(call generate-rs-spec-inc,rs-object-type-enums) -endif - -ifneq ($(findstring RSDataElementEnums.inc,$(RS_SPEC_TABLES)),) -LOCAL_GENERATED_SOURCES += $(intermediates)/RSDataElementEnums.inc -$(intermediates)/RSDataElementEnums.inc: $(RS_SPEC_GEN) - $(call generate-rs-spec-inc,rs-data-element-enums) -endif - -endif diff --git a/slang_rs_export_element.cpp b/slang_rs_export_element.cpp index 754c322..9847f22 100644 --- a/slang_rs_export_element.cpp +++ b/slang_rs_export_element.cpp @@ -31,26 +31,40 @@ namespace slang { bool RSExportElement::Initialized = false; RSExportElement::ElementInfoMapTy RSExportElement::ElementInfoMap; +struct DataElementInfo { + const char *name; + RSExportPrimitiveType::DataType dataType; + bool normalized; + int vsize; +}; + +// TODO This is very similar to DataElements[] in slang_rs_spec_table.cpp. Merge. +static DataElementInfo DataElementInfoTable[] = { + {"rs_pixel_l", RSExportPrimitiveType::DataTypeUnsigned8, true, 1}, + {"rs_pixel_a", RSExportPrimitiveType::DataTypeUnsigned8, true, 1}, + {"rs_pixel_la", RSExportPrimitiveType::DataTypeUnsigned8, true, 2}, + {"rs_pixel_rgb", RSExportPrimitiveType::DataTypeUnsigned8, true, 3}, + {"rs_pixel_rgba", RSExportPrimitiveType::DataTypeUnsigned8, true, 4}, + {"rs_pixel_rgb565", RSExportPrimitiveType::DataTypeUnsigned8, true, 3}, + {"rs_pixel_rgb5551", RSExportPrimitiveType::DataTypeUnsigned8, true, 4}, + {"rs_pixel_rgb4444", RSExportPrimitiveType::DataTypeUnsigned8, true, 4}, +}; + +const int DataElementInfoTableCount = sizeof(DataElementInfoTable) / sizeof(DataElementInfoTable[0]); + +// TODO Rename RSExportElement to RSExportDataElement void RSExportElement::Init() { if (!Initialized) { // Initialize ElementInfoMap -#define ENUM_RS_DATA_ELEMENT(_name, _dt, _norm, _vsize) \ - { \ - ElementInfo *EI = new ElementInfo; \ - EI->type = RSExportPrimitiveType::DataType ## _dt; \ - EI->normalized = _norm; \ - EI->vsize = _vsize; \ - \ - llvm::StringRef Name(_name); \ - ElementInfoMap.insert( \ - ElementInfoMapTy::value_type::Create( \ - Name.begin(), \ - Name.end(), \ - ElementInfoMap.getAllocator(), \ - EI)); \ + for (int i = 0; i < DataElementInfoTableCount; i++) { + ElementInfo *EI = new ElementInfo; + EI->type = DataElementInfoTable[i].dataType; + EI->normalized = DataElementInfoTable[i].normalized; + EI->vsize = DataElementInfoTable[i].vsize; + llvm::StringRef Name(DataElementInfoTable[i].name); + ElementInfoMap.insert(ElementInfoMapTy::value_type::Create( + Name.begin(), Name.end(), ElementInfoMap.getAllocator(), EI)); } -#include "RSDataElementEnums.inc" - Initialized = true; } return; diff --git a/slang_rs_export_type.cpp b/slang_rs_export_type.cpp index 3f302ac..0006117 100644 --- a/slang_rs_export_type.cpp +++ b/slang_rs_export_type.cpp @@ -42,43 +42,126 @@ namespace slang { namespace { +/* For the data types we support, their category, names, and size (in bits). + * + * IMPORTANT: The data types in this table should be at the same index + * as specified by the corresponding DataType enum. + */ static RSReflectionType gReflectionTypes[] = { - {"FLOAT_16", "F16", 16, "half", "half", "Half", "Half", false}, - {"FLOAT_32", "F32", 32, "float", "float", "Float", "Float", false}, - {"FLOAT_64", "F64", 64, "double", "double", "Double", "Double",false}, - {"SIGNED_8", "I8", 8, "int8_t", "byte", "Byte", "Byte", false}, - {"SIGNED_16", "I16", 16, "int16_t", "short", "Short", "Short", false}, - {"SIGNED_32", "I32", 32, "int32_t", "int", "Int", "Int", false}, - {"SIGNED_64", "I64", 64, "int64_t", "long", "Long", "Long", false}, - {"UNSIGNED_8", "U8", 8, "uint8_t", "short", "UByte", "Short", true}, - {"UNSIGNED_16", "U16", 16, "uint16_t", "int", "UShort", "Int", true}, - {"UNSIGNED_32", "U32", 32, "uint32_t", "long", "UInt", "Long", true}, - {"UNSIGNED_64", "U64", 64, "uint64_t", "long", "ULong", "Long", false}, - - {"BOOLEAN", "BOOLEAN", 8, "bool", "boolean", NULL, NULL, false}, - - {"UNSIGNED_5_6_5", NULL, 16, NULL, NULL, NULL, NULL, false}, - {"UNSIGNED_5_5_5_1", NULL, 16, NULL, NULL, NULL, NULL, false}, - {"UNSIGNED_4_4_4_4", NULL, 16, NULL, NULL, NULL, NULL, false}, - - {"MATRIX_2X2", NULL, 4*32, "rsMatrix_2x2", "Matrix2f", NULL, NULL, false}, - {"MATRIX_3X3", NULL, 9*32, "rsMatrix_3x3", "Matrix3f", NULL, NULL, false}, - {"MATRIX_4X4", NULL, 16*32, "rsMatrix_4x4", "Matrix4f", NULL, NULL, false}, - - {"RS_ELEMENT", "ELEMENT", 32, "Element", "Element", NULL, NULL, false}, - {"RS_TYPE", "TYPE", 32, "Type", "Type", NULL, NULL, false}, - {"RS_ALLOCATION", "ALLOCATION", 32, "Allocation", "Allocation", NULL, NULL, false}, - {"RS_SAMPLER", "SAMPLER", 32, "Sampler", "Sampler", NULL, NULL, false}, - {"RS_SCRIPT", "SCRIPT", 32, "Script", "Script", NULL, NULL, false}, - {"RS_MESH", "MESH", 32, "Mesh", "Mesh", NULL, NULL, false}, - {"RS_PATH", "PATH", 32, "Path", "Path", NULL, NULL, false}, - {"RS_PROGRAM_FRAGMENT", "PROGRAM_FRAGMENT", 32, "ProgramFragment", "ProgramFragment", NULL, NULL, false}, - {"RS_PROGRAM_VERTEX", "PROGRAM_VERTEX", 32, "ProgramVertex", "ProgramVertex", NULL, NULL, false}, - {"RS_PROGRAM_RASTER", "PROGRAM_RASTER", 32, "ProgramRaster", "ProgramRaster", NULL, NULL, false}, - {"RS_PROGRAM_STORE", "PROGRAM_STORE", 32, "ProgramStore", "ProgramStore", NULL, NULL, false}, - {"RS_FONT", "FONT", 32, "Font", "Font", NULL, NULL, false} + {PrimitiveDataType, "FLOAT_16", "F16", 16, "half", "half", "Half", "Half", false}, + {PrimitiveDataType, "FLOAT_32", "F32", 32, "float", "float", "Float", "Float", false}, + {PrimitiveDataType, "FLOAT_64", "F64", 64, "double", "double", "Double", "Double",false}, + {PrimitiveDataType, "SIGNED_8", "I8", 8, "int8_t", "byte", "Byte", "Byte", false}, + {PrimitiveDataType, "SIGNED_16", "I16", 16, "int16_t", "short", "Short", "Short", false}, + {PrimitiveDataType, "SIGNED_32", "I32", 32, "int32_t", "int", "Int", "Int", false}, + {PrimitiveDataType, "SIGNED_64", "I64", 64, "int64_t", "long", "Long", "Long", false}, + {PrimitiveDataType, "UNSIGNED_8", "U8", 8, "uint8_t", "short", "UByte", "Short", true}, + {PrimitiveDataType, "UNSIGNED_16", "U16", 16, "uint16_t", "int", "UShort", "Int", true}, + {PrimitiveDataType, "UNSIGNED_32", "U32", 32, "uint32_t", "long", "UInt", "Long", true}, + {PrimitiveDataType, "UNSIGNED_64", "U64", 64, "uint64_t", "long", "ULong", "Long", false}, + + {PrimitiveDataType, "BOOLEAN", "BOOLEAN", 8, "bool", "boolean", NULL, NULL, false}, + + {PrimitiveDataType, "UNSIGNED_5_6_5", NULL, 16, NULL, NULL, NULL, NULL, false}, + {PrimitiveDataType, "UNSIGNED_5_5_5_1", NULL, 16, NULL, NULL, NULL, NULL, false}, + {PrimitiveDataType, "UNSIGNED_4_4_4_4", NULL, 16, NULL, NULL, NULL, NULL, false}, + + {MatrixDataType, "MATRIX_2X2", NULL, 4*32, "rsMatrix_2x2", "Matrix2f", NULL, NULL, false}, + {MatrixDataType, "MATRIX_3X3", NULL, 9*32, "rsMatrix_3x3", "Matrix3f", NULL, NULL, false}, + {MatrixDataType, "MATRIX_4X4", NULL, 16*32, "rsMatrix_4x4", "Matrix4f", NULL, NULL, false}, + + // TODO: For 64 bit, what will be the size of the objects?? + {ObjectDataType, "RS_ELEMENT", "ELEMENT", 32, "Element", "Element", NULL, NULL, false}, + {ObjectDataType, "RS_TYPE", "TYPE", 32, "Type", "Type", NULL, NULL, false}, + {ObjectDataType, "RS_ALLOCATION", "ALLOCATION", 32, "Allocation", "Allocation", NULL, NULL, false}, + {ObjectDataType, "RS_SAMPLER", "SAMPLER", 32, "Sampler", "Sampler", NULL, NULL, false}, + {ObjectDataType, "RS_SCRIPT", "SCRIPT", 32, "Script", "Script", NULL, NULL, false}, + {ObjectDataType, "RS_MESH", "MESH", 32, "Mesh", "Mesh", NULL, NULL, false}, + {ObjectDataType, "RS_PATH", "PATH", 32, "Path", "Path", NULL, NULL, false}, + + {ObjectDataType, "RS_PROGRAM_FRAGMENT", "PROGRAM_FRAGMENT", 32, "ProgramFragment", "ProgramFragment", NULL, NULL, false}, + {ObjectDataType, "RS_PROGRAM_VERTEX", "PROGRAM_VERTEX", 32, "ProgramVertex", "ProgramVertex", NULL, NULL, false}, + {ObjectDataType, "RS_PROGRAM_RASTER", "PROGRAM_RASTER", 32, "ProgramRaster", "ProgramRaster", NULL, NULL, false}, + {ObjectDataType, "RS_PROGRAM_STORE", "PROGRAM_STORE", 32, "ProgramStore", "ProgramStore", NULL, NULL, false}, + {ObjectDataType, "RS_FONT", "FONT", 32, "Font", "Font", NULL, NULL, false} +}; + +const int kMaxVectorSize = 4; + +struct BuiltinInfo { + clang::BuiltinType::Kind builtinTypeKind; + RSExportPrimitiveType::DataType type; + /* TODO If we return std::string instead of llvm::StringRef, we could build + * the name instead of duplicating the entries. + */ + const char *cname[kMaxVectorSize]; +}; + +BuiltinInfo BuiltinInfoTable[] = { + {clang::BuiltinType::Bool, RSExportPrimitiveType::DataTypeBoolean, + {"bool", "bool2", "bool3", "bool4"}}, + {clang::BuiltinType::Char_U, RSExportPrimitiveType::DataTypeUnsigned8, + {"uchar", "uchar2", "uchar3", "uchar4"}}, + {clang::BuiltinType::UChar, RSExportPrimitiveType::DataTypeUnsigned8, + {"uchar", "uchar2", "uchar3", "uchar4"}}, + {clang::BuiltinType::Char16, RSExportPrimitiveType::DataTypeSigned16, + {"short", "short2", "short3", "short4"}}, + {clang::BuiltinType::Char32, RSExportPrimitiveType::DataTypeSigned32, + {"int", "int2", "int3", "int4"}}, + {clang::BuiltinType::UShort, RSExportPrimitiveType::DataTypeUnsigned16, + {"ushort", "ushort2", "ushort3", "ushort4"}}, + {clang::BuiltinType::UInt, RSExportPrimitiveType::DataTypeUnsigned32, + {"uint", "uint2", "uint3", "uint4"}}, + {clang::BuiltinType::ULong, RSExportPrimitiveType::DataTypeUnsigned32, + {"uint", "uint2", "uint3", "uint4"}}, + {clang::BuiltinType::ULongLong, RSExportPrimitiveType::DataTypeUnsigned64, + {"ulong", "ulong2", "ulong3", "ulong4"}}, + + {clang::BuiltinType::Char_S, RSExportPrimitiveType::DataTypeSigned8, + {"char", "char2", "char3", "char4"}}, + {clang::BuiltinType::SChar, RSExportPrimitiveType::DataTypeSigned8, + {"char", "char2", "char3", "char4"}}, + {clang::BuiltinType::Short, RSExportPrimitiveType::DataTypeSigned16, + {"short", "short2", "short3", "short4"}}, + {clang::BuiltinType::Int, RSExportPrimitiveType::DataTypeSigned32, + {"int", "int2", "int3", "int4"}}, + {clang::BuiltinType::Long, RSExportPrimitiveType::DataTypeSigned64, + {"long", "long2", "long3", "long4"}}, + {clang::BuiltinType::LongLong, RSExportPrimitiveType::DataTypeSigned64, + {"long", "long2", "long3", "long4"}}, + {clang::BuiltinType::Float, RSExportPrimitiveType::DataTypeFloat32, + {"float", "float2", "float3", "float4"}}, + {clang::BuiltinType::Double, RSExportPrimitiveType::DataTypeFloat64, + {"double", "double2", "double3", "double4"}}, +}; +const int BuiltinInfoTableCount = sizeof(BuiltinInfoTable) / sizeof(BuiltinInfoTable[0]); + +struct NameAndPrimitiveType { + const char *name; + RSExportPrimitiveType::DataType dataType; +}; + +static NameAndPrimitiveType MatrixAndObjectDataTypes[] = { + {"rs_matrix2x2", RSExportPrimitiveType::DataTypeRSMatrix2x2}, + {"rs_matrix3x3", RSExportPrimitiveType::DataTypeRSMatrix3x3}, + {"rs_matrix4x4", RSExportPrimitiveType::DataTypeRSMatrix4x4}, + {"rs_element", RSExportPrimitiveType::DataTypeRSElement}, + {"rs_type", RSExportPrimitiveType::DataTypeRSType}, + {"rs_allocation", RSExportPrimitiveType::DataTypeRSAllocation}, + {"rs_sampler", RSExportPrimitiveType::DataTypeRSSampler}, + {"rs_script", RSExportPrimitiveType::DataTypeRSScript}, + {"rs_mesh", RSExportPrimitiveType::DataTypeRSMesh}, + {"rs_path", RSExportPrimitiveType::DataTypeRSPath}, + {"rs_program_fragment", RSExportPrimitiveType::DataTypeRSProgramFragment}, + {"rs_program_vertex", RSExportPrimitiveType::DataTypeRSProgramVertex}, + {"rs_program_raster", RSExportPrimitiveType::DataTypeRSProgramRaster}, + {"rs_program_store", RSExportPrimitiveType::DataTypeRSProgramStore}, + {"rs_font", RSExportPrimitiveType::DataTypeRSFont}, }; +const int MatrixAndObjectDataTypesCount = + sizeof(MatrixAndObjectDataTypes) / sizeof(MatrixAndObjectDataTypes[0]); + static const clang::Type *TypeExportableHelper( const clang::Type *T, llvm::SmallPtrSet<const clang::Type*, 8>& SPS, @@ -145,6 +228,15 @@ static const clang::Type *ConstantArrayTypeExportableHelper( } } +BuiltinInfo *FindBuiltinType(clang::BuiltinType::Kind builtinTypeKind) { + for (int i = 0; i < BuiltinInfoTableCount; i++) { + if (builtinTypeKind == BuiltinInfoTable[i].builtinTypeKind) { + return &BuiltinInfoTable[i]; + } + } + return NULL; +} + static const clang::Type *TypeExportableHelper( clang::Type const *T, llvm::SmallPtrSet<clang::Type const *, 8> &SPS, @@ -162,16 +254,7 @@ static const clang::Type *TypeExportableHelper( case clang::Type::Builtin: { const clang::BuiltinType *BT = UNSAFE_CAST_TYPE(const clang::BuiltinType, T); - - switch (BT->getKind()) { -#define ENUM_SUPPORT_BUILTIN_TYPE(builtin_type, type, cname) \ - case builtin_type: -#include "RSClangBuiltinEnums.inc" - return T; - default: { - return NULL; - } - } + return FindBuiltinType(BT->getKind()) == NULL ? NULL : T; } case clang::Type::Record: { if (RSExportPrimitiveType::GetRSSpecificType(T) != @@ -592,18 +675,11 @@ llvm::StringRef RSExportType::GetTypeName(const clang::Type* T) { case clang::Type::Builtin: { const clang::BuiltinType *BT = UNSAFE_CAST_TYPE(const clang::BuiltinType, T); - - switch (BT->getKind()) { -#define ENUM_SUPPORT_BUILTIN_TYPE(builtin_type, type, cname) \ - case builtin_type: \ - return cname; \ - break; -#include "RSClangBuiltinEnums.inc" - default: { - slangAssert(false && "Unknown data type of the builtin"); - break; - } + BuiltinInfo *info = FindBuiltinType(BT->getKind()); + if (info != NULL) { + return info->cname[0]; } + slangAssert(false && "Unknown data type of the builtin"); break; } case clang::Type::Record: { @@ -838,12 +914,10 @@ RSExportPrimitiveType::GetRSSpecificType(const llvm::StringRef &TypeName) { return DataTypeUnknown; if (RSSpecificTypeMap->empty()) { -#define ENUM_RS_MATRIX_TYPE(type, cname, dim) \ - RSSpecificTypeMap->GetOrCreateValue(cname, DataType ## type); -#include "RSMatrixTypeEnums.inc" -#define ENUM_RS_OBJECT_TYPE(type, cname) \ - RSSpecificTypeMap->GetOrCreateValue(cname, DataType ## type); -#include "RSObjectTypeEnums.inc" + for (int i = 0; i < MatrixAndObjectDataTypesCount; i++) { + RSSpecificTypeMap->GetOrCreateValue(MatrixAndObjectDataTypes[i].name, + MatrixAndObjectDataTypes[i].dataType); + } } RSSpecificTypeMapTy::const_iterator I = RSSpecificTypeMap->find(TypeName); @@ -863,11 +937,17 @@ RSExportPrimitiveType::GetRSSpecificType(const clang::Type *T) { } bool RSExportPrimitiveType::IsRSMatrixType(DataType DT) { - return ((DT >= FirstRSMatrixType) && (DT <= LastRSMatrixType)); + if (DT < 0 || DT >= DataTypeMax) { + return false; + } + return gReflectionTypes[DT].category == MatrixDataType; } bool RSExportPrimitiveType::IsRSObjectType(DataType DT) { - return ((DT >= FirstRSObjectType) && (DT <= LastRSObjectType)); + if (DT < 0 || DT >= DataTypeMax) { + return false; + } + return gReflectionTypes[DT].category == ObjectDataType; } bool RSExportPrimitiveType::IsStructureTypeWithRSObject(const clang::Type *T) { @@ -931,18 +1011,11 @@ bool RSExportPrimitiveType::IsStructureTypeWithRSObject(const clang::Type *T) { return RSObjectTypeSeen; } -const size_t RSExportPrimitiveType::SizeOfDataTypeInBits[] = { -#define ENUM_RS_DATA_TYPE(type, cname, bits) \ - bits, -#include "RSDataTypeEnums.inc" - 0 // DataTypeMax -}; - size_t RSExportPrimitiveType::GetSizeInBits(const RSExportPrimitiveType *EPT) { - slangAssert(((EPT->getType() > DataTypeUnknown) && - (EPT->getType() < DataTypeMax)) && + int type = EPT->getType(); + slangAssert((type > DataTypeUnknown && type < DataTypeMax) && "RSExportPrimitiveType::GetSizeInBits : unknown data type"); - return SizeOfDataTypeInBits[ static_cast<int>(EPT->getType()) ]; + return gReflectionTypes[type].size_in_bits; } RSExportPrimitiveType::DataType @@ -954,20 +1027,14 @@ RSExportPrimitiveType::GetDataType(RSContext *Context, const clang::Type *T) { case clang::Type::Builtin: { const clang::BuiltinType *BT = UNSAFE_CAST_TYPE(const clang::BuiltinType, T); - switch (BT->getKind()) { -#define ENUM_SUPPORT_BUILTIN_TYPE(builtin_type, type, cname) \ - case builtin_type: { \ - return DataType ## type; \ - } -#include "RSClangBuiltinEnums.inc" - // The size of type WChar depend on platform so we abandon the support - // to them. - default: { - Context->ReportError("built-in type cannot be exported: '%0'") - << T->getTypeClassName(); - break; - } + BuiltinInfo *info = FindBuiltinType(BT->getKind()); + if (info != NULL) { + return info->type; } + // The size of type WChar depend on platform so we abandon the support + // to them. + Context->ReportError("built-in type cannot be exported: '%0'") + << T->getTypeClassName(); break; } case clang::Type::Record: { @@ -1154,30 +1221,29 @@ bool RSExportPointerType::equals(const RSExportable *E) const { llvm::StringRef RSExportVectorType::GetTypeName(const clang::ExtVectorType *EVT) { const clang::Type *ElementType = GET_EXT_VECTOR_ELEMENT_TYPE(EVT); + llvm::StringRef name; if ((ElementType->getTypeClass() != clang::Type::Builtin)) - return llvm::StringRef(); + return name; const clang::BuiltinType *BT = UNSAFE_CAST_TYPE(const clang::BuiltinType, ElementType); if ((EVT->getNumElements() < 1) || (EVT->getNumElements() > 4)) - return llvm::StringRef(); + return name; - switch (BT->getKind()) { + BuiltinInfo *info = FindBuiltinType(BT->getKind()); + if (info != NULL) { // Compiler is smart enough to optimize following *big if branches* since // they all become "constant comparison" after macro expansion -#define ENUM_SUPPORT_BUILTIN_TYPE(builtin_type, type, cname) \ - case builtin_type: { \ - const char *Name[] = { cname"2", cname"3", cname"4" }; \ - return Name[EVT->getNumElements() - 2]; \ - break; \ - } -#include "RSClangBuiltinEnums.inc" - default: { - return llvm::StringRef(); + int I = EVT->getNumElements() - 1; + if (I < kMaxVectorSize) { + name = info->cname[I]; + } else { + slangAssert(false && "Max vector is 4"); } } + return name; } RSExportVectorType *RSExportVectorType::Create(RSContext *Context, diff --git a/slang_rs_export_type.h b/slang_rs_export_type.h index 80bb317..3a87dcb 100644 --- a/slang_rs_export_type.h +++ b/slang_rs_export_type.h @@ -61,7 +61,15 @@ namespace slang { class RSContext; + // Broad grouping of the data types + enum DataTypeCategory { + PrimitiveDataType, + MatrixDataType, + ObjectDataType + }; + typedef struct { + DataTypeCategory category; const char * rs_type; const char * rs_short_type; uint32_t size_in_bits; @@ -217,29 +225,59 @@ class RSExportPrimitiveType : public RSExportType { friend class RSExportElement; public: // From graphics/java/android/renderscript/Element.java: Element.DataType - typedef enum { + // TODO move out of here + /* NOTE: The values of the enums are found compiled in the bit code (i.e. as + * values, not symbolic. When adding new types, you must add them to the end. + * If removing types, you can't re-use the integer value. + * + * TODO: but if you do this, you won't be able to keep using First* & Last* + * for validation. + * + * IMPORTANT: This enum should correspond one-for-one to the entries found in the + * gReflectionsTypes table (except for the two negative numbers). Don't edit one without + * the other. + */ + enum DataType { DataTypeIsStruct = -2, DataTypeUnknown = -1, -#define ENUM_PRIMITIVE_DATA_TYPE_RANGE(begin_type, end_type) \ - FirstPrimitiveType = DataType ## begin_type, \ - LastPrimitiveType = DataType ## end_type, - -#define ENUM_RS_MATRIX_DATA_TYPE_RANGE(begin_type, end_type) \ - FirstRSMatrixType = DataType ## begin_type, \ - LastRSMatrixType = DataType ## end_type, - -#define ENUM_RS_OBJECT_DATA_TYPE_RANGE(begin_type, end_type) \ - FirstRSObjectType = DataType ## begin_type, \ - LastRSObjectType = DataType ## end_type, - -#define ENUM_RS_DATA_TYPE(type, cname, bits) \ - DataType ## type, - -#include "RSDataTypeEnums.inc" - + DataTypeFloat16 = 0, + DataTypeFloat32 = 1, + DataTypeFloat64 = 2, + DataTypeSigned8 = 3, + DataTypeSigned16 = 4, + DataTypeSigned32 = 5, + DataTypeSigned64 = 6, + DataTypeUnsigned8 = 7, + DataTypeUnsigned16 = 8, + DataTypeUnsigned32 = 9, + DataTypeUnsigned64 = 10, + DataTypeBoolean = 11, + DataTypeUnsigned565 = 12, + DataTypeUnsigned5551 = 13, + DataTypeUnsigned4444 = 14, + + DataTypeRSMatrix2x2 = 15, + DataTypeRSMatrix3x3 = 16, + DataTypeRSMatrix4x4 = 17, + + DataTypeRSElement = 18, + DataTypeRSType = 19, + DataTypeRSAllocation = 20, + DataTypeRSSampler = 21, + DataTypeRSScript = 22, + DataTypeRSMesh = 23, + DataTypeRSPath = 24, + DataTypeRSProgramFragment = 25, + DataTypeRSProgramVertex = 26, + DataTypeRSProgramRaster = 27, + DataTypeRSProgramStore = 28, + DataTypeRSFont = 29, + + // This should always be last and correspond to the size of the gReflectionTypes table. DataTypeMax - } DataType; + }; + private: // NOTE: There's no any instance of RSExportPrimitiveType which mType @@ -309,7 +347,7 @@ class RSExportPrimitiveType : public RSExportType { inline DataType getType() const { return mType; } inline bool isRSObjectType() const { - return ((mType >= FirstRSObjectType) && (mType <= LastRSObjectType)); + return IsRSObjectType(mType); } virtual bool equals(const RSExportable *E) const; diff --git a/slang_rs_metadata_spec_encoder.cpp b/slang_rs_metadata_spec_encoder.cpp index 26a4766..86aa582 100644 --- a/slang_rs_metadata_spec_encoder.cpp +++ b/slang_rs_metadata_spec_encoder.cpp @@ -92,10 +92,13 @@ class RSMetadataEncoderInternal { unsigned encodeTypeBase(const struct RSTypeBase *Base); unsigned encodeTypeBaseAsKey(const struct RSTypeBase *Base); -#define ENUM_RS_DATA_TYPE_CLASS(x) \ - unsigned encode ## x ## Type(const union RSType *T); -RS_DATA_TYPE_CLASS_ENUMS -#undef ENUM_RS_DATA_TYPE_CLASS + + unsigned encodePrimitiveType(const union RSType *T); + unsigned encodePointerType(const union RSType *T); + unsigned encodeVectorType(const union RSType *T); + unsigned encodeMatrixType(const union RSType *T); + unsigned encodeConstantArrayType(const union RSType *T); + unsigned encodeRecordType(const union RSType *T); unsigned encodeRSType(const union RSType *T); @@ -292,11 +295,21 @@ unsigned RSMetadataEncoderInternal::encodeRecordType(const union RSType *T) { unsigned RSMetadataEncoderInternal::encodeRSType(const union RSType *T) { switch (static_cast<enum RSTypeClass>(RS_TYPE_GET_CLASS(T))) { -#define ENUM_RS_DATA_TYPE_CLASS(x) \ - case RS_TC_ ## x: return encode ## x ## Type(T); - RS_DATA_TYPE_CLASS_ENUMS -#undef ENUM_RS_DATA_TYPE_CLASS - default: return 0; + case RS_TC_Primitive: + return encodePrimitiveType(T); + case RS_TC_Pointer: + return encodePointerType(T); + case RS_TC_Vector: + return encodeVectorType(T); + case RS_TC_Matrix: + return encodeMatrixType(T); + case RS_TC_ConstantArray: + return encodeConstantArrayType(T); + case RS_TC_Record: + return encodeRecordType(T); + default: + slangAssert(false && "unexpected data type"); + return 0; } return 0; } diff --git a/slang_rs_object_ref_count.cpp b/slang_rs_object_ref_count.cpp index 166344e..03f0c5f 100644 --- a/slang_rs_object_ref_count.cpp +++ b/slang_rs_object_ref_count.cpp @@ -32,17 +32,16 @@ namespace slang { -clang::FunctionDecl *RSObjectRefCount:: - RSSetObjectFD[RSExportPrimitiveType::LastRSObjectType - - RSExportPrimitiveType::FirstRSObjectType + 1]; -clang::FunctionDecl *RSObjectRefCount:: - RSClearObjectFD[RSExportPrimitiveType::LastRSObjectType - - RSExportPrimitiveType::FirstRSObjectType + 1]; +/* Even though those two arrays are of size DataTypeMax, only entries that + * correspond to object types will be set. + */ +clang::FunctionDecl * +RSObjectRefCount::RSSetObjectFD[RSExportPrimitiveType::DataTypeMax]; +clang::FunctionDecl * +RSObjectRefCount::RSClearObjectFD[RSExportPrimitiveType::DataTypeMax]; void RSObjectRefCount::GetRSRefCountingFunctions(clang::ASTContext &C) { - for (unsigned i = 0; - i < (sizeof(RSClearObjectFD) / sizeof(clang::FunctionDecl*)); - i++) { + for (unsigned i = 0; i < RSExportPrimitiveType::DataTypeMax; i++) { RSSetObjectFD[i] = NULL; RSClearObjectFD[i] = NULL; } @@ -83,7 +82,11 @@ void RSObjectRefCount::GetRSRefCountingFunctions(clang::ASTContext &C) { slangAssert(RSExportPrimitiveType::IsRSObjectType(DT) && "must be RS object type"); - RSObjectFD[(DT - RSExportPrimitiveType::FirstRSObjectType)] = FD; + if (DT >= 0 && DT < RSExportPrimitiveType::DataTypeMax) { + RSObjectFD[DT] = FD; + } else { + slangAssert(false && "incorrect type"); + } } } } diff --git a/slang_rs_object_ref_count.h b/slang_rs_object_ref_count.h index 1e87ca1..3721af8 100644 --- a/slang_rs_object_ref_count.h +++ b/slang_rs_object_ref_count.h @@ -119,7 +119,12 @@ class RSObjectRefCount : public clang::StmtVisitor<RSObjectRefCount> { static clang::FunctionDecl *GetRSSetObjectFD( RSExportPrimitiveType::DataType DT) { slangAssert(RSExportPrimitiveType::IsRSObjectType(DT)); - return RSSetObjectFD[(DT - RSExportPrimitiveType::FirstRSObjectType)]; + if (DT >= 0 && DT < RSExportPrimitiveType::DataTypeMax) { + return RSSetObjectFD[DT]; + } else { + slangAssert(false && "incorrect type"); + return NULL; + } } static clang::FunctionDecl *GetRSSetObjectFD(const clang::Type *T) { @@ -129,7 +134,12 @@ class RSObjectRefCount : public clang::StmtVisitor<RSObjectRefCount> { static clang::FunctionDecl *GetRSClearObjectFD( RSExportPrimitiveType::DataType DT) { slangAssert(RSExportPrimitiveType::IsRSObjectType(DT)); - return RSClearObjectFD[(DT - RSExportPrimitiveType::FirstRSObjectType)]; + if (DT >= 0 && DT < RSExportPrimitiveType::DataTypeMax) { + return RSClearObjectFD[DT]; + } else { + slangAssert(false && "incorrect type"); + return NULL; + } } static clang::FunctionDecl *GetRSClearObjectFD(const clang::Type *T) { diff --git a/slang_rs_spec_table.cpp b/slang_rs_spec_table.cpp deleted file mode 100644 index 87fb3b5..0000000 --- a/slang_rs_spec_table.cpp +++ /dev/null @@ -1,411 +0,0 @@ -/* - * Copyright 2010, The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <cstdio> -#include <cstring> - -#include <string> - -#include "slang_rs_type_spec.h" - -enum { -#define ENUM_PRIMITIVE_DATA_TYPE(x, name, bits) x, -#define PRIMITIVE_DATA_TYPE_RANGE(x, y) \ - FirstPrimitiveType = x, \ - LastPrimitiveType = y, - PRIMITIVE_DATA_TYPE_ENUMS -#undef ENUM_PRIMITIVE_DATA_TYPE -#undef PRIMITIVE_DATA_TYPE_RANGE - -#define ENUM_RS_MATRIX_DATA_TYPE(x, name, dim) x, -#define RS_MATRIX_DATA_TYPE_RANGE(x, y) \ - FirstRSMatrixType = x, \ - LastRSMatrixType = y, - RS_MATRIX_DATA_TYPE_ENUMS -#undef ENUM_RS_MATRIX_DATA_TYPE -#undef RS_MATRIX_DATA_TYPE_RANGE - -#define ENUM_RS_OBJECT_DATA_TYPE(x, name) x, -#define RS_OBJECT_DATA_TYPE_RANGE(x, y) \ - FirstRSObjectType = x, \ - LastRSObjectType = y, - RS_OBJECT_DATA_TYPE_ENUMS -#undef ENUM_RS_OBJECT_DATA_TYPE -#undef RS_OBJECT_DATA_TYPE_RANGE -}; - -class RSDataTypeSpec { - private: - const char *mTypeName; // e.g. Float32 - // FIXME: better name - const char *mTypePragmaName; // e.g. float - size_t mBits; - - protected: - enum { - DT_PrimitiveClass, - DT_RSMatrixClass, - DT_RSObjectClass - } mClass; - - public: - RSDataTypeSpec(const char *TypeName, - const char *TypePragmaName, - size_t Bits) - : mTypeName(TypeName), - mTypePragmaName(TypePragmaName), - mBits(Bits), - mClass(DT_PrimitiveClass) { - return; - } - - inline const char *getTypeName() const { return mTypeName; } - inline const char *getTypePragmaName() const { return mTypePragmaName; } - inline size_t getSizeInBit() const { return mBits; } - inline bool isRSMatrix() const { return (mClass == DT_RSMatrixClass); } - inline bool isRSObject() const { return (mClass == DT_RSObjectClass); } -}; - -class RSMatrixDataTypeSpec : public RSDataTypeSpec { - private: - unsigned mDim; - static float ignore; - - public: - RSMatrixDataTypeSpec(const char *TypeName, - const char *TypePragmaName, - unsigned Dim) - : RSDataTypeSpec(TypeName, TypePragmaName, Dim * Dim * sizeof(ignore)), - mDim(Dim) { - mClass = DT_RSMatrixClass; - return; - } - - inline unsigned getDim() const { return mDim; } -}; - -class RSObjectDataTypeSpec : public RSDataTypeSpec { - public: - RSObjectDataTypeSpec(const char *TypeName, - const char *TypePragmaName) - : RSDataTypeSpec(TypeName, TypePragmaName, 32 /* opaque pointer */) { - mClass = DT_RSObjectClass; - return; - } -}; - -///////////////////////////////////////////////////////////////////////////// - -// clang::BuiltinType::Kind -> RSDataTypeSpec -class ClangBuiltinTypeMap { - const char *mBuiltinTypeKind; - const RSDataTypeSpec *mDataType; - - public: - ClangBuiltinTypeMap(const char *BuiltinTypeKind, - const RSDataTypeSpec *DataType) - : mBuiltinTypeKind(BuiltinTypeKind), - mDataType(DataType) { - return; - } - - inline const char *getBuiltinTypeKind() const { return mBuiltinTypeKind; } - inline const RSDataTypeSpec *getDataType() const { return mDataType; } -}; - -///////////////////////////////////////////////////////////////////////////// - -class RSDataElementSpec { - private: - const char *mElementName; - const RSDataTypeSpec *mDataType; - bool mIsNormal; - unsigned mVectorSize; - - public: - RSDataElementSpec(const char *ElementName, - const RSDataTypeSpec *DataType, - bool IsNormal, - unsigned VectorSize) - : mElementName(ElementName), - mDataType(DataType), - mIsNormal(IsNormal), - mVectorSize(VectorSize) { - return; - } - - inline const char *getElementName() const { return mElementName; } - inline const RSDataTypeSpec *getDataType() const { return mDataType; } - inline bool isNormal() const { return mIsNormal; } - inline unsigned getVectorSize() const { return mVectorSize; } -}; - -///////////////////////////////////////////////////////////////////////////// - -// -gen-rs-data-type-enums -// -// ENUM_PRIMITIVE_DATA_TYPE(type, cname, bits) -// ENUM_PRIMITIVE_DATA_TYPE_RANGE(begin_type, end_type) -// ENUM_RS_MATRIX_DATA_TYPE(type, cname, bits) -// ENUM_RS_MATRIX_DATA_TYPE_RANGE(begin_type, end_type) -// ENUM_RS_OBJECT_DATA_TYPE(type, cname, bits) -// ENUM_RS_OBJECT_DATA_TYPE_RANGE(begin_type, end_type) -// -// ENUM_RS_DATA_TYPE(type, cname, bits) -// e.g., ENUM_RS_DATA_TYPE(Float32, "float", 256) -static int GenRSDataTypeEnums(const RSDataTypeSpec *const DataTypes[], - unsigned NumDataTypes) { - // Alias missing #define -#define ALIAS_DEF(x, y) \ - printf("#ifndef " #x "\n"); \ - printf("#define " #x "(type, cname, bits) " #y "(type, cname, bits)\n"); \ - printf("#endif\n\n") - ALIAS_DEF(ENUM_PRIMITIVE_DATA_TYPE, ENUM_RS_DATA_TYPE); - ALIAS_DEF(ENUM_RS_MATRIX_DATA_TYPE, ENUM_RS_DATA_TYPE); - ALIAS_DEF(ENUM_RS_OBJECT_DATA_TYPE, ENUM_RS_DATA_TYPE); -#undef ALIAS_DEF - -#define ALIAS_DEF(x) \ - printf("#ifndef " #x "\n"); \ - printf("#define " #x "(begin_type, end_type)\n"); \ - printf("#endif\n\n") - ALIAS_DEF(ENUM_PRIMITIVE_DATA_TYPE_RANGE); - ALIAS_DEF(ENUM_RS_MATRIX_DATA_TYPE_RANGE); - ALIAS_DEF(ENUM_RS_OBJECT_DATA_TYPE_RANGE); -#undef ALIAS_DEF - -#define DEF(x) \ - printf(#x "(%s, \"%s\", %lu)\n", \ - DataTypes[i]->getTypeName(), \ - DataTypes[i]->getTypePragmaName(), \ - (unsigned long) DataTypes[i]->getSizeInBit()); // NOLINT(runtime/int) -#define DEF_RANGE(x, begin, end) \ - printf(#x "(%s, %s)\n\n", \ - DataTypes[begin]->getTypeName(), \ - DataTypes[end]->getTypeName()) - for (unsigned i = FirstPrimitiveType; i <= LastPrimitiveType; i++) - DEF(ENUM_PRIMITIVE_DATA_TYPE); - DEF_RANGE(ENUM_PRIMITIVE_DATA_TYPE_RANGE, - FirstPrimitiveType, LastPrimitiveType); - for (unsigned i = FirstRSMatrixType; i <= LastRSMatrixType; i++) - DEF(ENUM_RS_MATRIX_DATA_TYPE) - DEF_RANGE(ENUM_RS_MATRIX_DATA_TYPE_RANGE, - FirstRSMatrixType, LastRSMatrixType); - for (unsigned i = FirstRSObjectType; i <= LastRSObjectType; i++) - DEF(ENUM_RS_OBJECT_DATA_TYPE) - DEF_RANGE(ENUM_RS_OBJECT_DATA_TYPE_RANGE, - FirstRSObjectType, LastRSObjectType); -#undef DEF -#undef DEF_RANGE - -#define UNDEF(x) \ - printf("#undef " #x "\n") - UNDEF(ENUM_PRIMITIVE_DATA_TYPE); - UNDEF(ENUM_RS_MATRIX_DATA_TYPE); - UNDEF(ENUM_RS_OBJECT_DATA_TYPE); - UNDEF(ENUM_PRIMITIVE_DATA_TYPE_RANGE); - UNDEF(ENUM_RS_MATRIX_DATA_TYPE_RANGE); - UNDEF(ENUM_RS_OBJECT_DATA_TYPE_RANGE); - UNDEF(ENUM_RS_DATA_TYPE); - return 0; -} - -// -gen-clang-builtin-cnames -// -// ENUM_SUPPORT_BUILTIN_TYPE(builtin_type, type, cname) -// e.g., ENUM_SUPPORT_BUILTIN_TYPE(clang::BuiltinType::Float, Float32, "float") -static int GenClangBuiltinEnum( - const ClangBuiltinTypeMap *const ClangBuilitinsMap[], - unsigned NumClangBuilitins) { - for (unsigned i = 0; i < NumClangBuilitins; i++) - printf("ENUM_SUPPORT_BUILTIN_TYPE(%s, %s, \"%s\")\n", - ClangBuilitinsMap[i]->getBuiltinTypeKind(), - ClangBuilitinsMap[i]->getDataType()->getTypeName(), - ClangBuilitinsMap[i]->getDataType()->getTypePragmaName()); - printf("#undef ENUM_SUPPORT_BUILTIN_TYPE\n"); - return 0; -} - -// -gen-rs-matrix-type-enums -// -// ENUM_RS_MATRIX_TYPE(type, cname, dim) -// e.g., ENUM_RS_MATRIX_TYPE(RSMatrix2x2, "rs_matrix2x2", 2) -static int GenRSMatrixTypeEnums(const RSDataTypeSpec *const DataTypes[], - unsigned NumDataTypes) { - for (unsigned i = 0; i < NumDataTypes; i++) - if (DataTypes[i]->isRSMatrix()) { - const RSMatrixDataTypeSpec *const MatrixDataType = - static_cast<const RSMatrixDataTypeSpec *const>(DataTypes[i]); - printf("ENUM_RS_MATRIX_TYPE(%s, \"%s\", %u)\n", - MatrixDataType->getTypeName(), - MatrixDataType->getTypePragmaName(), - MatrixDataType->getDim()); - } - printf("#undef ENUM_RS_MATRIX_TYPE\n"); - return 0; -} - -// -gen-rs-object-type-enums -// -// ENUM_RS_OBJECT_TYPE(type, cname) -// e.g., ENUM_RS_OBJECT_TYPE(RSElement, "rs_element") -static int GenRSObjectTypeEnums(const RSDataTypeSpec *const DataTypes[], - unsigned NumDataTypes) { - for (unsigned i = 0; i < NumDataTypes; i++) - if (DataTypes[i]->isRSObject()) - printf("ENUM_RS_OBJECT_TYPE(%s, \"%s\")\n", - DataTypes[i]->getTypeName(), - DataTypes[i]->getTypePragmaName()); - printf("#undef ENUM_RS_OBJECT_TYPE\n"); - return 0; -} - -// -gen-rs-data-element-enums -// -// ENUM_RS_DATA_ELEMENT(name, dt, dk, normailized, vsize) -// e.g., ENUM_RS_DATA_ELEMENT("rs_pixel_rgba", PixelRGB, Unsigned8, true, 4) -int GenRSDataElementEnums(const RSDataElementSpec *const DataElements[], - unsigned NumDataElements) { - for (unsigned i = 0; i < NumDataElements; i++) - printf("ENUM_RS_DATA_ELEMENT(\"%s\", %s, %s, %d)\n", - DataElements[i]->getElementName(), - DataElements[i]->getDataType()->getTypeName(), - ((DataElements[i]->isNormal()) ? "true" : "false"), - DataElements[i]->getVectorSize()); - printf("#undef ENUM_RS_DATA_ELEMENT\n"); - return 0; -} - -int main(int argc, char **argv) { - if (argc < 2) { - fprintf(stderr, "usage: %s [gen type]\n", argv[0]); - return 1; - } - - RSDataTypeSpec *DataTypes[] = { -#define ENUM_PRIMITIVE_DATA_TYPE(x, name, bits) \ - new RSDataTypeSpec(#x , name, bits), -#define PRIMITIVE_DATA_TYPE_RANGE(x, y) - PRIMITIVE_DATA_TYPE_ENUMS -#undef ENUM_PRIMITIVE_DATA_TYPE -#undef PRIMITIVE_DATA_TYPE_RANGE - -#define ENUM_RS_MATRIX_DATA_TYPE(x, name, dim) \ - new RSMatrixDataTypeSpec(#x , name, dim), -#define RS_MATRIX_DATA_TYPE_RANGE(x, y) - RS_MATRIX_DATA_TYPE_ENUMS -#undef ENUM_RS_MATRIX_DATA_TYPE -#undef RS_MATRIX_DATA_TYPE_RANGE - -#define ENUM_RS_OBJECT_DATA_TYPE(x, name) \ - new RSObjectDataTypeSpec(#x, name), -#define RS_OBJECT_DATA_TYPE_RANGE(x, y) - RS_OBJECT_DATA_TYPE_ENUMS -#undef ENUM_RS_OBJECT_DATA_TYPE -#undef RS_OBJECT_DATA_TYPE_RANGE - }; - - unsigned NumDataTypes = sizeof(DataTypes) / sizeof(DataTypes[0]); - ///////////////////////////////////////////////////////////////////////////// - - ClangBuiltinTypeMap *ClangBuilitinsMap[] = { - new ClangBuiltinTypeMap("clang::BuiltinType::Bool", DataTypes[Boolean]), - new ClangBuiltinTypeMap("clang::BuiltinType::Char_U", DataTypes[Unsigned8]), - new ClangBuiltinTypeMap("clang::BuiltinType::UChar", DataTypes[Unsigned8]), - new ClangBuiltinTypeMap("clang::BuiltinType::Char16", DataTypes[Signed16]), - new ClangBuiltinTypeMap("clang::BuiltinType::Char32", DataTypes[Signed32]), - new ClangBuiltinTypeMap( - "clang::BuiltinType::UShort", DataTypes[Unsigned16]), - new ClangBuiltinTypeMap( - "clang::BuiltinType::UInt", DataTypes[Unsigned32]), - new ClangBuiltinTypeMap( - "clang::BuiltinType::ULong", DataTypes[Unsigned32]), - new ClangBuiltinTypeMap( - "clang::BuiltinType::ULongLong", DataTypes[Unsigned64]), - - new ClangBuiltinTypeMap("clang::BuiltinType::Char_S", DataTypes[Signed8]), - new ClangBuiltinTypeMap("clang::BuiltinType::SChar", DataTypes[Signed8]), - new ClangBuiltinTypeMap("clang::BuiltinType::Short", DataTypes[Signed16]), - new ClangBuiltinTypeMap("clang::BuiltinType::Int", DataTypes[Signed32]), - new ClangBuiltinTypeMap("clang::BuiltinType::Long", DataTypes[Signed64]), - new ClangBuiltinTypeMap( - "clang::BuiltinType::LongLong", DataTypes[Signed64]), - - new ClangBuiltinTypeMap("clang::BuiltinType::Float", DataTypes[Float32]), - new ClangBuiltinTypeMap("clang::BuiltinType::Double", DataTypes[Float64]) - }; - - unsigned NumClangBuilitins = - sizeof(ClangBuilitinsMap) / sizeof(ClangBuilitinsMap[0]); - - ///////////////////////////////////////////////////////////////////////////// - - RSDataElementSpec *DataElements[] = { - new RSDataElementSpec("rs_pixel_l", - DataTypes[Unsigned8], - /* IsNormal = */true, /* VectorSize = */1), - new RSDataElementSpec("rs_pixel_a", - DataTypes[Unsigned8], - true, 1), - new RSDataElementSpec("rs_pixel_la", - DataTypes[Unsigned8], - true, 2), - new RSDataElementSpec("rs_pixel_rgb", - DataTypes[Unsigned8], - true, 3), - new RSDataElementSpec("rs_pixel_rgba", - DataTypes[Unsigned8], - true, 4), - new RSDataElementSpec("rs_pixel_rgb565", - DataTypes[Unsigned8], - true, 3), - new RSDataElementSpec("rs_pixel_rgb5551", - DataTypes[Unsigned8], - true, 4), - new RSDataElementSpec("rs_pixel_rgb4444", - DataTypes[Unsigned8], - true, 4), - }; - - unsigned NumDataElements = sizeof(DataElements) / sizeof(DataElements[0]); - ///////////////////////////////////////////////////////////////////////////// - int Result = 1; - - if (::strcmp(argv[1], "-gen-rs-data-type-enums") == 0) - Result = GenRSDataTypeEnums(DataTypes, NumDataTypes); - else if (::strcmp(argv[1], "-gen-clang-builtin-enums") == 0) - Result = GenClangBuiltinEnum(ClangBuilitinsMap, NumClangBuilitins); - else if (::strcmp(argv[1], "-gen-rs-matrix-type-enums") == 0) - Result = GenRSMatrixTypeEnums(DataTypes, NumDataTypes); - else if (::strcmp(argv[1], "-gen-rs-object-type-enums") == 0) - Result = GenRSObjectTypeEnums(DataTypes, NumDataTypes); - else if (::strcmp(argv[1], "-gen-rs-data-element-enums") == 0) - Result = GenRSDataElementEnums(DataElements, NumDataElements); - else - fprintf(stderr, "%s: Unknown table generation type '%s'\n", - argv[0], argv[1]); - - - ///////////////////////////////////////////////////////////////////////////// - for (unsigned i = 0; i < NumDataTypes; i++) - delete DataTypes[i]; - for (unsigned i = 0; i < NumClangBuilitins; i++) - delete ClangBuilitinsMap[i]; - for (unsigned i = 0; i < NumDataElements; i++) - delete DataElements[i]; - - return Result; -} diff --git a/slang_rs_type_spec.h b/slang_rs_type_spec.h index 1bb2e25..77bd843 100644 --- a/slang_rs_type_spec.h +++ b/slang_rs_type_spec.h @@ -17,85 +17,48 @@ #ifndef _COMPILE_SLANG_SLANG_RS_TYPE_SPEC_H_ // NOLINT #define _COMPILE_SLANG_SLANG_RS_TYPE_SPEC_H_ -#define RS_DATA_TYPE_CLASS_ENUMS \ - ENUM_RS_DATA_TYPE_CLASS(Primitive) \ - ENUM_RS_DATA_TYPE_CLASS(Pointer) \ - ENUM_RS_DATA_TYPE_CLASS(Vector) \ - ENUM_RS_DATA_TYPE_CLASS(Matrix) \ - ENUM_RS_DATA_TYPE_CLASS(ConstantArray) \ - ENUM_RS_DATA_TYPE_CLASS(Record) - -#define PRIMITIVE_DATA_TYPE_ENUMS \ - ENUM_PRIMITIVE_DATA_TYPE(Float16, NULL, 16) \ - ENUM_PRIMITIVE_DATA_TYPE(Float32, "float", 32) \ - ENUM_PRIMITIVE_DATA_TYPE(Float64, "double", 64) \ - ENUM_PRIMITIVE_DATA_TYPE(Signed8, "char", 8) \ - ENUM_PRIMITIVE_DATA_TYPE(Signed16, "short", 16) \ - ENUM_PRIMITIVE_DATA_TYPE(Signed32, "int", 32) \ - ENUM_PRIMITIVE_DATA_TYPE(Signed64, "long", 64) \ - ENUM_PRIMITIVE_DATA_TYPE(Unsigned8, "uchar", 8) \ - ENUM_PRIMITIVE_DATA_TYPE(Unsigned16, "ushort", 16) \ - ENUM_PRIMITIVE_DATA_TYPE(Unsigned32, "uint", 32) \ - ENUM_PRIMITIVE_DATA_TYPE(Unsigned64, "ulong", 64) \ - ENUM_PRIMITIVE_DATA_TYPE(Boolean, "bool", 8) \ - ENUM_PRIMITIVE_DATA_TYPE(Unsigned565, "u565", 16) \ - ENUM_PRIMITIVE_DATA_TYPE(Unsigned5551, "u5551", 16) \ - ENUM_PRIMITIVE_DATA_TYPE(Unsigned4444, "u4444", 16) \ - PRIMITIVE_DATA_TYPE_RANGE(Float16, Unsigned4444) - -#define RS_MATRIX_DATA_TYPE_ENUMS \ - ENUM_RS_MATRIX_DATA_TYPE(RSMatrix2x2, "rs_matrix2x2", 2) \ - ENUM_RS_MATRIX_DATA_TYPE(RSMatrix3x3, "rs_matrix3x3", 3) \ - ENUM_RS_MATRIX_DATA_TYPE(RSMatrix4x4, "rs_matrix4x4", 4) \ - RS_MATRIX_DATA_TYPE_RANGE(RSMatrix2x2, RSMatrix4x4) - -#define RS_OBJECT_DATA_TYPE_ENUMS \ - ENUM_RS_OBJECT_DATA_TYPE(RSElement, "rs_element") \ - ENUM_RS_OBJECT_DATA_TYPE(RSType, "rs_type") \ - ENUM_RS_OBJECT_DATA_TYPE(RSAllocation, "rs_allocation") \ - ENUM_RS_OBJECT_DATA_TYPE(RSSampler, "rs_sampler") \ - ENUM_RS_OBJECT_DATA_TYPE(RSScript, "rs_script") \ - ENUM_RS_OBJECT_DATA_TYPE(RSMesh, "rs_mesh") \ - ENUM_RS_OBJECT_DATA_TYPE(RSPath, "rs_path") \ - ENUM_RS_OBJECT_DATA_TYPE(RSProgramFragment, "rs_program_fragment") \ - ENUM_RS_OBJECT_DATA_TYPE(RSProgramVertex, "rs_program_vertex") \ - ENUM_RS_OBJECT_DATA_TYPE(RSProgramRaster, "rs_program_raster") \ - ENUM_RS_OBJECT_DATA_TYPE(RSProgramStore, "rs_program_store") \ - ENUM_RS_OBJECT_DATA_TYPE(RSFont, "rs_font") \ - RS_OBJECT_DATA_TYPE_RANGE(RSElement, RSFont) - enum RSTypeClass { -#define ENUM_RS_DATA_TYPE_CLASS(x) RS_TC_ ## x, - RS_DATA_TYPE_CLASS_ENUMS -#undef ENUM_RS_DATA_TYPE_CLASS + RS_TC_Primitive, + RS_TC_Pointer, + RS_TC_Vector, + RS_TC_Matrix, + RS_TC_ConstantArray, + RS_TC_Record, RS_TC_Max }; +// TODO We have the same enum in PrimitiveDataType. Join them. enum RSDataType { -#define ENUM_PRIMITIVE_DATA_TYPE(x, name, bits) RS_DT_ ## x, -#define PRIMITIVE_DATA_TYPE_RANGE(x, y) \ - RS_DT_FirstPrimitiveType = RS_DT_ ## x, \ - RS_DT_LastPrimitiveType = RS_DT_ ## y, - PRIMITIVE_DATA_TYPE_ENUMS -#undef ENUM_PRIMITIVE_DATA_TYPE -#undef PRIMITIVE_DATA_TYPE_RANGE - -#define ENUM_RS_MATRIX_DATA_TYPE(x, name, dim) RS_DT_ ## x, -#define RS_MATRIX_DATA_TYPE_RANGE(x, y) \ - RS_DT_FirstMatrixType = RS_DT_ ## x, \ - RS_DT_LastMatrixType = RS_DT_ ## y, - RS_MATRIX_DATA_TYPE_ENUMS -#undef ENUM_RS_MATRIX_DATA_TYPE -#undef RS_MATRIX_DATA_TYPE_RANGE - -#define ENUM_RS_OBJECT_DATA_TYPE(x, name) RS_DT_ ## x, -#define RS_OBJECT_DATA_TYPE_RANGE(x, y) \ - RS_DT_FirstRSObjectType = RS_DT_ ## x, \ - RS_DT_LastRSObjectType = RS_DT_ ## y, - RS_OBJECT_DATA_TYPE_ENUMS -#undef ENUM_RS_OBJECT_DATA_TYPE -#undef RS_OBJECT_DATA_TYPE_RANGE - + RS_DT_Float16 = 0, + RS_DT_Float32 = 1, + RS_DT_Float64 = 2, + RS_DT_Signed8 = 3, + RS_DT_Signed16 = 4, + RS_DT_Signed32 = 5, + RS_DT_Signed64 = 6, + RS_DT_Unsigned8 = 7, + RS_DT_Unsigned16 = 8, + RS_DT_Unsigned32 = 9, + RS_DT_Unsigned64 = 10, + RS_DT_Boolean = 11, + RS_DT_Unsigned565 = 12, + RS_DT_Unsigned5551 = 13, + RS_DT_Unsigned4444 = 14, + RS_DT_RSMatrix2x2 = 15, + RS_DT_RSMatrix3x3 = 16, + RS_DT_RSMatrix4x4 = 17, + RS_DT_RSElement = 18, + RS_DT_RSType = 19, + RS_DT_RSAllocation = 20, + RS_DT_RSSampler = 21, + RS_DT_RSScript = 22, + RS_DT_RSMesh = 23, + RS_DT_RSPath = 24, + RS_DT_RSProgramFragment = 25, + RS_DT_RSProgramVertex = 26, + RS_DT_RSProgramRaster = 27, + RS_DT_RSProgramStore = 28, + RS_DT_RSFont = 29, RS_DT_USER_DEFINED }; |