1 /* 2 * Copyright (C) 2018 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_RUNTIME_DEX_REGISTER_LOCATION_H_ 18 #define ART_RUNTIME_DEX_REGISTER_LOCATION_H_ 19 20 #include <array> 21 #include <cstdint> 22 23 #include "base/dchecked_vector.h" 24 #include "base/macros.h" 25 #include "base/memory_region.h" 26 27 namespace art HIDDEN { 28 29 // Dex register location container used by DexRegisterMap and StackMapStream. 30 class DexRegisterLocation { 31 public: 32 enum class Kind : int32_t { 33 kInvalid = -2, // only used internally during register map decoding. 34 kNone = -1, // vreg has not been set. 35 kInStack, // vreg is on the stack, value holds the stack offset. 36 kConstant, // vreg is a constant value. 37 kInRegister, // vreg is in low 32 bits of a core physical register. 38 kInRegisterHigh, // vreg is in high 32 bits of a core physical register. 39 kInFpuRegister, // vreg is in low 32 bits of an FPU register. 40 kInFpuRegisterHigh, // vreg is in high 32 bits of an FPU register. 41 }; 42 DexRegisterLocation(Kind kind,int32_t value)43 DexRegisterLocation(Kind kind, int32_t value) : kind_(kind), value_(value) {} 44 None()45 static DexRegisterLocation None() { return DexRegisterLocation(Kind::kNone, 0); } Invalid()46 static DexRegisterLocation Invalid() { return DexRegisterLocation(Kind::kInvalid, 0); } 47 IsLive()48 bool IsLive() const { return kind_ != Kind::kNone; } 49 GetKind()50 Kind GetKind() const { return kind_; } 51 GetValue()52 int32_t GetValue() const { return value_; } 53 54 bool operator==(DexRegisterLocation other) const { 55 return kind_ == other.kind_ && value_ == other.value_; 56 } 57 58 bool operator!=(DexRegisterLocation other) const { 59 return !(*this == other); 60 } 61 GetStackOffsetInBytes()62 int32_t GetStackOffsetInBytes() const { 63 DCHECK(kind_ == Kind::kInStack); 64 return value_; 65 } 66 GetConstant()67 int32_t GetConstant() const { 68 DCHECK(kind_ == Kind::kConstant); 69 return value_; 70 } 71 GetMachineRegister()72 int32_t GetMachineRegister() const { 73 DCHECK(kind_ == Kind::kInRegister || 74 kind_ == Kind::kInRegisterHigh || 75 kind_ == Kind::kInFpuRegister || 76 kind_ == Kind::kInFpuRegisterHigh); 77 return value_; 78 } 79 80 private: DexRegisterLocation()81 DexRegisterLocation() {} 82 83 Kind kind_; 84 int32_t value_; 85 86 friend class DexRegisterMap; // Allow creation of uninitialized array of locations. 87 }; 88 89 EXPORT std::ostream& operator<<(std::ostream& stream, DexRegisterLocation::Kind kind); 90 std::ostream& operator<<(std::ostream& stream, const DexRegisterLocation& reg); 91 92 } // namespace art 93 94 #endif // ART_RUNTIME_DEX_REGISTER_LOCATION_H_ 95