// File: /workspace/github_cpp_makefile_star2_O3/kelwinfc[P]ci4721-Fernandez-Gyomrey/src/AST.cpp
// Function: AST_function::AST_function(int, tokenId*, AST_arg_list*, AST_block*)
AST_function::AST_function(TYPE t, tokenId* id, AST_arg_list* args,
                           AST_block* code
                          )
{
    line = id->line;
    column = id->column;
    
    vector< symbol* >::iterator it;
    vector< TYPE > types;
    for (it = args->args.begin(); it != args->args.end(); ++ it){
        types.push_back( (*it)->getType() );
    }
    
    if ( t ){
        func = new symbol_function(id->ident, t, id->line, id->column,
                                   types);
    } else {
        func = new symbol_function(id->ident, id->line, id->column, types );
    }
    
    delete id;
    
    formal_parameters = args;
    instructions = code;
    
    if ( func->getType() != NONE ){
        if ( code->has_return == NO ){
            // Reportar error de tipo de argumento
            logger->buf << "Función '" << id->ident << "' sin retorno.";
            logger->error(line, column);
        } else if ( code->has_return == MAYBE ){
            logger->buf << "Función '" << id->ident << "' posiblemente sin retorno.";
            logger->warning(line, column);
        }
    }
    has_return = NO;
    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r8, 0x30(%rsp)
movq %rcx, %r12
movq %rdx, %r14
movl %esi, 0xc(%rsp)
movq %rdi, %rbx
leaq 0x18(%rdi), %rax
movq %rax, 0x20(%rdi)
movq %rax, 0x18(%rdi)
xorl %eax, %eax
movq %rax, 0x28(%rdi)
leaq 0x30(%rdi), %rcx
movq %rcx, 0x38(%rdi)
movq %rcx, 0x30(%rdi)
movq %rax, 0x40(%rdi)
leaq 0x48(%rdi), %rcx
movq %rcx, 0x50(%rdi)
movq %rcx, 0x48(%rdi)
movq %rax, 0x58(%rdi)
leaq 0x60(%rdi), %rcx
movq %rcx, 0x68(%rdi)
movq %rcx, 0x60(%rdi)
movq %rax, 0x70(%rdi)
leaq 0x88(%rdi), %rcx
movq %rcx, 0x78(%rdi)
movq %rax, 0x80(%rdi)
movb $0x0, 0x88(%rdi)
leaq 0x28c2e(%rip), %rcx     # 0x3e598
movq %rcx, (%rdi)
movq (%rdx), %rcx
movq %rcx, 0x8(%rdi)
movq %rax, 0x20(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq 0x10(%r12), %rbp
cmpq 0x18(%r12), %rbp
je 0x159d3
leaq 0x10(%rsp), %r13
leaq 0x2c(%rsp), %r15
movq (%rbp), %rdi
callq 0x1801a
movl %eax, 0x2c(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x159bd
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x159c8
movq %r13, %rdi
movq %r15, %rdx
callq 0x17be6
addq $0x8, %rbp
cmpq 0x18(%r12), %rbp
jne 0x15997
cmpl $0x0, 0xc(%rsp)
je 0x15a35
movl $0x90, %edi
callq 0x62f0
movq 0x30(%rsp), %rbp
movq %rax, %r13
leaq 0x68(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rdx
addq %rsi, %rdx
leaq 0x58(%rsp), %rdi
callq 0x16c68
movl (%r14), %ecx
movl 0x4(%r14), %r8d
leaq 0x58(%rsp), %rsi
leaq 0x10(%rsp), %r9
movq %r13, %rdi
movl 0xc(%rsp), %edx
callq 0x1814a
movq %r13, 0x98(%rbx)
movq 0x58(%rsp), %rdi
jmp 0x15a8a
movl $0x90, %edi
callq 0x62f0
movq 0x30(%rsp), %rbp
movq %rax, %r13
leaq 0x48(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rdx
addq %rsi, %rdx
leaq 0x38(%rsp), %rdi
callq 0x16c68
movl (%r14), %edx
movl 0x4(%r14), %ecx
leaq 0x38(%rsp), %rsi
leaq 0x10(%rsp), %r8
movq %r13, %rdi
callq 0x18062
movq %r13, 0x98(%rbx)
movq 0x38(%rsp), %rdi
cmpq %r15, %rdi
je 0x15a9a
movq (%r15), %rsi
incq %rsi
callq 0x6300
movq $0x0, 0x10(%r14)
movq 0x8(%r14), %rax
movb $0x0, (%rax)
movq 0x8(%r14), %rdi
leaq 0x18(%r14), %rax
cmpq %rax, %rdi
je 0x15ac1
movq (%rax), %rsi
incq %rsi
callq 0x6300
movl $0x28, %esi
movq %r14, %rdi
callq 0x6300
movq %r12, 0xa0(%rbx)
movq %rbp, 0xa8(%rbx)
movq 0x98(%rbx), %rdi
callq 0x1801a
cmpl $0x2, %eax
je 0x15bb0
movl 0x78(%rbp), %eax
cmpl $0x2, %eax
je 0x15b5a
cmpl $0x1, %eax
jne 0x15bb0
leaq 0x298ff(%rip), %r12     # 0x3f408
movq (%r12), %r15
addq $0x48, %r15
leaq 0x17ec7(%rip), %rsi     # 0x2d9df
movl $0xa, %edx
movq %r15, %rdi
callq 0x6370
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rdx
movq %r15, %rdi
callq 0x6370
leaq 0x1960c(%rip), %rsi     # 0x2f148
movl $0xe, %edx
movq %rax, %rdi
callq 0x6370
movq (%r12), %rdi
movl 0x8(%rbx), %esi
movl 0xc(%rbx), %edx
callq 0x1aa40
jmp 0x15bb0
leaq 0x298a7(%rip), %r12     # 0x3f408
movq (%r12), %r15
addq $0x48, %r15
leaq 0x17e6f(%rip), %rsi     # 0x2d9df
movl $0xa, %edx
movq %r15, %rdi
callq 0x6370
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rdx
movq %r15, %rdi
callq 0x6370
leaq 0x195c3(%rip), %rsi     # 0x2f157
movl $0x1b, %edx
movq %rax, %rdi
callq 0x6370
movq (%r12), %rdi
movl 0x8(%rbx), %esi
movl 0xc(%rbx), %edx
callq 0x1a874
movl $0x1, 0x10(%rbx)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x15bce
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x6300
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq 0x38(%rsp), %rdi
cmpq %r15, %rdi
je 0x15c12
movq 0x48(%rsp), %rsi
jmp 0x15c05
jmp 0x15c0f
movq %rax, %r14
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0x15c12
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x6300
jmp 0x15c12
movq %rax, %r14
movl $0x90, %esi
movq %r13, %rdi
callq 0x6300
jmp 0x15c26
jmp 0x15c23
movq %rax, %r14
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x15c3d
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x6300
movq %rbx, %rdi
callq 0x1699c
movq %r14, %rdi
callq 0x6560
nop