Skip to content

Commit

Permalink
Rename indexType -> addressType. NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 committed Nov 6, 2024
1 parent 92917c2 commit ff022a2
Show file tree
Hide file tree
Showing 27 changed files with 196 additions and 196 deletions.
2 changes: 1 addition & 1 deletion src/abi/stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Export>();
memoryExport->name = exportName;
Expand Down
8 changes: 4 additions & 4 deletions src/ir/child-typer.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ template<typename Subtype> struct ChildTyper : OverriddenVisitor<Subtype> {
}

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); }
Expand Down Expand Up @@ -270,8 +270,8 @@ template<typename Subtype> struct ChildTyper : OverriddenVisitor<Subtype> {
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);
Expand Down Expand Up @@ -762,7 +762,7 @@ template<typename Subtype> struct ChildTyper : OverriddenVisitor<Subtype> {
}

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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ir/module-utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/parser/context-decls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Result<Table*> ParseDeclsCtx::addTableDecl(Index pos,
ImportNames* importNames,
TableType type) {
auto t = std::make_unique<Table>();
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()) {
Expand Down Expand Up @@ -139,7 +139,7 @@ Result<Memory*> ParseDeclsCtx::addMemoryDecl(Index pos,
ImportNames* importNames,
MemType type) {
auto m = std::make_unique<Memory>();
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;
Expand Down Expand Up @@ -178,7 +178,7 @@ Result<> ParseDeclsCtx::addImplicitData(DataStringT&& data) {
auto d = std::make_unique<DataSegment>();
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));
Expand Down
14 changes: 7 additions & 7 deletions src/parser/contexts.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct Limits {
};

struct MemType {
Type indexType;
Type addressType;
Limits limits;
bool shared;
};
Expand All @@ -57,7 +57,7 @@ struct Memarg {
};

struct TableType {
Type indexType;
Type addressType;
Limits limits;
};

Expand Down Expand Up @@ -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<char> makeDataString() { return {}; }
Expand All @@ -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<TypeUseT>
Expand Down Expand Up @@ -1273,7 +1273,7 @@ struct ParseModuleTypesCtx : TypeParserCtx<ParseModuleTypesCtx>,

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{}; }
Expand Down
46 changes: 23 additions & 23 deletions src/parser/parsers.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ template<typename Ctx> Result<typename Ctx::LimitsT> limits32(Ctx&);
template<typename Ctx> Result<typename Ctx::LimitsT> limits64(Ctx&);
template<typename Ctx> Result<typename Ctx::MemTypeT> memtype(Ctx&);
template<typename Ctx>
Result<typename Ctx::MemTypeT> memtypeContinued(Ctx&, Type indexType);
Result<typename Ctx::MemTypeT> memtypeContinued(Ctx&, Type addressType);
template<typename Ctx> Result<typename Ctx::TableTypeT> tabletype(Ctx&);
template<typename Ctx>
Result<typename Ctx::TableTypeT> tabletypeContinued(Ctx&, Type indexType);
Result<typename Ctx::TableTypeT> tabletypeContinued(Ctx&, Type addressType);
template<typename Ctx> Result<typename Ctx::GlobalTypeT> globaltype(Ctx&);
template<typename Ctx> Result<uint32_t> tupleArity(Ctx&);

Expand Down Expand Up @@ -780,45 +780,45 @@ template<typename Ctx> Result<typename Ctx::LimitsT> limits64(Ctx& ctx) {
// note: the index type 'i32' or 'i64' is already parsed to simplify parsing of
// memory abbreviations.
template<typename Ctx> Result<typename Ctx::MemTypeT> 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<typename Ctx>
Result<typename Ctx::MemTypeT> memtypeContinued(Ctx& ctx, Type indexType) {
assert(indexType == Type::i32 || indexType == Type::i64);
auto limits = indexType == Type::i32 ? limits32(ctx) : limits64(ctx);
Result<typename Ctx::MemTypeT> 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<typename Ctx> Result<typename Ctx::TableTypeT> 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<typename Ctx>
Result<typename Ctx::TableTypeT> tabletypeContinued(Ctx& ctx, Type indexType) {
auto limits = indexType == Type::i32 ? limits32(ctx) : limits64(ctx);
Result<typename Ctx::TableTypeT> 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
Expand Down Expand Up @@ -3036,9 +3036,9 @@ template<typename Ctx> 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);
}
Expand Down Expand Up @@ -3077,10 +3077,10 @@ template<typename Ctx> 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;
}
Expand Down Expand Up @@ -3119,9 +3119,9 @@ template<typename Ctx> 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);
}
Expand All @@ -3137,10 +3137,10 @@ template<typename Ctx> 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;
}
Expand Down
Loading

0 comments on commit ff022a2

Please sign in to comment.