Skip to content

Commit a747bd6

Browse files
committed
fix segfault
1 parent c352a41 commit a747bd6

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

source/backends/rm86.d

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ private struct Word {
1717
Node[] inlineNodes;
1818
bool error;
1919
Type[] params;
20+
size_t numReturns;
21+
22+
int StackEffect() => (-(cast(int) params.length) + (cast(int) numReturns));
2023
}
2124

2225
private struct RM86Opts {
@@ -279,6 +282,16 @@ class BackendRM86 : CompilerBackend {
279282
}
280283
else {
281284
if (word.raw) {
285+
int stackEffect = word.StackEffect() * 8;
286+
287+
if (stackEffect != 0) {
288+
output ~= format("lea ax, [si + %d]\n", stackEffect);
289+
output ~= "push ax\n";
290+
}
291+
else {
292+
output ~= "push si\n";
293+
}
294+
282295
output ~= format("call %s\n", node.name);
283296
}
284297
else {

source/backends/x86_64.d

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -525,21 +525,7 @@ class BackendX86_64 : CompilerBackend {
525525
}
526526
}
527527
else {
528-
int stackEffect = word.StackEffect() * 8;
529-
530-
if (stackEffect != 0) {
531-
output ~= format("lea r14, [r15 + %d]\n", stackEffect);
532-
output ~= "push r14\n";
533-
}
534-
else {
535-
output ~= "push r15\n";
536-
}
537-
538528
output ~= format("call __func__%s\n", node.name.Sanitise());
539-
540-
if (word.error) {
541-
output ~= "pop r15\n";
542-
}
543529
}
544530
}
545531

0 commit comments

Comments
 (0)