Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/abi/stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ inline Index stackAlign(Index size) {
// Allocate some space on the stack, and assign it to a local.
// The local will have the same constant value in all the function, so you can
// just local.get it anywhere there.
//
// FIXME: This function assumes that the stack grows upward, per the convention
// used by fastcomp. The stack grows downward when using the WASM backend.

inline void
getStackSpace(Index local, Function* func, Index size, Module& wasm) {
Expand All @@ -55,22 +52,25 @@ getStackSpace(Index local, Function* func, Index size, Module& wasm) {
// TODO: find existing stack usage, and add on top of that - carefully
Builder builder(wasm);
auto* block = builder.makeBlock();
block->list.push_back(builder.makeLocalSet(
local, builder.makeGlobalGet(stackPointer->name, pointerType)));
// TODO: add stack max check
Expression* added;
if (pointerType == Type::i32) {
// The stack goes downward in the LLVM wasm backend.
added = builder.makeBinary(SubInt32,
builder.makeLocalGet(local, pointerType),
builder.makeConst(int32_t(size)));
added =
builder.makeBinary(SubInt32,
builder.makeGlobalGet(stackPointer->name, pointerType),
builder.makeConst(int32_t(size)));
} else {
WASM_UNREACHABLE("unhandled pointerType");
}
block->list.push_back(builder.makeGlobalSet(stackPointer->name, added));
block->list.push_back(builder.makeGlobalSet(
stackPointer->name, builder.makeLocalTee(local, added, pointerType)));
auto makeStackRestore = [&]() {
return builder.makeGlobalSet(stackPointer->name,
builder.makeLocalGet(local, pointerType));
return builder.makeGlobalSet(
stackPointer->name,
builder.makeBinary(AddInt32,
builder.makeLocalGet(local, pointerType),
builder.makeConst(int32_t(size))));
};
// add stack restores to the returns
FindAllPointers<Return> finder(func->body);
Expand Down
Loading