diff options
Diffstat (limited to 'src/wasm-emscripten.h')
-rw-r--r-- | src/wasm-emscripten.h | 46 |
1 files changed, 33 insertions, 13 deletions
diff --git a/src/wasm-emscripten.h b/src/wasm-emscripten.h index 7400a8b0f..90a7d9a86 100644 --- a/src/wasm-emscripten.h +++ b/src/wasm-emscripten.h @@ -18,27 +18,47 @@ #define wasm_wasm_emscripten_h #include "wasm.h" +#include "wasm-builder.h" namespace wasm { -class LinkerObject; +// Class which modifies a wasm module for use with emscripten. Generates +// runtime functions and emits metadata. +class EmscriptenGlueGenerator { +public: + EmscriptenGlueGenerator(Module& wasm, Address stackPointerOffset = Address(0)) + : wasm(wasm), + builder(wasm), + stackPointerOffset(stackPointerOffset) { } -namespace emscripten { + void generateRuntimeFunctions(); + void generateMemoryGrowthFunction(); -void generateRuntimeFunctions(LinkerObject& linker); -void generateMemoryGrowthFunction(Module&); + // Create thunks for use with emscripten Runtime.dynCall. Creates one for each + // signature in the indirect function table. + void generateDynCallThunks(); -// Create thunks for use with emscripten Runtime.dynCall. Creates one for each -// signature in the indirect function table. -std::vector<Function*> makeDynCallThunks(Module& wasm, std::vector<Name> const& tableSegmentData); + std::string generateEmscriptenMetadata( + Address staticBump, std::vector<Name> const& initializerFunctions); -void generateEmscriptenMetadata(std::ostream& o, - Module& wasm, - std::unordered_map<Address, Address> segmentsByAddress, - Address staticBump, - std::vector<Name> const& initializerFunctions); +private: + Module& wasm; + Builder builder; + Address stackPointerOffset; -} // namespace emscripten + Load* generateLoadStackPointer(); + Store* generateStoreStackPointer(Expression* value); + void generateStackSaveFunction(); + void generateStackAllocFunction(); + void generateStackRestoreFunction(); +}; + +std::string emscriptenGlue( + Module& wasm, + bool allowMemoryGrowth, + Address stackPointer, + Address staticBump, + std::vector<Name> const& initializerFunctions); } // namespace wasm |