Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Unified Diff: src/IceTypes.h

Issue 613483002: Change some explicit type checks into using helper functions. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: rename Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/IceTypes.h
diff --git a/src/IceTypes.h b/src/IceTypes.h
index cc782ab59d1c24bdbe59bc9fa6ec5c1503631dce..6480c2c57bdb8b52326013f5d53559de20c47ff4 100644
--- a/src/IceTypes.h
+++ b/src/IceTypes.h
@@ -69,6 +69,34 @@ Type getCompareResultType(Type Ty);
/// Returns the number of bits in a scalar integer type.
SizeT getScalarIntBitWidth(Type Ty);
+// Check if a type is byte sized (slight optimization over typeWidthInBytes).
+inline bool isByteSizedType(Type Ty) {
+ bool result = Ty == IceType_i8 || Ty == IceType_i1;
+ assert(result == (1 == typeWidthInBytes(Ty)));
+ return result;
+}
+
+// Check if Ty is byte sized and specifically i8. Assert that it's not
+// byte sized due to being an i1.
+inline bool isByteSizedArithType(Type Ty) {
+ assert(Ty != IceType_i1);
+ return Ty == IceType_i8;
+}
+
+// Return true if Ty is i32. This asserts that Ty is either i32 or i64.
+inline bool isInt32Asserting32Or64(Type Ty) {
+ bool result = Ty == IceType_i32;
+ assert(result || Ty == IceType_i64);
+ return result;
+}
+
+// Return true if Ty is f32. This asserts that Ty is either f32 or f64.
+inline bool isFloat32Asserting32Or64(Type Ty) {
+ bool result = Ty == IceType_f32;
+ assert(result || Ty == IceType_f64);
+ return result;
+}
+
template <typename StreamType>
inline StreamType &operator<<(StreamType &Str, const Type &Ty) {
Str << typeString(Ty);

Powered by Google App Engine
This is Rietveld 408576698