Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 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 | */ |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 16 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_OFFSETS_H_ |
| 18 | #define ART_RUNTIME_OFFSETS_H_ |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 19 | |
| 20 | #include <iostream> // NOLINT |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 21 | #include "globals.h" |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 22 | |
| 23 | namespace art { |
| 24 | |
| 25 | // Allow the meaning of offsets to be strongly typed |
| 26 | class Offset { |
| 27 | public: |
| 28 | explicit Offset(size_t val) : val_(val) {} |
| 29 | int32_t Int32Value() const { |
| 30 | return static_cast<int32_t>(val_); |
| 31 | } |
| 32 | uint32_t Uint32Value() const { |
| 33 | return static_cast<uint32_t>(val_); |
| 34 | } |
| 35 | protected: |
| 36 | size_t val_; |
| 37 | }; |
| 38 | std::ostream& operator<<(std::ostream& os, const Offset& offs); |
| 39 | |
| 40 | // Offsets relative to the current frame |
| 41 | class FrameOffset : public Offset { |
| 42 | public: |
| 43 | explicit FrameOffset(size_t val) : Offset(val) {} |
| 44 | bool operator>(FrameOffset other) const { return val_ > other.val_; } |
| 45 | bool operator<(FrameOffset other) const { return val_ < other.val_; } |
| 46 | }; |
| 47 | |
| 48 | // Offsets relative to the current running thread |
| 49 | class ThreadOffset : public Offset { |
| 50 | public: |
| 51 | explicit ThreadOffset(size_t val) : Offset(val) {} |
| 52 | }; |
| 53 | |
| 54 | // Offsets relative to an object |
| 55 | class MemberOffset : public Offset { |
| 56 | public: |
| 57 | explicit MemberOffset(size_t val) : Offset(val) {} |
| 58 | }; |
| 59 | |
| 60 | } // namespace art |
| 61 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 62 | #endif // ART_RUNTIME_OFFSETS_H_ |