From a6032446c6bf7f64d1e201bf438a4c7605a3dbb4 Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 15 Sep 2022 14:22:59 -0700 Subject: Language feature: pointer sized int types. (#2401) * Language feature: pointer sized int types. * Fix. * small change to test. * Fix stdlib. * Fix. * Fix. * Add typedef for `size_t` in stdlib. * Fix test. * Add `intptr_t::size` constant. Co-authored-by: Yong He --- source/slang/slang-emit-c-like.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'source/slang/slang-emit-c-like.cpp') diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp index 7a7951ba1..734471fd0 100644 --- a/source/slang/slang-emit-c-like.cpp +++ b/source/slang/slang-emit-c-like.cpp @@ -215,11 +215,13 @@ void CLikeSourceEmitter::emitSimpleType(IRType* type) case kIROp_Int16Type: return UnownedStringSlice("int16_t"); case kIROp_IntType: return UnownedStringSlice("int"); case kIROp_Int64Type: return UnownedStringSlice("int64_t"); + case kIROp_IntPtrType: return UnownedStringSlice("intptr_t"); case kIROp_UInt8Type: return UnownedStringSlice("uint8_t"); case kIROp_UInt16Type: return UnownedStringSlice("uint16_t"); case kIROp_UIntType: return UnownedStringSlice("uint"); case kIROp_UInt64Type: return UnownedStringSlice("uint64_t"); + case kIROp_UIntPtrType: return UnownedStringSlice("uintptr_t"); case kIROp_HalfType: return UnownedStringSlice("half"); @@ -959,6 +961,33 @@ void CLikeSourceEmitter::emitSimpleValueImpl(IRInst* inst) m_writer->emit("ULL"); break; } + case BaseType::IntPtr: + { +#if SLANG_PTR_IS_64 + m_writer->emit("int64_t("); + m_writer->emitInt64(int64_t(litInst->value.intVal)); + m_writer->emit(")"); +#else + m_writer->emit("int("); + m_writer->emit(int(litInst->value.intVal)); + m_writer->emit(")"); +#endif + break; + } + case BaseType::UIntPtr: + { +#if SLANG_PTR_IS_64 + m_writer->emit("uint64_t("); + m_writer->emitUInt64(uint64_t(litInst->value.intVal)); + m_writer->emit(")"); +#else + m_writer->emit("uint("); + m_writer->emit(UInt(uint32_t(litInst->value.intVal))); + m_writer->emit(")"); +#endif + break; + } + } } else -- cgit v1.2.3