blob: 4ad1763754bfc8eee45747ccc0ebcb33c7da8b7c [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
Ian Rogers166db042013-07-26 12:05:57 -070017#ifndef ART_COMPILER_UTILS_MANAGED_REGISTER_H_
18#define ART_COMPILER_UTILS_MANAGED_REGISTER_H_
Ian Rogersb033c752011-07-20 12:22:35 -070019
Ian Rogers2c8f6532011-09-02 17:16:34 -070020namespace art {
21
Ian Rogers2c8f6532011-09-02 17:16:34 -070022namespace arm {
23class ArmManagedRegister;
24}
jeffhao7fbee072012-08-24 17:56:54 -070025namespace mips {
26class MipsManagedRegister;
27}
28namespace x86 {
29class X86ManagedRegister;
30}
Ian Rogers2c8f6532011-09-02 17:16:34 -070031
32class 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 Rogers2c8f6532011-09-02 17:16:34 -070044 arm::ArmManagedRegister AsArm() const;
jeffhao7fbee072012-08-24 17:56:54 -070045 mips::MipsManagedRegister AsMips() const;
46 x86::X86ManagedRegister AsX86() const;
Ian Rogers2c8f6532011-09-02 17:16:34 -070047
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 Hughesa51a3dd2011-10-17 15:19:26 -070065 explicit ManagedRegister(int reg_id) : id_(reg_id) { }
Ian Rogers2c8f6532011-09-02 17:16:34 -070066
67 int id_;
68};
69
70} // namespace art
Ian Rogersb033c752011-07-20 12:22:35 -070071
Ian Rogers166db042013-07-26 12:05:57 -070072#endif // ART_COMPILER_UTILS_MANAGED_REGISTER_H_