Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/ir/effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace wasm {

class EffectAnalyzer {
public:
EffectAnalyzer(const PassOptions& passOptions, Module& module)
EffectAnalyzer(const PassOptions& passOptions, const Module& module)
: ignoreImplicitTraps(passOptions.ignoreImplicitTraps),
trapsNeverHappen(passOptions.trapsNeverHappen), branchesOut(false),
calls(false), readsMemory(false), writesMemory(false),
Expand All @@ -46,7 +46,7 @@ class EffectAnalyzer {
features(module.features) {}

EffectAnalyzer(const PassOptions& passOptions,
Module& module,
const Module& module,
Expression* ast)
: EffectAnalyzer(passOptions, module) {
walk(ast);
Expand Down Expand Up @@ -136,7 +136,7 @@ class EffectAnalyzer {
// more here.)
bool hasReturnCallThrow : 1;

Module& module;
const Module& module;
FeatureSet features;

std::set<Index> localsRead;
Expand Down
4 changes: 2 additions & 2 deletions src/ir/intrinsics.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
namespace wasm {

class Intrinsics {
Module& module;
const Module& module;

public:
Intrinsics(Module& module) : module(module) {}
Intrinsics(const Module& module) : module(module) {}

// Check if an instruction is the Binaryen call.without.effects intrinsic.
//
Expand Down
2 changes: 1 addition & 1 deletion src/ir/js-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ inline bool hasPossibleJSPrototypeField(HeapType type) {

// Calls flowIn and flowOut on all types that may flow in from or out to JS.
template<typename In, typename Out>
void iterJSInterface(Module& wasm, In flowIn, Out flowOut) {
void iterJSInterface(const Module& wasm, In flowIn, Out flowOut) {
// @binaryen.js.called functions are called from JS. Their parameters flow
// in from JS and their results flow back out.
for (auto f : Intrinsics(wasm).getJSCalledFunctions()) {
Expand Down
2 changes: 1 addition & 1 deletion src/passes/Unsubtyping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ struct Unsubtyping : Pass, Noter<Unsubtyping> {
}
}

void analyzeJSInterface(Module& wasm) {
void analyzeJSInterface(const Module& wasm) {
if (!wasm.features.hasCustomDescriptors()) {
return;
}
Expand Down
38 changes: 19 additions & 19 deletions src/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -2699,30 +2699,30 @@ class Module {
public:
Module() = default;

Export* getExport(Name name);
Function* getFunction(Name name);
Table* getTable(Name name);
ElementSegment* getElementSegment(Name name);
Memory* getMemory(Name name);
DataSegment* getDataSegment(Name name);
Global* getGlobal(Name name);
Tag* getTag(Name name);

Export* getExportOrNull(Name name);
Table* getTableOrNull(Name name);
Memory* getMemoryOrNull(Name name);
ElementSegment* getElementSegmentOrNull(Name name);
DataSegment* getDataSegmentOrNull(Name name);
Function* getFunctionOrNull(Name name);
Global* getGlobalOrNull(Name name);
Tag* getTagOrNull(Name name);
Export* getExport(Name name) const;
Function* getFunction(Name name) const;
Table* getTable(Name name) const;
ElementSegment* getElementSegment(Name name) const;
Memory* getMemory(Name name) const;
DataSegment* getDataSegment(Name name) const;
Global* getGlobal(Name name) const;
Tag* getTag(Name name) const;

Export* getExportOrNull(Name name) const;
Table* getTableOrNull(Name name) const;
Memory* getMemoryOrNull(Name name) const;
ElementSegment* getElementSegmentOrNull(Name name) const;
DataSegment* getDataSegmentOrNull(Name name) const;
Function* getFunctionOrNull(Name name) const;
Global* getGlobalOrNull(Name name) const;
Tag* getTagOrNull(Name name) const;

// get* methods that are generic over the kind, that is, items are identified
// by their kind and their name. Otherwise, they are similar to the above
// get* methods. These return items that can be imports.
// TODO: Add methods for things that cannot be imports (segments).
Importable* getImport(ModuleItemKind kind, Name name);
Importable* getImportOrNull(ModuleItemKind kind, Name name);
Importable* getImport(ModuleItemKind kind, Name name) const;
Importable* getImportOrNull(ModuleItemKind kind, Name name) const;

Export* addExport(Export* curr);
Function* addFunction(Function* curr);
Expand Down
61 changes: 33 additions & 28 deletions src/wasm/wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@

namespace wasm {

namespace {

template<typename Value>
const Value& getModuleElement(const std::unordered_map<Name, Value>& m,
Name name,
std::string_view funcName) {
auto iter = m.find(name);
if (iter == m.end()) {
Fatal() << "Module::" << funcName << ": " << name << " does not exist";
}
return iter->second;
}

} // namespace

// shared constants

Name RETURN_FLOW("*return:)*");
Expand Down Expand Up @@ -1705,45 +1720,35 @@ void Function::clearDebugInfo() {
epilogLocation.reset();
}

template<typename Map>
typename Map::mapped_type&
getModuleElement(Map& m, Name name, std::string_view funcName) {
auto iter = m.find(name);
if (iter == m.end()) {
Fatal() << "Module::" << funcName << ": " << name << " does not exist";
}
return iter->second;
}

Export* Module::getExport(Name name) {
Export* Module::getExport(Name name) const {
return getModuleElement(exportsMap, name, "getExport");
}

Function* Module::getFunction(Name name) {
Function* Module::getFunction(Name name) const {
return getModuleElement(functionsMap, name, "getFunction");
}

Table* Module::getTable(Name name) {
Table* Module::getTable(Name name) const {
return getModuleElement(tablesMap, name, "getTable");
}

ElementSegment* Module::getElementSegment(Name name) {
ElementSegment* Module::getElementSegment(Name name) const {
return getModuleElement(elementSegmentsMap, name, "getElementSegment");
}

Memory* Module::getMemory(Name name) {
Memory* Module::getMemory(Name name) const {
return getModuleElement(memoriesMap, name, "getMemory");
}

DataSegment* Module::getDataSegment(Name name) {
DataSegment* Module::getDataSegment(Name name) const {
return getModuleElement(dataSegmentsMap, name, "getDataSegment");
}

Global* Module::getGlobal(Name name) {
Global* Module::getGlobal(Name name) const {
return getModuleElement(globalsMap, name, "getGlobal");
}

Tag* Module::getTag(Name name) {
Tag* Module::getTag(Name name) const {
return getModuleElement(tagsMap, name, "getTag");
}

Expand All @@ -1756,39 +1761,39 @@ typename Map::mapped_type getModuleElementOrNull(Map& m, Name name) {
return iter->second;
}

Export* Module::getExportOrNull(Name name) {
Export* Module::getExportOrNull(Name name) const {
return getModuleElementOrNull(exportsMap, name);
}

Function* Module::getFunctionOrNull(Name name) {
Function* Module::getFunctionOrNull(Name name) const {
return getModuleElementOrNull(functionsMap, name);
}

Table* Module::getTableOrNull(Name name) {
Table* Module::getTableOrNull(Name name) const {
return getModuleElementOrNull(tablesMap, name);
}

ElementSegment* Module::getElementSegmentOrNull(Name name) {
ElementSegment* Module::getElementSegmentOrNull(Name name) const {
return getModuleElementOrNull(elementSegmentsMap, name);
}

Memory* Module::getMemoryOrNull(Name name) {
Memory* Module::getMemoryOrNull(Name name) const {
return getModuleElementOrNull(memoriesMap, name);
}

DataSegment* Module::getDataSegmentOrNull(Name name) {
DataSegment* Module::getDataSegmentOrNull(Name name) const {
return getModuleElementOrNull(dataSegmentsMap, name);
}

Global* Module::getGlobalOrNull(Name name) {
Global* Module::getGlobalOrNull(Name name) const {
return getModuleElementOrNull(globalsMap, name);
}

Tag* Module::getTagOrNull(Name name) {
Tag* Module::getTagOrNull(Name name) const {
return getModuleElementOrNull(tagsMap, name);
}

Importable* Module::getImport(ModuleItemKind kind, Name name) {
Importable* Module::getImport(ModuleItemKind kind, Name name) const {
switch (kind) {
case ModuleItemKind::Function:
return getFunction(name);
Expand All @@ -1809,7 +1814,7 @@ Importable* Module::getImport(ModuleItemKind kind, Name name) {
WASM_UNREACHABLE("unexpected kind");
}

Importable* Module::getImportOrNull(ModuleItemKind kind, Name name) {
Importable* Module::getImportOrNull(ModuleItemKind kind, Name name) const {
auto doReturn = [](Importable* importable) {
return importable ? importable->imported() ? importable : nullptr : nullptr;
};
Expand Down
Loading