Commit fac55170 by Jim Stichnoth

Subzero: Move to C++11 static_assert().

BUG= none R=jvoung@chromium.org, kschimpf@google.com Review URL: https://codereview.chromium.org/618313003
parent 9c234e2a
...@@ -32,15 +32,8 @@ ...@@ -32,15 +32,8 @@
#include "llvm/ADT/SmallBitVector.h" #include "llvm/ADT/SmallBitVector.h"
#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Casting.h" #include "llvm/Support/Casting.h"
#include "llvm/Support/Compiler.h" // LLVM_STATIC_ASSERT
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
// Roll our own static_assert<> in the absence of C++11. TODO: change
// to static_assert<> with C++11.
template <bool> struct staticAssert;
template <> struct staticAssert<true> {}; // only true is defined
#define STATIC_ASSERT(x) staticAssert<(x)>()
namespace Ice { namespace Ice {
class Cfg; class Cfg;
......
...@@ -23,11 +23,10 @@ ...@@ -23,11 +23,10 @@
namespace Ice { namespace Ice {
namespace { static_assert(sizeof(Intrinsics::IntrinsicInfo) == 4,
"Unexpected sizeof(IntrinsicInfo)");
void __attribute__((unused)) xIntrinsicInfoSizeCheck() { namespace {
STATIC_ASSERT(sizeof(Intrinsics::IntrinsicInfo) == 4);
}
#define INTRIN(ID, SE, RT) { Intrinsics::ID, Intrinsics::SE, Intrinsics::RT } #define INTRIN(ID, SE, RT) { Intrinsics::ID, Intrinsics::SE, Intrinsics::RT }
......
...@@ -18,61 +18,61 @@ namespace Ice { ...@@ -18,61 +18,61 @@ namespace Ice {
namespace { namespace {
// Dummy function to make sure the two type tables have the same // Show tags match between ICETYPE_TABLE and ICETYPE_PROPS_TABLE.
// enumerated types.
void __attribute__((unused)) xIceTypeMacroIntegrityCheck() {
// Show tags match between ICETYPE_TABLE and ICETYPE_PROPS_TABLE. // Define a temporary set of enum values based on ICETYPE_TABLE
enum {
// Define a temporary set of enum values based on ICETYPE_TABLE
enum {
#define X(tag, size, align, elts, elty, str) _table_tag_##tag, #define X(tag, size, align, elts, elty, str) _table_tag_##tag,
ICETYPE_TABLE ICETYPE_TABLE
#undef X #undef X
_enum_table_tag_Names _enum_table_tag_Names
}; };
// Define a temporary set of enum values based on ICETYPE_PROPS_TABLE // Define a temporary set of enum values based on ICETYPE_PROPS_TABLE
enum { enum {
#define X(tag, IsVec, IsInt, IsFloat, IsIntArith, IsLoadStore, CompareResult) \ #define X(tag, IsVec, IsInt, IsFloat, IsIntArith, IsLoadStore, CompareResult) \
_props_table_tag_##tag, _props_table_tag_##tag,
ICETYPE_PROPS_TABLE ICETYPE_PROPS_TABLE
#undef X #undef X
_enum_props_table_tag_Names _enum_props_table_tag_Names
}; };
// Assert that tags in ICETYPE_TABLE are also in ICETYPE_PROPS_TABLE. // Assert that tags in ICETYPE_TABLE are also in ICETYPE_PROPS_TABLE.
#define X(tag, size, align, elts, elty, str) \ #define X(tag, size, align, elts, elty, str) \
STATIC_ASSERT((unsigned)_table_tag_##tag == (unsigned)_props_table_tag_##tag); static_assert( \
ICETYPE_TABLE; (unsigned)_table_tag_##tag == (unsigned)_props_table_tag_##tag, \
"Inconsistency between ICETYPE_PROPS_TABLE and ICETYPE_TABLE");
ICETYPE_TABLE;
#undef X #undef X
// Assert that tags in ICETYPE_PROPS_TABLE is in ICETYPE_TABLE. // Assert that tags in ICETYPE_PROPS_TABLE is in ICETYPE_TABLE.
#define X(tag, IsVec, IsInt, IsFloat, IsIntArith, IsLoadStore, CompareResult) \ #define X(tag, IsVec, IsInt, IsFloat, IsIntArith, IsLoadStore, CompareResult) \
STATIC_ASSERT((unsigned)_table_tag_##tag == (unsigned)_props_table_tag_##tag); static_assert( \
ICETYPE_PROPS_TABLE (unsigned)_table_tag_##tag == (unsigned)_props_table_tag_##tag, \
"Inconsistency between ICETYPE_PROPS_TABLE and ICETYPE_TABLE");
ICETYPE_PROPS_TABLE
#undef X #undef X
// Show vector definitions match in ICETYPE_TABLE and // Show vector definitions match in ICETYPE_TABLE and
// ICETYPE_PROPS_TABLE. // ICETYPE_PROPS_TABLE.
// Define constants for each element size in ICETYPE_TABLE. // Define constants for each element size in ICETYPE_TABLE.
enum { enum {
#define X(tag, size, align, elts, elty, str) _table_elts_##tag = elts, #define X(tag, size, align, elts, elty, str) _table_elts_##tag = elts,
ICETYPE_TABLE ICETYPE_TABLE
#undef X #undef X
_enum_table_elts_Elements = 0 _enum_table_elts_Elements = 0
}; };
// Define constants for boolean flag if vector in ICETYPE_PROPS_TABLE. // Define constants for boolean flag if vector in ICETYPE_PROPS_TABLE.
enum { enum {
#define X(tag, IsVec, IsInt, IsFloat, IsIntArith, IsLoadStore, CompareResult) \ #define X(tag, IsVec, IsInt, IsFloat, IsIntArith, IsLoadStore, CompareResult) \
_props_table_IsVec_##tag = IsVec, _props_table_IsVec_##tag = IsVec,
ICETYPE_PROPS_TABLE ICETYPE_PROPS_TABLE
#undef X #undef X
}; };
// Verify that the number of vector elements is consistent with IsVec. // Verify that the number of vector elements is consistent with IsVec.
#define X(tag, IsVec, IsInt, IsFloat, IsIntArith, IsLoadStore, CompareResult) \ #define X(tag, IsVec, IsInt, IsFloat, IsIntArith, IsLoadStore, CompareResult) \
STATIC_ASSERT((_table_elts_##tag > 1) == _props_table_IsVec_##tag); static_assert((_table_elts_##tag > 1) == _props_table_IsVec_##tag, \
ICETYPE_PROPS_TABLE; "Inconsistent vector specification in ICETYPE_PROPS_TABLE");
ICETYPE_PROPS_TABLE;
#undef X #undef X
}
struct TypeAttributeFields { struct TypeAttributeFields {
size_t TypeWidthInBytes; size_t TypeWidthInBytes;
...@@ -86,7 +86,7 @@ const struct TypeAttributeFields TypeAttributes[] = { ...@@ -86,7 +86,7 @@ const struct TypeAttributeFields TypeAttributes[] = {
#define X(tag, size, align, elts, elty, str) \ #define X(tag, size, align, elts, elty, str) \
{ size, align, elts, elty, str } \ { size, align, elts, elty, str } \
, ,
ICETYPE_TABLE ICETYPE_TABLE
#undef X #undef X
}; };
...@@ -110,7 +110,7 @@ const TypePropertyFields TypePropertiesTable[] = { ...@@ -110,7 +110,7 @@ const TypePropertyFields TypePropertiesTable[] = {
IsFloat && !IsVec, IsFloat && IsVec, IsLoadStore, CompareResult \ IsFloat && !IsVec, IsFloat && IsVec, IsLoadStore, CompareResult \
} \ } \
, ,
ICETYPE_PROPS_TABLE ICETYPE_PROPS_TABLE
#undef X #undef X
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment