summaryrefslogtreecommitdiff
path: root/src/wasm-linker.h
diff options
context:
space:
mode:
authorjgravelle-google <jgravelle@google.com>2016-11-30 15:34:39 -0800
committerGitHub <noreply@github.com>2016-11-30 15:34:39 -0800
commit4caea4872aed6d1cb7ef42c9a2364870eb574e41 (patch)
treefdaf20b77bd46d1da14d57a7401525ddf9f6850e /src/wasm-linker.h
parent36be3e0151dd7357e47b2d8f432bdd706a30466c (diff)
downloadbinaryen-4caea4872aed6d1cb7ef42c9a2364870eb574e41.tar.gz
binaryen-4caea4872aed6d1cb7ef42c9a2364870eb574e41.tar.bz2
binaryen-4caea4872aed6d1cb7ef42c9a2364870eb574e41.zip
Handle importing globals in s2wasm (#843)
* Handle importing globals in s2wasm * Make importedGlobals a set of Names, make Names hashable * Revert "Make importedGlobals a set of Names, make Names hashable" This reverts commit 1d0ca7a5e3839b15ca60593330979864c9c3ed60. * Refactor relocation parsing to handle expressions directly * PR Feedback - Move comment where it belongs - Add comment about ownership to addRelocation - Remove do-nothing parseImportGlobal * Reword "imported globals" to "imported objects" - Flip isObjectImported to isObjectImplemented, for consistency * Add tests for s2wasm globals. Also implement import relocation expression handling * Simplify globals.s test * Fix memory leak of relocation * Use unique_ptr instead of delete in getRelocatableExpression
Diffstat (limited to 'src/wasm-linker.h')
-rw-r--r--src/wasm-linker.h17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/wasm-linker.h b/src/wasm-linker.h
index 3660b3038..76ea62d7d 100644
--- a/src/wasm-linker.h
+++ b/src/wasm-linker.h
@@ -58,6 +58,7 @@ class LinkerObject {
struct SymbolInfo {
std::unordered_set<cashew::IString> implementedFunctions;
std::unordered_set<cashew::IString> undefinedFunctions;
+ std::unordered_set<cashew::IString> importedObjects;
// TODO: it's not clear that this really belongs here.
std::unordered_map<cashew::IString, SymbolAlias> aliasedSymbols;
@@ -70,6 +71,8 @@ class LinkerObject {
}
implementedFunctions.insert(other.implementedFunctions.begin(),
other.implementedFunctions.end());
+ importedObjects.insert(other.importedObjects.begin(),
+ other.importedObjects.end());
aliasedSymbols.insert(other.aliasedSymbols.begin(),
other.aliasedSymbols.end());
}
@@ -86,18 +89,20 @@ class LinkerObject {
globls.push_back(name);
}
- void addRelocation(Relocation::Kind kind, uint32_t* target, Name name, int addend) {
- relocations.emplace_back(new Relocation(kind, target, name, addend));
- }
-
- Relocation* getCurrentRelocation() {
- return relocations.back().get();
+ // This takes ownership of the added Relocation
+ void addRelocation(Relocation* relocation) {
+ relocations.emplace_back(relocation);
}
bool isFunctionImplemented(Name name) {
return symbolInfo.implementedFunctions.count(name) != 0;
}
+ // An object is considered implemented if it is not imported
+ bool isObjectImplemented(Name name) {
+ return symbolInfo.importedObjects.count(name) == 0;
+ }
+
// If name is an alias, return what it points to. Otherwise return name.
Name resolveAlias(Name name, Relocation::Kind kind) {
auto aliased = symbolInfo.aliasedSymbols.find(name);