Fix check for when stack frame is needed
This commit is contained in:
parent
c37e48e8b2
commit
3fa0e5f655
|
@ -586,14 +586,21 @@ class CompileData:
|
|||
break
|
||||
saved_registers = list(saved_registers)
|
||||
|
||||
does_call = False
|
||||
# Stack frame is needed for builtin functions, functions with local variables
|
||||
# and functions that call other functions
|
||||
needs_stack_frame = False
|
||||
if name.startswith('__builtin'):
|
||||
needs_stack_frame = True
|
||||
elif name in self.sem_data.callables and len(self.sem_data.callables[name].children_formals) > 0:
|
||||
needs_stack_frame = True
|
||||
else:
|
||||
for instruction in code:
|
||||
if instruction.opcode == 'call':
|
||||
does_call = True
|
||||
needs_stack_frame = True
|
||||
break
|
||||
|
||||
code_str += name + ':\n'
|
||||
if does_call:
|
||||
if needs_stack_frame:
|
||||
code_str += ' pushq %rbp\n'
|
||||
code_str += ' movq %rsp, %rbp\n'
|
||||
for reg in saved_registers:
|
||||
|
@ -609,7 +616,7 @@ class CompileData:
|
|||
code_str += ' addq $8, %rsp\n'
|
||||
for reg in reversed(saved_registers):
|
||||
code_str += f' popq {reg}\n'
|
||||
if does_call:
|
||||
if needs_stack_frame:
|
||||
code_str += ' leave\n'
|
||||
code_str += ' ret\n'
|
||||
code_str += '\n'
|
||||
|
|
Loading…
Reference in New Issue