summaryrefslogtreecommitdiffstats
path: root/llvm/lib
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
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')
-rw-r--r--llvm/lib/MC/WasmObjectWriter.cpp18
-rw-r--r--llvm/lib/Object/WasmObjectFile.cpp34
-rw-r--r--llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp2
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp6
4 files changed, 24 insertions, 36 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());
}
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp
index f32f57b8ba1..b47d6bb2abb 100644
--- a/llvm/lib/Object/WasmObjectFile.cpp
+++ b/llvm/lib/Object/WasmObjectFile.cpp
@@ -99,18 +99,6 @@ static uint8_t readVaruint1(const uint8_t *&Ptr) {
return result;
}
-static int8_t readVarint7(const uint8_t *&Ptr) {
- int64_t result = readLEB128(Ptr);
- assert(result <= VARINT7_MAX && result >= VARINT7_MIN);
- return result;
-}
-
-static uint8_t readVaruint7(const uint8_t *&Ptr) {
- uint64_t result = readULEB128(Ptr);
- assert(result <= VARUINT7_MAX);
- return result;
-}
-
static int32_t readVarint32(const uint8_t *&Ptr) {
int64_t result = readLEB128(Ptr);
assert(result <= INT32_MAX && result >= INT32_MIN);
@@ -174,7 +162,7 @@ static wasm::WasmLimits readLimits(const uint8_t *&Ptr) {
static wasm::WasmTable readTable(const uint8_t *&Ptr) {
wasm::WasmTable Table;
- Table.ElemType = readVarint7(Ptr);
+ Table.ElemType = readUint8(Ptr);
Table.Limits = readLimits(Ptr);
return Table;
}
@@ -182,7 +170,7 @@ static wasm::WasmTable readTable(const uint8_t *&Ptr) {
static Error readSection(WasmSection &Section, const uint8_t *&Ptr,
const uint8_t *Start, const uint8_t *Eof) {
Section.Offset = Ptr - Start;
- Section.Type = readVaruint7(Ptr);
+ Section.Type = readUint8(Ptr);
uint32_t Size = readVaruint32(Ptr);
if (Size == 0)
return make_error<StringError>("Zero length section",
@@ -274,7 +262,7 @@ Error WasmObjectFile::parseNameSection(const uint8_t *Ptr, const uint8_t *End) {
}
while (Ptr < End) {
- uint8_t Type = readVarint7(Ptr);
+ uint8_t Type = readUint8(Ptr);
uint32_t Size = readVaruint32(Ptr);
const uint8_t *SubSectionEnd = Ptr + Size;
switch (Type) {
@@ -324,7 +312,7 @@ Error WasmObjectFile::parseLinkingSection(const uint8_t *Ptr,
}
while (Ptr < End) {
- uint8_t Type = readVarint7(Ptr);
+ uint8_t Type = readUint8(Ptr);
uint32_t Size = readVaruint32(Ptr);
const uint8_t *SubSectionEnd = Ptr + Size;
switch (Type) {
@@ -548,7 +536,7 @@ WasmSection* WasmObjectFile::findSectionByType(uint32_t Type) {
Error WasmObjectFile::parseRelocSection(StringRef Name, const uint8_t *Ptr,
const uint8_t *End) {
- uint8_t SectionCode = readVarint7(Ptr);
+ uint8_t SectionCode = readUint8(Ptr);
WasmSection* Section = nullptr;
if (SectionCode == wasm::WASM_SEC_CUSTOM) {
StringRef Name = readString(Ptr);
@@ -613,7 +601,7 @@ Error WasmObjectFile::parseTypeSection(const uint8_t *Ptr, const uint8_t *End) {
while (Count--) {
wasm::WasmSignature Sig;
Sig.ReturnType = wasm::WASM_TYPE_NORESULT;
- int8_t Form = readVarint7(Ptr);
+ uint8_t Form = readUint8(Ptr);
if (Form != wasm::WASM_TYPE_FUNC) {
return make_error<GenericBinaryError>("Invalid signature type",
object_error::parse_failed);
@@ -621,7 +609,7 @@ Error WasmObjectFile::parseTypeSection(const uint8_t *Ptr, const uint8_t *End) {
uint32_t ParamCount = readVaruint32(Ptr);
Sig.ParamTypes.reserve(ParamCount);
while (ParamCount--) {
- uint32_t ParamType = readVarint7(Ptr);
+ uint32_t ParamType = readUint8(Ptr);
Sig.ParamTypes.push_back(ParamType);
}
uint32_t ReturnCount = readVaruint32(Ptr);
@@ -630,7 +618,7 @@ Error WasmObjectFile::parseTypeSection(const uint8_t *Ptr, const uint8_t *End) {
return make_error<GenericBinaryError>(
"Multiple return types not supported", object_error::parse_failed);
}
- Sig.ReturnType = readVarint7(Ptr);
+ Sig.ReturnType = readUint8(Ptr);
}
Signatures.push_back(Sig);
}
@@ -655,7 +643,7 @@ Error WasmObjectFile::parseImportSection(const uint8_t *Ptr, const uint8_t *End)
break;
case wasm::WASM_EXTERNAL_GLOBAL:
NumImportedGlobals++;
- Im.Global.Type = readVarint7(Ptr);
+ Im.Global.Type = readUint8(Ptr);
Im.Global.Mutable = readVaruint1(Ptr);
break;
case wasm::WASM_EXTERNAL_MEMORY:
@@ -726,7 +714,7 @@ Error WasmObjectFile::parseGlobalSection(const uint8_t *Ptr, const uint8_t *End)
while (Count--) {
wasm::WasmGlobal Global;
Global.Index = NumImportedGlobals + Globals.size();
- Global.Type.Type = readVarint7(Ptr);
+ Global.Type.Type = readUint8(Ptr);
Global.Type.Mutable = readVaruint1(Ptr);
if (Error Err = readInitExpr(Global.InitExpr, Ptr))
return Err;
@@ -834,7 +822,7 @@ Error WasmObjectFile::parseCodeSection(const uint8_t *Ptr, const uint8_t *End) {
while (NumLocalDecls--) {
wasm::WasmLocalDecl Decl;
Decl.Count = readVaruint32(Ptr);
- Decl.Type = readVarint7(Ptr);
+ Decl.Type = readUint8(Ptr);
Function.Locals.push_back(Decl);
}
diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp
index 9d4f308ca3c..cab14e9b47b 100644
--- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp
+++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp
@@ -31,7 +31,7 @@ WebAssemblyTargetStreamer::WebAssemblyTargetStreamer(MCStreamer &S)
: MCTargetStreamer(S) {}
void WebAssemblyTargetStreamer::emitValueType(wasm::ValType Type) {
- Streamer.EmitSLEB128IntValue(int32_t(Type));
+ Streamer.EmitIntValue(uint8_t(Type), 1);
}
WebAssemblyTargetAsmStreamer::WebAssemblyTargetAsmStreamer(
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
index c8afa39e6e9..ac2258abc24 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
@@ -95,10 +95,10 @@ MCSymbol *WebAssemblyMCInstLower::GetExternalSymbolSymbol(
// here; this method is precisely there for fetching the signatures of known
// Clang-provided symbols.
if (strcmp(Name, "__stack_pointer") == 0) {
- wasm::ValType iPTR =
- Subtarget.hasAddr64() ? wasm::ValType::I64 : wasm::ValType::I32;
WasmSym->setType(wasm::WASM_SYMBOL_TYPE_GLOBAL);
- WasmSym->setGlobalType(wasm::WasmGlobalType{int32_t(iPTR), true});
+ WasmSym->setGlobalType(wasm::WasmGlobalType{
+ Subtarget.hasAddr64() ? wasm::WASM_TYPE_I64 : wasm::WASM_TYPE_I32,
+ true});
return WasmSym;
}
OpenPOWER on IntegriCloud