summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC/WasmObjectWriter.cpp
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2018-03-01 18:06:21 +0000
committerSam Clegg <sbc@chromium.org>2018-03-01 18:06:21 +0000
commit03e101f1b00d463d3a070a43a7ac8f13db291c37 (patch)
tree000e836f3e42c60f9803b35cc41f798471314bf3 /llvm/lib/MC/WasmObjectWriter.cpp
parentc6a75a69f15e42dd4c6b1a79f6d1a4e3df9f75ea (diff)
downloadbcm5719-llvm-03e101f1b00d463d3a070a43a7ac8f13db291c37.tar.gz
bcm5719-llvm-03e101f1b00d463d3a070a43a7ac8f13db291c37.zip
[WebAssembly] Use uint8_t for single byte values to match the spec
The original BinaryEncoding.md document used to specify that these values were `varint7`, but the official spec lists them explicitly as single byte values and not LEB. A similar change for wabt is in flight: https://github.com/WebAssembly/wabt/pull/782 Differential Revision: https://reviews.llvm.org/D43921 llvm-svn: 326454
Diffstat (limited to 'llvm/lib/MC/WasmObjectWriter.cpp')
-rw-r--r--llvm/lib/MC/WasmObjectWriter.cpp18
1 files changed, 9 insertions, 9 deletions
diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp
index 93bab05b538..3c86ca47e48 100644
--- a/llvm/lib/MC/WasmObjectWriter.cpp
+++ b/llvm/lib/MC/WasmObjectWriter.cpp
@@ -258,7 +258,7 @@ private:
}
void writeValueType(wasm::ValType Ty) {
- encodeSLEB128(int32_t(Ty), getStream());
+ write8(static_cast<uint8_t>(Ty));
}
void writeTypeSection(ArrayRef<WasmFunctionType> FunctionTypes);
@@ -300,7 +300,7 @@ void WasmObjectWriter::startSection(SectionBookkeeping &Section,
"Only custom sections can have names");
DEBUG(dbgs() << "startSection " << SectionId << ": " << Name << "\n");
- encodeULEB128(SectionId, getStream());
+ write8(SectionId);
Section.SizeOffset = getStream().tell();
@@ -625,7 +625,7 @@ void WasmObjectWriter::writeRelocations(
RelEntry.FixupSection->getSectionOffset();
uint32_t Index = getRelocationIndexValue(RelEntry);
- encodeULEB128(RelEntry.Type, Stream);
+ write8(RelEntry.Type);
encodeULEB128(Offset, Stream);
encodeULEB128(Index, Stream);
if (RelEntry.hasAddend())
@@ -644,7 +644,7 @@ void WasmObjectWriter::writeTypeSection(
encodeULEB128(FunctionTypes.size(), getStream());
for (const WasmFunctionType &FuncTy : FunctionTypes) {
- encodeSLEB128(wasm::WASM_TYPE_FUNC, getStream());
+ write8(wasm::WASM_TYPE_FUNC);
encodeULEB128(FuncTy.Params.size(), getStream());
for (wasm::ValType Ty : FuncTy.Params)
writeValueType(Ty);
@@ -671,22 +671,22 @@ void WasmObjectWriter::writeImportSection(ArrayRef<wasm::WasmImport> Imports,
for (const wasm::WasmImport &Import : Imports) {
writeString(Import.Module);
writeString(Import.Field);
- encodeULEB128(Import.Kind, getStream());
+ write8(Import.Kind);
switch (Import.Kind) {
case wasm::WASM_EXTERNAL_FUNCTION:
encodeULEB128(Import.SigIndex, getStream());
break;
case wasm::WASM_EXTERNAL_GLOBAL:
- encodeSLEB128(Import.Global.Type, getStream());
- encodeULEB128(uint32_t(Import.Global.Mutable), getStream());
+ write8(Import.Global.Type);
+ write8(Import.Global.Mutable ? 1 : 0);
break;
case wasm::WASM_EXTERNAL_MEMORY:
encodeULEB128(0, getStream()); // flags
encodeULEB128(NumPages, getStream()); // initial
break;
case wasm::WASM_EXTERNAL_TABLE:
- encodeSLEB128(Import.Table.ElemType, getStream());
+ write8(Import.Table.ElemType);
encodeULEB128(0, getStream()); // flags
encodeULEB128(NumElements, getStream()); // initial
break;
@@ -742,7 +742,7 @@ void WasmObjectWriter::writeExportSection(ArrayRef<wasm::WasmExport> Exports) {
encodeULEB128(Exports.size(), getStream());
for (const wasm::WasmExport &Export : Exports) {
writeString(Export.Name);
- encodeSLEB128(Export.Kind, getStream());
+ write8(Export.Kind);
encodeULEB128(Export.Index, getStream());
}
OpenPOWER on IntegriCloud