| 1 |
/* |
| 2 |
Copyright (C) 2010-2018 David Anderson. All rights reserved. |
| 3 |
|
| 4 |
Redistribution and use in source and binary forms, with |
| 5 |
or without modification, are permitted provided that the |
| 6 |
following conditions are met: |
| 7 |
|
| 8 |
* Redistributions of source code must retain the above copyright |
| 9 |
notice, this list of conditions and the following disclaimer. |
| 10 |
* Redistributions in binary form must reproduce the above |
| 11 |
copyright notice, this list of conditions and the following |
| 12 |
disclaimer in the documentation and/or other materials |
| 13 |
provided with the distribution. |
| 14 |
* Neither the name of the example nor the |
| 15 |
names of its contributors may be used to endorse or |
| 16 |
promote products derived from this software without |
| 17 |
specific prior written permission. |
| 18 |
|
| 19 |
THIS SOFTWARE IS PROVIDED BY David Anderson ''AS IS'' AND ANY |
| 20 |
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 21 |
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| 22 |
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL David |
| 23 |
Anderson BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 |
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 25 |
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 26 |
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 27 |
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 28 |
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 29 |
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 30 |
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 |
|
| 32 |
*/ |
| 33 |
// general.h |
| 34 |
// The following needed in code using this. |
| 35 |
#ifndef GENERAL_H |
| 36 |
#define GENERAL_H |
| 37 |
#include <sstream> |
| 38 |
#include <iomanip> // iomanip for setw etc |
| 39 |
|
| 40 |
// Run time flags from command line. |
| 41 |
extern struct CmdOptions { |
| 42 |
bool transformHighpcToConst; |
| 43 |
int defaultInfoStringForm; |
| 44 |
bool showrelocdetails; |
| 45 |
bool adddata16; |
| 46 |
bool addimplicitconst; |
| 47 |
bool addframeadvanceloc; |
| 48 |
bool addSUNfuncoffsets; |
| 49 |
bool adddebugsup; |
| 50 |
bool addskipbranch; |
| 51 |
} cmdoptions; |
| 52 |
|
| 53 |
template <typename T > |
| 54 |
std::string IToHex(T v,unsigned l=0) |
| 55 |
{ |
| 56 |
if (v == 0) { |
| 57 |
// For a zero value, ostringstream does not insert 0x. |
| 58 |
// So we do zeroes here. |
| 59 |
std::string out = "0x0"; |
| 60 |
if (l > 3) { |
| 61 |
out.append(l-3,'0'); |
| 62 |
} |
| 63 |
return out; |
| 64 |
} |
| 65 |
std::ostringstream s; |
| 66 |
s.setf(std::ios::hex,std::ios::basefield); |
| 67 |
s.setf(std::ios::showbase); |
| 68 |
if (l > 0) { |
| 69 |
s << std::setw(l); |
| 70 |
} |
| 71 |
s << v ; |
| 72 |
return s.str(); |
| 73 |
} |
| 74 |
|
| 75 |
template <typename T> |
| 76 |
std::string BldName(const std::string & prefix, T v) |
| 77 |
{ |
| 78 |
std::ostringstream s; |
| 79 |
s << prefix; |
| 80 |
s << v; |
| 81 |
return s.str(); |
| 82 |
} |
| 83 |
#endif /* GENERAL_H */ |