Home | History | Annotate | Download | only in utils
      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  */
     16 
     17 #ifndef ART_COMPILER_UTILS_MANAGED_REGISTER_H_
     18 #define ART_COMPILER_UTILS_MANAGED_REGISTER_H_
     19 
     20 namespace art {
     21 
     22 namespace arm {
     23 class ArmManagedRegister;
     24 }
     25 namespace mips {
     26 class MipsManagedRegister;
     27 }
     28 namespace x86 {
     29 class X86ManagedRegister;
     30 }
     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 
     44   arm::ArmManagedRegister AsArm() const;
     45   mips::MipsManagedRegister AsMips() const;
     46   x86::X86ManagedRegister AsX86() const;
     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) { }
     65   explicit ManagedRegister(int reg_id) : id_(reg_id) { }
     66 
     67   int id_;
     68 };
     69 
     70 }  // namespace art
     71 
     72 #endif  // ART_COMPILER_UTILS_MANAGED_REGISTER_H_
     73