def visitMethod_call(self, ctx: DecafParser.Method_callContext): if ctx.method_name(): for i in range(len(ctx.expr())): self.visit(ctx.expr(i)) self.st.stack_pointer[-1] += 8 self.body += 'movq %rax, ' + str(-self.st.stack_pointer[-1]) + '(%rsp)\n' for i in range(len(ctx.expr())): self.body += 'movq ' + str(-self.st.stack_pointer[-1]) + '(%rsp), ' + param_registers[ len(ctx.expr()) - i - 1] + '\n' self.st.stack_pointer[-1] -= 8 # adjust stack to 16-byte alignment (multiple of 8 that is not divisible by 16) stack_len = self.st.stack_pointer[-1] stack_len = stack_len + (stack_len // 8 + 1 % 2) * 8 self.body += 'subq $' + str(stack_len) + ', %rsp\n' method_name = ctx.method_name().getText() self.body += 'call ' + method_name + '\n' self.body += 'addq $' + str(stack_len) + ', %rsp\n' elif ctx.CALLOUT(): for i in range(len(ctx.callout_arg())): if ctx.callout_arg(i).STRING_LITERAL(): callout_arg = ctx.callout_arg(i).getText() label = 'str' + str(ctx.callout_arg(i).start.start) self.head += label + ': .asciz ' + callout_arg + '\n' self.st.stack_pointer[-1] += 8 self.body += 'movq $' + label + ', ' + str(-self.st.stack_pointer[-1]) + '(%rsp)\n' else: pass
def visitMethod_call(self, ctx:DecafParser.Method_callContext): if ctx.method_name(): for i in range(len(ctx.expr())): self.visit(ctx.expr(i)) self.st.stack_pointer[-1] += 8 ptr = self.st.stack_pointer[-1] self.body += 'movq %rax, ' + str(ptr) + '(%rsp)\n' for z in range(len(ctx.expr())): ptr = self.st.stack_pointer[-1] reg = param_registers[z] self.body += 'movq ' + str(ptr) + '(% rsp), ' + reg + '\n' self.st.stack_pointer[-1] -= 8 #Current pos stored in symbol table #Needs to be 16 byte aligned or we get segmentation errors stack_len = self.st.stack_pointer[-1] stack_len = stack_len + (int(stack_len/8+1) % 2) * 8 self.body += 'subq $' + str(stack_len) + ', %rsp\n' method_name = ctx.method_name().getText() self.body += 'call ' + method_name + '\n' self.body += 'addq $' + str(stack_len) + ', %rsp\n' elif ctx.CALLOUT(): pass else: self.visitChildren(ctx)