// A wasm function to be written into the function section.
struct WasmFunction {
- unsigned Type;
+ int32_t Type;
const MCSymbolWasm *Sym;
};
// A wasm global to be written into the global section.
struct WasmGlobal {
- unsigned Type;
+ wasm::ValType Type;
bool IsMutable;
uint32_t InitialValue;
};
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<WasmFunctionType, unsigned, WasmFunctionTypeDenseMapInfo>
+ DenseMap<WasmFunctionType, int32_t, WasmFunctionTypeDenseMapInfo>
FunctionTypeIndices;
SmallVector<WasmFunctionType, 4> FunctionTypes;
SmallVector<WasmFunction, 4> Functions;
// Populate the Imports set.
for (const MCSymbol &S : Asm.symbols()) {
const auto &WS = static_cast<const MCSymbolWasm &>(S);
- unsigned Type;
+ int32_t Type;
if (WS.isFunction()) {
// Prepare the function's type, if we haven't seen it yet.
Type = Pair.first->second;
} else {
- Type = PtrType;
+ Type = int32_t(PtrType);
}
// If the symbol is not defined in this translation unit, import it.
const SmallVectorImpl<char> &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);
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.
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);
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) {}
void WebAssemblyTargetELFStreamer::emitLocal(ArrayRef<MVT> 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<MVT> Types) {
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));
}
}
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();
}