Index: llvm/trunk/lib/MC/WasmObjectWriter.cpp =================================================================== --- llvm/trunk/lib/MC/WasmObjectWriter.cpp +++ llvm/trunk/lib/MC/WasmObjectWriter.cpp @@ -343,7 +343,7 @@ // A wasm function to be written into the function section. struct WasmFunction { - unsigned Type; + int32_t Type; const MCSymbolWasm *Sym; }; @@ -356,7 +356,7 @@ // A wasm global to be written into the global section. struct WasmGlobal { - unsigned Type; + wasm::ValType Type; bool IsMutable; uint32_t InitialValue; }; @@ -510,10 +510,10 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) { MCContext &Ctx = Asm.getContext(); - unsigned PtrType = is64Bit() ? wasm::WASM_TYPE_I64 : wasm::WASM_TYPE_I32; + wasm::ValType PtrType = is64Bit() ? wasm::ValType::I64 : wasm::ValType::I32; // Collect information from the available symbols. - DenseMap + DenseMap FunctionTypeIndices; SmallVector FunctionTypes; SmallVector Functions; @@ -552,7 +552,7 @@ // Populate the Imports set. for (const MCSymbol &S : Asm.symbols()) { const auto &WS = static_cast(S); - unsigned Type; + int32_t Type; if (WS.isFunction()) { // Prepare the function's type, if we haven't seen it yet. @@ -566,7 +566,7 @@ Type = Pair.first->second; } else { - Type = PtrType; + Type = int32_t(PtrType); } // If the symbol is not defined in this translation unit, import it. @@ -607,7 +607,7 @@ const SmallVectorImpl &Contents = DataFrag.getContents(); for (char p : Contents) { WasmGlobal G; - G.Type = uint8_t(p); + G.Type = wasm::ValType(p); G.IsMutable = true; G.InitialValue = 0; Globals.push_back(G); @@ -632,7 +632,7 @@ if (Pair.second) FunctionTypes.push_back(F); - unsigned Type = Pair.first->second; + int32_t Type = Pair.first->second; if (WS.isDefined(/*SetUsed=*/false)) { // A definition. Take the next available index. @@ -850,7 +850,7 @@ encodeULEB128(Globals.size(), getStream()); for (const WasmGlobal &Global : Globals) { - encodeSLEB128(Global.Type, getStream()); + writeValueType(Global.Type); write8(Global.IsMutable); write8(wasm::WASM_OPCODE_I32_CONST); Index: llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.h =================================================================== --- llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.h +++ llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.h @@ -18,6 +18,7 @@ #include "llvm/CodeGen/MachineValueType.h" #include "llvm/MC/MCStreamer.h" +#include "llvm/Support/Wasm.h" namespace llvm { @@ -50,6 +51,9 @@ virtual void emitIndIdx(const MCExpr *Value) = 0; /// .import_global virtual void emitGlobalImport(StringRef name) = 0; + +protected: + void emitValueType(wasm::ValType Type); }; /// This part is for ascii assembly output Index: llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp =================================================================== --- llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp +++ llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp @@ -31,6 +31,10 @@ WebAssemblyTargetStreamer::WebAssemblyTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {} +void WebAssemblyTargetStreamer::emitValueType(wasm::ValType Type) { + Streamer.EmitSLEB128IntValue(int32_t(Type)); +} + WebAssemblyTargetAsmStreamer::WebAssemblyTargetAsmStreamer( MCStreamer &S, formatted_raw_ostream &OS) : WebAssemblyTargetStreamer(S), OS(OS) {} @@ -128,7 +132,7 @@ void WebAssemblyTargetELFStreamer::emitLocal(ArrayRef Types) { Streamer.EmitULEB128IntValue(Types.size()); for (MVT Type : Types) - Streamer.EmitIntValue(int64_t(WebAssembly::toValType(Type)), 1); + emitValueType(WebAssembly::toValType(Type)); } void WebAssemblyTargetELFStreamer::emitGlobal(ArrayRef Types) { @@ -182,7 +186,7 @@ Streamer.EmitULEB128IntValue(Grouped.size()); for (auto Pair : Grouped) { Streamer.EmitULEB128IntValue(Pair.second); - Streamer.EmitULEB128IntValue(uint64_t(WebAssembly::toValType(Pair.first))); + emitValueType(WebAssembly::toValType(Pair.first)); } } @@ -194,7 +198,7 @@ Streamer.SwitchSection(Streamer.getContext() .getWasmSection(".global_variables", 0, 0)); for (MVT Ty : Types) - Streamer.EmitIntValue(uint64_t(WebAssembly::toValType(Ty)), 1); + Streamer.EmitIntValue(int64_t(WebAssembly::toValType(Ty)), 1); Streamer.PopSection(); }