Use stdint types everywhere

R=mark at https://breakpad.appspot.com/535002/

git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@1121 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
ted.mielczarek@gmail.com 2013-03-06 14:04:42 +00:00
parent c02002a581
commit aeffe1056f
117 changed files with 1385 additions and 1379 deletions

View file

@ -41,10 +41,10 @@ namespace google_breakpad {
using dwarf2reader::DwarfPointerEncoding;
CFISection &CFISection::CIEHeader(u_int64_t code_alignment_factor,
CFISection &CFISection::CIEHeader(uint64_t code_alignment_factor,
int data_alignment_factor,
unsigned return_address_register,
u_int8_t version,
uint8_t version,
const string &augmentation,
bool dwarf64) {
assert(!entry_length_);
@ -73,8 +73,8 @@ CFISection &CFISection::CIEHeader(u_int64_t code_alignment_factor,
}
CFISection &CFISection::FDEHeader(Label cie_pointer,
u_int64_t initial_location,
u_int64_t address_range,
uint64_t initial_location,
uint64_t address_range,
bool dwarf64) {
assert(!entry_length_);
entry_length_ = new PendingLength();
@ -117,7 +117,7 @@ CFISection &CFISection::FinishEntry() {
return *this;
}
CFISection &CFISection::EncodedPointer(u_int64_t address,
CFISection &CFISection::EncodedPointer(uint64_t address,
DwarfPointerEncoding encoding,
const EncodedPointerBases &bases) {
// Omitted data is extremely easy to emit.
@ -131,7 +131,7 @@ CFISection &CFISection::EncodedPointer(u_int64_t address,
// Find the base address to which this pointer is relative. The upper
// nybble of the encoding specifies this.
u_int64_t base;
uint64_t base;
switch (encoding & 0xf0) {
case dwarf2reader::DW_EH_PE_absptr: base = 0; break;
case dwarf2reader::DW_EH_PE_pcrel: base = bases.cfi + Size(); break;
@ -189,10 +189,10 @@ CFISection &CFISection::EncodedPointer(u_int64_t address,
return *this;
};
const u_int32_t CFISection::kDwarf64InitialLengthMarker;
const u_int32_t CFISection::kDwarf32CIEIdentifier;
const u_int64_t CFISection::kDwarf64CIEIdentifier;
const u_int32_t CFISection::kEHFrame32CIEIdentifier;
const u_int64_t CFISection::kEHFrame64CIEIdentifier;
const uint32_t CFISection::kDwarf64InitialLengthMarker;
const uint32_t CFISection::kDwarf32CIEIdentifier;
const uint64_t CFISection::kDwarf64CIEIdentifier;
const uint32_t CFISection::kEHFrame32CIEIdentifier;
const uint64_t CFISection::kEHFrame64CIEIdentifier;
} // namespace google_breakpad

View file

@ -80,14 +80,14 @@ class CFISection: public Section {
// The starting address of this CFI section in memory, for
// DW_EH_PE_pcrel. DW_EH_PE_pcrel pointers may only be used in data
// that has is loaded into the program's address space.
u_int64_t cfi;
uint64_t cfi;
// The starting address of this file's .text section, for DW_EH_PE_textrel.
u_int64_t text;
uint64_t text;
// The starting address of this file's .got or .eh_frame_hdr section,
// for DW_EH_PE_datarel.
u_int64_t data;
uint64_t data;
};
// Create a CFISection whose endianness is ENDIANNESS, and where
@ -133,10 +133,10 @@ class CFISection: public Section {
// Before calling this function, you will typically want to use Mark
// or Here to make a label to pass to FDEHeader that refers to this
// CIE's position in the section.
CFISection &CIEHeader(u_int64_t code_alignment_factor,
CFISection &CIEHeader(uint64_t code_alignment_factor,
int data_alignment_factor,
unsigned return_address_register,
u_int8_t version = 3,
uint8_t version = 3,
const string &augmentation = "",
bool dwarf64 = false);
@ -151,8 +151,8 @@ class CFISection: public Section {
// value.) Nor does it support .debug_frame sections longer than
// 0xffffff00 bytes.
CFISection &FDEHeader(Label cie_pointer,
u_int64_t initial_location,
u_int64_t address_range,
uint64_t initial_location,
uint64_t address_range,
bool dwarf64 = false);
// Note the current position as the end of the last CIE or FDE we
@ -171,7 +171,7 @@ class CFISection: public Section {
// Append ADDRESS to this section, in the appropriate size and
// endianness. Return a reference to this section.
CFISection &Address(u_int64_t address) {
CFISection &Address(uint64_t address) {
Section::Append(endianness(), address_size_, address);
return *this;
}
@ -189,26 +189,26 @@ class CFISection: public Section {
//
// (C++ doesn't let me use default arguments here, because I want to
// refer to members of *this in the default argument expression.)
CFISection &EncodedPointer(u_int64_t address) {
CFISection &EncodedPointer(uint64_t address) {
return EncodedPointer(address, pointer_encoding_, encoded_pointer_bases_);
}
CFISection &EncodedPointer(u_int64_t address, DwarfPointerEncoding encoding) {
CFISection &EncodedPointer(uint64_t address, DwarfPointerEncoding encoding) {
return EncodedPointer(address, encoding, encoded_pointer_bases_);
}
CFISection &EncodedPointer(u_int64_t address, DwarfPointerEncoding encoding,
CFISection &EncodedPointer(uint64_t address, DwarfPointerEncoding encoding,
const EncodedPointerBases &bases);
// Restate some member functions, to keep chaining working nicely.
CFISection &Mark(Label *label) { Section::Mark(label); return *this; }
CFISection &D8(u_int8_t v) { Section::D8(v); return *this; }
CFISection &D16(u_int16_t v) { Section::D16(v); return *this; }
CFISection &D8(uint8_t v) { Section::D8(v); return *this; }
CFISection &D16(uint16_t v) { Section::D16(v); return *this; }
CFISection &D16(Label v) { Section::D16(v); return *this; }
CFISection &D32(u_int32_t v) { Section::D32(v); return *this; }
CFISection &D32(uint32_t v) { Section::D32(v); return *this; }
CFISection &D32(const Label &v) { Section::D32(v); return *this; }
CFISection &D64(u_int64_t v) { Section::D64(v); return *this; }
CFISection &D64(uint64_t v) { Section::D64(v); return *this; }
CFISection &D64(const Label &v) { Section::D64(v); return *this; }
CFISection &LEB128(long long v) { Section::LEB128(v); return *this; }
CFISection &ULEB128(u_int64_t v) { Section::ULEB128(v); return *this; }
CFISection &ULEB128(uint64_t v) { Section::ULEB128(v); return *this; }
private:
// A length value that we've appended to the section, but is not yet
@ -224,13 +224,13 @@ class CFISection: public Section {
// If the first four bytes of an "initial length" are this constant, then
// the data uses the 64-bit DWARF format, and the length itself is the
// subsequent eight bytes.
static const u_int32_t kDwarf64InitialLengthMarker = 0xffffffffU;
static const uint32_t kDwarf64InitialLengthMarker = 0xffffffffU;
// The CIE identifier for 32- and 64-bit DWARF CFI and .eh_frame data.
static const u_int32_t kDwarf32CIEIdentifier = ~(u_int32_t)0;
static const u_int64_t kDwarf64CIEIdentifier = ~(u_int64_t)0;
static const u_int32_t kEHFrame32CIEIdentifier = 0;
static const u_int64_t kEHFrame64CIEIdentifier = 0;
static const uint32_t kDwarf32CIEIdentifier = ~(uint32_t)0;
static const uint64_t kDwarf64CIEIdentifier = ~(uint64_t)0;
static const uint32_t kEHFrame32CIEIdentifier = 0;
static const uint64_t kEHFrame64CIEIdentifier = 0;
// The size of a machine address for the data in this section.
size_t address_size_;
@ -261,7 +261,7 @@ class CFISection: public Section {
// If in_fde_ is true, this is its starting address. We use this for
// emitting DW_EH_PE_funcrel pointers.
u_int64_t fde_start_address_;
uint64_t fde_start_address_;
};
} // namespace google_breakpad

View file

@ -2326,14 +2326,14 @@ struct ELFSectionHeader {
alignment(1), entry_size(0) { }
Label name;
unsigned int type;
u_int64_t flags;
u_int64_t address;
uint64_t flags;
uint64_t address;
Label file_offset;
Label file_size;
unsigned int link;
unsigned int info;
u_int64_t alignment;
u_int64_t entry_size;
uint64_t alignment;
uint64_t entry_size;
};
void AppendSectionHeader(CFISection *table, const ELFSectionHeader &header) {

View file

@ -289,7 +289,7 @@ TEST_P(DwarfForms, addr) {
StartSingleAttributeDIE(GetParam(), dwarf2reader::DW_TAG_compile_unit,
dwarf2reader::DW_AT_low_pc,
dwarf2reader::DW_FORM_addr);
u_int64_t value;
uint64_t value;
if (GetParam().address_size == 4) {
value = 0xc8e9ffcc;
info.D32(value);
@ -372,7 +372,7 @@ TEST_P(DwarfForms, sec_offset) {
StartSingleAttributeDIE(GetParam(), (DwarfTag) 0x1d971689,
(DwarfAttribute) 0xa060bfd1,
dwarf2reader::DW_FORM_sec_offset);
u_int64_t value;
uint64_t value;
if (GetParam().format_size == 4) {
value = 0xacc9c388;
info.D32(value);

View file

@ -97,7 +97,7 @@ class TestCompilationUnit: public google_breakpad::test_assembler::Section {
// The offset of the point in the compilation unit header immediately
// after the initial length field.
u_int64_t post_length_offset_;
uint64_t post_length_offset_;
// The length of the compilation unit, not including the initial length field.
Label length_;

View file

@ -46,14 +46,14 @@
//
class GUIDGenerator {
public:
static u_int32_t BytesToUInt32(const u_int8_t bytes[]) {
return ((u_int32_t) bytes[0]
| ((u_int32_t) bytes[1] << 8)
| ((u_int32_t) bytes[2] << 16)
| ((u_int32_t) bytes[3] << 24));
static uint32_t BytesToUInt32(const uint8_t bytes[]) {
return ((uint32_t) bytes[0]
| ((uint32_t) bytes[1] << 8)
| ((uint32_t) bytes[2] << 16)
| ((uint32_t) bytes[3] << 24));
}
static void UInt32ToBytes(u_int8_t bytes[], u_int32_t n) {
static void UInt32ToBytes(uint8_t bytes[], uint32_t n) {
bytes[0] = n & 0xff;
bytes[1] = (n >> 8) & 0xff;
bytes[2] = (n >> 16) & 0xff;
@ -63,8 +63,8 @@ class GUIDGenerator {
static bool CreateGUID(GUID *guid) {
InitOnce();
guid->data1 = random();
guid->data2 = (u_int16_t)(random());
guid->data3 = (u_int16_t)(random());
guid->data2 = (uint16_t)(random());
guid->data3 = (uint16_t)(random());
UInt32ToBytes(&guid->data4[0], random());
UInt32ToBytes(&guid->data4[4], random());
return true;

View file

@ -97,7 +97,7 @@ bool MemoryMappedFile::Map(const char* path) {
void MemoryMappedFile::Unmap() {
if (content_.data()) {
sys_munmap(const_cast<u_int8_t*>(content_.data()), content_.length());
sys_munmap(const_cast<uint8_t*>(content_.data()), content_.length());
content_.Set(NULL, 0);
}
}

View file

@ -164,11 +164,11 @@ class MachMessage {
public:
// The receiver of the message can retrieve the raw data this way
u_int8_t *GetData() {
uint8_t *GetData() {
return GetDataLength() > 0 ? GetDataPacket()->data : NULL;
}
u_int32_t GetDataLength() {
uint32_t GetDataLength() {
return EndianU32_LtoN(GetDataPacket()->data_length);
}
@ -210,7 +210,7 @@ class MachMessage {
struct MessageDataPacket {
int32_t id; // little-endian
int32_t data_length; // little-endian
u_int8_t data[1]; // actual size limited by sizeof(MachMessage)
uint8_t data[1]; // actual size limited by sizeof(MachMessage)
};
MessageDataPacket* GetDataPacket();
@ -223,7 +223,7 @@ class MachMessage {
mach_msg_header_t head;
mach_msg_body_t body;
u_int8_t padding[1024]; // descriptors and data may be embedded here
uint8_t padding[1024]; // descriptors and data may be embedded here
};
//==============================================================================

View file

@ -67,7 +67,7 @@ class MemoryRange {
// Sets this memory range to point to |data| and its length to |length|.
void Set(const void* data, size_t length) {
data_ = reinterpret_cast<const u_int8_t*>(data);
data_ = reinterpret_cast<const uint8_t*>(data);
// Always set |length_| to zero if |data_| is NULL.
length_ = data ? length : 0;
}
@ -127,14 +127,14 @@ class MemoryRange {
}
// Returns a pointer to the beginning of this memory range.
const u_int8_t* data() const { return data_; }
const uint8_t* data() const { return data_; }
// Returns the length, in bytes, of this memory range.
size_t length() const { return length_; }
private:
// Pointer to the beginning of this memory range.
const u_int8_t* data_;
const uint8_t* data_;
// Length, in bytes, of this memory range.
size_t length_;

View file

@ -37,9 +37,9 @@ using testing::Message;
namespace {
const u_int32_t kBuffer[10] = { 0 };
const uint32_t kBuffer[10] = { 0 };
const size_t kBufferSize = sizeof(kBuffer);
const u_int8_t* kBufferPointer = reinterpret_cast<const u_int8_t*>(kBuffer);
const uint8_t* kBufferPointer = reinterpret_cast<const uint8_t*>(kBuffer);
// Test vectors for verifying Covers, GetData, and Subrange.
const struct {

View file

@ -60,7 +60,7 @@ using std::map;
class Module {
public:
// The type of addresses and sizes in a symbol table.
typedef u_int64_t Address;
typedef uint64_t Address;
struct File;
struct Function;
struct Line;

View file

@ -156,7 +156,7 @@ const char *kStrtabName = ".strtab";
const int demangleLen = 20000;
// Offset to the string table.
u_int64_t stringOffset = 0;
uint64_t stringOffset = 0;
// Update the offset to the start of the string index of the next
// object module for every N_ENDM stabs.

View file

@ -53,10 +53,10 @@ class GUIDGenerator {
bool CreateGUID(GUID *guid) const {
guid->data1 = random();
guid->data2 = (u_int16_t)(random());
guid->data3 = (u_int16_t)(random());
*reinterpret_cast<u_int32_t*>(&guid->data4[0]) = random();
*reinterpret_cast<u_int32_t*>(&guid->data4[4]) = random();
guid->data2 = (uint16_t)(random());
guid->data3 = (uint16_t)(random());
*reinterpret_cast<uint32_t*>(&guid->data4[0]) = random();
*reinterpret_cast<uint32_t*>(&guid->data4[4]) = random();
return true;
}
};
@ -74,8 +74,8 @@ bool GUIDToString(const GUID *guid, char *buf, int buf_len) {
assert(buf_len > kGUIDStringLength);
int num = snprintf(buf, buf_len, kGUIDFormatString,
guid->data1, guid->data2, guid->data3,
*reinterpret_cast<const u_int32_t *>(&(guid->data4[0])),
*reinterpret_cast<const u_int32_t *>(&(guid->data4[4])));
*reinterpret_cast<const uint32_t *>(&(guid->data4[0])),
*reinterpret_cast<const uint32_t *>(&(guid->data4[4])));
if (num != kGUIDStringLength)
return false;

View file

@ -565,7 +565,7 @@ TEST_F(Stabs, OnePublicSymbol) {
stabs.set_endianness(kLittleEndian);
stabs.set_value_size(4);
const u_int32_t kExpectedAddress = 0x9000;
const uint32_t kExpectedAddress = 0x9000;
const string kExpectedFunctionName("public_function");
stabs
.Stab(N_SECT, 1, 0, kExpectedAddress, kExpectedFunctionName);
@ -584,9 +584,9 @@ TEST_F(Stabs, TwoPublicSymbols) {
stabs.set_endianness(kLittleEndian);
stabs.set_value_size(4);
const u_int32_t kExpectedAddress1 = 0xB0B0B0B0;
const uint32_t kExpectedAddress1 = 0xB0B0B0B0;
const string kExpectedFunctionName1("public_function");
const u_int32_t kExpectedAddress2 = 0xF0F0F0F0;
const uint32_t kExpectedAddress2 = 0xF0F0F0F0;
const string kExpectedFunctionName2("something else");
stabs
.Stab(N_SECT, 1, 0, kExpectedAddress1, kExpectedFunctionName1)

View file

@ -38,15 +38,15 @@ namespace google_breakpad {
using std::vector;
void UTF8ToUTF16(const char *in, vector<u_int16_t> *out) {
void UTF8ToUTF16(const char *in, vector<uint16_t> *out) {
size_t source_length = strlen(in);
const UTF8 *source_ptr = reinterpret_cast<const UTF8 *>(in);
const UTF8 *source_end_ptr = source_ptr + source_length;
// Erase the contents and zero fill to the expected size
out->clear();
out->insert(out->begin(), source_length, 0);
u_int16_t *target_ptr = &(*out)[0];
u_int16_t *target_end_ptr = target_ptr + out->capacity() * sizeof(u_int16_t);
uint16_t *target_ptr = &(*out)[0];
uint16_t *target_end_ptr = target_ptr + out->capacity() * sizeof(uint16_t);
ConversionResult result = ConvertUTF8toUTF16(&source_ptr, source_end_ptr,
&target_ptr, target_end_ptr,
strictConversion);
@ -55,11 +55,11 @@ void UTF8ToUTF16(const char *in, vector<u_int16_t> *out) {
out->resize(result == conversionOK ? target_ptr - &(*out)[0] + 1: 0);
}
int UTF8ToUTF16Char(const char *in, int in_length, u_int16_t out[2]) {
int UTF8ToUTF16Char(const char *in, int in_length, uint16_t out[2]) {
const UTF8 *source_ptr = reinterpret_cast<const UTF8 *>(in);
const UTF8 *source_end_ptr = source_ptr + sizeof(char);
u_int16_t *target_ptr = out;
u_int16_t *target_end_ptr = target_ptr + 2 * sizeof(u_int16_t);
uint16_t *target_ptr = out;
uint16_t *target_end_ptr = target_ptr + 2 * sizeof(uint16_t);
out[0] = out[1] = 0;
// Process one character at a time
@ -82,15 +82,15 @@ int UTF8ToUTF16Char(const char *in, int in_length, u_int16_t out[2]) {
return 0;
}
void UTF32ToUTF16(const wchar_t *in, vector<u_int16_t> *out) {
void UTF32ToUTF16(const wchar_t *in, vector<uint16_t> *out) {
size_t source_length = wcslen(in);
const UTF32 *source_ptr = reinterpret_cast<const UTF32 *>(in);
const UTF32 *source_end_ptr = source_ptr + source_length;
// Erase the contents and zero fill to the expected size
out->clear();
out->insert(out->begin(), source_length, 0);
u_int16_t *target_ptr = &(*out)[0];
u_int16_t *target_end_ptr = target_ptr + out->capacity() * sizeof(u_int16_t);
uint16_t *target_ptr = &(*out)[0];
uint16_t *target_end_ptr = target_ptr + out->capacity() * sizeof(uint16_t);
ConversionResult result = ConvertUTF32toUTF16(&source_ptr, source_end_ptr,
&target_ptr, target_end_ptr,
strictConversion);
@ -99,11 +99,11 @@ void UTF32ToUTF16(const wchar_t *in, vector<u_int16_t> *out) {
out->resize(result == conversionOK ? target_ptr - &(*out)[0] + 1: 0);
}
void UTF32ToUTF16Char(wchar_t in, u_int16_t out[2]) {
void UTF32ToUTF16Char(wchar_t in, uint16_t out[2]) {
const UTF32 *source_ptr = reinterpret_cast<const UTF32 *>(&in);
const UTF32 *source_end_ptr = source_ptr + 1;
u_int16_t *target_ptr = out;
u_int16_t *target_end_ptr = target_ptr + 2 * sizeof(u_int16_t);
uint16_t *target_ptr = out;
uint16_t *target_end_ptr = target_ptr + 2 * sizeof(uint16_t);
out[0] = out[1] = 0;
ConversionResult result = ConvertUTF32toUTF16(&source_ptr, source_end_ptr,
&target_ptr, target_end_ptr,
@ -114,20 +114,20 @@ void UTF32ToUTF16Char(wchar_t in, u_int16_t out[2]) {
}
}
static inline u_int16_t Swap(u_int16_t value) {
return (value >> 8) | static_cast<u_int16_t>(value << 8);
static inline uint16_t Swap(uint16_t value) {
return (value >> 8) | static_cast<uint16_t>(value << 8);
}
string UTF16ToUTF8(const vector<u_int16_t> &in, bool swap) {
string UTF16ToUTF8(const vector<uint16_t> &in, bool swap) {
const UTF16 *source_ptr = &in[0];
scoped_ptr<u_int16_t> source_buffer;
scoped_ptr<uint16_t> source_buffer;
// If we're to swap, we need to make a local copy and swap each byte pair
if (swap) {
int idx = 0;
source_buffer.reset(new u_int16_t[in.size()]);
source_buffer.reset(new uint16_t[in.size()]);
UTF16 *source_buffer_ptr = source_buffer.get();
for (vector<u_int16_t>::const_iterator it = in.begin();
for (vector<uint16_t>::const_iterator it = in.begin();
it != in.end(); ++it, ++idx)
source_buffer_ptr[idx] = Swap(*it);

View file

@ -44,24 +44,24 @@ using std::vector;
// Convert |in| to UTF-16 into |out|. Use platform byte ordering. If the
// conversion failed, |out| will be zero length.
void UTF8ToUTF16(const char *in, vector<u_int16_t> *out);
void UTF8ToUTF16(const char *in, vector<uint16_t> *out);
// Convert at least one character (up to a maximum of |in_length|) from |in|
// to UTF-16 into |out|. Return the number of characters consumed from |in|.
// Any unused characters in |out| will be initialized to 0. No memory will
// be allocated by this routine.
int UTF8ToUTF16Char(const char *in, int in_length, u_int16_t out[2]);
int UTF8ToUTF16Char(const char *in, int in_length, uint16_t out[2]);
// Convert |in| to UTF-16 into |out|. Use platform byte ordering. If the
// conversion failed, |out| will be zero length.
void UTF32ToUTF16(const wchar_t *in, vector<u_int16_t> *out);
void UTF32ToUTF16(const wchar_t *in, vector<uint16_t> *out);
// Convert |in| to UTF-16 into |out|. Any unused characters in |out| will be
// initialized to 0. No memory will be allocated by this routine.
void UTF32ToUTF16Char(wchar_t in, u_int16_t out[2]);
void UTF32ToUTF16Char(wchar_t in, uint16_t out[2]);
// Convert |in| to UTF-8. If |swap| is true, swap bytes before converting.
string UTF16ToUTF8(const vector<u_int16_t> &in, bool swap);
string UTF16ToUTF8(const vector<uint16_t> &in, bool swap);
} // namespace google_breakpad

View file

@ -45,7 +45,7 @@ namespace test_assembler {
using std::back_insert_iterator;
Label::Label() : value_(new Binding()) { }
Label::Label(u_int64_t value) : value_(new Binding(value)) { }
Label::Label(uint64_t value) : value_(new Binding(value)) { }
Label::Label(const Label &label) {
value_ = label.value_;
value_->Acquire();
@ -54,7 +54,7 @@ Label::~Label() {
if (value_->Release()) delete value_;
}
Label &Label::operator=(u_int64_t value) {
Label &Label::operator=(uint64_t value) {
value_->Set(NULL, value);
return *this;
}
@ -64,13 +64,13 @@ Label &Label::operator=(const Label &label) {
return *this;
}
Label Label::operator+(u_int64_t addend) const {
Label Label::operator+(uint64_t addend) const {
Label l;
l.value_->Set(this->value_, addend);
return l;
}
Label Label::operator-(u_int64_t subtrahend) const {
Label Label::operator-(uint64_t subtrahend) const {
Label l;
l.value_->Set(this->value_, -subtrahend);
return l;
@ -89,31 +89,31 @@ Label Label::operator-(u_int64_t subtrahend) const {
#define ALWAYS_EVALUATE_AND_ASSERT(x) assert(x)
#endif
u_int64_t Label::operator-(const Label &label) const {
u_int64_t offset;
uint64_t Label::operator-(const Label &label) const {
uint64_t offset;
ALWAYS_EVALUATE_AND_ASSERT(IsKnownOffsetFrom(label, &offset));
return offset;
}
u_int64_t Label::Value() const {
u_int64_t v = 0;
uint64_t Label::Value() const {
uint64_t v = 0;
ALWAYS_EVALUATE_AND_ASSERT(IsKnownConstant(&v));
return v;
};
bool Label::IsKnownConstant(u_int64_t *value_p) const {
bool Label::IsKnownConstant(uint64_t *value_p) const {
Binding *base;
u_int64_t addend;
uint64_t addend;
value_->Get(&base, &addend);
if (base != NULL) return false;
if (value_p) *value_p = addend;
return true;
}
bool Label::IsKnownOffsetFrom(const Label &label, u_int64_t *offset_p) const
bool Label::IsKnownOffsetFrom(const Label &label, uint64_t *offset_p) const
{
Binding *label_base, *this_base;
u_int64_t label_addend, this_addend;
uint64_t label_addend, this_addend;
label.value_->Get(&label_base, &label_addend);
value_->Get(&this_base, &this_addend);
// If this and label are related, Get will find their final
@ -126,7 +126,7 @@ bool Label::IsKnownOffsetFrom(const Label &label, u_int64_t *offset_p) const
Label::Binding::Binding() : base_(this), addend_(), reference_count_(1) { }
Label::Binding::Binding(u_int64_t addend)
Label::Binding::Binding(uint64_t addend)
: base_(NULL), addend_(addend), reference_count_(1) { }
Label::Binding::~Binding() {
@ -135,7 +135,7 @@ Label::Binding::~Binding() {
delete base_;
}
void Label::Binding::Set(Binding *binding, u_int64_t addend) {
void Label::Binding::Set(Binding *binding, uint64_t addend) {
if (!base_ && !binding) {
// We're equating two constants. This could be okay.
assert(addend_ == addend);
@ -150,7 +150,7 @@ void Label::Binding::Set(Binding *binding, u_int64_t addend) {
// another variable (otherwise, it wouldn't be final), this
// guarantees we won't create cycles here, even for code like this:
// l = m, m = n, n = l;
u_int64_t binding_addend;
uint64_t binding_addend;
binding->Get(&binding, &binding_addend);
addend += binding_addend;
}
@ -183,14 +183,14 @@ void Label::Binding::Set(Binding *binding, u_int64_t addend) {
}
}
void Label::Binding::Get(Binding **base, u_int64_t *addend) {
void Label::Binding::Get(Binding **base, uint64_t *addend) {
if (base_ && base_ != this) {
// Recurse to find the end of our reference chain (the root of our
// tree), and then rewrite every binding along the chain to refer
// to it directly, adjusting addends appropriately. (This is why
// this member function isn't this-const.)
Binding *final_base;
u_int64_t final_addend;
uint64_t final_addend;
base_->Get(&final_base, &final_addend);
if (final_base) final_base->Acquire();
if (base_->Release()) delete base_;
@ -203,7 +203,7 @@ void Label::Binding::Get(Binding **base, u_int64_t *addend) {
template<typename Inserter>
static inline void InsertEndian(test_assembler::Endianness endianness,
size_t size, u_int64_t number, Inserter dest) {
size_t size, uint64_t number, Inserter dest) {
assert(size > 0);
if (endianness == kLittleEndian) {
for (size_t i = 0; i < size; i++) {
@ -218,7 +218,7 @@ static inline void InsertEndian(test_assembler::Endianness endianness,
}
}
Section &Section::Append(Endianness endianness, size_t size, u_int64_t number) {
Section &Section::Append(Endianness endianness, size_t size, uint64_t number) {
InsertEndian(endianness, size, number,
back_insert_iterator<string>(contents_));
return *this;
@ -228,7 +228,7 @@ Section &Section::Append(Endianness endianness, size_t size,
const Label &label) {
// If this label's value is known, there's no reason to waste an
// entry in references_ on it.
u_int64_t value;
uint64_t value;
if (label.IsKnownConstant(&value))
return Append(endianness, size, value);
@ -246,7 +246,7 @@ Section &Section::Append(Endianness endianness, size_t size,
#define ENDIANNESS(e) ENDIANNESS_ ## e
#define DEFINE_SHORT_APPEND_NUMBER_ENDIAN(e, bits) \
Section &Section::e ## bits(u_int ## bits ## _t v) { \
Section &Section::e ## bits(uint ## bits ## _t v) { \
InsertEndian(ENDIANNESS(e), bits / 8, v, \
back_insert_iterator<string>(contents_)); \
return *this; \
@ -272,7 +272,7 @@ DEFINE_SHORT_APPEND_ENDIAN(B, 32);
DEFINE_SHORT_APPEND_ENDIAN(B, 64);
#define DEFINE_SHORT_APPEND_NUMBER_DEFAULT(bits) \
Section &Section::D ## bits(u_int ## bits ## _t v) { \
Section &Section::D ## bits(uint ## bits ## _t v) { \
InsertEndian(endianness_, bits / 8, v, \
back_insert_iterator<string>(contents_)); \
return *this; \
@ -312,7 +312,7 @@ Section &Section::LEB128(long long value) {
return *this;
}
Section &Section::ULEB128(u_int64_t value) {
Section &Section::ULEB128(uint64_t value) {
while (value > 0x7f) {
contents_ += (value & 0x7f) | 0x80;
value = (value >> 7);
@ -321,7 +321,7 @@ Section &Section::ULEB128(u_int64_t value) {
return *this;
}
Section &Section::Align(size_t alignment, u_int8_t pad_byte) {
Section &Section::Align(size_t alignment, uint8_t pad_byte) {
// ALIGNMENT must be a power of two.
assert(((alignment - 1) & alignment) == 0);
size_t new_size = (contents_.size() + alignment - 1) & ~(alignment - 1);
@ -340,7 +340,7 @@ bool Section::GetContents(string *contents) {
// the section's contents.
for (size_t i = 0; i < references_.size(); i++) {
Reference &r = references_[i];
u_int64_t value;
uint64_t value;
if (!r.label.IsKnownConstant(&value)) {
fprintf(stderr, "Undefined label #%zu at offset 0x%zx\n", i, r.offset);
return false;

View file

@ -110,7 +110,7 @@ namespace test_assembler {
class Label {
public:
Label(); // An undefined label.
Label(u_int64_t value); // A label with a fixed value
Label(uint64_t value); // A label with a fixed value
Label(const Label &value); // A label equal to another.
~Label();
@ -119,23 +119,23 @@ class Label {
// Providing this as a cast operator is nifty, but the conversions
// happen in unexpected places. In particular, ISO C++ says that
// Label + size_t becomes ambigious, because it can't decide whether
// to convert the Label to a u_int64_t and then to a size_t, or use
// to convert the Label to a uint64_t and then to a size_t, or use
// the overloaded operator that returns a new label, even though the
// former could fail if the label is not yet defined and the latter won't.
u_int64_t Value() const;
uint64_t Value() const;
Label &operator=(u_int64_t value);
Label &operator=(uint64_t value);
Label &operator=(const Label &value);
Label operator+(u_int64_t addend) const;
Label operator-(u_int64_t subtrahend) const;
u_int64_t operator-(const Label &subtrahend) const;
Label operator+(uint64_t addend) const;
Label operator-(uint64_t subtrahend) const;
uint64_t operator-(const Label &subtrahend) const;
// We could also provide == and != that work on undefined, but
// related, labels.
// Return true if this label's value is known. If VALUE_P is given,
// set *VALUE_P to the known value if returning true.
bool IsKnownConstant(u_int64_t *value_p = NULL) const;
bool IsKnownConstant(uint64_t *value_p = NULL) const;
// Return true if the offset from LABEL to this label is known. If
// OFFSET_P is given, set *OFFSET_P to the offset when returning true.
@ -150,12 +150,12 @@ class Label {
// m = l + 10;
// l.IsKnownConstant(); // false
// m.IsKnownConstant(); // false
// u_int64_t d;
// uint64_t d;
// l.IsKnownOffsetFrom(m, &d); // true, and sets d to -10.
// l-m // -10
// m-l // 10
// m.Value() // error: m's value is not known
bool IsKnownOffsetFrom(const Label &label, u_int64_t *offset_p = NULL) const;
bool IsKnownOffsetFrom(const Label &label, uint64_t *offset_p = NULL) const;
private:
// A label's value, or if that is not yet known, how the value is
@ -173,7 +173,7 @@ class Label {
class Binding {
public:
Binding();
Binding(u_int64_t addend);
Binding(uint64_t addend);
~Binding();
// Increment our reference count.
@ -186,7 +186,7 @@ class Label {
// Update every binding on this binding's chain to point directly
// to BINDING, or to be a constant, with addends adjusted
// appropriately.
void Set(Binding *binding, u_int64_t value);
void Set(Binding *binding, uint64_t value);
// Return what we know about the value of this binding.
// - If this binding's value is a known constant, set BASE to
@ -198,7 +198,7 @@ class Label {
// value.
// - If this binding is unconstrained, set BASE to this, and leave
// ADDEND unchanged.
void Get(Binding **base, u_int64_t *addend);
void Get(Binding **base, uint64_t *addend);
private:
// There are three cases:
@ -221,7 +221,7 @@ class Label {
// binding on the chain to point directly to the final value,
// adjusting addends as appropriate.
Binding *base_;
u_int64_t addend_;
uint64_t addend_;
// The number of Labels and Bindings pointing to this binding.
// (When a binding points to itself, indicating a completely
@ -233,7 +233,7 @@ class Label {
Binding *value_;
};
inline Label operator+(u_int64_t a, const Label &l) { return l + a; }
inline Label operator+(uint64_t a, const Label &l) { return l + a; }
// Note that int-Label isn't defined, as negating a Label is not an
// operation we support.
@ -288,7 +288,7 @@ class Section {
// Append the SIZE bytes at DATA or the contents of STRING to the
// end of this section. Return a reference to this section.
Section &Append(const u_int8_t *data, size_t size) {
Section &Append(const uint8_t *data, size_t size) {
contents_.append(reinterpret_cast<const char *>(data), size);
return *this;
};
@ -299,7 +299,7 @@ class Section {
// Append SIZE copies of BYTE to the end of this section. Return a
// reference to this section.
Section &Append(size_t size, u_int8_t byte) {
Section &Append(size_t size, uint8_t byte) {
contents_.append(size, (char) byte);
return *this;
}
@ -307,7 +307,7 @@ class Section {
// Append NUMBER to this section. ENDIANNESS is the endianness to
// use to write the number. SIZE is the length of the number in
// bytes. Return a reference to this section.
Section &Append(Endianness endianness, size_t size, u_int64_t number);
Section &Append(Endianness endianness, size_t size, uint64_t number);
Section &Append(Endianness endianness, size_t size, const Label &label);
// Append SECTION to the end of this section. The labels SECTION
@ -352,12 +352,12 @@ class Section {
// the compiler will properly sign-extend a signed value before
// passing it to the function, at which point the function's
// behavior is the same either way.
Section &L8(u_int8_t value) { contents_ += value; return *this; }
Section &B8(u_int8_t value) { contents_ += value; return *this; }
Section &D8(u_int8_t value) { contents_ += value; return *this; }
Section &L16(u_int16_t), &L32(u_int32_t), &L64(u_int64_t),
&B16(u_int16_t), &B32(u_int32_t), &B64(u_int64_t),
&D16(u_int16_t), &D32(u_int32_t), &D64(u_int64_t);
Section &L8(uint8_t value) { contents_ += value; return *this; }
Section &B8(uint8_t value) { contents_ += value; return *this; }
Section &D8(uint8_t value) { contents_ += value; return *this; }
Section &L16(uint16_t), &L32(uint32_t), &L64(uint64_t),
&B16(uint16_t), &B32(uint32_t), &B64(uint64_t),
&D16(uint16_t), &D32(uint32_t), &D64(uint64_t);
Section &L8(const Label &label), &L16(const Label &label),
&L32(const Label &label), &L64(const Label &label),
&B8(const Label &label), &B16(const Label &label),
@ -399,13 +399,13 @@ class Section {
//
// Note that VALUE cannot be a Label (we would have to implement
// relaxation).
Section &ULEB128(u_int64_t value);
Section &ULEB128(uint64_t value);
// Jump to the next location aligned on an ALIGNMENT-byte boundary,
// relative to the start of the section. Fill the gap with PAD_BYTE.
// ALIGNMENT must be a power of two. Return a reference to this
// section.
Section &Align(size_t alignment, u_int8_t pad_byte = 0);
Section &Align(size_t alignment, uint8_t pad_byte = 0);
// Clear the contents of this section.
void Clear();

View file

@ -60,7 +60,7 @@ TEST(ConstructLabelDeathTest, Undefined) {
TEST(ConstructLabel, Constant) {
Label l(0x060b9f974eaf301eULL);
u_int64_t v;
uint64_t v;
EXPECT_TRUE(l.IsKnownConstant(&v));
EXPECT_EQ(v, 0x060b9f974eaf301eULL);
EXPECT_EQ(l.Value(), 0x060b9f974eaf301eULL);
@ -69,7 +69,7 @@ TEST(ConstructLabel, Constant) {
TEST(ConstructLabel, Copy) {
Label l;
Label m(l);
u_int64_t v;
uint64_t v;
EXPECT_TRUE(l.IsKnownOffsetFrom(m, &v));
EXPECT_EQ(0U, v);
}
@ -82,7 +82,7 @@ TEST(Assignment, UnconstrainedToUnconstrained) {
l = m;
EXPECT_EQ(0U, l-m);
EXPECT_TRUE(l.IsKnownOffsetFrom(m));
u_int64_t d;
uint64_t d;
EXPECT_TRUE(l.IsKnownOffsetFrom(m, &d));
EXPECT_EQ(0U, d);
EXPECT_FALSE(l.IsKnownConstant());
@ -94,7 +94,7 @@ TEST(Assignment, UnconstrainedToRelated) {
l = m;
EXPECT_EQ(0U, l-m);
EXPECT_TRUE(l.IsKnownOffsetFrom(m));
u_int64_t d;
uint64_t d;
EXPECT_TRUE(l.IsKnownOffsetFrom(m, &d));
EXPECT_EQ(0U, d);
EXPECT_FALSE(l.IsKnownConstant());
@ -106,7 +106,7 @@ TEST(Assignment, UnconstrainedToKnown) {
l = m;
EXPECT_EQ(0U, l-m);
EXPECT_TRUE(l.IsKnownOffsetFrom(m));
u_int64_t d;
uint64_t d;
EXPECT_TRUE(l.IsKnownOffsetFrom(m, &d));
EXPECT_EQ(0U, d);
EXPECT_TRUE(m.IsKnownConstant());
@ -119,7 +119,7 @@ TEST(Assignment, RelatedToUnconstrained) {
l = m;
EXPECT_EQ(0U, l-n);
EXPECT_TRUE(l.IsKnownOffsetFrom(n));
u_int64_t d;
uint64_t d;
EXPECT_TRUE(l.IsKnownOffsetFrom(n, &d));
EXPECT_EQ(0U, d);
EXPECT_FALSE(l.IsKnownConstant());
@ -132,7 +132,7 @@ TEST(Assignment, RelatedToRelated) {
l = m;
EXPECT_EQ(0U, n-o);
EXPECT_TRUE(n.IsKnownOffsetFrom(o));
u_int64_t d;
uint64_t d;
EXPECT_TRUE(n.IsKnownOffsetFrom(o, &d));
EXPECT_EQ(0U, d);
EXPECT_FALSE(l.IsKnownConstant());
@ -234,7 +234,7 @@ TEST(Addition, LabelConstant) {
Label l, m;
m = l + 0x5248d93e8bbe9497ULL;
EXPECT_TRUE(m.IsKnownOffsetFrom(l));
u_int64_t d;
uint64_t d;
EXPECT_TRUE(m.IsKnownOffsetFrom(l, &d));
EXPECT_EQ(0x5248d93e8bbe9497ULL, d);
EXPECT_FALSE(m.IsKnownConstant());
@ -244,7 +244,7 @@ TEST(Addition, ConstantLabel) {
Label l, m;
m = 0xf51e94e00d6e3c84ULL + l;
EXPECT_TRUE(m.IsKnownOffsetFrom(l));
u_int64_t d;
uint64_t d;
EXPECT_TRUE(m.IsKnownOffsetFrom(l, &d));
EXPECT_EQ(0xf51e94e00d6e3c84ULL, d);
EXPECT_FALSE(m.IsKnownConstant());
@ -255,7 +255,7 @@ TEST(Addition, KnownLabelConstant) {
l = 0x16286307042ce0d8ULL;
m = l + 0x3fdddd91306719d7ULL;
EXPECT_TRUE(m.IsKnownOffsetFrom(l));
u_int64_t d;
uint64_t d;
EXPECT_TRUE(m.IsKnownOffsetFrom(l, &d));
EXPECT_EQ(0x3fdddd91306719d7ULL, d);
EXPECT_TRUE(m.IsKnownConstant());
@ -267,7 +267,7 @@ TEST(Addition, ConstantKnownLabel) {
l = 0x50f62d0cdd1031deULL;
m = 0x1b13462d8577c538ULL + l;
EXPECT_TRUE(m.IsKnownOffsetFrom(l));
u_int64_t d;
uint64_t d;
EXPECT_TRUE(m.IsKnownOffsetFrom(l, &d));
EXPECT_EQ(0x1b13462d8577c538ULL, d);
EXPECT_TRUE(m.IsKnownConstant());
@ -278,7 +278,7 @@ TEST(Subtraction, LabelConstant) {
Label l, m;
m = l - 0x0620884d21d3138eULL;
EXPECT_TRUE(m.IsKnownOffsetFrom(l));
u_int64_t d;
uint64_t d;
EXPECT_TRUE(m.IsKnownOffsetFrom(l, &d));
EXPECT_EQ(-0x0620884d21d3138eULL, d);
EXPECT_FALSE(m.IsKnownConstant());
@ -289,7 +289,7 @@ TEST(Subtraction, KnownLabelConstant) {
l = 0x6237fbaf9ef7929eULL;
m = l - 0x317730995d2ab6eeULL;
EXPECT_TRUE(m.IsKnownOffsetFrom(l));
u_int64_t d;
uint64_t d;
EXPECT_TRUE(m.IsKnownOffsetFrom(l, &d));
EXPECT_EQ(-0x317730995d2ab6eeULL, d);
EXPECT_TRUE(m.IsKnownConstant());
@ -475,10 +475,10 @@ TEST(LabelChain, AssignEndRelationBeforeForward) {
b = a + 0x1;
c = b + 0x10;
d = c + 0x100;
EXPECT_EQ(-(u_int64_t)0x111U, a-x);
EXPECT_EQ(-(u_int64_t)0x110U, b-x);
EXPECT_EQ(-(u_int64_t)0x100U, c-x);
EXPECT_EQ(-(u_int64_t)0U, d-x);
EXPECT_EQ(-(uint64_t)0x111U, a-x);
EXPECT_EQ(-(uint64_t)0x110U, b-x);
EXPECT_EQ(-(uint64_t)0x100U, c-x);
EXPECT_EQ(-(uint64_t)0U, d-x);
}
TEST(LabelChain, AssignEndRelationBeforeBackward) {
@ -488,10 +488,10 @@ TEST(LabelChain, AssignEndRelationBeforeBackward) {
d = c + 0x100;
c = b + 0x10;
b = a + 0x1;
EXPECT_EQ(-(u_int64_t)0x111U, a-x);
EXPECT_EQ(-(u_int64_t)0x110U, b-x);
EXPECT_EQ(-(u_int64_t)0x100U, c-x);
EXPECT_EQ(-(u_int64_t)0U, d-x);
EXPECT_EQ(-(uint64_t)0x111U, a-x);
EXPECT_EQ(-(uint64_t)0x110U, b-x);
EXPECT_EQ(-(uint64_t)0x100U, c-x);
EXPECT_EQ(-(uint64_t)0U, d-x);
}
TEST(LabelChain, AssignEndRelationAfterForward) {
@ -501,10 +501,10 @@ TEST(LabelChain, AssignEndRelationAfterForward) {
c = b + 0x10;
d = c + 0x100;
x = d;
EXPECT_EQ(-(u_int64_t)0x111U, a-x);
EXPECT_EQ(-(u_int64_t)0x110U, b-x);
EXPECT_EQ(-(u_int64_t)0x100U, c-x);
EXPECT_EQ(-(u_int64_t)0x000U, d-x);
EXPECT_EQ(-(uint64_t)0x111U, a-x);
EXPECT_EQ(-(uint64_t)0x110U, b-x);
EXPECT_EQ(-(uint64_t)0x100U, c-x);
EXPECT_EQ(-(uint64_t)0x000U, d-x);
}
TEST(LabelChain, AssignEndRelationAfterBackward) {
@ -514,10 +514,10 @@ TEST(LabelChain, AssignEndRelationAfterBackward) {
c = b + 0x10;
b = a + 0x1;
x = d;
EXPECT_EQ(-(u_int64_t)0x111U, a-x);
EXPECT_EQ(-(u_int64_t)0x110U, b-x);
EXPECT_EQ(-(u_int64_t)0x100U, c-x);
EXPECT_EQ(-(u_int64_t)0x000U, d-x);
EXPECT_EQ(-(uint64_t)0x111U, a-x);
EXPECT_EQ(-(uint64_t)0x110U, b-x);
EXPECT_EQ(-(uint64_t)0x100U, c-x);
EXPECT_EQ(-(uint64_t)0x000U, d-x);
}
TEST(LabelChain, AssignEndValueBeforeForward) {
@ -623,10 +623,10 @@ TEST(LabelChain, ConstructEndRelationAfterForward) {
Label c(b + 0x10);
Label d(c + 0x100);
x = d;
EXPECT_EQ(-(u_int64_t)0x111U, a-x);
EXPECT_EQ(-(u_int64_t)0x110U, b-x);
EXPECT_EQ(-(u_int64_t)0x100U, c-x);
EXPECT_EQ(-(u_int64_t)0x000U, d-x);
EXPECT_EQ(-(uint64_t)0x111U, a-x);
EXPECT_EQ(-(uint64_t)0x110U, b-x);
EXPECT_EQ(-(uint64_t)0x100U, c-x);
EXPECT_EQ(-(uint64_t)0x000U, d-x);
}
TEST(LabelChain, ConstructEndValueAfterForward) {
@ -732,11 +732,11 @@ class SectionFixture {
public:
Section section;
string contents;
static const u_int8_t data[];
static const uint8_t data[];
static const size_t data_size;
};
const u_int8_t SectionFixture::data[] = {
const uint8_t SectionFixture::data[] = {
0x87, 0x4f, 0x43, 0x67, 0x30, 0xd0, 0xd4, 0x0e
};
@ -753,7 +753,7 @@ const u_int8_t SectionFixture::data[] = {
#define ASSERT_BYTES(s, b) \
do \
{ \
static const u_int8_t expected_bytes[] = b; \
static const uint8_t expected_bytes[] = b; \
ASSERT_EQ(sizeof(expected_bytes), s.size()); \
ASSERT_TRUE(memcmp(s.data(), (const char *) expected_bytes, \
sizeof(expected_bytes)) == 0); \
@ -1361,7 +1361,7 @@ TEST_F(Append, Variety) {
ASSERT_EQ(8 * 18U, section.Size());
ASSERT_TRUE(section.GetContents(&contents));
static const u_int8_t expected[] = {
static const uint8_t expected[] = {
0x35, 0xa6, 0x6b, 0x28, 0xf7, 0xa8, 0x99, 0xa1, 0x61,
0x8b, 0x39, 0x44, 0x8f, 0x44, 0x40, 0x65, 0xa5, 0x0e,
0xc9, 0x1c, 0x5e, 0x87, 0xbf, 0xa4, 0x28, 0xb9, 0xf4,