summaryrefslogtreecommitdiff
path: root/src/wasm.h
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-04-04 14:34:02 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-04-04 14:34:10 -0700
commit9fb040740ec3ca1c298ecd95f21c071ab1ab170e (patch)
tree9726c9c7b7e94fb4bd1a277b0436d1abe096b6aa /src/wasm.h
parent891807fbf2c97df974b38fae5abc353d6843c8f1 (diff)
downloadbinaryen-9fb040740ec3ca1c298ecd95f21c071ab1ab170e.tar.gz
binaryen-9fb040740ec3ca1c298ecd95f21c071ab1ab170e.tar.bz2
binaryen-9fb040740ec3ca1c298ecd95f21c071ab1ab170e.zip
add apis for accessing module elements
Diffstat (limited to 'src/wasm.h')
-rw-r--r--src/wasm.h28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/wasm.h b/src/wasm.h
index af767b688..a07ab3079 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -1114,23 +1114,41 @@ public:
class Module {
public:
- // internal wasm contents (don't access these from outside; use add*() and the *Map objects)
+ // wasm contents (generally you shouldn't access these from outside, except maybe for iterating; use add*() and the get() functions)
std::vector<FunctionType*> functionTypes;
std::vector<Import*> imports;
std::vector<Export*> exports;
std::vector<Function*> functions;
- // publicly-accessible content
+ Table table;
+ Memory memory;
+ Name start;
+
+private:
+ // TODO: add a build option where Names are just indices, and then these methods are not needed
std::map<Name, FunctionType*> functionTypesMap;
std::map<Name, Import*> importsMap;
std::map<Name, Export*> exportsMap;
std::map<Name, Function*> functionsMap;
- Table table;
- Memory memory;
- Name start;
+public:
Module() : functionTypeIndex(0), importIndex(0), exportIndex(0), functionIndex(0) {}
+ FunctionType* getFunctionType(size_t i) { assert(i < functionTypes.size());return functionTypes[i]; }
+ Import* getImport(size_t i) { assert(i < imports.size()); return imports[i]; }
+ Export* getExport(size_t i) { assert(i < exports.size()); return exports[i]; }
+ Function* getFunction(size_t i) { assert(i < functions.size()); return functions[i]; }
+
+ FunctionType* getFunctionType(Name name) { assert(functionTypesMap[name]); return functionTypesMap[name]; }
+ Import* getImport(Name name) { assert(importsMap[name]); return importsMap[name]; }
+ Export* getExport(Name name) { assert(exportsMap[name]); return exportsMap[name]; }
+ Function* getFunction(Name name) { assert(functionsMap[name]); return functionsMap[name]; }
+
+ FunctionType* checkFunctionType(Name name) { if (functionTypesMap.find(name) == functionTypesMap.end()) return nullptr; return functionTypesMap[name]; }
+ Import* checkImport(Name name) { if (importsMap.find(name) == importsMap.end()) return nullptr; return importsMap[name]; }
+ Export* checkExport(Name name) { if (exportsMap.find(name) == exportsMap.end()) return nullptr; return exportsMap[name]; }
+ Function* checkFunction(Name name) { if (functionsMap.find(name) == functionsMap.end()) return nullptr; return functionsMap[name]; }
+
void addFunctionType(FunctionType* curr) {
Name numericName = Name::fromInt(functionTypeIndex); // TODO: remove all these, assert on names already existing, do numeric stuff in wasm-s-parser etc.
if (curr->name.isNull()) {