Alex Light | eb7c144 | 2015-08-31 13:17:42 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_RUNTIME_EXPERIMENTAL_FLAGS_H_ |
| 18 | #define ART_RUNTIME_EXPERIMENTAL_FLAGS_H_ |
| 19 | |
| 20 | #include <ostream> |
| 21 | |
| 22 | namespace art { |
| 23 | |
| 24 | // Possible experimental features that might be enabled. |
| 25 | struct ExperimentalFlags { |
| 26 | // The actual flag values. |
| 27 | enum { |
| 28 | kNone = 0x0000, |
Narayan Kamath | 25352fc | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 29 | kMethodHandles = 0x0004, // 0b00000100 |
Alex Light | eb7c144 | 2015-08-31 13:17:42 -0700 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | constexpr ExperimentalFlags() : value_(0x0000) {} |
Igor Murashkin | 5573c37 | 2017-11-16 13:34:30 -0800 | [diff] [blame] | 33 | constexpr ExperimentalFlags(decltype(kNone) t) // NOLINT [runtime/explicit] |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 34 | : value_(static_cast<uint32_t>(t)) {} |
Alex Light | eb7c144 | 2015-08-31 13:17:42 -0700 | [diff] [blame] | 35 | |
Igor Murashkin | 5573c37 | 2017-11-16 13:34:30 -0800 | [diff] [blame] | 36 | constexpr operator decltype(kNone)() const { |
Alex Light | eb7c144 | 2015-08-31 13:17:42 -0700 | [diff] [blame] | 37 | return static_cast<decltype(kNone)>(value_); |
| 38 | } |
| 39 | |
| 40 | constexpr explicit operator bool() const { |
| 41 | return value_ != kNone; |
| 42 | } |
| 43 | |
| 44 | constexpr ExperimentalFlags operator|(const decltype(kNone)& b) const { |
| 45 | return static_cast<decltype(kNone)>(value_ | static_cast<uint32_t>(b)); |
| 46 | } |
| 47 | constexpr ExperimentalFlags operator|(const ExperimentalFlags& b) const { |
| 48 | return static_cast<decltype(kNone)>(value_ | b.value_); |
| 49 | } |
| 50 | |
| 51 | constexpr ExperimentalFlags operator&(const ExperimentalFlags& b) const { |
| 52 | return static_cast<decltype(kNone)>(value_ & b.value_); |
| 53 | } |
| 54 | constexpr ExperimentalFlags operator&(const decltype(kNone)& b) const { |
| 55 | return static_cast<decltype(kNone)>(value_ & static_cast<uint32_t>(b)); |
| 56 | } |
| 57 | |
| 58 | constexpr bool operator==(const ExperimentalFlags& b) const { |
| 59 | return value_ == b.value_; |
| 60 | } |
| 61 | |
| 62 | private: |
| 63 | uint32_t value_; |
| 64 | }; |
| 65 | |
Alex Light | 7233c7e | 2016-07-28 10:07:45 -0700 | [diff] [blame] | 66 | inline std::ostream& operator<<(std::ostream& stream, const ExperimentalFlags& e) { |
| 67 | bool started = false; |
Narayan Kamath | 25352fc | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 68 | if (e & ExperimentalFlags::kMethodHandles) { |
| 69 | stream << (started ? "|" : "") << "kMethodHandles"; |
| 70 | started = true; |
| 71 | } |
Alex Light | 7233c7e | 2016-07-28 10:07:45 -0700 | [diff] [blame] | 72 | if (!started) { |
| 73 | stream << "kNone"; |
| 74 | } |
Alex Light | eb7c144 | 2015-08-31 13:17:42 -0700 | [diff] [blame] | 75 | return stream; |
| 76 | } |
| 77 | |
| 78 | inline std::ostream& operator<<(std::ostream& stream, const decltype(ExperimentalFlags::kNone)& e) { |
| 79 | return stream << ExperimentalFlags(e); |
| 80 | } |
| 81 | |
| 82 | } // namespace art |
| 83 | |
| 84 | #endif // ART_RUNTIME_EXPERIMENTAL_FLAGS_H_ |