Chromium Code Reviews| 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 Defines constexpr functions to query various #define values. | 11 /// \brief Define the Ice::BuildDefs Namespace |
|
Jim Stichnoth
2015/12/12 00:04:34
lowercase "namespace"
rkotlerimgtec
2015/12/12 02:23:35
Done.
| |
| 12 /// | |
| 13 //===----------------------------------------------------------------------===// | 12 //===----------------------------------------------------------------------===// |
| 14 | 13 |
| 15 #ifndef SUBZERO_SRC_ICEBUILDDEFS_H | 14 #ifndef SUBZERO_SRC_ICEBUILDDEFS_H |
| 16 #define SUBZERO_SRC_ICEBUILDDEFS_H | 15 #define SUBZERO_SRC_ICEBUILDDEFS_H |
| 17 | 16 |
| 18 namespace Ice { | 17 namespace Ice { |
| 18 /// \brief Defines constexpr functions that express various subzero build | |
|
Jim Stichnoth
2015/12/12 00:04:33
Capitalize Subzero
rkotlerimgtec
2015/12/12 02:23:35
Done.
| |
| 19 /// system defined values. | |
| 20 /// | |
| 21 /// These resulting constexpr functions allow code to in effect be | |
| 22 /// conditionally compiled without having to do this using the older c++ | |
|
Jim Stichnoth
2015/12/12 00:04:34
C++
rkotlerimgtec
2015/12/12 02:23:35
Done.
| |
| 23 /// preprocessor solution. | |
| 24 /** \verbatim | |
|
Jim Stichnoth
2015/12/12 00:04:34
It seems like this \verbatim section could/should
rkotlerimgtec
2015/12/12 02:23:35
Verbatim does not flow at all. It's verbatim so I'
| |
| 25 For example whenever the value of FEATURE_SUPPORTED is needed, instead of | |
| 26 (except for in these constexpr functions): | |
| 27 | |
| 28 #if FEATURE_SUPPORTED ... | |
| 29 ... | |
| 30 #endif | |
| 31 | |
| 32 We can have: | |
| 33 namespace Ice { | |
| 34 namespace BuildDefs | |
| 35 .... | |
| 36 constexpr bool hasFeature() { return FEATURE_SUPPORTED; } | |
|
Jim Stichnoth
2015/12/12 00:04:33
I suggest adding a comment above, something like:
rkotlerimgtec
2015/12/12 02:23:35
Done.
| |
| 37 | |
| 38 or | |
| 39 | |
| 40 constexpr bool hasFeature() { | |
|
Jim Stichnoth
2015/12/12 00:04:34
Likewise, a comment like:
// Use this form when F
rkotlerimgtec
2015/12/12 02:23:35
Done.
| |
| 41 #ifdef FEATURE_SUPPORTED | |
|
Jim Stichnoth
2015/12/12 00:04:34
With one exception, Subzero uses "#if" instead of
rkotlerimgtec
2015/12/12 02:23:35
Done.
| |
| 42 return true; | |
| 43 #else | |
| 44 return false; | |
| 45 #endif | |
| 46 } | |
| 47 | |
| 48 ...} // of BuildDefs | |
|
Jim Stichnoth
2015/12/12 00:04:34
Might as well use the same comment style as in the
rkotlerimgtec
2015/12/12 02:23:35
Done.
| |
| 49 } // end of Ice | |
|
Jim Stichnoth
2015/12/12 00:04:33
Same here --
// end of namespace Ice
rkotlerimgtec
2015/12/12 02:23:35
Done.
| |
| 50 | |
| 51 Depending on whether the build system gives a value always to | |
|
Jim Stichnoth
2015/12/12 00:04:33
Remove this paragraph if you agree with the corres
rkotlerimgtec
2015/12/12 02:23:35
Done.
| |
| 52 FEATURE_SUPPORTED | |
| 53 | |
| 54 And later in the code: | |
| 55 | |
| 56 if (Ice::BuildDefs::hasFeature() { | |
| 57 ... | |
| 58 } | |
| 59 | |
| 60 Since hasFeature() returns a constexpr, an optimizing compiler will know to | |
| 61 keep or discard the above fragment. In addition, the code will always be | |
| 62 looked at by the compiler which eliminates the problem with defines in that | |
| 63 if you don't build that variant, you don't even know if the code would | |
| 64 compile unless you build with that variant. | |
| 65 | |
| 66 \endverbatim **/ | |
| 67 | |
| 68 | |
| 19 namespace BuildDefs { | 69 namespace BuildDefs { |
| 20 | 70 |
| 21 // The ALLOW_* etc. symbols must be #defined to zero or non-zero. | 71 // The ALLOW_* etc. symbols must be #defined to zero or non-zero. |
| 72 /// return true if ALLOW_DISABLE_IR_GEN is defined as a non-zero value | |
|
Jim Stichnoth
2015/12/12 00:04:33
Should "Return" be capitalized, here and below?
rkotlerimgtec
2015/12/12 02:23:35
Done.
| |
| 22 constexpr bool disableIrGen() { return ALLOW_DISABLE_IR_GEN; } | 73 constexpr bool disableIrGen() { return ALLOW_DISABLE_IR_GEN; } |
| 74 /// return true if ALLOW_DUMP is defined as a non-zero value | |
| 23 constexpr bool dump() { return ALLOW_DUMP; } | 75 constexpr bool dump() { return ALLOW_DUMP; } |
| 76 /// return true if ALLOW_LLVM_CL is defined as a non-zero value | |
| 24 constexpr bool llvmCl() { return ALLOW_LLVM_CL; } | 77 constexpr bool llvmCl() { return ALLOW_LLVM_CL; } |
| 78 /// return true if ALLOW_LLVM_IR is defined as a non-zero value | |
| 25 constexpr bool llvmIr() { return ALLOW_LLVM_IR; } | 79 constexpr bool llvmIr() { return ALLOW_LLVM_IR; } |
| 80 /// return true if ALLOW_LLVM_IR_AS_INPUT is defined as a non-zero value | |
| 26 constexpr bool llvmIrAsInput() { return ALLOW_LLVM_IR_AS_INPUT; } | 81 constexpr bool llvmIrAsInput() { return ALLOW_LLVM_IR_AS_INPUT; } |
| 82 /// return true if ALLOW_MINIMUM is defined as a non-zero value | |
|
Jim Stichnoth
2015/12/12 00:04:34
ALLOW_MINIMAL_BUILD
rkotlerimgtec
2015/12/12 02:23:35
Done.
| |
| 27 constexpr bool minimal() { return ALLOW_MINIMAL_BUILD; } | 83 constexpr bool minimal() { return ALLOW_MINIMAL_BUILD; } |
| 28 | 84 |
| 29 // NDEBUG can be undefined, or defined to something arbitrary. | 85 /// return true if NDEBUG is defined |
| 30 constexpr bool asserts() { | 86 constexpr bool asserts() { |
| 31 #ifdef NDEBUG | 87 #ifdef NDEBUG |
| 32 return false; | 88 return false; |
| 33 #else // !NDEBUG | 89 #else // !NDEBUG |
| 34 return true; | 90 return true; |
| 35 #endif // !NDEBUG | 91 #endif // !NDEBUG |
| 36 } | 92 } |
| 37 | 93 |
| 38 // PNACL_BROWSER_TRANSLATOR can be undefined, or defined to something non-zero | 94 /// return true if PNACL_BROWSER_TRANSLATOR is defined |
| 39 // to indicate a browser-based translator. | |
| 40 constexpr bool browser() { | 95 constexpr bool browser() { |
| 41 #if PNACL_BROWSER_TRANSLATOR | 96 #if PNACL_BROWSER_TRANSLATOR |
| 42 return true; | 97 return true; |
| 43 #else // !PNACL_BROWSER_TRANSLATOR | 98 #else // !PNACL_BROWSER_TRANSLATOR |
| 44 return false; | 99 return false; |
| 45 #endif // !PNACL_BROWSER_TRANSLATOR | 100 #endif // !PNACL_BROWSER_TRANSLATOR |
| 46 } | 101 } |
| 47 | 102 |
| 48 // ALLOW_EXTRA_VALIDATION can be undefined, or defined to something non-zero. | 103 /// return true if ALLOW_EXTRA_VALIDATION is defined |
| 49 constexpr bool extraValidation() { | 104 constexpr bool extraValidation() { |
| 50 #if ALLOW_EXTRA_VALIDATION | 105 #if ALLOW_EXTRA_VALIDATION |
| 51 return true; | 106 return true; |
| 52 #else // !ALLOW_EXTRA_VALIDATION | 107 #else // !ALLOW_EXTRA_VALIDATION |
| 53 return false; | 108 return false; |
| 54 #endif // !ALLOW_EXTRA_VALIDATION | 109 #endif // !ALLOW_EXTRA_VALIDATION |
| 55 } | 110 } |
| 56 | 111 |
| 57 } // end of namespace BuildDefs | 112 } // end of namespace BuildDefs |
| 58 } // end of namespace Ice | 113 } // end of namespace Ice |
| 59 | 114 |
| 60 #endif // SUBZERO_SRC_ICEBUILDDEFS_H | 115 #endif // SUBZERO_SRC_ICEBUILDDEFS_H |
| OLD | NEW |