[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
diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp
index 93bab05..3c86ca4 100644
--- a/llvm/lib/MC/WasmObjectWriter.cpp
+++ b/llvm/lib/MC/WasmObjectWriter.cpp
@@ -258,7 +258,7 @@
}
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 @@
"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 @@
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 @@
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 @@
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 @@
encodeULEB128(Exports.size(), getStream());
for (const wasm::WasmExport &Export : Exports) {
writeString(Export.Name);
- encodeSLEB128(Export.Kind, getStream());
+ write8(Export.Kind);
encodeULEB128(Export.Index, getStream());
}