[lld] r194305 - [mach-o] Use LEB128 stuff from llvm/Support. No functionality change.
Nick Kledzik
kledzik at apple.com
Fri Nov 8 17:00:51 PST 2013
Author: kledzik
Date: Fri Nov 8 19:00:51 2013
New Revision: 194305
URL: http://llvm.org/viewvc/llvm-project?rev=194305&view=rev
Log:
[mach-o] Use LEB128 stuff from llvm/Support. No functionality change.
Modified:
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp?rev=194305&r1=194304&r2=194305&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp Fri Nov 8 19:00:51 2013
@@ -35,6 +35,7 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileOutputBuffer.h"
#include "llvm/Support/Host.h"
+#include "llvm/Support/LEB128.h"
#include "llvm/Support/MachO.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
@@ -111,18 +112,37 @@ private:
class ByteBuffer {
public:
- ByteBuffer();
- void append_byte(uint8_t);
- void append_uleb128(uint64_t);
- void append_sleb128(int64_t);
- void append_string(StringRef);
- void align(unsigned);
- size_t size();
- const uint8_t *bytes();
+ ByteBuffer() : _ostream(_bytes) { }
+ void append_byte(uint8_t b) {
+ _ostream << b;
+ }
+ void append_uleb128(uint64_t value) {
+ llvm::encodeULEB128(value, _ostream);
+ }
+ void append_sleb128(int64_t value) {
+ llvm::encodeSLEB128(value, _ostream);
+ }
+ void append_string(StringRef str) {
+ _ostream << str;
+ append_byte(0);
+ }
+ void align(unsigned alignment) {
+ while ( (_ostream.tell() % alignment) != 0 )
+ append_byte(0);
+ }
+ size_t size() {
+ return _ostream.tell();
+ }
+ const uint8_t *bytes() {
+ return reinterpret_cast<const uint8_t*>(_ostream.str().data());
+ }
private:
- std::vector<uint8_t> _bytes;
+ SmallVector<char, 128> _bytes;
+ // Stream ivar must be after SmallVector ivar to construct properly.
+ llvm::raw_svector_ostream _ostream;
};
+
struct SegExtraInfo {
uint32_t fileOffset;
std::vector<const Section*> sections;
@@ -190,64 +210,6 @@ uint32_t MachOFileLayout::pointerAlign(u
}
-MachOFileLayout::ByteBuffer::ByteBuffer() {
- _bytes.reserve(256);
-}
-
-void MachOFileLayout::ByteBuffer::append_byte(uint8_t b) {
- _bytes.push_back(b);
-}
-
-
-void MachOFileLayout::ByteBuffer::append_uleb128(uint64_t value) {
- uint8_t byte;
- do {
- byte = value & 0x7F;
- value &= ~0x7F;
- if ( value != 0 )
- byte |= 0x80;
- _bytes.push_back(byte);
- value = value >> 7;
- } while( byte >= 0x80 );
-}
-
-void MachOFileLayout::ByteBuffer::append_sleb128(int64_t value) {
- bool isNeg = ( value < 0 );
- uint8_t byte;
- bool more;
- do {
- byte = value & 0x7F;
- value = value >> 7;
- if ( isNeg )
- more = ( (value != -1) || ((byte & 0x40) == 0) );
- else
- more = ( (value != 0) || ((byte & 0x40) != 0) );
- if ( more )
- byte |= 0x80;
- _bytes.push_back(byte);
- }
- while( more );
-}
-
-void MachOFileLayout::ByteBuffer::append_string(StringRef str) {
- _bytes.insert(_bytes.end(), str.begin(), str.end());
- _bytes.push_back('\0');
-}
-
-void MachOFileLayout::ByteBuffer::align(unsigned alignment) {
- while ( (_bytes.size() % alignment) != 0 )
- _bytes.push_back(0);
-}
-
-const uint8_t *MachOFileLayout::ByteBuffer::bytes() {
- return &_bytes[0];
-}
-
-size_t MachOFileLayout::ByteBuffer::size() {
- return _bytes.size();
-}
-
-
MachOFileLayout::MachOFileLayout(const NormalizedFile &file)
More information about the llvm-commits
mailing list