[lld] r326455 - [WebAssembly] Use uint8_t for single byte values to match the spec

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 1 10:06:39 PST 2018


Author: sbc
Date: Thu Mar  1 10:06:39 2018
New Revision: 326455

URL: http://llvm.org/viewvc/llvm-project?rev=326455&view=rev
Log:
[WebAssembly] Use uint8_t for single byte values to match the spec

Differential Revision: https://reviews.llvm.org/D43922

Modified:
    lld/trunk/wasm/Writer.cpp
    lld/trunk/wasm/WriterUtils.cpp
    lld/trunk/wasm/WriterUtils.h

Modified: lld/trunk/wasm/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Writer.cpp?rev=326455&r1=326454&r2=326455&view=diff
==============================================================================
--- lld/trunk/wasm/Writer.cpp (original)
+++ lld/trunk/wasm/Writer.cpp Thu Mar  1 10:06:39 2018
@@ -261,7 +261,7 @@ void Writer::createTableSection() {
   raw_ostream &OS = Section->getStream();
 
   writeUleb128(OS, 1, "table count");
-  writeSleb128(OS, WASM_TYPE_ANYFUNC, "table type");
+  writeU8(OS, WASM_TYPE_ANYFUNC, "table type");
   writeUleb128(OS, WASM_LIMITS_FLAG_HAS_MAX, "table flags");
   writeUleb128(OS, TableSize, "table initial size");
   writeUleb128(OS, TableSize, "table max size");
@@ -427,7 +427,7 @@ void Writer::createLinkingSection() {
       WasmSymbolType Kind = Sym->getWasmType();
       uint32_t Flags = getWasmFlags(Sym);
 
-      writeUleb128(Sub.OS, Kind, "sym kind");
+      writeU8(Sub.OS, Kind, "sym kind");
       writeUleb128(Sub.OS, Flags, "sym flags");
 
       switch (Kind) {
@@ -503,7 +503,7 @@ void Writer::createLinkingSection() {
       writeUleb128(Sub.OS, 0, "comdat flags"); // flags for future use
       writeUleb128(Sub.OS, C.second.size(), "num entries");
       for (const ComdatEntry &Entry : C.second) {
-        writeUleb128(Sub.OS, Entry.Kind, "entry kind");
+        writeU8(Sub.OS, Entry.Kind, "entry kind");
         writeUleb128(Sub.OS, Entry.Index, "entry index");
       }
     }

Modified: lld/trunk/wasm/WriterUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/WriterUtils.cpp?rev=326455&r1=326454&r2=326455&view=diff
==============================================================================
--- lld/trunk/wasm/WriterUtils.cpp (original)
+++ lld/trunk/wasm/WriterUtils.cpp Thu Mar  1 10:06:39 2018
@@ -19,7 +19,7 @@ using namespace llvm;
 using namespace llvm::wasm;
 using namespace lld::wasm;
 
-static const char *valueTypeToString(int32_t Type) {
+static const char *valueTypeToString(uint8_t Type) {
   switch (Type) {
   case WASM_TYPE_I32:
     return "i32";
@@ -73,15 +73,14 @@ void wasm::writeU32(raw_ostream &OS, uin
   support::endian::Writer<support::little>(OS).write(Number);
 }
 
-void wasm::writeValueType(raw_ostream &OS, int32_t Type, const Twine &Msg) {
-  debugWrite(OS.tell(), Msg + "[type: " + valueTypeToString(Type) + "]");
-  encodeSLEB128(Type, OS);
+void wasm::writeValueType(raw_ostream &OS, uint8_t Type, const Twine &Msg) {
+  writeU8(OS, Type, Msg + "[type: " + valueTypeToString(Type) + "]");
 }
 
 void wasm::writeSig(raw_ostream &OS, const WasmSignature &Sig) {
-  writeSleb128(OS, WASM_TYPE_FUNC, "signature type");
+  writeU8(OS, WASM_TYPE_FUNC, "signature type");
   writeUleb128(OS, Sig.ParamTypes.size(), "param Count");
-  for (int32_t ParamType : Sig.ParamTypes) {
+  for (uint8_t ParamType : Sig.ParamTypes) {
     writeValueType(OS, ParamType, "param type");
   }
   if (Sig.ReturnType == WASM_TYPE_NORESULT) {
@@ -111,7 +110,7 @@ void wasm::writeInitExpr(raw_ostream &OS
 }
 
 void wasm::writeLimits(raw_ostream &OS, const WasmLimits &Limits) {
-  writeUleb128(OS, Limits.Flags, "limits flags");
+  writeU8(OS, Limits.Flags, "limits flags");
   writeUleb128(OS, Limits.Initial, "limits initial");
   if (Limits.Flags & WASM_LIMITS_FLAG_HAS_MAX)
     writeUleb128(OS, Limits.Maximum, "limits max");
@@ -119,7 +118,7 @@ void wasm::writeLimits(raw_ostream &OS,
 
 void wasm::writeGlobalType(raw_ostream &OS, const WasmGlobalType &Type) {
   writeValueType(OS, Type.Type, "global type");
-  writeUleb128(OS, Type.Mutable, "global mutable");
+  writeU8(OS, Type.Mutable, "global mutable");
 }
 
 void wasm::writeGlobal(raw_ostream &OS, const WasmGlobal &Global) {

Modified: lld/trunk/wasm/WriterUtils.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/WriterUtils.h?rev=326455&r1=326454&r2=326455&view=diff
==============================================================================
--- lld/trunk/wasm/WriterUtils.h (original)
+++ lld/trunk/wasm/WriterUtils.h Thu Mar  1 10:06:39 2018
@@ -57,7 +57,7 @@ void writeU8(raw_ostream &OS, uint8_t by
 
 void writeU32(raw_ostream &OS, uint32_t Number, const Twine &Msg);
 
-void writeValueType(raw_ostream &OS, int32_t Type, const Twine &Msg);
+void writeValueType(raw_ostream &OS, uint8_t Type, const Twine &Msg);
 
 void writeSig(raw_ostream &OS, const llvm::wasm::WasmSignature &Sig);
 




More information about the llvm-commits mailing list