Skip to content

Commit f8e7a73

Browse files
aheejinarichardson
authored andcommitted
[WebAssembly] Make tag attribute's encoding uint8
This changes the encoding of the `attribute` field, which currently only contains the value `0` denoting this tag is for an exception, from `varuint32` to `uint8`. This field is effectively unused at the moment and reserved for future use, and it is not likely to need `varuint32` even in future. See WebAssembly/exception-handling#162. This does not change any encoded binaries because `0` is encoded in the same way both in `varuint32` and `uint8`. Reviewed By: tlively Differential Revision: https://reviews.llvm.org/D104571
2 parents 1cf16fc + 1c7b841 commit f8e7a73

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

llvm/include/llvm/BinaryFormat/Wasm.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ struct WasmGlobal {
103103

104104
struct WasmTagType {
105105
// Kind of tag. Currently only WASM_TAG_ATTRIBUTE_EXCEPTION is possible.
106-
uint32_t Attribute;
106+
uint8_t Attribute;
107107
uint32_t SigIndex;
108108
};
109109

@@ -363,7 +363,7 @@ enum WasmSegmentFlag : unsigned {
363363
};
364364

365365
// Kinds of tag attributes.
366-
enum WasmTagAttribute : unsigned {
366+
enum WasmTagAttribute : uint8_t {
367367
WASM_TAG_ATTRIBUTE_EXCEPTION = 0x0,
368368
};
369369

llvm/lib/MC/WasmObjectWriter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ void WasmObjectWriter::writeImportSection(ArrayRef<wasm::WasmImport> Imports,
814814
encodeULEB128(NumElements, W->OS); // initial
815815
break;
816816
case wasm::WASM_EXTERNAL_TAG:
817-
encodeULEB128(Import.Tag.Attribute, W->OS);
817+
W->OS << char(Import.Tag.Attribute);
818818
encodeULEB128(Import.Tag.SigIndex, W->OS);
819819
break;
820820
default:
@@ -848,7 +848,7 @@ void WasmObjectWriter::writeTagSection(ArrayRef<wasm::WasmTagType> Tags) {
848848

849849
encodeULEB128(Tags.size(), W->OS);
850850
for (const wasm::WasmTagType &Tag : Tags) {
851-
encodeULEB128(Tag.Attribute, W->OS);
851+
W->OS << char(Tag.Attribute);
852852
encodeULEB128(Tag.SigIndex, W->OS);
853853
}
854854

llvm/lib/Object/WasmObjectFile.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ Error WasmObjectFile::parseImportSection(ReadContext &Ctx) {
10661066
}
10671067
case wasm::WASM_EXTERNAL_TAG:
10681068
NumImportedTags++;
1069-
Im.Tag.Attribute = readVarint32(Ctx);
1069+
Im.Tag.Attribute = readUint8(Ctx);
10701070
Im.Tag.SigIndex = readVarint32(Ctx);
10711071
break;
10721072
default:
@@ -1143,7 +1143,7 @@ Error WasmObjectFile::parseTagSection(ReadContext &Ctx) {
11431143
while (Count--) {
11441144
wasm::WasmTag Tag;
11451145
Tag.Index = NumImportedTags + Tags.size();
1146-
Tag.Type.Attribute = readVaruint32(Ctx);
1146+
Tag.Type.Attribute = readUint8(Ctx);
11471147
Tag.Type.SigIndex = readVaruint32(Ctx);
11481148
Tags.push_back(Tag);
11491149
}

0 commit comments

Comments
 (0)