// File: /workspace/github_cpp_makefile_star2_O1/Davidc2525[P]Leaf/main.cpp
// Function: main
int main(int argc, char **argv)
{

    //prepare default global configuration
    prepare_default_conf();

    /*if(argc<2){ 
        log("falta el archivo de programa",1)
    }
    string filename(args[1]);
    Scanner * s = new Scanner((const unsigned char *)filename.c_str(),filename.length());
    Parser * p = new Parser(s);
    p->Parse();*/

    int x86_64_registers = RegisterManager::getInstance()->addProvider(
        new X86_64RegisterProvider());
    int x86_32_registers = RegisterManager::getInstance()->addProvider(
        new X86_32RegisterProvider());

    RegisterProvider *rp = RegisterManager::getInstance()->getProvider(x86_64_registers);
    try
    {
        Register *r = rp->reserve();
        rp->free(r->id);
    }
    catch (const char *ex)
    {
        cout << ex << endl;
        exit(1);
    }
    catch (int ex)
    {
        cout << ex << endl;
        exit(1);
    }
    if (argc == 2)
    {
        wchar_t *fileName = coco_string_create(argv[1]);
        Scanner *scanner = new Scanner(fileName);
        Parser *parser = new Parser(scanner);
        parser->tab = new symbol_table();
        //parser->ss = new ExternSymbols();
        //parser->sl = new StringLiterals();
        ast_visitor_args *args = new ast_visitor_args;
        args->ass = new Assembly(new Program());
        //args->outfile = new string("tmp_pro_leaf_asm.asm");

        parser->data_section = args->ass->get_program()->section(Sections::data);
        parser->visitor_generator =
            new x86_64_linux_generator_visitor(args);

        try
        {
            //parser->ast_h = ThreeFactory::getInstance()->getAstHandler(handler);
        }
        catch (char const *ex)
        {
            cout << "Exception: " << ex << endl;
            exit(1);
        }

        parser->Parse();
        //test
        //cout<<*label_of_function(symbol_table::find(new string("david")))<<endl;
        //cout<<*label_of_function(symbol_table::find(new string("main")))<<endl;
        //test
        return 0;
        if (parser->errors->count == 0)
        {
        }
        else
        {
            dlog(" errores: " + to_string(parser->errors->count), 1)
        }

        coco_string_delete(fileName);

        delete parser;
        delete scanner;
    }
    else
        clog("-- No source file specified", 1) return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %rbx
movl %edi, %ebp
callq 0x7a50
callq 0x11b02
movq %rax, %r15
movl $0x38, %edi
callq 0x5290
movq %rax, %r14
movq %rax, %rdi
callq 0x12856
movq %r15, %rdi
movq %r14, %rsi
callq 0x11b20
movl %eax, %r14d
callq 0x11b02
movq %rax, %r12
movl $0x38, %edi
callq 0x5290
movq %rax, %r15
movq %rax, %rdi
callq 0x14696
movq %r12, %rdi
movq %r15, %rsi
callq 0x11b20
callq 0x11b02
movq %rax, %rdi
movl %r14d, %esi
callq 0x11b32
movq %rax, %r14
movq (%rax), %rax
movq %r14, %rdi
callq *0x50(%rax)
movl (%rax), %esi
movq (%r14), %rax
movq %r14, %rdi
callq *0x28(%rax)
cmpl $0x2, %ebp
jne 0x7c96
movq 0x8(%rbx), %rdi
callq 0x94af
movq %rax, %rbx
movl $0xa0, %edi
callq 0x5290
movq %rax, %r15
movq %rax, %rdi
movq %rbx, %rsi
callq 0xa552
movl $0x58, %edi
callq 0x5290
movq %rax, %r14
movq %rax, %rdi
movq %r15, %rsi
callq 0xe62e
movl $0x1, %edi
callq 0x5290
movq %rax, %r15
movq %rax, %rdi
callq 0x112be
movq %r15, 0x38(%r14)
movl $0x10, %edi
callq 0x5290
movq %rax, %rbx
movl $0x8, %edi
callq 0x5290
movq %rax, %r15
movl $0x38, %edi
callq 0x5290
movq %rax, %r12
movq %rax, %rdi
callq 0x10282
movq %r12, (%r15)
movq %r15, 0x8(%rbx)
movq %r12, %rdi
xorl %esi, %esi
callq 0x102f0
movq %rax, 0x48(%r14)
movl $0x40, %edi
callq 0x5290
movq %rax, %r15
movq %rax, %rdi
movq %rbx, %rsi
callq 0x15f50
movq %r15, 0x50(%r14)
movq %r14, %rdi
callq 0xe5b4
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x1e33b(%rip), %rdi     # 0x25fd8
leaq 0x114a6(%rip), %rsi     # 0x1914a
callq 0x5270
movq %rax, %rdi
callq 0x5130
jmp 0x7d6b
movq %rax, %rbx
movl $0x40, %esi
jmp 0x7d02
movq %rax, %rbx
movl $0x38, %esi
movq %r12, %rdi
callq 0x52a0
jmp 0x7cd5
movq %rax, %rbx
movl $0x8, %esi
jmp 0x7d02
movq %rax, %rbx
movl $0x1, %esi
jmp 0x7d02
movq %rax, %rbx
movl $0x58, %esi
jmp 0x7d0f
movq %rax, %rbx
movl $0xa0, %esi
jmp 0x7d02
movq %rax, %rbx
movl $0x38, %esi
movq %r15, %rdi
jmp 0x7d12
movq %rax, %rbx
movl $0x38, %esi
movq %r14, %rdi
callq 0x52a0
movq %rbx, %rdi
callq 0x5470
movq %rax, %rbx
cmpl $0x2, %edx
jne 0x7d48
movq %rbx, %rdi
callq 0x5110
movq 0x1e2a2(%rip), %rdi     # 0x25fd8
movq %rax, %rsi
callq 0x5270
movq %rax, %rdi
callq 0x5130
jmp 0x7d6b
cmpl $0x1, %edx
jne 0x7d17
movq %rbx, %rdi
callq 0x5110
movl (%rax), %esi
movq 0x1e27a(%rip), %rdi     # 0x25fd8
callq 0x5460
movq %rax, %rdi
callq 0x5130
movl $0x1, %edi
callq 0x5340
jmp 0x7d77
movq %rax, %rbx
callq 0x5430
jmp 0x7d17