blob: 8490c5504ce071bb2a6f123ae5b981963e5aea2d [file] [log] [blame]
Jim Stichnoth20b71f52015-06-24 15:52:24 -07001//===- 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 Scull9612d322015-07-06 14:53:25 -07009///
10/// \file
Reed Kotler2a18dd32015-12-12 07:04:17 -080011/// \brief Define the Ice::BuildDefs namespace
Jim Stichnoth20b71f52015-06-24 15:52:24 -070012//===----------------------------------------------------------------------===//
13
14#ifndef SUBZERO_SRC_ICEBUILDDEFS_H
15#define SUBZERO_SRC_ICEBUILDDEFS_H
16
17namespace Ice {
Jim Stichnoth0d4fc922015-12-13 21:36:33 -080018/// \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 Kotler2a18dd32015-12-12 07:04:17 -080024
Jim Stichnoth0d4fc922015-12-13 21:36:33 -080025/** \verbatim
Reed Kotler2a18dd32015-12-12 07:04:17 -080026
Jim Stichnoth0d4fc922015-12-13 21:36:33 -080027 For example whenever the value of FEATURE_SUPPORTED is needed, instead
28 of (except in these constexpr functions):
Reed Kotler2a18dd32015-12-12 07:04:17 -080029
Jim Stichnoth0d4fc922015-12-13 21:36:33 -080030 #if FEATURE_SUPPORTED ...
31 ...
32 #endif
Reed Kotler2a18dd32015-12-12 07:04:17 -080033
Jim Stichnoth0d4fc922015-12-13 21:36:33 -080034 We can have:
Reed Kotler2a18dd32015-12-12 07:04:17 -080035
Jim Stichnoth0d4fc922015-12-13 21:36:33 -080036 namespace Ice {
37 namespace BuildDefs {
Reed Kotler2a18dd32015-12-12 07:04:17 -080038
Jim Stichnoth0d4fc922015-12-13 21:36:33 -080039 // 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 Kotler2a18dd32015-12-12 07:04:17 -080042
Jim Stichnoth0d4fc922015-12-13 21:36:33 -080043 or
Reed Kotler2a18dd32015-12-12 07:04:17 -080044
Jim Stichnoth0d4fc922015-12-13 21:36:33 -080045 // 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 Kotler2a18dd32015-12-12 07:04:17 -080054
Jim Stichnoth0d4fc922015-12-13 21:36:33 -080055 ...} // end of namespace BuildDefs
56 } // end of namespace Ice
Reed Kotler2a18dd32015-12-12 07:04:17 -080057
58
Jim Stichnoth0d4fc922015-12-13 21:36:33 -080059 And later in the code:
Reed Kotler2a18dd32015-12-12 07:04:17 -080060
Jim Stichnoth0d4fc922015-12-13 21:36:33 -080061 if (Ice::BuildDefs::hasFeature() {
62 ...
63 }
Reed Kotler2a18dd32015-12-12 07:04:17 -080064
Jim Stichnoth0d4fc922015-12-13 21:36:33 -080065 \endverbatim
Reed Kotler2a18dd32015-12-12 07:04:17 -080066
Jim Stichnoth0d4fc922015-12-13 21:36:33 -080067 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 Kotler2a18dd32015-12-12 07:04:17 -080072
Jim Stichnoth0d4fc922015-12-13 21:36:33 -080073 **/
Reed Kotler2a18dd32015-12-12 07:04:17 -080074
Jim Stichnoth20b71f52015-06-24 15:52:24 -070075namespace BuildDefs {
76
77// The ALLOW_* etc. symbols must be #defined to zero or non-zero.
Reed Kotler8344bfe2015-12-15 08:54:14 -080078/// Return true if ALLOW_DUMP is defined as a non-zero value
Jim Stichnoth20b71f52015-06-24 15:52:24 -070079constexpr bool dump() { return ALLOW_DUMP; }
Jim Stichnothb88d8c82016-03-11 15:33:00 -080080/// Return true if ALLOW_TIMERS is defined as a non-zero value
81constexpr bool timers() { return ALLOW_TIMERS; }
Reed Kotler2a18dd32015-12-12 07:04:17 -080082/// Return true if ALLOW_LLVM_CL is defined as a non-zero value
Jim Stichnoth87e5a6c2015-12-15 08:53:23 -080083// 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 Stichnoth20b71f52015-06-24 15:52:24 -070086constexpr bool llvmCl() { return ALLOW_LLVM_CL; }
Reed Kotler2a18dd32015-12-12 07:04:17 -080087/// Return true if ALLOW_LLVM_IR is defined as a non-zero value
Jim Stichnoth20b71f52015-06-24 15:52:24 -070088constexpr bool llvmIr() { return ALLOW_LLVM_IR; }
Reed Kotler2a18dd32015-12-12 07:04:17 -080089/// Return true if ALLOW_LLVM_IR_AS_INPUT is defined as a non-zero value
Jim Stichnoth20b71f52015-06-24 15:52:24 -070090constexpr bool llvmIrAsInput() { return ALLOW_LLVM_IR_AS_INPUT; }
Reed Kotler2a18dd32015-12-12 07:04:17 -080091/// Return true if ALLOW_MINIMAL_BUILD is defined as a non-zero value
Jim Stichnoth20b71f52015-06-24 15:52:24 -070092constexpr bool minimal() { return ALLOW_MINIMAL_BUILD; }
Eric Holk16f80612016-04-04 17:07:42 -070093/// Return true if ALLOW_WASM is defined as a non-zero value
94constexpr bool wasm() { return ALLOW_WASM; }
Jim Stichnoth20b71f52015-06-24 15:52:24 -070095
Reed Kotler2a18dd32015-12-12 07:04:17 -080096/// Return true if NDEBUG is defined
Jim Stichnoth20b71f52015-06-24 15:52:24 -070097constexpr bool asserts() {
98#ifdef NDEBUG
99 return false;
100#else // !NDEBUG
101 return true;
102#endif // !NDEBUG
103}
104
Reed Kotler2a18dd32015-12-12 07:04:17 -0800105/// Return true if PNACL_BROWSER_TRANSLATOR is defined
Reed Kotler43e8ab32015-12-07 14:31:01 -0800106constexpr 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 Kotler2a18dd32015-12-12 07:04:17 -0800114/// Return true if ALLOW_EXTRA_VALIDATION is defined
Jim Stichnoth20b71f52015-06-24 15:52:24 -0700115constexpr 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