| OLD | NEW |
| 1 //===- subzero/src/IceBuildDefs.h - Translator build defines ----*- C++ -*-===// | 1 //===- subzero/src/IceBuildDefs.h - Translator build defines ----*- C++ -*-===// |
| 2 // | 2 // |
| 3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 /// | 9 /// |
| 10 /// \file | 10 /// \file |
| 11 /// \brief Define the Ice::BuildDefs namespace | 11 /// \brief Define the Ice::BuildDefs namespace |
| 12 //===----------------------------------------------------------------------===// | 12 //===----------------------------------------------------------------------===// |
| 13 | 13 |
| 14 #ifndef SUBZERO_SRC_ICEBUILDDEFS_H | 14 #ifndef SUBZERO_SRC_ICEBUILDDEFS_H |
| 15 #define SUBZERO_SRC_ICEBUILDDEFS_H | 15 #define SUBZERO_SRC_ICEBUILDDEFS_H |
| 16 | 16 |
| 17 namespace Ice { | 17 namespace Ice { |
| 18 /// \brief Defines constexpr functions that express various Subzero build | 18 /// \brief Defines constexpr functions that express various Subzero build |
| 19 /// system defined values. | 19 /// system defined values. |
| 20 /// | 20 /// |
| 21 /// These resulting constexpr functions allow code to in effect be | 21 /// These resulting constexpr functions allow code to in effect be |
| 22 /// conditionally compiled without having to do this using the older C++ | 22 /// conditionally compiled without having to do this using the older C++ |
| 23 /// preprocessor solution. | 23 /// preprocessor solution. |
| 24 | 24 |
| 25 /** \verbatim | 25 /** \verbatim |
| 26 | 26 |
| 27 For example whenever the value of FEATURE_SUPPORTED is needed, instead | 27 For example whenever the value of FEATURE_SUPPORTED is needed, instead |
| 28 of (except in these constexpr functions): | 28 of (except in these constexpr functions): |
| 29 | 29 |
| 30 #if FEATURE_SUPPORTED ... | 30 #if FEATURE_SUPPORTED ... |
| 31 ... | 31 ... |
| 32 #endif | 32 #endif |
| 33 | 33 |
| 34 We can have: | 34 We can have: |
| 35 | 35 |
| 36 namespace Ice { | 36 namespace Ice { |
| 37 namespace BuildDefs { | 37 namespace BuildDefs { |
| 38 | 38 |
| 39 // Use this form when FEATURE_SUPPORTED is guaranteed to be defined on the | 39 // Use this form when FEATURE_SUPPORTED is guaranteed to be defined on the |
| 40 // C++ compiler command line as 0 or 1. | 40 // C++ compiler command line as 0 or 1. |
| 41 constexpr bool hasFeature() { return FEATURE_SUPPORTED; } | 41 constexpr bool hasFeature() { return FEATURE_SUPPORTED; } |
| 42 | 42 |
| 43 or | 43 or |
| 44 | 44 |
| 45 // Use this form when FEATURE_SUPPORTED may not necessarily be defined on | 45 // Use this form when FEATURE_SUPPORTED may not necessarily be defined on |
| 46 // the C++ compiler command line. | 46 // the C++ compiler command line. |
| 47 constexpr bool hasFeature() { | 47 constexpr bool hasFeature() { |
| 48 #if FEATURE_SUPPORTED | 48 #if FEATURE_SUPPORTED |
| 49 return true; | 49 return true; |
| 50 #else // !FEATURE_SUPPORTED | 50 #else // !FEATURE_SUPPORTED |
| 51 return false; | 51 return false; |
| 52 #endif // !FEATURE_SUPPORTED | 52 #endif // !FEATURE_SUPPORTED |
| 53 } | 53 } |
| 54 | 54 |
| 55 ...} // end of namespace BuildDefs | 55 ...} // end of namespace BuildDefs |
| 56 } // end of namespace Ice | 56 } // end of namespace Ice |
| 57 | 57 |
| 58 | 58 |
| 59 And later in the code: | 59 And later in the code: |
| 60 | 60 |
| 61 if (Ice::BuildDefs::hasFeature() { | 61 if (Ice::BuildDefs::hasFeature() { |
| 62 ... | 62 ... |
| 63 } | 63 } |
| 64 | 64 |
| 65 \endverbatim | 65 \endverbatim |
| 66 | 66 |
| 67 Since hasFeature() returns a constexpr, an optimizing compiler will know to | 67 Since hasFeature() returns a constexpr, an optimizing compiler will know to |
| 68 keep or discard the above fragment. In addition, the code will always be | 68 keep or discard the above fragment. In addition, the code will always be |
| 69 looked at by the compiler which eliminates the problem with defines in that | 69 looked at by the compiler which eliminates the problem with defines in that |
| 70 if you don't build that variant, you don't even know if the code would | 70 if you don't build that variant, you don't even know if the code would |
| 71 compile unless you build with that variant. | 71 compile unless you build with that variant. |
| 72 | 72 |
| 73 **/ | 73 **/ |
| 74 | |
| 75 | 74 |
| 76 namespace BuildDefs { | 75 namespace BuildDefs { |
| 77 | 76 |
| 78 // The ALLOW_* etc. symbols must be #defined to zero or non-zero. | 77 // The ALLOW_* etc. symbols must be #defined to zero or non-zero. |
| 79 /// Return true if ALLOW_DISABLE_IR_GEN is defined as a non-zero value | |
| 80 constexpr bool disableIrGen() { return ALLOW_DISABLE_IR_GEN; } | |
| 81 /// Return true if ALLOW_DUMP is defined as a non-zero value | |
| 82 constexpr bool dump() { return ALLOW_DUMP; } | 78 constexpr bool dump() { return ALLOW_DUMP; } |
| 83 /// Return true if ALLOW_LLVM_CL is defined as a non-zero value | 79 /// Return true if ALLOW_LLVM_CL is defined as a non-zero value |
| 84 constexpr bool llvmCl() { return ALLOW_LLVM_CL; } | 80 constexpr bool llvmCl() { return ALLOW_LLVM_CL; } |
| 85 /// Return true if ALLOW_LLVM_IR is defined as a non-zero value | 81 /// Return true if ALLOW_LLVM_IR is defined as a non-zero value |
| 86 constexpr bool llvmIr() { return ALLOW_LLVM_IR; } | 82 constexpr bool llvmIr() { return ALLOW_LLVM_IR; } |
| 87 /// Return true if ALLOW_LLVM_IR_AS_INPUT is defined as a non-zero value | 83 /// Return true if ALLOW_LLVM_IR_AS_INPUT is defined as a non-zero value |
| 88 constexpr bool llvmIrAsInput() { return ALLOW_LLVM_IR_AS_INPUT; } | 84 constexpr bool llvmIrAsInput() { return ALLOW_LLVM_IR_AS_INPUT; } |
| 89 /// Return true if ALLOW_MINIMAL_BUILD is defined as a non-zero value | 85 /// Return true if ALLOW_MINIMAL_BUILD is defined as a non-zero value |
| 90 constexpr bool minimal() { return ALLOW_MINIMAL_BUILD; } | 86 constexpr bool minimal() { return ALLOW_MINIMAL_BUILD; } |
| 91 | 87 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 113 return true; | 109 return true; |
| 114 #else // !ALLOW_EXTRA_VALIDATION | 110 #else // !ALLOW_EXTRA_VALIDATION |
| 115 return false; | 111 return false; |
| 116 #endif // !ALLOW_EXTRA_VALIDATION | 112 #endif // !ALLOW_EXTRA_VALIDATION |
| 117 } | 113 } |
| 118 | 114 |
| 119 } // end of namespace BuildDefs | 115 } // end of namespace BuildDefs |
| 120 } // end of namespace Ice | 116 } // end of namespace Ice |
| 121 | 117 |
| 122 #endif // SUBZERO_SRC_ICEBUILDDEFS_H | 118 #endif // SUBZERO_SRC_ICEBUILDDEFS_H |
| OLD | NEW |