// File: /workspace/github_cpp_makefile_star2_O1/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 0x27c5c(%rip), %rcx     # 0x3d598
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 0x159a5
leaq 0x10(%rsp), %r13
leaq 0x2c(%rsp), %r15
movq (%rbp), %rdi
callq 0x17fde
movl %eax, 0x2c(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x1598f
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x1599a
movq %r13, %rdi
movq %r15, %rdx
callq 0x17bb0
addq $0x8, %rbp
cmpq 0x18(%r12), %rbp
jne 0x15969
cmpl $0x0, 0xc(%rsp)
je 0x15a07
movl $0x90, %edi
callq 0x62e0
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 0x16c42
movl (%r14), %ecx
movl 0x4(%r14), %r8d
leaq 0x58(%rsp), %rsi
leaq 0x10(%rsp), %r9
movq %r13, %rdi
movl 0xc(%rsp), %edx
callq 0x1810e
movq %r13, 0x98(%rbx)
movq 0x58(%rsp), %rdi
jmp 0x15a5c
movl $0x90, %edi
callq 0x62e0
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 0x16c42
movl (%r14), %edx
movl 0x4(%r14), %ecx
leaq 0x38(%rsp), %rsi
leaq 0x10(%rsp), %r8
movq %r13, %rdi
callq 0x18026
movq %r13, 0x98(%rbx)
movq 0x38(%rsp), %rdi
cmpq %r15, %rdi
je 0x15a6c
movq (%r15), %rsi
incq %rsi
callq 0x62f0
movq $0x0, 0x10(%r14)
movq 0x8(%r14), %rax
movb $0x0, (%rax)
movq 0x8(%r14), %rdi
leaq 0x18(%r14), %rax
cmpq %rax, %rdi
je 0x15a93
movq (%rax), %rsi
incq %rsi
callq 0x62f0
movl $0x28, %esi
movq %r14, %rdi
callq 0x62f0
movq %r12, 0xa0(%rbx)
movq %rbp, 0xa8(%rbx)
movq 0x98(%rbx), %rdi
callq 0x17fde
cmpl $0x2, %eax
je 0x15b82
movl 0x78(%rbp), %eax
cmpl $0x2, %eax
je 0x15b2c
cmpl $0x1, %eax
jne 0x15b82
leaq 0x28925(%rip), %r12     # 0x3e400
movq (%r12), %r15
addq $0x48, %r15
leaq 0x16ef5(%rip), %rsi     # 0x2c9df
movl $0xa, %edx
movq %r15, %rdi
callq 0x6360
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rdx
movq %r15, %rdi
callq 0x6360
leaq 0x1863a(%rip), %rsi     # 0x2e148
movl $0xe, %edx
movq %rax, %rdi
callq 0x6360
movq (%r12), %rdi
movl 0x8(%rbx), %esi
movl 0xc(%rbx), %edx
callq 0x1a9e6
jmp 0x15b82
leaq 0x288cd(%rip), %r12     # 0x3e400
movq (%r12), %r15
addq $0x48, %r15
leaq 0x16e9d(%rip), %rsi     # 0x2c9df
movl $0xa, %edx
movq %r15, %rdi
callq 0x6360
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rdx
movq %r15, %rdi
callq 0x6360
leaq 0x185f1(%rip), %rsi     # 0x2e157
movl $0x1b, %edx
movq %rax, %rdi
callq 0x6360
movq (%r12), %rdi
movl 0x8(%rbx), %esi
movl 0xc(%rbx), %edx
callq 0x1a814
movl $0x1, 0x10(%rbx)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x15ba0
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x62f0
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 0x15be4
movq 0x48(%rsp), %rsi
jmp 0x15bd7
jmp 0x15be1
movq %rax, %r14
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0x15be4
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x62f0
jmp 0x15be4
movq %rax, %r14
movl $0x90, %esi
movq %r13, %rdi
callq 0x62f0
jmp 0x15bf8
jmp 0x15bf5
movq %rax, %r14
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x15c0f
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x62f0
movq %rbx, %rdi
callq 0x1697e
movq %r14, %rdi
callq 0x6550
nop