diff options
Diffstat (limited to 'source/slang/slang.cpp')
| -rw-r--r-- | source/slang/slang.cpp | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index bfc77b2e3..5fdec8259 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -37,6 +37,61 @@ namespace Slang { +/* static */const BaseTypeInfo BaseTypeInfo::s_info[Index(BaseType::CountOf)] = +{ + { 0, 0, uint8_t(BaseType::Void) }, + { uint8_t(sizeof(bool)), 0, uint8_t(BaseType::Bool) }, + { uint8_t(sizeof(int8_t)), BaseTypeInfo::Flag::Signed | BaseTypeInfo::Flag::Integer , uint8_t(BaseType::Int8) }, + { uint8_t(sizeof(int16_t)), BaseTypeInfo::Flag::Signed | BaseTypeInfo::Flag::Integer , uint8_t(BaseType::Int16) }, + { uint8_t(sizeof(int32_t)), BaseTypeInfo::Flag::Signed | BaseTypeInfo::Flag::Integer , uint8_t(BaseType::Int) }, + { uint8_t(sizeof(int64_t)), BaseTypeInfo::Flag::Signed | BaseTypeInfo::Flag::Integer , uint8_t(BaseType::Int64) }, + { uint8_t(sizeof(uint8_t)), BaseTypeInfo::Flag::Integer , uint8_t(BaseType::UInt8) }, + { uint8_t(sizeof(uint16_t)), BaseTypeInfo::Flag::Integer , uint8_t(BaseType::UInt16) }, + { uint8_t(sizeof(uint32_t)), BaseTypeInfo::Flag::Integer , uint8_t(BaseType::UInt) }, + { uint8_t(sizeof(uint64_t)), BaseTypeInfo::Flag::Integer, uint8_t(BaseType::UInt64) }, + { uint8_t(sizeof(uint16_t)), BaseTypeInfo::Flag::FloatingPoint , uint8_t(BaseType::Half) }, + { uint8_t(sizeof(float)), BaseTypeInfo::Flag::FloatingPoint , uint8_t(BaseType::Float) }, + { uint8_t(sizeof(double)), BaseTypeInfo::Flag::FloatingPoint , uint8_t(BaseType::Double) }, +}; + +/* static */bool BaseTypeInfo::check() +{ + for (Index i = 0; i < SLANG_COUNT_OF(s_info); ++i) + { + if (s_info[i].baseType != i) + { + SLANG_ASSERT(!"Inconsistency between the s_info table and BaseInfo"); + return false; + } + } + return true; +} + +/* static */UnownedStringSlice BaseTypeInfo::asText(BaseType baseType) +{ + switch (baseType) + { + case BaseType::Void: return UnownedStringSlice::fromLiteral("void"); + case BaseType::Bool: return UnownedStringSlice::fromLiteral("bool"); + case BaseType::Int8: return UnownedStringSlice::fromLiteral("int8_t"); + case BaseType::Int16: return UnownedStringSlice::fromLiteral("int16_t"); + case BaseType::Int: return UnownedStringSlice::fromLiteral("int"); + case BaseType::Int64: return UnownedStringSlice::fromLiteral("int64_t"); + case BaseType::UInt8: return UnownedStringSlice::fromLiteral("uint8_t"); + case BaseType::UInt16: return UnownedStringSlice::fromLiteral("uint16_t"); + case BaseType::UInt: return UnownedStringSlice::fromLiteral("uint"); + case BaseType::UInt64: return UnownedStringSlice::fromLiteral("uint64_t"); + case BaseType::Half: return UnownedStringSlice::fromLiteral("half"); + case BaseType::Float: return UnownedStringSlice::fromLiteral("float"); + case BaseType::Double: return UnownedStringSlice::fromLiteral("double"); + default: + { + SLANG_ASSERT(!"Unknown basic type"); + return UnownedStringSlice(); + } + } +} + // Allocate static const storage for the various interface IDs that the Slang API needs to expose static const Guid IID_IComponentType = SLANG_UUID_IComponentType; static const Guid IID_IEntryPoint = SLANG_UUID_IEntryPoint; @@ -48,6 +103,8 @@ static const Guid IID_ISlangUnknown = SLANG_UUID_ISlangUnknown; void Session::init() { + SLANG_ASSERT(BaseTypeInfo::check()); + ::memset(m_downstreamCompilerLocators, 0, sizeof(m_downstreamCompilerLocators)); DownstreamCompilerUtil::setDefaultLocators(m_downstreamCompilerLocators); m_downstreamCompilerSet = new DownstreamCompilerSet; @@ -2548,7 +2605,10 @@ Session::~Session() destroyTypeCheckingCache(); - builtinTypes = decltype(builtinTypes)(); + for (Index i = 0; i < SLANG_COUNT_OF(builtinTypes); ++i) + { + builtinTypes[i].setNull(); + } // destroy modules next loadedModuleCode = decltype(loadedModuleCode)(); } |
