Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | */ |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 16 | |
| 17 | #ifndef ART_SRC_MANAGED_REGISTER_H_ |
| 18 | #define ART_SRC_MANAGED_REGISTER_H_ |
| 19 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 20 | namespace art { |
| 21 | |
| 22 | namespace x86 { |
| 23 | class X86ManagedRegister; |
| 24 | } |
| 25 | namespace arm { |
| 26 | class ArmManagedRegister; |
| 27 | } |
| 28 | |
| 29 | class ManagedRegister { |
| 30 | public: |
| 31 | // ManagedRegister is a value class. There exists no method to change the |
| 32 | // internal state. We therefore allow a copy constructor and an |
| 33 | // assignment-operator. |
| 34 | ManagedRegister(const ManagedRegister& other) : id_(other.id_) { } |
| 35 | |
| 36 | ManagedRegister& operator=(const ManagedRegister& other) { |
| 37 | id_ = other.id_; |
| 38 | return *this; |
| 39 | } |
| 40 | |
| 41 | x86::X86ManagedRegister AsX86() const; |
| 42 | arm::ArmManagedRegister AsArm() const; |
| 43 | |
| 44 | // It is valid to invoke Equals on and with a NoRegister. |
| 45 | bool Equals(const ManagedRegister& other) const { |
| 46 | return id_ == other.id_; |
| 47 | } |
| 48 | |
| 49 | bool IsNoRegister() const { |
| 50 | return id_ == kNoRegister; |
| 51 | } |
| 52 | |
| 53 | static ManagedRegister NoRegister() { |
| 54 | return ManagedRegister(); |
| 55 | } |
| 56 | |
| 57 | protected: |
| 58 | static const int kNoRegister = -1; |
| 59 | |
| 60 | ManagedRegister() : id_(kNoRegister) { } |
Elliott Hughes | a51a3dd | 2011-10-17 15:19:26 -0700 | [diff] [blame] | 61 | explicit ManagedRegister(int reg_id) : id_(reg_id) { } |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 62 | |
| 63 | int id_; |
| 64 | }; |
| 65 | |
| 66 | } // namespace art |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 67 | |
| 68 | #endif // ART_SRC_MANAGED_REGISTER_H_ |