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