From 8cfe8badf70a7da0fa41e7f236bd6c5e52fa41ff Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 27 Jul 2021 08:28:59 -0400 Subject: [PATCH] sirit: Add TypeSInt/TypeUInt helpers Provides shorthands for specific signedness, so that usage code doesn't need to explicitly use raw booleans. TypeUInt(32), is easier to gloss than TypeInt(32, false), especially for those not familiar with the API. --- include/sirit/sirit.h | 6 ++++++ src/instructions/type.cpp | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/include/sirit/sirit.h b/include/sirit/sirit.h index 3baa56f..589ea06 100644 --- a/include/sirit/sirit.h +++ b/include/sirit/sirit.h @@ -125,6 +125,12 @@ public: /// Returns type integer. Id TypeInt(int width, bool is_signed); + /// Returns type signed integer. + Id TypeSInt(int width); + + /// Returns type unsigned integer. + Id TypeUInt(int width); + /// Returns type float. Id TypeFloat(int width); diff --git a/src/instructions/type.cpp b/src/instructions/type.cpp index c3d04a0..3509d1f 100644 --- a/src/instructions/type.cpp +++ b/src/instructions/type.cpp @@ -28,6 +28,14 @@ Id Module::TypeInt(int width, bool is_signed) { return *declarations << OpId{spv::Op::OpTypeInt} << width << is_signed << EndOp{}; } +Id Module::TypeSInt(int width) { + return TypeInt(width, true); +} + +Id Module::TypeUInt(int width) { + return TypeInt(width, false); +} + Id Module::TypeFloat(int width) { declarations->Reserve(3); return *declarations << OpId{spv::Op::OpTypeFloat} << width << EndOp{};