diff --git a/src/abi/stack.h b/src/abi/stack.h index 752aecae46d..ae488e8c2a2 100644 --- a/src/abi/stack.h +++ b/src/abi/stack.h @@ -48,7 +48,7 @@ getStackSpace(Index local, Function* func, Index size, Module& wasm) { // align the size size = stackAlign(size); auto pointerType = - !wasm.memories.empty() ? wasm.memories[0]->indexType : Type::i32; + !wasm.memories.empty() ? wasm.memories[0]->addressType : Type::i32; // TODO: find existing stack usage, and add on top of that - carefully Builder builder(wasm); auto* block = builder.makeBlock(); diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index 64462c35465..854b0c9953b 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -5088,7 +5088,7 @@ void BinaryenSetMemory(BinaryenModuleRef module, memory->initial = initial; memory->max = int32_t(maximum); // Make sure -1 extends. memory->shared = shared; - memory->indexType = memory64 ? Type::i64 : Type::i32; + memory->addressType = memory64 ? Type::i64 : Type::i32; if (exportName) { auto memoryExport = std::make_unique(); memoryExport->name = exportName; diff --git a/src/ir/child-typer.h b/src/ir/child-typer.h index 499a7e4ddfc..154da0e455c 100644 --- a/src/ir/child-typer.h +++ b/src/ir/child-typer.h @@ -78,7 +78,7 @@ template struct ChildTyper : OverriddenVisitor { } void notePointer(Expression** ptrp, Name mem) { - note(ptrp, wasm.getMemory(mem)->indexType); + note(ptrp, wasm.getMemory(mem)->addressType); } void noteAny(Expression** childp) { self().noteAnyType(childp); } @@ -270,8 +270,8 @@ template struct ChildTyper : OverriddenVisitor { void visitDataDrop(DataDrop* curr) {} void visitMemoryCopy(MemoryCopy* curr) { - assert(wasm.getMemory(curr->destMemory)->indexType == - wasm.getMemory(curr->sourceMemory)->indexType); + assert(wasm.getMemory(curr->destMemory)->addressType == + wasm.getMemory(curr->sourceMemory)->addressType); notePointer(&curr->dest, curr->destMemory); notePointer(&curr->source, curr->sourceMemory); notePointer(&curr->size, curr->destMemory); @@ -762,7 +762,7 @@ template struct ChildTyper : OverriddenVisitor { } void visitTableInit(TableInit* curr) { - note(&curr->dest, wasm.getTable(curr->table)->indexType); + note(&curr->dest, wasm.getTable(curr->table)->addressType); note(&curr->offset, Type::i32); note(&curr->size, Type::i32); } diff --git a/src/ir/module-utils.cpp b/src/ir/module-utils.cpp index 2f26cfa779c..af9a2c85f0a 100644 --- a/src/ir/module-utils.cpp +++ b/src/ir/module-utils.cpp @@ -185,7 +185,7 @@ Memory* copyMemory(const Memory* memory, Module& out) { ret->initial = memory->initial; ret->max = memory->max; ret->shared = memory->shared; - ret->indexType = memory->indexType; + ret->addressType = memory->addressType; ret->module = memory->module; ret->base = memory->base; diff --git a/src/parser/context-decls.cpp b/src/parser/context-decls.cpp index 8e9638ae7b3..c124689d334 100644 --- a/src/parser/context-decls.cpp +++ b/src/parser/context-decls.cpp @@ -84,7 +84,7 @@ Result ParseDeclsCtx::addTableDecl(Index pos, ImportNames* importNames, TableType type) { auto t = std::make_unique(); - t->indexType = type.indexType; + t->addressType = type.addressType; t->initial = type.limits.initial; t->max = type.limits.max ? *type.limits.max : Table::kUnlimitedSize; if (name.is()) { @@ -139,7 +139,7 @@ Result ParseDeclsCtx::addMemoryDecl(Index pos, ImportNames* importNames, MemType type) { auto m = std::make_unique(); - m->indexType = type.indexType; + m->addressType = type.addressType; m->initial = type.limits.initial; m->max = type.limits.max ? *type.limits.max : Memory::kUnlimitedSize; m->shared = type.shared; @@ -178,7 +178,7 @@ Result<> ParseDeclsCtx::addImplicitData(DataStringT&& data) { auto d = std::make_unique(); d->memory = mem.name; d->isPassive = false; - d->offset = Builder(wasm).makeConstPtr(0, mem.indexType); + d->offset = Builder(wasm).makeConstPtr(0, mem.addressType); d->data = std::move(data); d->name = Names::getValidDataSegmentName(wasm, "implicit-data"); wasm.addDataSegment(std::move(d)); diff --git a/src/parser/contexts.h b/src/parser/contexts.h index b0cd1458bb6..807b6c0030e 100644 --- a/src/parser/contexts.h +++ b/src/parser/contexts.h @@ -46,7 +46,7 @@ struct Limits { }; struct MemType { - Type indexType; + Type addressType; Limits limits; bool shared; }; @@ -57,7 +57,7 @@ struct Memarg { }; struct TableType { - Type indexType; + Type addressType; Limits limits; }; @@ -965,8 +965,8 @@ struct ParseDeclsCtx : NullTypeParserCtx, NullInstrParserCtx { Limits getLimitsFromElems(Index elems) { return {elems, elems}; } - TableType makeTableType(Type indexType, Limits limits, TypeT) { - return {indexType, limits}; + TableType makeTableType(Type addressType, Limits limits, TypeT) { + return {addressType, limits}; } std::vector makeDataString() { return {}; } @@ -979,8 +979,8 @@ struct ParseDeclsCtx : NullTypeParserCtx, NullInstrParserCtx { return {size, size}; } - MemType makeMemType(Type indexType, Limits limits, bool shared) { - return {indexType, limits, shared}; + MemType makeMemType(Type addressType, Limits limits, bool shared) { + return {addressType, limits, shared}; } Result @@ -1273,7 +1273,7 @@ struct ParseModuleTypesCtx : TypeParserCtx, LimitsT getLimitsFromElems(ElemListT) { return Ok{}; } - Type makeTableType(Type indexType, LimitsT, Type type) { return type; } + Type makeTableType(Type addressType, LimitsT, Type type) { return type; } LimitsT getLimitsFromData(DataStringT) { return Ok{}; } MemTypeT makeMemType(Type, LimitsT, bool) { return Ok{}; } diff --git a/src/parser/parsers.h b/src/parser/parsers.h index 02c2e9e4760..d095f57cda4 100644 --- a/src/parser/parsers.h +++ b/src/parser/parsers.h @@ -47,10 +47,10 @@ template Result limits32(Ctx&); template Result limits64(Ctx&); template Result memtype(Ctx&); template -Result memtypeContinued(Ctx&, Type indexType); +Result memtypeContinued(Ctx&, Type addressType); template Result tabletype(Ctx&); template -Result tabletypeContinued(Ctx&, Type indexType); +Result tabletypeContinued(Ctx&, Type addressType); template Result globaltype(Ctx&); template Result tupleArity(Ctx&); @@ -780,45 +780,45 @@ template Result limits64(Ctx& ctx) { // note: the index type 'i32' or 'i64' is already parsed to simplify parsing of // memory abbreviations. template Result memtype(Ctx& ctx) { - Type indexType = Type::i32; + Type addressType = Type::i32; if (ctx.in.takeKeyword("i64"sv)) { - indexType = Type::i64; + addressType = Type::i64; } else { ctx.in.takeKeyword("i32"sv); } - return memtypeContinued(ctx, indexType); + return memtypeContinued(ctx, addressType); } template -Result memtypeContinued(Ctx& ctx, Type indexType) { - assert(indexType == Type::i32 || indexType == Type::i64); - auto limits = indexType == Type::i32 ? limits32(ctx) : limits64(ctx); +Result memtypeContinued(Ctx& ctx, Type addressType) { + assert(addressType == Type::i32 || addressType == Type::i64); + auto limits = addressType == Type::i32 ? limits32(ctx) : limits64(ctx); CHECK_ERR(limits); bool shared = false; if (ctx.in.takeKeyword("shared"sv)) { shared = true; } - return ctx.makeMemType(indexType, *limits, shared); + return ctx.makeMemType(addressType, *limits, shared); } // tabletype ::= (limits32 | 'i32' limits32 | 'i64' limit64) reftype template Result tabletype(Ctx& ctx) { - Type indexType = Type::i32; + Type addressType = Type::i32; if (ctx.in.takeKeyword("i64"sv)) { - indexType = Type::i64; + addressType = Type::i64; } else { ctx.in.takeKeyword("i32"sv); } - return tabletypeContinued(ctx, indexType); + return tabletypeContinued(ctx, addressType); } template -Result tabletypeContinued(Ctx& ctx, Type indexType) { - auto limits = indexType == Type::i32 ? limits32(ctx) : limits64(ctx); +Result tabletypeContinued(Ctx& ctx, Type addressType) { + auto limits = addressType == Type::i32 ? limits32(ctx) : limits64(ctx); CHECK_ERR(limits); auto type = reftype(ctx); CHECK_ERR(type); - return ctx.makeTableType(indexType, *limits, *type); + return ctx.makeTableType(addressType, *limits, *type); } // globaltype ::= t:valtype => const t @@ -3036,9 +3036,9 @@ template MaybeResult<> table(Ctx& ctx) { auto import = inlineImport(ctx.in); CHECK_ERR(import); - auto indexType = Type::i32; + auto addressType = Type::i32; if (ctx.in.takeKeyword("i64"sv)) { - indexType = Type::i64; + addressType = Type::i64; } else { ctx.in.takeKeyword("i32"sv); } @@ -3077,10 +3077,10 @@ template MaybeResult<> table(Ctx& ctx) { if (!ctx.in.takeRParen()) { return ctx.in.err("expected end of inline elems"); } - ttype = ctx.makeTableType(indexType, ctx.getLimitsFromElems(list), *type); + ttype = ctx.makeTableType(addressType, ctx.getLimitsFromElems(list), *type); elems = std::move(list); } else { - auto tabtype = tabletypeContinued(ctx, indexType); + auto tabtype = tabletypeContinued(ctx, addressType); CHECK_ERR(tabtype); ttype = *tabtype; } @@ -3119,9 +3119,9 @@ template MaybeResult<> memory(Ctx& ctx) { auto import = inlineImport(ctx.in); CHECK_ERR(import); - auto indexType = Type::i32; + auto addressType = Type::i32; if (ctx.in.takeKeyword("i64"sv)) { - indexType = Type::i64; + addressType = Type::i64; } else { ctx.in.takeKeyword("i32"sv); } @@ -3137,10 +3137,10 @@ template MaybeResult<> memory(Ctx& ctx) { if (!ctx.in.takeRParen()) { return ctx.in.err("expected end of inline data"); } - mtype = ctx.makeMemType(indexType, ctx.getLimitsFromData(*datastr), false); + mtype = ctx.makeMemType(addressType, ctx.getLimitsFromData(*datastr), false); data = *datastr; } else { - auto type = memtypeContinued(ctx, indexType); + auto type = memtypeContinued(ctx, addressType); CHECK_ERR(type); mtype = *type; } diff --git a/src/passes/AlignmentLowering.cpp b/src/passes/AlignmentLowering.cpp index d0ceeb6107b..52849ebaccb 100644 --- a/src/passes/AlignmentLowering.cpp +++ b/src/passes/AlignmentLowering.cpp @@ -35,10 +35,10 @@ struct AlignmentLowering : public WalkerPass> { return curr; } auto mem = getModule()->getMemory(curr->memory); - auto indexType = mem->indexType; + auto addressType = mem->addressType; Builder builder(*getModule()); assert(curr->type == Type::i32); - auto temp = builder.addVar(getFunction(), indexType); + auto temp = builder.addVar(getFunction(), addressType); Expression* ret; if (curr->bytes == 2) { ret = builder.makeBinary( @@ -47,7 +47,7 @@ struct AlignmentLowering : public WalkerPass> { false, curr->offset, 1, - builder.makeLocalGet(temp, indexType), + builder.makeLocalGet(temp, addressType), Type::i32, curr->memory), builder.makeBinary( @@ -56,7 +56,7 @@ struct AlignmentLowering : public WalkerPass> { false, curr->offset + 1, 1, - builder.makeLocalGet(temp, indexType), + builder.makeLocalGet(temp, addressType), Type::i32, curr->memory), builder.makeConst(int32_t(8)))); @@ -73,7 +73,7 @@ struct AlignmentLowering : public WalkerPass> { false, curr->offset, 1, - builder.makeLocalGet(temp, indexType), + builder.makeLocalGet(temp, addressType), Type::i32, curr->memory), builder.makeBinary( @@ -82,7 +82,7 @@ struct AlignmentLowering : public WalkerPass> { false, curr->offset + 1, 1, - builder.makeLocalGet(temp, indexType), + builder.makeLocalGet(temp, addressType), Type::i32, curr->memory), builder.makeConst(int32_t(8)))), @@ -94,7 +94,7 @@ struct AlignmentLowering : public WalkerPass> { false, curr->offset + 2, 1, - builder.makeLocalGet(temp, indexType), + builder.makeLocalGet(temp, addressType), Type::i32, curr->memory), builder.makeConst(int32_t(16))), @@ -104,7 +104,7 @@ struct AlignmentLowering : public WalkerPass> { false, curr->offset + 3, 1, - builder.makeLocalGet(temp, indexType), + builder.makeLocalGet(temp, addressType), Type::i32, curr->memory), builder.makeConst(int32_t(24))))); @@ -115,7 +115,7 @@ struct AlignmentLowering : public WalkerPass> { false, curr->offset, 2, - builder.makeLocalGet(temp, indexType), + builder.makeLocalGet(temp, addressType), Type::i32, curr->memory), builder.makeBinary( @@ -124,7 +124,7 @@ struct AlignmentLowering : public WalkerPass> { false, curr->offset + 2, 2, - builder.makeLocalGet(temp, indexType), + builder.makeLocalGet(temp, addressType), Type::i32, curr->memory), builder.makeConst(int32_t(16)))); @@ -145,8 +145,8 @@ struct AlignmentLowering : public WalkerPass> { Builder builder(*getModule()); assert(curr->value->type == Type::i32); auto mem = getModule()->getMemory(curr->memory); - auto indexType = mem->indexType; - auto tempPtr = builder.addVar(getFunction(), indexType); + auto addressType = mem->addressType; + auto tempPtr = builder.addVar(getFunction(), addressType); auto tempValue = builder.addVar(getFunction(), Type::i32); auto* block = builder.makeBlock({builder.makeLocalSet(tempPtr, curr->ptr), @@ -156,7 +156,7 @@ struct AlignmentLowering : public WalkerPass> { builder.makeStore(1, curr->offset, 1, - builder.makeLocalGet(tempPtr, indexType), + builder.makeLocalGet(tempPtr, addressType), builder.makeLocalGet(tempValue, Type::i32), Type::i32, curr->memory)); @@ -164,7 +164,7 @@ struct AlignmentLowering : public WalkerPass> { 1, curr->offset + 1, 1, - builder.makeLocalGet(tempPtr, indexType), + builder.makeLocalGet(tempPtr, addressType), builder.makeBinary(ShrUInt32, builder.makeLocalGet(tempValue, Type::i32), builder.makeConst(int32_t(8))), @@ -176,7 +176,7 @@ struct AlignmentLowering : public WalkerPass> { builder.makeStore(1, curr->offset, 1, - builder.makeLocalGet(tempPtr, indexType), + builder.makeLocalGet(tempPtr, addressType), builder.makeLocalGet(tempValue, Type::i32), Type::i32, curr->memory)); @@ -184,7 +184,7 @@ struct AlignmentLowering : public WalkerPass> { 1, curr->offset + 1, 1, - builder.makeLocalGet(tempPtr, indexType), + builder.makeLocalGet(tempPtr, addressType), builder.makeBinary(ShrUInt32, builder.makeLocalGet(tempValue, Type::i32), builder.makeConst(int32_t(8))), @@ -194,7 +194,7 @@ struct AlignmentLowering : public WalkerPass> { 1, curr->offset + 2, 1, - builder.makeLocalGet(tempPtr, indexType), + builder.makeLocalGet(tempPtr, addressType), builder.makeBinary(ShrUInt32, builder.makeLocalGet(tempValue, Type::i32), builder.makeConst(int32_t(16))), @@ -204,7 +204,7 @@ struct AlignmentLowering : public WalkerPass> { 1, curr->offset + 3, 1, - builder.makeLocalGet(tempPtr, indexType), + builder.makeLocalGet(tempPtr, addressType), builder.makeBinary(ShrUInt32, builder.makeLocalGet(tempValue, Type::i32), builder.makeConst(int32_t(24))), @@ -215,7 +215,7 @@ struct AlignmentLowering : public WalkerPass> { builder.makeStore(2, curr->offset, 2, - builder.makeLocalGet(tempPtr, indexType), + builder.makeLocalGet(tempPtr, addressType), builder.makeLocalGet(tempValue, Type::i32), Type::i32, curr->memory)); @@ -223,7 +223,7 @@ struct AlignmentLowering : public WalkerPass> { 2, curr->offset + 2, 2, - builder.makeLocalGet(tempPtr, indexType), + builder.makeLocalGet(tempPtr, addressType), builder.makeBinary(ShrUInt32, builder.makeLocalGet(tempValue, Type::i32), builder.makeConst(int32_t(16))), @@ -275,15 +275,15 @@ struct AlignmentLowering : public WalkerPass> { } // Load two 32-bit pieces, and combine them. auto mem = getModule()->getMemory(curr->memory); - auto indexType = mem->indexType; - auto temp = builder.addVar(getFunction(), indexType); + auto addressType = mem->addressType; + auto temp = builder.addVar(getFunction(), addressType); auto* set = builder.makeLocalSet(temp, curr->ptr); Expression* low = lowerLoadI32(builder.makeLoad(4, false, curr->offset, curr->align, - builder.makeLocalGet(temp, indexType), + builder.makeLocalGet(temp, addressType), Type::i32, curr->memory)); low = builder.makeUnary(ExtendUInt32, low); @@ -296,7 +296,7 @@ struct AlignmentLowering : public WalkerPass> { false, curr->offset + 4, curr->align, - builder.makeLocalGet(temp, indexType), + builder.makeLocalGet(temp, addressType), Type::i32, curr->memory)); high = builder.makeUnary(ExtendUInt32, high); @@ -357,8 +357,8 @@ struct AlignmentLowering : public WalkerPass> { } // Store as two 32-bit pieces. auto mem = getModule()->getMemory(curr->memory); - auto indexType = mem->indexType; - auto tempPtr = builder.addVar(getFunction(), indexType); + auto addressType = mem->addressType; + auto tempPtr = builder.addVar(getFunction(), addressType); auto* setPtr = builder.makeLocalSet(tempPtr, curr->ptr); auto tempValue = builder.addVar(getFunction(), Type::i64); auto* setValue = builder.makeLocalSet(tempValue, value); @@ -368,7 +368,7 @@ struct AlignmentLowering : public WalkerPass> { builder.makeStore(4, curr->offset, curr->align, - builder.makeLocalGet(tempPtr, indexType), + builder.makeLocalGet(tempPtr, addressType), low, Type::i32, curr->memory)); @@ -385,7 +385,7 @@ struct AlignmentLowering : public WalkerPass> { builder.makeStore(4, curr->offset + 4, curr->align, - builder.makeLocalGet(tempPtr, indexType), + builder.makeLocalGet(tempPtr, addressType), high, Type::i32, curr->memory)); diff --git a/src/passes/AvoidReinterprets.cpp b/src/passes/AvoidReinterprets.cpp index 94ae42b61a1..32a19018048 100644 --- a/src/passes/AvoidReinterprets.cpp +++ b/src/passes/AvoidReinterprets.cpp @@ -121,7 +121,7 @@ struct AvoidReinterprets : public WalkerPass> { if (info.reinterpreted && canReplaceWithReinterpret(load)) { // We should use another load here, to avoid reinterprets. auto mem = getModule()->getMemory(load->memory); - info.ptrLocal = Builder::addVar(func, mem->indexType); + info.ptrLocal = Builder::addVar(func, mem->addressType); info.reinterpretedLocal = Builder::addVar(func, load->type.reinterpret()); } else { @@ -176,8 +176,8 @@ struct AvoidReinterprets : public WalkerPass> { Builder builder(*module); auto* ptr = curr->ptr; auto mem = getModule()->getMemory(curr->memory); - auto indexType = mem->indexType; - curr->ptr = builder.makeLocalGet(info.ptrLocal, indexType); + auto addressType = mem->addressType; + curr->ptr = builder.makeLocalGet(info.ptrLocal, addressType); // Note that the other load can have its sign set to false - if the // original were an integer, the other is a float anyhow; and if // original were a float, we don't know what sign to use. @@ -186,7 +186,7 @@ struct AvoidReinterprets : public WalkerPass> { builder.makeLocalSet( info.reinterpretedLocal, makeReinterpretedLoad( - curr, builder.makeLocalGet(info.ptrLocal, indexType))), + curr, builder.makeLocalGet(info.ptrLocal, addressType))), curr})); } } diff --git a/src/passes/GenerateDynCalls.cpp b/src/passes/GenerateDynCalls.cpp index 6e6e0a71781..89f74b54fd1 100644 --- a/src/passes/GenerateDynCalls.cpp +++ b/src/passes/GenerateDynCalls.cpp @@ -146,11 +146,11 @@ void GenerateDynCalls::generateDynCallThunk(HeapType funcType) { auto* table = wasm->addTable(Builder::makeTable(Name::fromInt(0))); table->module = ENV; table->base = "__indirect_function_table"; - table->indexType = wasm->memories[0]->indexType; + table->addressType = wasm->memories[0]->addressType; } auto& table = wasm->tables[0]; - namedParams.emplace_back("fptr", table->indexType); // function pointer param - params.push_back(table->indexType); + namedParams.emplace_back("fptr", table->addressType); // function pointer param + params.push_back(table->addressType); int p = 0; for (const auto& param : sig.params) { namedParams.emplace_back(std::to_string(p++), param); @@ -159,7 +159,7 @@ void GenerateDynCalls::generateDynCallThunk(HeapType funcType) { auto f = builder.makeFunction( name, std::move(namedParams), Signature(Type(params), sig.results), {}); f->hasExplicitName = true; - Expression* fptr = builder.makeLocalGet(0, table->indexType); + Expression* fptr = builder.makeLocalGet(0, table->addressType); std::vector args; Index i = 0; for (const auto& param : sig.params) { diff --git a/src/passes/InstrumentMemory.cpp b/src/passes/InstrumentMemory.cpp index b3c9aebbd35..76adc8effc5 100644 --- a/src/passes/InstrumentMemory.cpp +++ b/src/passes/InstrumentMemory.cpp @@ -104,14 +104,14 @@ struct InstrumentMemory : public WalkerPass> { id++; Builder builder(*getModule()); auto mem = getModule()->getMemory(curr->memory); - auto indexType = mem->indexType; - auto offset = builder.makeConstPtr(curr->offset.addr, indexType); + auto addressType = mem->addressType; + auto offset = builder.makeConstPtr(curr->offset.addr, addressType); curr->ptr = builder.makeCall(load_ptr, {builder.makeConst(int32_t(id)), builder.makeConst(int32_t(curr->bytes)), offset, curr->ptr}, - indexType); + addressType); Name target; switch (curr->type.getBasic()) { case Type::i32: @@ -137,14 +137,14 @@ struct InstrumentMemory : public WalkerPass> { id++; Builder builder(*getModule()); auto mem = getModule()->getMemory(curr->memory); - auto indexType = mem->indexType; - auto offset = builder.makeConstPtr(curr->offset.addr, indexType); + auto addressType = mem->addressType; + auto offset = builder.makeConstPtr(curr->offset.addr, addressType); curr->ptr = builder.makeCall(store_ptr, {builder.makeConst(int32_t(id)), builder.makeConst(int32_t(curr->bytes)), offset, curr->ptr}, - indexType); + addressType); Name target; switch (curr->value->type.getBasic()) { case Type::i32: @@ -251,12 +251,12 @@ struct InstrumentMemory : public WalkerPass> { } void visitModule(Module* curr) { - auto indexType = - curr->memories.empty() ? Type::i32 : curr->memories[0]->indexType; + auto addressType = + curr->memories.empty() ? Type::i32 : curr->memories[0]->addressType; // Load. addImport( - curr, load_ptr, {Type::i32, Type::i32, indexType, indexType}, indexType); + curr, load_ptr, {Type::i32, Type::i32, addressType, addressType}, addressType); addImport(curr, load_val_i32, {Type::i32, Type::i32}, Type::i32); addImport(curr, load_val_i64, {Type::i32, Type::i64}, Type::i64); addImport(curr, load_val_f32, {Type::i32, Type::f32}, Type::f32); @@ -264,7 +264,7 @@ struct InstrumentMemory : public WalkerPass> { // Store. addImport( - curr, store_ptr, {Type::i32, Type::i32, indexType, indexType}, indexType); + curr, store_ptr, {Type::i32, Type::i32, addressType, addressType}, addressType); addImport(curr, store_val_i32, {Type::i32, Type::i32}, Type::i32); addImport(curr, store_val_i64, {Type::i32, Type::i64}, Type::i64); addImport(curr, store_val_f32, {Type::i32, Type::f32}, Type::f32); diff --git a/src/passes/Memory64Lowering.cpp b/src/passes/Memory64Lowering.cpp index 0a19d11c812..a3913c7598b 100644 --- a/src/passes/Memory64Lowering.cpp +++ b/src/passes/Memory64Lowering.cpp @@ -187,7 +187,7 @@ struct Memory64Lowering : public WalkerPass> { // we don't want to depend on that specific ordering. for (auto& memory : module->memories) { if (memory->is64()) { - memory->indexType = Type::i32; + memory->addressType = Type::i32; if (memory->hasMax() && memory->max > Memory::kMaxSize32) { memory->max = Memory::kMaxSize32; } diff --git a/src/passes/MemoryPacking.cpp b/src/passes/MemoryPacking.cpp index ad562faf49a..6c411378b23 100644 --- a/src/passes/MemoryPacking.cpp +++ b/src/passes/MemoryPacking.cpp @@ -92,7 +92,7 @@ makeGtShiftedMemorySize(Builder& builder, Module& module, MemoryInit* curr) { curr->dest, builder.makeBinary(mem->is64() ? ShlInt64 : ShlInt32, builder.makeMemorySize(mem->name), - builder.makeConstPtr(16, mem->indexType))); + builder.makeConstPtr(16, mem->addressType))); } } // anonymous namespace @@ -781,7 +781,7 @@ void MemoryPacking::createReplacements(Module* module, // Calculate dest, either as a const or as an addition to the dest local Expression* dest; - Type ptrType = module->getMemory(init->memory)->indexType; + Type ptrType = module->getMemory(init->memory)->addressType; if (auto* c = init->dest->dynCast()) { dest = builder.makeConstPtr(c->value.getInteger() + bytesWritten, ptrType); @@ -819,8 +819,8 @@ void MemoryPacking::createReplacements(Module* module, replacements[init] = [module, init, setVar, getVars, result](Function* function) { if (setVar != nullptr) { - auto indexType = module->getMemory(init->memory)->indexType; - Index destVar = Builder(*module).addVar(function, indexType); + auto addressType = module->getMemory(init->memory)->addressType; + Index destVar = Builder(*module).addVar(function, addressType); *setVar = destVar; for (auto* getVar : getVars) { *getVar = destVar; diff --git a/src/passes/MultiMemoryLowering.cpp b/src/passes/MultiMemoryLowering.cpp index b214959f710..c22477b79c5 100644 --- a/src/passes/MultiMemoryLowering.cpp +++ b/src/passes/MultiMemoryLowering.cpp @@ -430,7 +430,7 @@ struct MultiMemoryLowering : public Pass { Memory& getFirstMemory() { return *wasm->memories[0]; } void prepCombinedMemory() { - pointerType = getFirstMemory().indexType; + pointerType = getFirstMemory().addressType; memoryInfo = pointerType == Type::i32 ? Builder::MemoryInfo::Memory32 : Builder::MemoryInfo::Memory64; isShared = getFirstMemory().shared; @@ -439,7 +439,7 @@ struct MultiMemoryLowering : public Pass { // We are assuming that each memory is configured the same as the first // and assert if any of the memories does not match this configuration assert(memory->shared == isShared); - assert(memory->indexType == pointerType); + assert(memory->addressType == pointerType); // TODO: handle memory import for memories other than the first if (memory->name != getFirstMemory().name && memory->imported()) { @@ -690,7 +690,7 @@ struct MultiMemoryLowering : public Pass { void addCombinedMemory() { auto memory = Builder::makeMemory(combinedMemory); memory->shared = isShared; - memory->indexType = pointerType; + memory->addressType = pointerType; memory->initial = totalInitialPages; memory->max = totalMaxPages; if (isImported) { diff --git a/src/passes/SafeHeap.cpp b/src/passes/SafeHeap.cpp index 7baeb365e39..2ff6cfb5a7f 100644 --- a/src/passes/SafeHeap.cpp +++ b/src/passes/SafeHeap.cpp @@ -85,7 +85,7 @@ struct AccessInstrumenter : public WalkerPass> { auto memory = getModule()->getMemory(curr->memory); replaceCurrent(builder.makeCall( getLoadName(curr), - {curr->ptr, builder.makeConstPtr(curr->offset.addr, memory->indexType)}, + {curr->ptr, builder.makeConstPtr(curr->offset.addr, memory->addressType)}, curr->type)); } @@ -99,7 +99,7 @@ struct AccessInstrumenter : public WalkerPass> { replaceCurrent(builder.makeCall( getStoreName(curr), {curr->ptr, - builder.makeConstPtr(curr->offset.addr, memory->indexType), + builder.makeConstPtr(curr->offset.addr, memory->addressType), curr->value}, Type::none)); } @@ -156,7 +156,7 @@ struct SafeHeap : public Pass { void addImports(Module* module) { ImportInfo info(*module); - auto indexType = module->memories[0]->indexType; + auto addressType = module->memories[0]->addressType; if (auto* existing = info.getImportedFunction(ENV, GET_SBRK_PTR)) { getSbrkPtr = existing->name; } else if (auto* existing = module->getExportOrNull(GET_SBRK_PTR)) { @@ -165,7 +165,7 @@ struct SafeHeap : public Pass { sbrk = existing->name; } else { auto import = Builder::makeFunction( - GET_SBRK_PTR, Signature(Type::none, indexType), {}); + GET_SBRK_PTR, Signature(Type::none, addressType), {}); getSbrkPtr = GET_SBRK_PTR; import->module = ENV; import->base = GET_SBRK_PTR; @@ -283,17 +283,17 @@ struct SafeHeap : public Pass { } // pointer, offset auto memory = module->getMemory(style.memory); - auto indexType = memory->indexType; - auto funcSig = Signature({indexType, indexType}, style.type); - auto func = Builder::makeFunction(name, funcSig, {indexType}); + auto addressType = memory->addressType; + auto funcSig = Signature({addressType, addressType}, style.type); + auto func = Builder::makeFunction(name, funcSig, {addressType}); Builder builder(*module); auto* block = builder.makeBlock(); // stash the sum of the pointer (0) and the size (1) in a local (2) block->list.push_back(builder.makeLocalSet( 2, builder.makeBinary(memory->is64() ? AddInt64 : AddInt32, - builder.makeLocalGet(0, indexType), - builder.makeLocalGet(1, indexType)))); + builder.makeLocalGet(0, addressType), + builder.makeLocalGet(1, addressType)))); // check for reading past valid memory: if pointer + offset + bytes block->list.push_back(makeBoundsCheck(style.type, builder, @@ -301,7 +301,7 @@ struct SafeHeap : public Pass { 2, style.bytes, module, - memory->indexType, + memory->addressType, memory->is64(), memory->name)); // check proper alignment @@ -312,7 +312,7 @@ struct SafeHeap : public Pass { // do the load auto* load = module->allocator.alloc(); *load = style; // basically the same as the template we are given! - load->ptr = builder.makeLocalGet(2, indexType); + load->ptr = builder.makeLocalGet(2, addressType); Expression* last = load; if (load->isAtomic && load->signed_) { // atomic loads cannot be signed, manually sign it @@ -332,19 +332,19 @@ struct SafeHeap : public Pass { return; } auto memory = module->getMemory(style.memory); - auto indexType = memory->indexType; + auto addressType = memory->addressType; bool is64 = memory->is64(); // pointer, offset, value auto funcSig = - Signature({indexType, indexType, style.valueType}, Type::none); - auto func = Builder::makeFunction(name, funcSig, {indexType}); + Signature({addressType, addressType, style.valueType}, Type::none); + auto func = Builder::makeFunction(name, funcSig, {addressType}); Builder builder(*module); auto* block = builder.makeBlock(); block->list.push_back(builder.makeLocalSet( 3, builder.makeBinary(is64 ? AddInt64 : AddInt32, - builder.makeLocalGet(0, indexType), - builder.makeLocalGet(1, indexType)))); + builder.makeLocalGet(0, addressType), + builder.makeLocalGet(1, addressType)))); // check for reading past valid memory: if pointer + offset + bytes block->list.push_back(makeBoundsCheck(style.valueType, builder, @@ -352,7 +352,7 @@ struct SafeHeap : public Pass { 3, style.bytes, module, - indexType, + addressType, is64, memory->name)); // check proper alignment @@ -364,7 +364,7 @@ struct SafeHeap : public Pass { auto* store = module->allocator.alloc(); *store = style; // basically the same as the template we are given! store->memory = memory->name; - store->ptr = builder.makeLocalGet(3, indexType); + store->ptr = builder.makeLocalGet(3, addressType); store->value = builder.makeLocalGet(2, style.valueType); block->list.push_back(store); block->finalize(Type::none); @@ -378,8 +378,8 @@ struct SafeHeap : public Pass { Module* module, Name memoryName) { auto memory = module->getMemory(memoryName); - auto indexType = memory->indexType; - Expression* ptrBits = builder.makeLocalGet(local, indexType); + auto addressType = memory->addressType; + Expression* ptrBits = builder.makeLocalGet(local, addressType); if (memory->is64()) { ptrBits = builder.makeUnary(WrapInt64, ptrBits); } @@ -399,7 +399,7 @@ struct SafeHeap : public Pass { Index sumLocal, Index bytes, Module* module, - Type indexType, + Type addressType, bool is64, Name memory) { bool lowMemUnused = getPassOptions().lowMemoryUnused; @@ -409,37 +409,37 @@ struct SafeHeap : public Pass { Expression* brkLocation; if (sbrk.is()) { brkLocation = - builder.makeCall(sbrk, {builder.makeConstPtr(0, indexType)}, indexType); + builder.makeCall(sbrk, {builder.makeConstPtr(0, addressType)}, addressType); } else { Expression* sbrkPtr; if (dynamicTopPtr.is()) { - sbrkPtr = builder.makeGlobalGet(dynamicTopPtr, indexType); + sbrkPtr = builder.makeGlobalGet(dynamicTopPtr, addressType); } else { - sbrkPtr = builder.makeCall(getSbrkPtr, {}, indexType); + sbrkPtr = builder.makeCall(getSbrkPtr, {}, addressType); } auto size = is64 ? 8 : 4; brkLocation = - builder.makeLoad(size, false, 0, size, sbrkPtr, indexType, memory); + builder.makeLoad(size, false, 0, size, sbrkPtr, addressType, memory); } auto gtuOp = is64 ? GtUInt64 : GtUInt32; auto addOp = is64 ? AddInt64 : AddInt32; auto* upperCheck = builder.makeBinary(upperOp, - builder.makeLocalGet(sumLocal, indexType), - builder.makeConstPtr(upperBound, indexType)); + builder.makeLocalGet(sumLocal, addressType), + builder.makeConstPtr(upperBound, addressType)); auto* lowerCheck = builder.makeBinary( gtuOp, builder.makeBinary(addOp, - builder.makeLocalGet(sumLocal, indexType), - builder.makeConstPtr(bytes, indexType)), + builder.makeLocalGet(sumLocal, addressType), + builder.makeConstPtr(bytes, addressType)), brkLocation); // Check for an overflow when adding the pointer and the size, using the // rule that for any unsigned x and y, // x + y < x <=> x + y overflows auto* overflowCheck = builder.makeBinary(is64 ? LtUInt64 : LtUInt32, - builder.makeLocalGet(sumLocal, indexType), - builder.makeLocalGet(ptrLocal, indexType)); + builder.makeLocalGet(sumLocal, addressType), + builder.makeLocalGet(ptrLocal, addressType)); // Add an unreachable right after the call to segfault for performance // reasons: the call never returns, and this helps optimizations benefit // from that. diff --git a/src/passes/SimplifyLocals.cpp b/src/passes/SimplifyLocals.cpp index eca503ad4c4..cf0b7495011 100644 --- a/src/passes/SimplifyLocals.cpp +++ b/src/passes/SimplifyLocals.cpp @@ -1088,15 +1088,15 @@ struct SimplifyLocals } auto bestType = func->getLocalType(best); - auto indexType = func->getLocalType(index); - if (!Type::isSubType(indexType, bestType)) { + auto addressType = func->getLocalType(index); + if (!Type::isSubType(addressType, bestType)) { // This is less refined than the current best; ignore. continue; } // This is better if it has a more refined type, or if it has more // uses. - if (indexType != bestType || + if (addressType != bestType || getNumGetsIgnoringCurr(index) > getNumGetsIgnoringCurr(best)) { best = index; } diff --git a/src/passes/SpillPointers.cpp b/src/passes/SpillPointers.cpp index db7fca85abf..cfa432a4ed4 100644 --- a/src/passes/SpillPointers.cpp +++ b/src/passes/SpillPointers.cpp @@ -79,7 +79,7 @@ struct SpillPointers Type pointerType; void spillPointers() { - pointerType = getModule()->memories[0]->indexType; + pointerType = getModule()->memories[0]->addressType; // we only care about possible pointers auto* func = getFunction(); diff --git a/src/passes/StackCheck.cpp b/src/passes/StackCheck.cpp index ce5d346b944..31bf791fd80 100644 --- a/src/passes/StackCheck.cpp +++ b/src/passes/StackCheck.cpp @@ -151,17 +151,17 @@ struct StackCheck : public Pass { Builder builder(*module); // Add the globals. - Type indexType = - module->memories.empty() ? Type::i32 : module->memories[0]->indexType; + Type addressType = + module->memories.empty() ? Type::i32 : module->memories[0]->addressType; auto stackBase = module->addGlobal(builder.makeGlobal(stackBaseName, stackPointer->type, - builder.makeConstPtr(0, indexType), + builder.makeConstPtr(0, addressType), Builder::Mutable)); auto stackLimit = module->addGlobal(builder.makeGlobal(stackLimitName, stackPointer->type, - builder.makeConstPtr(0, indexType), + builder.makeConstPtr(0, addressType), Builder::Mutable)); // Instrument all the code. diff --git a/src/passes/Table64Lowering.cpp b/src/passes/Table64Lowering.cpp index b4a538df9a9..1167515de17 100644 --- a/src/passes/Table64Lowering.cpp +++ b/src/passes/Table64Lowering.cpp @@ -144,7 +144,7 @@ struct Table64Lowering : public WalkerPass> { // we don't want to depend on that specific ordering. for (auto& table : module->tables) { if (table->is64()) { - table->indexType = Type::i32; + table->addressType = Type::i32; } } } diff --git a/src/tools/fuzzing/fuzzing.cpp b/src/tools/fuzzing/fuzzing.cpp index 5dcdc66d5b0..74d9e4212d0 100644 --- a/src/tools/fuzzing/fuzzing.cpp +++ b/src/tools/fuzzing/fuzzing.cpp @@ -668,7 +668,7 @@ void TranslateToFuzzReader::addHashMemorySupport() { std::vector contents; contents.push_back( builder.makeLocalSet(0, builder.makeConst(uint32_t(5381)))); - auto zero = Literal::makeFromInt32(0, wasm.memories[0]->indexType); + auto zero = Literal::makeFromInt32(0, wasm.memories[0]->addressType); for (Index i = 0; i < USABLE_MEMORY; i++) { contents.push_back(builder.makeLocalSet( 0, @@ -2165,7 +2165,7 @@ Expression* TranslateToFuzzReader::makeTupleExtract(Type type) { } Expression* TranslateToFuzzReader::makePointer() { - auto* ret = make(wasm.memories[0]->indexType); + auto* ret = make(wasm.memories[0]->addressType); // with high probability, mask the pointer so it's in a reasonable // range. otherwise, most pointers are going to be out of range and // most memory ops will just trap @@ -4414,7 +4414,7 @@ Expression* TranslateToFuzzReader::makeMemoryCopy() { } Expression* dest = makePointer(); Expression* source = makePointer(); - Expression* size = make(wasm.memories[0]->indexType); + Expression* size = make(wasm.memories[0]->addressType); return builder.makeMemoryCopy( dest, source, size, wasm.memories[0]->name, wasm.memories[0]->name); } @@ -4425,7 +4425,7 @@ Expression* TranslateToFuzzReader::makeMemoryFill() { } Expression* dest = makePointer(); Expression* value = make(Type::i32); - Expression* size = make(wasm.memories[0]->indexType); + Expression* size = make(wasm.memories[0]->addressType); return builder.makeMemoryFill(dest, value, size, wasm.memories[0]->name); } diff --git a/src/tools/wasm-split/instrumenter.cpp b/src/tools/wasm-split/instrumenter.cpp index 1c825f29fba..93971ed941b 100644 --- a/src/tools/wasm-split/instrumenter.cpp +++ b/src/tools/wasm-split/instrumenter.cpp @@ -195,7 +195,7 @@ void Instrumenter::addProfileExport(size_t numFuncs) { } } - auto ptrType = wasm->memories[0]->indexType; + auto ptrType = wasm->memories[0]->addressType; // Create and export a function to dump the profile into a given memory // buffer. The function takes the available address and buffer size as diff --git a/src/wasm-binary.h b/src/wasm-binary.h index ca14bd41f25..82f48708556 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -1523,7 +1523,7 @@ class WasmBinaryReader { void getResizableLimits(Address& initial, Address& max, bool& shared, - Type& indexType, + Type& addressType, Address defaultIfNoMax); void readImports(); diff --git a/src/wasm-builder.h b/src/wasm-builder.h index 8f8895781bd..15b7a2059e4 100644 --- a/src/wasm-builder.h +++ b/src/wasm-builder.h @@ -87,11 +87,11 @@ class Builder { Nullable), Address initial = 0, Address max = Table::kMaxSize, - Type indexType = Type::i32) { + Type addressType = Type::i32) { auto table = std::make_unique
(); table->name = name; table->type = type; - table->indexType = indexType; + table->addressType = addressType; table->initial = initial; table->max = max; return table; @@ -114,13 +114,13 @@ class Builder { Address initial = 0, Address max = Memory::kMaxSize32, bool shared = false, - Type indexType = Type::i32) { + Type addressType = Type::i32) { auto memory = std::make_unique(); memory->name = name; memory->initial = initial; memory->max = max; memory->shared = shared; - memory->indexType = indexType; + memory->addressType = addressType; return memory; } @@ -612,8 +612,8 @@ class Builder { ret->finalize(); return ret; } - Const* makeConstPtr(uint64_t val, Type indexType) { - return makeConst(Literal::makeFromInt64(val, indexType)); + Const* makeConstPtr(uint64_t val, Type addressType) { + return makeConst(Literal::makeFromInt64(val, addressType)); } Binary* makeBinary(BinaryOp op, Expression* left, Expression* right) { auto* ret = wasm.allocator.alloc(); diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 5f20819a1c8..4c1260a14af 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -3197,7 +3197,7 @@ class ModuleRunnerBase : public ExpressionRunner { } auto info = getTableInstanceInfo(curr->table); auto* table = info.instance->wasm.getTable(info.name); - auto address = table->indexType == Type::i64 + auto address = table->addressType == Type::i64 ? index.getSingleValue().geti64() : index.getSingleValue().geti32(); return info.interface()->tableLoad(info.name, address); @@ -3214,7 +3214,7 @@ class ModuleRunnerBase : public ExpressionRunner { } auto info = getTableInstanceInfo(curr->table); auto* table = info.instance->wasm.getTable(info.name); - auto address = table->indexType == Type::i64 + auto address = table->addressType == Type::i64 ? indexFlow.getSingleValue().geti64() : indexFlow.getSingleValue().geti32(); info.interface()->tableStore( @@ -3227,7 +3227,7 @@ class ModuleRunnerBase : public ExpressionRunner { auto info = getTableInstanceInfo(curr->table); auto* table = info.instance->wasm.getTable(info.name); Index tableSize = info.interface()->tableSize(curr->table); - return Literal::makeFromInt64(tableSize, table->indexType); + return Literal::makeFromInt64(tableSize, table->addressType); } Flow visitTableGrow(TableGrow* curr) { @@ -3244,8 +3244,8 @@ class ModuleRunnerBase : public ExpressionRunner { uint64_t tableSize = info.interface()->tableSize(info.name); auto* table = info.instance->wasm.getTable(info.name); - Flow ret = Literal::makeFromInt64(tableSize, table->indexType); - Flow fail = Literal::makeFromInt64(-1, table->indexType); + Flow ret = Literal::makeFromInt64(tableSize, table->addressType); + Flow fail = Literal::makeFromInt64(-1, table->addressType); uint64_t delta = deltaFlow.getSingleValue().getUnsigned(); uint64_t newSize; @@ -3821,7 +3821,7 @@ class ModuleRunnerBase : public ExpressionRunner { auto info = getMemoryInstanceInfo(curr->memory); auto memorySize = info.instance->getMemorySize(info.name); auto* memory = info.instance->wasm.getMemory(info.name); - return Literal::makeFromInt64(memorySize, memory->indexType); + return Literal::makeFromInt64(memorySize, memory->addressType); } Flow visitMemoryGrow(MemoryGrow* curr) { NOTE_ENTER("MemoryGrow"); @@ -3832,14 +3832,14 @@ class ModuleRunnerBase : public ExpressionRunner { auto info = getMemoryInstanceInfo(curr->memory); auto memorySize = info.instance->getMemorySize(info.name); auto* memory = info.instance->wasm.getMemory(info.name); - auto indexType = memory->indexType; - auto fail = Literal::makeFromInt64(-1, memory->indexType); - Flow ret = Literal::makeFromInt64(memorySize, indexType); + auto addressType = memory->addressType; + auto fail = Literal::makeFromInt64(-1, memory->addressType); + Flow ret = Literal::makeFromInt64(memorySize, addressType); uint64_t delta = flow.getSingleValue().getUnsigned(); - if (delta > uint32_t(-1) / Memory::kPageSize && indexType == Type::i32) { + if (delta > uint32_t(-1) / Memory::kPageSize && addressType == Type::i32) { return fail; } - if (memorySize >= uint32_t(-1) - delta && indexType == Type::i32) { + if (memorySize >= uint32_t(-1) - delta && addressType == Type::i32) { return fail; } auto newSize = memorySize + delta; diff --git a/src/wasm.h b/src/wasm.h index 85473b1f957..22e71560f4a 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -2204,11 +2204,11 @@ class Table : public Importable { Address initial = 0; Address max = kMaxSize; - Type indexType = Type::i32; + Type addressType = Type::i32; Type type = Type(HeapType::func, Nullable); bool hasMax() { return max != kUnlimitedSize; } - bool is64() { return indexType == Type::i64; } + bool is64() { return addressType == Type::i64; } void clear() { name = ""; initial = 0; @@ -2238,16 +2238,16 @@ class Memory : public Importable { Address max = kMaxSize32; bool shared = false; - Type indexType = Type::i32; + Type addressType = Type::i32; bool hasMax() { return max != kUnlimitedSize; } - bool is64() { return indexType == Type::i64; } + bool is64() { return addressType == Type::i64; } void clear() { name = ""; initial = 0; max = kMaxSize32; shared = false; - indexType = Type::i32; + addressType = Type::i32; } }; diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 173a89163b2..7e1daf0b11d 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -2246,7 +2246,7 @@ void WasmBinaryReader::readMemories() { getResizableLimits(memory->initial, memory->max, memory->shared, - memory->indexType, + memory->addressType, Memory::kUnlimitedSize); wasm.addMemory(std::move(memory)); } @@ -2491,7 +2491,7 @@ Memory* WasmBinaryReader::getMemory(Index index) { void WasmBinaryReader::getResizableLimits(Address& initial, Address& max, bool& shared, - Type& indexType, + Type& addressType, Address defaultIfNoMax) { auto flags = getU32LEB(); bool hasMax = (flags & BinaryConsts::HasMaximum) != 0; @@ -2502,7 +2502,7 @@ void WasmBinaryReader::getResizableLimits(Address& initial, throwError("shared memory must have max size"); } shared = isShared; - indexType = is64 ? Type::i64 : Type::i32; + addressType = is64 ? Type::i64 : Type::i32; if (hasMax) { max = is64 ? getU64LEB() : getU32LEB(); } else { @@ -2552,7 +2552,7 @@ void WasmBinaryReader::readImports() { getResizableLimits(table->initial, table->max, is_shared, - table->indexType, + table->addressType, Table::kUnlimitedSize); if (is_shared) { throwError("Tables may not be shared"); @@ -2568,7 +2568,7 @@ void WasmBinaryReader::readImports() { getResizableLimits(memory->initial, memory->max, memory->shared, - memory->indexType, + memory->addressType, Memory::kUnlimitedSize); wasm.addMemory(std::move(memory)); break; @@ -3393,7 +3393,7 @@ void WasmBinaryReader::readTableDeclarations() { getResizableLimits(table->initial, table->max, is_shared, - table->indexType, + table->addressType, Table::kUnlimitedSize); if (is_shared) { throwError("Tables may not be shared"); @@ -4706,7 +4706,7 @@ Index WasmBinaryReader::readMemoryAccess(Address& alignment, Address& offset) { throwError("Memory index out of range while reading memory alignment."); } auto* memory = wasm.memories[memIdx].get(); - offset = memory->indexType == Type::i32 ? getU32LEB() : getU64LEB(); + offset = memory->addressType == Type::i32 ? getU32LEB() : getU64LEB(); return memIdx; } diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index 5867c04a06a..5978371d28f 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -993,7 +993,7 @@ void FunctionValidator::visitCallIndirect(CallIndirect* curr) { if (shouldBeTrue(!!table, curr, "call-indirect table must exist")) { shouldBeEqualOrFirstIsUnreachable( curr->target->type, - table->indexType, + table->addressType, curr, "call-indirect call target must match the table index type"); shouldBeTrue(!!table, curr, "call-indirect table must exist"); @@ -1095,7 +1095,7 @@ void FunctionValidator::visitLoad(Load* curr) { validateAlignment(curr->align, curr->type, curr->bytes, curr->isAtomic, curr); shouldBeEqualOrFirstIsUnreachable( curr->ptr->type, - memory->indexType, + memory->addressType, curr, "load pointer type must match memory index type"); if (curr->isAtomic) { @@ -1128,7 +1128,7 @@ void FunctionValidator::visitStore(Store* curr) { curr->align, curr->valueType, curr->bytes, curr->isAtomic, curr); shouldBeEqualOrFirstIsUnreachable( curr->ptr->type, - memory->indexType, + memory->addressType, curr, "store pointer must match memory index type"); shouldBeUnequal(curr->value->type, @@ -1152,7 +1152,7 @@ void FunctionValidator::visitAtomicRMW(AtomicRMW* curr) { validateMemBytes(curr->bytes, curr->type, curr); shouldBeEqualOrFirstIsUnreachable( curr->ptr->type, - memory->indexType, + memory->addressType, curr, "AtomicRMW pointer type must match memory index type"); shouldBeEqualOrFirstIsUnreachable(curr->type, @@ -1172,7 +1172,7 @@ void FunctionValidator::visitAtomicCmpxchg(AtomicCmpxchg* curr) { validateMemBytes(curr->bytes, curr->type, curr); shouldBeEqualOrFirstIsUnreachable( curr->ptr->type, - memory->indexType, + memory->addressType, curr, "cmpxchg pointer must match memory index type"); if (curr->expected->type != Type::unreachable && @@ -1206,7 +1206,7 @@ void FunctionValidator::visitAtomicWait(AtomicWait* curr) { curr->type, Type(Type::i32), curr, "AtomicWait must have type i32"); shouldBeEqualOrFirstIsUnreachable( curr->ptr->type, - memory->indexType, + memory->addressType, curr, "AtomicWait pointer must match memory index type"); shouldBeIntOrUnreachable( @@ -1232,7 +1232,7 @@ void FunctionValidator::visitAtomicNotify(AtomicNotify* curr) { curr->type, Type(Type::i32), curr, "AtomicNotify must have type i32"); shouldBeEqualOrFirstIsUnreachable( curr->ptr->type, - memory->indexType, + memory->addressType, curr, "AtomicNotify pointer must match memory index type"); shouldBeEqualOrFirstIsUnreachable( @@ -1408,7 +1408,7 @@ void FunctionValidator::visitSIMDLoad(SIMDLoad* curr) { curr->type, Type(Type::v128), curr, "load_splat must have type v128"); shouldBeEqualOrFirstIsUnreachable( curr->ptr->type, - memory->indexType, + memory->addressType, curr, "load_splat address must match memory index type"); Type memAlignType = Type::none; @@ -1450,7 +1450,7 @@ void FunctionValidator::visitSIMDLoadStoreLane(SIMDLoadStoreLane* curr) { } shouldBeEqualOrFirstIsUnreachable( curr->ptr->type, - memory->indexType, + memory->addressType, curr, "loadX_lane or storeX_lane address must match memory index type"); shouldBeEqualOrFirstIsUnreachable( @@ -1500,7 +1500,7 @@ void FunctionValidator::visitMemoryInit(MemoryInit* curr) { curr->type, Type(Type::none), curr, "memory.init must have type none"); shouldBeEqualOrFirstIsUnreachable( curr->dest->type, - memory->indexType, + memory->addressType, curr, "memory.init dest must match memory index type"); shouldBeEqualOrFirstIsUnreachable(curr->offset->type, @@ -1542,22 +1542,22 @@ void FunctionValidator::visitMemoryCopy(MemoryCopy* curr) { shouldBeTrue(!!sourceMemory, curr, "memory.copy sourceMemory must exist"); shouldBeEqualOrFirstIsUnreachable( curr->dest->type, - destMemory->indexType, + destMemory->addressType, curr, "memory.copy dest must match destMemory index type"); shouldBeEqualOrFirstIsUnreachable( curr->source->type, - sourceMemory->indexType, + sourceMemory->addressType, curr, "memory.copy source must match sourceMemory index type"); shouldBeEqualOrFirstIsUnreachable( curr->size->type, - destMemory->indexType, + destMemory->addressType, curr, "memory.copy size must match destMemory index type"); shouldBeEqualOrFirstIsUnreachable( curr->size->type, - sourceMemory->indexType, + sourceMemory->addressType, curr, "memory.copy size must match destMemory index type"); } @@ -1572,7 +1572,7 @@ void FunctionValidator::visitMemoryFill(MemoryFill* curr) { curr->type, Type(Type::none), curr, "memory.fill must have type none"); shouldBeEqualOrFirstIsUnreachable( curr->dest->type, - memory->indexType, + memory->addressType, curr, "memory.fill dest must match memory index type"); shouldBeEqualOrFirstIsUnreachable(curr->value->type, @@ -1581,7 +1581,7 @@ void FunctionValidator::visitMemoryFill(MemoryFill* curr) { "memory.fill value must be an i32"); shouldBeEqualOrFirstIsUnreachable( curr->size->type, - memory->indexType, + memory->addressType, curr, "memory.fill size must match memory index type"); shouldBeTrue(!!memory, curr, "memory.fill memory must exist"); @@ -2257,7 +2257,7 @@ void FunctionValidator::visitMemoryGrow(MemoryGrow* curr) { auto* memory = getModule()->getMemoryOrNull(curr->memory); shouldBeTrue(!!memory, curr, "memory.grow memory must exist"); shouldBeEqualOrFirstIsUnreachable(curr->delta->type, - memory->indexType, + memory->addressType, curr, "memory.grow must match memory index type"); } @@ -2399,7 +2399,7 @@ void FunctionValidator::visitTableGet(TableGet* curr) { } shouldBeEqualOrFirstIsUnreachable( curr->index->type, - table->indexType, + table->addressType, curr, "table.get index must match the table index type."); } @@ -2419,7 +2419,7 @@ void FunctionValidator::visitTableSet(TableSet* curr) { } shouldBeEqualOrFirstIsUnreachable( curr->index->type, - table->indexType, + table->addressType, curr, "table.set index must match the table index type."); } @@ -2447,7 +2447,7 @@ void FunctionValidator::visitTableGrow(TableGrow* curr) { curr, "table.grow value must have right type"); shouldBeEqual(curr->delta->type, - table->indexType, + table->addressType, curr, "table.grow must match table index type"); } @@ -2467,12 +2467,12 @@ void FunctionValidator::visitTableFill(TableFill* curr) { "table.fill value must have right type"); shouldBeEqualOrFirstIsUnreachable( curr->dest->type, - table->indexType, + table->addressType, curr, "table.fill dest must match table index type"); shouldBeEqualOrFirstIsUnreachable( curr->size->type, - table->indexType, + table->addressType, curr, "table.fill size must match table index type"); } @@ -2492,11 +2492,11 @@ void FunctionValidator::visitTableCopy(TableCopy* curr) { "table.copy source must have right type for dest"); } shouldBeEqualOrFirstIsUnreachable(curr->dest->type, - destTable->indexType, + destTable->addressType, curr, "table.copy dest must be valid"); shouldBeEqualOrFirstIsUnreachable(curr->source->type, - sourceTable->indexType, + sourceTable->addressType, curr, "table.copy source must be valid"); Type sizeType = @@ -2519,7 +2519,7 @@ void FunctionValidator::visitTableInit(TableInit* curr) { "table.init source must have right type for dest"); } shouldBeEqualOrFirstIsUnreachable( - curr->dest->type, table->indexType, curr, "table.init dest must be valid"); + curr->dest->type, table->addressType, curr, "table.init dest must be valid"); shouldBeEqualOrFirstIsUnreachable(curr->offset->type, Type(Type::i32), curr, @@ -3905,7 +3905,7 @@ static void validateDataSegments(Module& module, ValidationInfo& info) { continue; } info.shouldBeEqual(segment->offset->type, - memory->indexType, + memory->addressType, segment->offset, "segment offset must match memory index type"); info.shouldBeTrue( @@ -4000,7 +4000,7 @@ static void validateTables(Module& module, ValidationInfo& info) { info.shouldBeTrue( !!segment->offset, "elem", "table segment offset must have an offset"); info.shouldBeEqual(segment->offset->type, - table->indexType, + table->addressType, segment->offset, "element segment offset must match table index type"); info.shouldBeTrue(