#ifndef wasm_ir_import_h
#define wasm_ir_import_h
#include "literal.h"
#include "wasm.h"
namespace wasm {
struct ImportInfo {
Module& wasm;
std::vector<Global*> importedGlobals;
std::vector<Function*> importedFunctions;
std::vector<Event*> importedEvents;
ImportInfo(Module& wasm) : wasm(wasm) {
for (auto& import : wasm.globals) {
if (import->imported()) {
importedGlobals.push_back(import.get());
}
}
for (auto& import : wasm.functions) {
if (import->imported()) {
importedFunctions.push_back(import.get());
}
}
for (auto& import : wasm.events) {
if (import->imported()) {
importedEvents.push_back(import.get());
}
}
}
Global* getImportedGlobal(Name module, Name base) {
for (auto* import : importedGlobals) {
if (import->module == module && import->base == base) {
return import;
}
}
return nullptr;
}
Function* getImportedFunction(Name module, Name base) {
for (auto* import : importedFunctions) {
if (import->module == module && import->base == base) {
return import;
}
}
return nullptr;
}
Event* getImportedEvent(Name module, Name base) {
for (auto* import : importedEvents) {
if (import->module == module && import->base == base) {
return import;
}
}
return nullptr;
}
Index getNumImportedGlobals() { return importedGlobals.size(); }
Index getNumImportedFunctions() { return importedFunctions.size(); }
Index getNumImportedEvents() { return importedEvents.size(); }
Index getNumImports() {
return getNumImportedGlobals() + getNumImportedFunctions() +
getNumImportedEvents() + (wasm.memory.imported() ? 1 : 0) +
(wasm.table.imported() ? 1 : 0);
}
Index getNumDefinedGlobals() {
return wasm.globals.size() - getNumImportedGlobals();
}
Index getNumDefinedFunctions() {
return wasm.functions.size() - getNumImportedFunctions();
}
Index getNumDefinedEvents() {
return wasm.events.size() - getNumImportedEvents();
}
};
}
#endif