Reformat per new coding guidelines.

Change-Id: Ib0e5d3a6fabe6db414d72b334ca7a7f33bc5726b
This commit is contained in:
Peter Johnson
2015-06-25 22:57:43 -07:00
parent f5a82be9e5
commit cee77a3228
26 changed files with 1296 additions and 1576 deletions

View File

@@ -9,7 +9,7 @@
#include "nt_raw_istream.h"
namespace NtImpl {
namespace ntimpl {
/**
* size_uleb128 - get size of unsigned LEB128 data
@@ -20,15 +20,13 @@ namespace NtImpl {
* on the encodings refer to section "7.6 - Variable Length Data". Return
* the number of bytes required.
*/
std::size_t
size_uleb128(unsigned long val)
{
std::size_t count = 0;
do {
val >>= 7;
++count;
} while (val != 0);
return count;
std::size_t size_uleb128(unsigned long val) {
std::size_t count = 0;
do {
val >>= 7;
++count;
} while (val != 0);
return count;
}
/**
@@ -41,24 +39,22 @@ size_uleb128(unsigned long val)
* encodings refer to section "7.6 - Variable Length Data". Return
* the number of bytes written.
*/
std::size_t
write_uleb128(char* addr, unsigned long val)
{
std::size_t count = 0;
std::size_t write_uleb128(char* addr, unsigned long val) {
std::size_t count = 0;
do {
unsigned char byte = val & 0x7f;
val >>= 7;
do {
unsigned char byte = val & 0x7f;
val >>= 7;
if (val != 0)
byte |= 0x80; // mark this byte to show that more bytes will follow
if (val != 0)
byte |= 0x80; // mark this byte to show that more bytes will follow
*((unsigned char *)addr) = byte;
addr++;
count++;
} while (val != 0);
*((unsigned char*)addr) = byte;
addr++;
count++;
} while (val != 0);
return count;
return count;
}
/**
@@ -71,29 +67,25 @@ write_uleb128(char* addr, unsigned long val)
* encodings refer to section "7.6 - Variable Length Data". Return
* the number of bytes read.
*/
std::size_t
read_uleb128(char* addr, unsigned long* ret)
{
unsigned long result = 0;
int shift = 0;
std::size_t count = 0;
std::size_t read_uleb128(char* addr, unsigned long* ret) {
unsigned long result = 0;
int shift = 0;
std::size_t count = 0;
while (1)
{
unsigned char byte = *((unsigned char *)addr);
addr++;
count++;
while (1) {
unsigned char byte = *((unsigned char*)addr);
addr++;
count++;
result |= (byte & 0x7f) << shift;
shift += 7;
result |= (byte & 0x7f) << shift;
shift += 7;
if (!(byte & 0x80))
break;
}
if (!(byte & 0x80)) break;
}
*ret = result;
*ret = result;
return count;
return count;
}
/**
@@ -106,28 +98,23 @@ read_uleb128(char* addr, unsigned long* ret)
* encodings refer to section "7.6 - Variable Length Data". Return
* false on stream error, true on success.
*/
bool
read_uleb128(raw_istream& is, unsigned long* ret)
{
unsigned long result = 0;
int shift = 0;
bool read_uleb128(raw_istream& is, unsigned long* ret) {
unsigned long result = 0;
int shift = 0;
while (1)
{
unsigned char byte;
if (!is.read((char*)&byte, 1))
return false;
while (1) {
unsigned char byte;
if (!is.read((char*)&byte, 1)) return false;
result |= (byte & 0x7f) << shift;
shift += 7;
result |= (byte & 0x7f) << shift;
shift += 7;
if (!(byte & 0x80))
break;
}
if (!(byte & 0x80)) break;
}
*ret = result;
*ret = result;
return true;
return true;
}
} // namespace NtImpl
} // namespace ntimpl