1 /*
2  * File:  Value.cpp
3  *
4  * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5  * See included license file for license details.
6  */
7 
8 #include "Value.h"
9 
10 using namespace elftosb;
11 
12 //! Returns a varying size depending on the word size attribute.
13 //!
getSize() const14 size_t SizedIntegerValue::getSize() const
15 {
16           switch (m_size)
17           {
18                     case kWordSize:
19                               return sizeof(uint32_t);
20                     case kHalfWordSize:
21                               return sizeof(uint16_t);
22                     case kByteSize:
23                               return sizeof(uint8_t);
24           }
25           return kWordSize;
26 }
27 
28 //! The resulting mask can be used to truncate the integer value to be
29 //! certain it doesn't extend beyond the associated word size.
getWordSizeMask() const30 uint32_t SizedIntegerValue::getWordSizeMask() const
31 {
32           switch (m_size)
33           {
34                     case kWordSize:
35                               return 0xffffffff;
36                     case kHalfWordSize:
37                               return 0x0000ffff;
38                     case kByteSize:
39                               return 0x000000ff;
40           }
41           return 0;
42 }
43 
44