Skip to content

Commit

Permalink
fix segfault
Browse files Browse the repository at this point in the history
  • Loading branch information
yeti0904 committed Nov 12, 2024
1 parent c352a41 commit a747bd6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
13 changes: 13 additions & 0 deletions source/backends/rm86.d
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ private struct Word {
Node[] inlineNodes;
bool error;
Type[] params;
size_t numReturns;

int StackEffect() => (-(cast(int) params.length) + (cast(int) numReturns));
}

private struct RM86Opts {
Expand Down Expand Up @@ -279,6 +282,16 @@ class BackendRM86 : CompilerBackend {
}
else {
if (word.raw) {
int stackEffect = word.StackEffect() * 8;

if (stackEffect != 0) {
output ~= format("lea ax, [si + %d]\n", stackEffect);
output ~= "push ax\n";
}
else {
output ~= "push si\n";
}

output ~= format("call %s\n", node.name);
}
else {
Expand Down
14 changes: 0 additions & 14 deletions source/backends/x86_64.d
Original file line number Diff line number Diff line change
Expand Up @@ -525,21 +525,7 @@ class BackendX86_64 : CompilerBackend {
}
}
else {
int stackEffect = word.StackEffect() * 8;

if (stackEffect != 0) {
output ~= format("lea r14, [r15 + %d]\n", stackEffect);
output ~= "push r14\n";
}
else {
output ~= "push r15\n";
}

output ~= format("call __func__%s\n", node.name.Sanitise());

if (word.error) {
output ~= "pop r15\n";
}
}
}

Expand Down

0 comments on commit a747bd6

Please sign in to comment.