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
52 changes: 0 additions & 52 deletions src/passes/PostEmscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,58 +78,6 @@ struct OptimizeCalls : public WalkerPass<PostWalker<OptimizeCalls>> {

struct PostEmscripten : public Pass {
void run(PassRunner* runner, Module* module) override {
// Apply the stack pointer, if it was provided. This is needed here
// because the emscripten JS compiler can add static data allocations that
// come before the stack.
auto stackPtrStr =
runner->options.getArgumentOrDefault("stack-pointer", "");
if (stackPtrStr != "") {
Global* stackPointer = getStackPointerGlobal(*module);
BYN_TRACE("stack_pointer: " << stackPtrStr << "\n");
if (stackPointer && !stackPointer->imported()) {
auto stackPtr = std::stoi(stackPtrStr);
auto oldValue = stackPointer->init->cast<Const>()->value;
BYN_TRACE("updating __stack_pointer: " << oldValue.geti32() << " -> "
<< stackPtr << "\n");
stackPointer->init = Builder(*module).makeConst(int32_t(stackPtr));
}
}

// Apply the sbrk ptr, if it was provided.
auto sbrkPtrStr =
runner->options.getArgumentOrDefault("emscripten-sbrk-ptr", "");
if (sbrkPtrStr != "") {
auto sbrkPtr = std::stoi(sbrkPtrStr);
ImportInfo imports(*module);
auto* func = imports.getImportedFunction(ENV, "emscripten_get_sbrk_ptr");
if (func) {
Builder builder(*module);
func->body = builder.makeConst(int32_t(sbrkPtr));
func->module = func->base = Name();
}
// Apply the sbrk ptr value, if it was provided. This lets emscripten set
// up sbrk entirely in wasm, without depending on the JS side to init
// anything; this is necessary for standalone wasm mode, in which we do
// not have any JS. Otherwise, the JS would set this value during
// startup.
auto sbrkValStr =
runner->options.getArgumentOrDefault("emscripten-sbrk-val", "");
if (sbrkValStr != "") {
uint32_t sbrkVal = std::stoi(sbrkValStr);
auto end = sbrkPtr + sizeof(sbrkVal);
// Flatten memory to make it simple to write to. Later passes can
// re-optimize it.
MemoryUtils::ensureExists(module->memory);
if (!MemoryUtils::flatten(module->memory, end, module)) {
Fatal() << "cannot apply sbrk-val since memory is not flattenable\n";
}
auto& segment = module->memory.segments[0];
assert(segment.offset->cast<Const>()->value.geti32() == 0);
assert(end <= segment.data.size());
memcpy(segment.data.data() + sbrkPtr, &sbrkVal, sizeof(sbrkVal));
}
}

// Optimize imports
optimizeImports(runner, module);

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions test/passes/post-emscripten_pass-arg=stack-pointer@1234.txt

This file was deleted.

4 changes: 0 additions & 4 deletions test/passes/post-emscripten_pass-arg=stack-pointer@1234.wast

This file was deleted.