@@ -78,58 +78,6 @@ struct OptimizeCalls : public WalkerPass<PostWalker<OptimizeCalls>> {
7878
7979struct PostEmscripten : public Pass {
8080 void run (PassRunner* runner, Module* module ) override {
81- // Apply the stack pointer, if it was provided. This is needed here
82- // because the emscripten JS compiler can add static data allocations that
83- // come before the stack.
84- auto stackPtrStr =
85- runner->options .getArgumentOrDefault (" stack-pointer" , " " );
86- if (stackPtrStr != " " ) {
87- Global* stackPointer = getStackPointerGlobal (*module );
88- BYN_TRACE (" stack_pointer: " << stackPtrStr << " \n " );
89- if (stackPointer && !stackPointer->imported ()) {
90- auto stackPtr = std::stoi (stackPtrStr);
91- auto oldValue = stackPointer->init ->cast <Const>()->value ;
92- BYN_TRACE (" updating __stack_pointer: " << oldValue.geti32 () << " -> "
93- << stackPtr << " \n " );
94- stackPointer->init = Builder (*module ).makeConst (int32_t (stackPtr));
95- }
96- }
97-
98- // Apply the sbrk ptr, if it was provided.
99- auto sbrkPtrStr =
100- runner->options .getArgumentOrDefault (" emscripten-sbrk-ptr" , " " );
101- if (sbrkPtrStr != " " ) {
102- auto sbrkPtr = std::stoi (sbrkPtrStr);
103- ImportInfo imports (*module );
104- auto * func = imports.getImportedFunction (ENV , " emscripten_get_sbrk_ptr" );
105- if (func) {
106- Builder builder (*module );
107- func->body = builder.makeConst (int32_t (sbrkPtr));
108- func->module = func->base = Name ();
109- }
110- // Apply the sbrk ptr value, if it was provided. This lets emscripten set
111- // up sbrk entirely in wasm, without depending on the JS side to init
112- // anything; this is necessary for standalone wasm mode, in which we do
113- // not have any JS. Otherwise, the JS would set this value during
114- // startup.
115- auto sbrkValStr =
116- runner->options .getArgumentOrDefault (" emscripten-sbrk-val" , " " );
117- if (sbrkValStr != " " ) {
118- uint32_t sbrkVal = std::stoi (sbrkValStr);
119- auto end = sbrkPtr + sizeof (sbrkVal);
120- // Flatten memory to make it simple to write to. Later passes can
121- // re-optimize it.
122- MemoryUtils::ensureExists (module ->memory );
123- if (!MemoryUtils::flatten (module ->memory , end, module )) {
124- Fatal () << " cannot apply sbrk-val since memory is not flattenable\n " ;
125- }
126- auto & segment = module ->memory .segments [0 ];
127- assert (segment.offset ->cast <Const>()->value .geti32 () == 0 );
128- assert (end <= segment.data .size ());
129- memcpy (segment.data .data () + sbrkPtr, &sbrkVal, sizeof (sbrkVal));
130- }
131- }
132-
13381 // Optimize imports
13482 optimizeImports (runner, module );
13583
0 commit comments