blob: e9236b94b22fc62471e68547aaf38df3360e12cb [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 Rogersb033c752011-07-20 12:22:35 -070016
17#ifndef ART_SRC_MANAGED_REGISTER_H_
18#define ART_SRC_MANAGED_REGISTER_H_
19
Ian Rogers2c8f6532011-09-02 17:16:34 -070020namespace art {
21
22namespace x86 {
23class X86ManagedRegister;
24}
25namespace arm {
26class ArmManagedRegister;
27}
28
29class 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 Hughesa51a3dd2011-10-17 15:19:26 -070061 explicit ManagedRegister(int reg_id) : id_(reg_id) { }
Ian Rogers2c8f6532011-09-02 17:16:34 -070062
63 int id_;
64};
65
66} // namespace art
Ian Rogersb033c752011-07-20 12:22:35 -070067
68#endif // ART_SRC_MANAGED_REGISTER_H_