2 * \file trc_printable_elem.cpp
5 * \copyright Copyright (c) 2015, ARM Limited. All Rights Reserved.
9 * Redistribution and use in source and binary forms, with or without modification,
10 * are permitted provided that the following conditions are met:
12 * 1. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
19 * 3. Neither the name of the copyright holder nor the names of its contributors
20 * may be used to endorse or promote products derived from this software without
21 * specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include "common/trc_printable_elem.h"
38 #if defined(_MSC_VER) && (_MSC_VER < 1900)
39 /** VS2010 does not support inttypes - remove when VS2010 support is dropped */
40 #define __PRI64_PREFIX "ll"
41 #define PRIX64 __PRI64_PREFIX "X"
42 #define PRIu64 __PRI64_PREFIX "u"
48 void trcPrintableElem::getValStr(std::string &valStr, const int valTotalBitSize, const int valValidBits, const uint64_t value, const bool asHex /* = true*/, const int updateBits /* = 0*/)
50 static char szStrBuffer[128];
51 static char szFormatBuffer[32];
53 assert((valTotalBitSize >= 4) && (valTotalBitSize <= 64));
55 uint64_t LimitMask = ~0ULL;
56 LimitMask >>= 64-valTotalBitSize;
61 int numHexChars = valTotalBitSize / 4;
62 numHexChars += ((valTotalBitSize % 4) > 0) ? 1 : 0;
64 int validChars = valValidBits / 4;
65 if((valValidBits % 4) > 0) validChars++;
66 int QM = numHexChars - validChars;
74 sprintf(szFormatBuffer,"%%0%dllX",validChars); // create the format
75 sprintf(szStrBuffer,szFormatBuffer,value); // fill the buffer
79 sprintf(szFormatBuffer,"%%0%dlX",validChars); // create the format
80 sprintf(szStrBuffer,szFormatBuffer,(uint32_t)value); // fill the buffer
83 if(valValidBits < valTotalBitSize)
85 sprintf(szStrBuffer," (%d:0)", valValidBits-1);
91 uint64_t updateMask = ~0ULL;
92 updateMask >>= 64-updateBits;
93 sprintf(szStrBuffer," ~[0x%" PRIX64 "]",value & updateMask);
100 if(valValidBits < valTotalBitSize)
102 if(valValidBits > 32)
104 sprintf(szStrBuffer,"%" PRIu64 ,value);
108 sprintf(szStrBuffer,"%" PRIu32 ,(uint32_t)value);
110 valStr += szStrBuffer;
111 if(valValidBits < valTotalBitSize)
113 sprintf(szStrBuffer," (%d:0)", valValidBits-1);
120 /* End of File trc_printable_elem.cpp */