summaryrefslogtreecommitdiffstats
path: root/common/Value.cpp
blob: 5a6a03426e7f3c430a41eb38bcf1c9698f9c67d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
 * File:	Value.cpp
 *
 * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
 * See included license file for license details.
 */

#include "Value.h"

using namespace elftosb;

//! Returns a varying size depending on the word size attribute.
//!
size_t SizedIntegerValue::getSize() const
{
	switch (m_size)
	{
		case kWordSize:
			return sizeof(uint32_t);
		case kHalfWordSize:
			return sizeof(uint16_t);
		case kByteSize:
			return sizeof(uint8_t);
	}
	return kWordSize;
}

//! The resulting mask can be used to truncate the integer value to be
//! certain it doesn't extend beyond the associated word size.
uint32_t SizedIntegerValue::getWordSizeMask() const
{
	switch (m_size)
	{
		case kWordSize:
			return 0xffffffff;
		case kHalfWordSize:
			return 0x0000ffff;
		case kByteSize:
			return 0x000000ff;
	}
	return 0;
}