Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 1 | //===- subzero/src/IceBuildDefs.h - Translator build defines ----*- C++ -*-===// |
| 2 | // |
| 3 | // The Subzero Code Generator |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 9 | /// |
| 10 | /// \file |
Reed Kotler | 2a18dd3 | 2015-12-12 07:04:17 -0800 | [diff] [blame] | 11 | /// \brief Define the Ice::BuildDefs namespace |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef SUBZERO_SRC_ICEBUILDDEFS_H |
| 15 | #define SUBZERO_SRC_ICEBUILDDEFS_H |
| 16 | |
| 17 | namespace Ice { |
Jim Stichnoth | 0d4fc92 | 2015-12-13 21:36:33 -0800 | [diff] [blame] | 18 | /// \brief Defines constexpr functions that express various Subzero build |
| 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++ |
| 23 | /// preprocessor solution. |
Reed Kotler | 2a18dd3 | 2015-12-12 07:04:17 -0800 | [diff] [blame] | 24 | |
Jim Stichnoth | 0d4fc92 | 2015-12-13 21:36:33 -0800 | [diff] [blame] | 25 | /** \verbatim |
Reed Kotler | 2a18dd3 | 2015-12-12 07:04:17 -0800 | [diff] [blame] | 26 | |
Jim Stichnoth | 0d4fc92 | 2015-12-13 21:36:33 -0800 | [diff] [blame] | 27 | For example whenever the value of FEATURE_SUPPORTED is needed, instead |
| 28 | of (except in these constexpr functions): |
Reed Kotler | 2a18dd3 | 2015-12-12 07:04:17 -0800 | [diff] [blame] | 29 | |
Jim Stichnoth | 0d4fc92 | 2015-12-13 21:36:33 -0800 | [diff] [blame] | 30 | #if FEATURE_SUPPORTED ... |
| 31 | ... |
| 32 | #endif |
Reed Kotler | 2a18dd3 | 2015-12-12 07:04:17 -0800 | [diff] [blame] | 33 | |
Jim Stichnoth | 0d4fc92 | 2015-12-13 21:36:33 -0800 | [diff] [blame] | 34 | We can have: |
Reed Kotler | 2a18dd3 | 2015-12-12 07:04:17 -0800 | [diff] [blame] | 35 | |
Jim Stichnoth | 0d4fc92 | 2015-12-13 21:36:33 -0800 | [diff] [blame] | 36 | namespace Ice { |
| 37 | namespace BuildDefs { |
Reed Kotler | 2a18dd3 | 2015-12-12 07:04:17 -0800 | [diff] [blame] | 38 | |
Jim Stichnoth | 0d4fc92 | 2015-12-13 21:36:33 -0800 | [diff] [blame] | 39 | // Use this form when FEATURE_SUPPORTED is guaranteed to be defined on the |
| 40 | // C++ compiler command line as 0 or 1. |
| 41 | constexpr bool hasFeature() { return FEATURE_SUPPORTED; } |
Reed Kotler | 2a18dd3 | 2015-12-12 07:04:17 -0800 | [diff] [blame] | 42 | |
Jim Stichnoth | 0d4fc92 | 2015-12-13 21:36:33 -0800 | [diff] [blame] | 43 | or |
Reed Kotler | 2a18dd3 | 2015-12-12 07:04:17 -0800 | [diff] [blame] | 44 | |
Jim Stichnoth | 0d4fc92 | 2015-12-13 21:36:33 -0800 | [diff] [blame] | 45 | // Use this form when FEATURE_SUPPORTED may not necessarily be defined on |
| 46 | // the C++ compiler command line. |
| 47 | constexpr bool hasFeature() { |
| 48 | #if FEATURE_SUPPORTED |
| 49 | return true; |
| 50 | #else // !FEATURE_SUPPORTED |
| 51 | return false; |
| 52 | #endif // !FEATURE_SUPPORTED |
| 53 | } |
Reed Kotler | 2a18dd3 | 2015-12-12 07:04:17 -0800 | [diff] [blame] | 54 | |
Jim Stichnoth | 0d4fc92 | 2015-12-13 21:36:33 -0800 | [diff] [blame] | 55 | ...} // end of namespace BuildDefs |
| 56 | } // end of namespace Ice |
Reed Kotler | 2a18dd3 | 2015-12-12 07:04:17 -0800 | [diff] [blame] | 57 | |
| 58 | |
Jim Stichnoth | 0d4fc92 | 2015-12-13 21:36:33 -0800 | [diff] [blame] | 59 | And later in the code: |
Reed Kotler | 2a18dd3 | 2015-12-12 07:04:17 -0800 | [diff] [blame] | 60 | |
Jim Stichnoth | 0d4fc92 | 2015-12-13 21:36:33 -0800 | [diff] [blame] | 61 | if (Ice::BuildDefs::hasFeature() { |
| 62 | ... |
| 63 | } |
Reed Kotler | 2a18dd3 | 2015-12-12 07:04:17 -0800 | [diff] [blame] | 64 | |
Jim Stichnoth | 0d4fc92 | 2015-12-13 21:36:33 -0800 | [diff] [blame] | 65 | \endverbatim |
Reed Kotler | 2a18dd3 | 2015-12-12 07:04:17 -0800 | [diff] [blame] | 66 | |
Jim Stichnoth | 0d4fc92 | 2015-12-13 21:36:33 -0800 | [diff] [blame] | 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 |
| 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 |
| 71 | compile unless you build with that variant. |
Reed Kotler | 2a18dd3 | 2015-12-12 07:04:17 -0800 | [diff] [blame] | 72 | |
Jim Stichnoth | 0d4fc92 | 2015-12-13 21:36:33 -0800 | [diff] [blame] | 73 | **/ |
Reed Kotler | 2a18dd3 | 2015-12-12 07:04:17 -0800 | [diff] [blame] | 74 | |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 75 | namespace BuildDefs { |
| 76 | |
| 77 | // The ALLOW_* etc. symbols must be #defined to zero or non-zero. |
Reed Kotler | 8344bfe | 2015-12-15 08:54:14 -0800 | [diff] [blame] | 78 | /// Return true if ALLOW_DUMP is defined as a non-zero value |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 79 | constexpr bool dump() { return ALLOW_DUMP; } |
Jim Stichnoth | b88d8c8 | 2016-03-11 15:33:00 -0800 | [diff] [blame] | 80 | /// Return true if ALLOW_TIMERS is defined as a non-zero value |
| 81 | constexpr bool timers() { return ALLOW_TIMERS; } |
Reed Kotler | 2a18dd3 | 2015-12-12 07:04:17 -0800 | [diff] [blame] | 82 | /// Return true if ALLOW_LLVM_CL is defined as a non-zero value |
Jim Stichnoth | 87e5a6c | 2015-12-15 08:53:23 -0800 | [diff] [blame] | 83 | // TODO(stichnot): this ALLOW_LLVM_CL is a TBD option which will |
| 84 | // allow for replacement of llvm:cl command line processor with a |
| 85 | // smaller footprint version for Subzero. |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 86 | constexpr bool llvmCl() { return ALLOW_LLVM_CL; } |
Reed Kotler | 2a18dd3 | 2015-12-12 07:04:17 -0800 | [diff] [blame] | 87 | /// Return true if ALLOW_LLVM_IR is defined as a non-zero value |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 88 | constexpr bool llvmIr() { return ALLOW_LLVM_IR; } |
Reed Kotler | 2a18dd3 | 2015-12-12 07:04:17 -0800 | [diff] [blame] | 89 | /// Return true if ALLOW_LLVM_IR_AS_INPUT is defined as a non-zero value |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 90 | constexpr bool llvmIrAsInput() { return ALLOW_LLVM_IR_AS_INPUT; } |
Reed Kotler | 2a18dd3 | 2015-12-12 07:04:17 -0800 | [diff] [blame] | 91 | /// Return true if ALLOW_MINIMAL_BUILD is defined as a non-zero value |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 92 | constexpr bool minimal() { return ALLOW_MINIMAL_BUILD; } |
Eric Holk | 16f8061 | 2016-04-04 17:07:42 -0700 | [diff] [blame] | 93 | /// Return true if ALLOW_WASM is defined as a non-zero value |
| 94 | constexpr bool wasm() { return ALLOW_WASM; } |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 95 | |
Reed Kotler | 2a18dd3 | 2015-12-12 07:04:17 -0800 | [diff] [blame] | 96 | /// Return true if NDEBUG is defined |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 97 | constexpr bool asserts() { |
| 98 | #ifdef NDEBUG |
| 99 | return false; |
| 100 | #else // !NDEBUG |
| 101 | return true; |
| 102 | #endif // !NDEBUG |
| 103 | } |
| 104 | |
Reed Kotler | 2a18dd3 | 2015-12-12 07:04:17 -0800 | [diff] [blame] | 105 | /// Return true if PNACL_BROWSER_TRANSLATOR is defined |
Reed Kotler | 43e8ab3 | 2015-12-07 14:31:01 -0800 | [diff] [blame] | 106 | constexpr bool browser() { |
| 107 | #if PNACL_BROWSER_TRANSLATOR |
| 108 | return true; |
| 109 | #else // !PNACL_BROWSER_TRANSLATOR |
| 110 | return false; |
| 111 | #endif // !PNACL_BROWSER_TRANSLATOR |
| 112 | } |
| 113 | |
Reed Kotler | 2a18dd3 | 2015-12-12 07:04:17 -0800 | [diff] [blame] | 114 | /// Return true if ALLOW_EXTRA_VALIDATION is defined |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 115 | constexpr bool extraValidation() { |
| 116 | #if ALLOW_EXTRA_VALIDATION |
| 117 | return true; |
| 118 | #else // !ALLOW_EXTRA_VALIDATION |
| 119 | return false; |
| 120 | #endif // !ALLOW_EXTRA_VALIDATION |
| 121 | } |
| 122 | |
| 123 | } // end of namespace BuildDefs |
| 124 | } // end of namespace Ice |
| 125 | |
| 126 | #endif // SUBZERO_SRC_ICEBUILDDEFS_H |