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, |
Alex Light | 7233c7e | 2016-07-28 10:07:45 -0700 | [diff] [blame] | 29 | kAgents = 0x0001, // 0b00000001 |
Alex Light | 185d134 | 2016-08-11 10:48:03 -0700 | [diff] [blame] | 30 | kRuntimePlugins = 0x0002, // 0b00000010 |
Narayan Kamath | 25352fc | 2016-08-03 12:46:58 +0100 | [diff] [blame^] | 31 | kMethodHandles = 0x0004, // 0b00000100 |
Alex Light | eb7c144 | 2015-08-31 13:17:42 -0700 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | constexpr ExperimentalFlags() : value_(0x0000) {} |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 35 | constexpr ExperimentalFlags(decltype(kNone) t) // NOLINT, implicit |
| 36 | : value_(static_cast<uint32_t>(t)) {} |
Alex Light | eb7c144 | 2015-08-31 13:17:42 -0700 | [diff] [blame] | 37 | |
| 38 | constexpr operator decltype(kNone)() const { |
| 39 | return static_cast<decltype(kNone)>(value_); |
| 40 | } |
| 41 | |
| 42 | constexpr explicit operator bool() const { |
| 43 | return value_ != kNone; |
| 44 | } |
| 45 | |
| 46 | constexpr ExperimentalFlags operator|(const decltype(kNone)& b) const { |
| 47 | return static_cast<decltype(kNone)>(value_ | static_cast<uint32_t>(b)); |
| 48 | } |
| 49 | constexpr ExperimentalFlags operator|(const ExperimentalFlags& b) const { |
| 50 | return static_cast<decltype(kNone)>(value_ | b.value_); |
| 51 | } |
| 52 | |
| 53 | constexpr ExperimentalFlags operator&(const ExperimentalFlags& b) const { |
| 54 | return static_cast<decltype(kNone)>(value_ & b.value_); |
| 55 | } |
| 56 | constexpr ExperimentalFlags operator&(const decltype(kNone)& b) const { |
| 57 | return static_cast<decltype(kNone)>(value_ & static_cast<uint32_t>(b)); |
| 58 | } |
| 59 | |
| 60 | constexpr bool operator==(const ExperimentalFlags& b) const { |
| 61 | return value_ == b.value_; |
| 62 | } |
| 63 | |
| 64 | private: |
| 65 | uint32_t value_; |
| 66 | }; |
| 67 | |
Alex Light | 7233c7e | 2016-07-28 10:07:45 -0700 | [diff] [blame] | 68 | inline std::ostream& operator<<(std::ostream& stream, const ExperimentalFlags& e) { |
| 69 | bool started = false; |
| 70 | if (e & ExperimentalFlags::kAgents) { |
| 71 | stream << (started ? "|" : "") << "kAgents"; |
| 72 | started = true; |
| 73 | } |
Alex Light | 185d134 | 2016-08-11 10:48:03 -0700 | [diff] [blame] | 74 | if (e & ExperimentalFlags::kRuntimePlugins) { |
| 75 | stream << (started ? "|" : "") << "kRuntimePlugins"; |
| 76 | started = true; |
| 77 | } |
Narayan Kamath | 25352fc | 2016-08-03 12:46:58 +0100 | [diff] [blame^] | 78 | if (e & ExperimentalFlags::kMethodHandles) { |
| 79 | stream << (started ? "|" : "") << "kMethodHandles"; |
| 80 | started = true; |
| 81 | } |
Alex Light | 7233c7e | 2016-07-28 10:07:45 -0700 | [diff] [blame] | 82 | if (!started) { |
| 83 | stream << "kNone"; |
| 84 | } |
Alex Light | eb7c144 | 2015-08-31 13:17:42 -0700 | [diff] [blame] | 85 | return stream; |
| 86 | } |
| 87 | |
| 88 | inline std::ostream& operator<<(std::ostream& stream, const decltype(ExperimentalFlags::kNone)& e) { |
| 89 | return stream << ExperimentalFlags(e); |
| 90 | } |
| 91 | |
| 92 | } // namespace art |
| 93 | |
| 94 | #endif // ART_RUNTIME_EXPERIMENTAL_FLAGS_H_ |