Commit | Line | Data |
---|---|---|
9a2167bd CB |
1 | /* |
2 | * Copyright (C) 2013 Freescale Semiconductor, Inc. | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
5 | * of this software and associated documentation files (the "Software"), to deal | |
6 | * in the Software without restriction, including without limitation the rights | |
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
8 | * copies of the Software, and to permit persons to whom the Software is | |
9 | * furnished to do so, subject to the following conditions: | |
10 | * | |
11 | * The above copyright notice and this permission notice shall be included | |
12 | * in all copies or substantial portions of the Software. | |
13 | * | |
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
20 | * IN THE SOFTWARE. | |
21 | */ | |
22 | ||
23 | #include "SizedAddress.h" | |
24 | #include <sstream> | |
25 | #include <iomanip> | |
26 | using std::ostringstream; | |
27 | using std::endl; | |
28 | using std::hex; | |
29 | using std::dec; | |
30 | using std::setfill; | |
31 | using std::setw; | |
32 | ||
33 | bool SizedAddress::operator==(const SizedAddress &rhs) const | |
34 | { | |
35 | bool ret = false; | |
36 | if (valid_ && rhs.valid_) { | |
37 | ret = address64() == rhs.address64(); | |
38 | } | |
39 | return ret; | |
40 | } | |
41 | ||
42 | bool SizedAddress::operator!=(const SizedAddress &rhs) const | |
43 | { | |
44 | return !(*this == rhs); | |
45 | } | |
46 | ||
47 | SizedAddress& SizedAddress::operator^=(const SizedAddress &rhs) | |
48 | { | |
49 | // both operands must be valid | |
50 | if (!valid_ || !rhs.valid_) { | |
51 | return *this; | |
52 | } | |
53 | ||
54 | pc_lo_ ^= rhs.pc_lo_; | |
55 | if (pc64_ && rhs.pc64_) { | |
56 | pc_hi_ ^= rhs.pc_hi_; | |
57 | } | |
58 | ||
59 | // promote to 64b if rhs is 64b | |
60 | if (!pc64_ && rhs.pc64_) { | |
61 | pc_hi_ = rhs.pc_hi_; | |
62 | pc64_ = true; | |
63 | } | |
64 | ||
65 | return *this; | |
66 | } | |
67 | ||
68 | const SizedAddress SizedAddress::operator^(const SizedAddress &rhs) | |
69 | { | |
70 | // return new object | |
71 | return SizedAddress(*this) ^= rhs; | |
72 | } | |
73 | ||
74 | // represent the SizedAddress as a formatted string | |
75 | string SizedAddress::asString() const | |
76 | { | |
77 | ostringstream os; | |
78 | if (valid_) { | |
79 | os << "0x"; | |
80 | if (pc64_) { | |
81 | os << hex << setfill('0') << setw(8) << pc_hi_ << ":"; | |
82 | } | |
83 | os << hex << setfill('0') << setw(8) << pc_lo_; | |
84 | } else { | |
85 | os << "uninitialized value"; | |
86 | } | |
87 | ||
88 | return os.str(); | |
89 | } |