blob: 04c972388fd27badd1a8d966cd887f6f280bfb9c [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}
Serban Constantinescued8dd492014-02-11 14:15:10 +000025namespace arm64 {
26class Arm64ManagedRegister;
27}
jeffhao7fbee072012-08-24 17:56:54 -070028namespace mips {
29class MipsManagedRegister;
30}
31namespace x86 {
32class X86ManagedRegister;
33}
Ian Rogers2c8f6532011-09-02 17:16:34 -070034
35class ManagedRegister {
36 public:
37 // ManagedRegister is a value class. There exists no method to change the
38 // internal state. We therefore allow a copy constructor and an
39 // assignment-operator.
40 ManagedRegister(const ManagedRegister& other) : id_(other.id_) { }
41
42 ManagedRegister& operator=(const ManagedRegister& other) {
43 id_ = other.id_;
44 return *this;
45 }
46
Ian Rogers2c8f6532011-09-02 17:16:34 -070047 arm::ArmManagedRegister AsArm() const;
Serban Constantinescued8dd492014-02-11 14:15:10 +000048 arm64::Arm64ManagedRegister AsArm64() const;
jeffhao7fbee072012-08-24 17:56:54 -070049 mips::MipsManagedRegister AsMips() const;
50 x86::X86ManagedRegister AsX86() const;
Ian Rogers2c8f6532011-09-02 17:16:34 -070051
52 // It is valid to invoke Equals on and with a NoRegister.
53 bool Equals(const ManagedRegister& other) const {
54 return id_ == other.id_;
55 }
56
57 bool IsNoRegister() const {
58 return id_ == kNoRegister;
59 }
60
61 static ManagedRegister NoRegister() {
62 return ManagedRegister();
63 }
64
65 protected:
66 static const int kNoRegister = -1;
67
68 ManagedRegister() : id_(kNoRegister) { }
Elliott Hughesa51a3dd2011-10-17 15:19:26 -070069 explicit ManagedRegister(int reg_id) : id_(reg_id) { }
Ian Rogers2c8f6532011-09-02 17:16:34 -070070
71 int id_;
72};
73
74} // namespace art
Ian Rogersb033c752011-07-20 12:22:35 -070075
Ian Rogers166db042013-07-26 12:05:57 -070076#endif // ART_COMPILER_UTILS_MANAGED_REGISTER_H_