summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC/WasmObjectWriter.cpp
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2019-01-30 22:47:35 +0000
committerSam Clegg <sbc@chromium.org>2019-01-30 22:47:35 +0000
commit19e8befabbf9a12b100a7e71dada5bf06d5a33a8 (patch)
tree50cac98f70997a0f4bf5639779eb6ba9add34f52 /llvm/lib/MC/WasmObjectWriter.cpp
parent0bb9865011731066ddc394f98942fbf959a4039b (diff)
downloadbcm5719-llvm-19e8befabbf9a12b100a7e71dada5bf06d5a33a8.tar.gz
bcm5719-llvm-19e8befabbf9a12b100a7e71dada5bf06d5a33a8.zip
[WebAssembly] MC: Use WritePatchableLEB helper function. NFC.
Subscribers: dschuff, jgravelle-google, aheejin, sunfish, llvm-commits Differential Revision: https://reviews.llvm.org/D57477 llvm-svn: 352683
Diffstat (limited to 'llvm/lib/MC/WasmObjectWriter.cpp')
-rw-r--r--llvm/lib/MC/WasmObjectWriter.cpp63
1 files changed, 30 insertions, 33 deletions
diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp
index c9601a8baef..d0ffe7c4a40 100644
--- a/llvm/lib/MC/WasmObjectWriter.cpp
+++ b/llvm/lib/MC/WasmObjectWriter.cpp
@@ -194,6 +194,33 @@ raw_ostream &operator<<(raw_ostream &OS, const WasmRelocationEntry &Rel) {
}
#endif
+// Write X as an (unsigned) LEB value at offset Offset in Stream, padded
+// to allow patching.
+static void WritePatchableLEB(raw_pwrite_stream &Stream, uint32_t X,
+ uint64_t Offset) {
+ uint8_t Buffer[5];
+ unsigned SizeLen = encodeULEB128(X, Buffer, 5);
+ assert(SizeLen == 5);
+ Stream.pwrite((char *)Buffer, SizeLen, Offset);
+}
+
+// Write X as an signed LEB value at offset Offset in Stream, padded
+// to allow patching.
+static void WritePatchableSLEB(raw_pwrite_stream &Stream, int32_t X,
+ uint64_t Offset) {
+ uint8_t Buffer[5];
+ unsigned SizeLen = encodeSLEB128(X, Buffer, 5);
+ assert(SizeLen == 5);
+ Stream.pwrite((char *)Buffer, SizeLen, Offset);
+}
+
+// Write X as a plain integer value at offset Offset in Stream.
+static void WriteI32(raw_pwrite_stream &Stream, uint32_t X, uint64_t Offset) {
+ uint8_t Buffer[4];
+ support::endian::write32le(Buffer, X);
+ Stream.pwrite((char *)Buffer, sizeof(Buffer), Offset);
+}
+
class WasmObjectWriter : public MCObjectWriter {
support::endian::Writer W;
@@ -345,7 +372,7 @@ void WasmObjectWriter::startSection(SectionBookkeeping &Section,
// The section size. We don't know the size yet, so reserve enough space
// for any 32-bit value; we'll patch it later.
- encodeULEB128(UINT32_MAX, W.OS);
+ encodeULEB128(0, W.OS, 5);
// The position where the section starts, for measuring its size.
Section.ContentsOffset = W.OS.tell();
@@ -379,11 +406,8 @@ void WasmObjectWriter::endSection(SectionBookkeeping &Section) {
// Write the final section size to the payload_len field, which follows
// the section id byte.
- uint8_t Buffer[16];
- unsigned SizeLen = encodeULEB128(Size, Buffer, 5);
- assert(SizeLen == 5);
- static_cast<raw_pwrite_stream &>(W.OS).pwrite((char *)Buffer, SizeLen,
- Section.SizeOffset);
+ WritePatchableLEB(static_cast<raw_pwrite_stream &>(W.OS), Size,
+ Section.SizeOffset);
}
// Emit the Wasm header.
@@ -532,33 +556,6 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm,
}
}
-// Write X as an (unsigned) LEB value at offset Offset in Stream, padded
-// to allow patching.
-static void WritePatchableLEB(raw_pwrite_stream &Stream, uint32_t X,
- uint64_t Offset) {
- uint8_t Buffer[5];
- unsigned SizeLen = encodeULEB128(X, Buffer, 5);
- assert(SizeLen == 5);
- Stream.pwrite((char *)Buffer, SizeLen, Offset);
-}
-
-// Write X as an signed LEB value at offset Offset in Stream, padded
-// to allow patching.
-static void WritePatchableSLEB(raw_pwrite_stream &Stream, int32_t X,
- uint64_t Offset) {
- uint8_t Buffer[5];
- unsigned SizeLen = encodeSLEB128(X, Buffer, 5);
- assert(SizeLen == 5);
- Stream.pwrite((char *)Buffer, SizeLen, Offset);
-}
-
-// Write X as a plain integer value at offset Offset in Stream.
-static void WriteI32(raw_pwrite_stream &Stream, uint32_t X, uint64_t Offset) {
- uint8_t Buffer[4];
- support::endian::write32le(Buffer, X);
- Stream.pwrite((char *)Buffer, sizeof(Buffer), Offset);
-}
-
static const MCSymbolWasm *ResolveSymbol(const MCSymbolWasm &Symbol) {
if (Symbol.isVariable()) {
const MCExpr *Expr = Symbol.getVariableValue();
OpenPOWER on IntegriCloud