// File: /workspace/github_cpp_makefile_star2_O1/sumanishs[P]boost-edif-parser2/edifreader.cpp
// Function: EdifReader::Read(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
bool 
EdifReader::Read(std::string& filename){

    typedef std::string::iterator base_iterator_type;
    typedef lex::lexertl::token< base_iterator_type, boost::mpl::vector<unsigned int, std::string> > token_type;
    typedef lex::lexertl::actor_lexer<token_type> lexer_type;
    typedef edif_tokens<lexer_type> edif_tokens;
    typedef edif_tokens::iterator_type iterator_type;
    typedef edif_grammar<iterator_type, edif_tokens::lexer_def> edif_grammar;

    EdifParseTreeBuilder* ptb = new EdifParseTreeBuilder();

    edif_tokens tokens;                                 // Our lexer
    edif_grammar grammar(tokens, ptb);                  // Our parser

    std::ifstream inFile;
    inFile.open(filename.c_str());
    if(inFile.fail()){
        std::cout << "Cannot open file to read...." << std::endl;
        return false;
    }

    std::stringstream strStream;
    strStream << inFile.rdbuf();
    std::string str(strStream.str());
    //str.pop_back();
    //std::cout << "File content:\n" << str << "!" << std::endl;
    inFile.close();

    std::string::iterator it = str.begin();
    iterator_type iter = tokens.begin(it, str.end());
    iterator_type end = tokens.end();

    //iterator_type itr = iter;
    //while (itr != end && token_is_valid(*itr))
    //{   
    //    std::cout << "Token: " << itr->id() << ": " /*<< tokens.nameof(itr)*/ << " ('" << itr->value() << "')\n";
    //    ++itr;
    //}   
    ////return 0;


    std::string ws("WS");
    bool r = qi::phrase_parse(iter, end, grammar, qi::in_state(ws)[tokens.self]);

    if (r && iter == end)
    {
        std::cout << "\n-------------------------\n";
        std::cout << "Parsing succeeded\n";
        std::cout << "-------------------------\n";
        return true;
    }
    else
    {
        std::cout << "\n-------------------------\n";
        std::cout << "Parsing failed\n";
        std::cout << "-------------------------\n";
        return false;
    }

    std::cout << "Bye... :-) \n\n";
    return true;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x2c20, %rsp           # imm = 0x2C20
movq %rsi, %rbx
movl $0x1, %edi
callq 0x52a0
movq %rax, %r14
leaq 0x450(%rsp), %r15
movq %r15, %rdi
callq 0x5f9a
leaq 0x19f0(%rsp), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x8728
leaq 0x248(%rsp), %rdi
callq 0x52f0
movq (%rbx), %rsi
leaq 0x248(%rsp), %rdi
movl $0x8, %edx
callq 0x5190
movq 0x248(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x268(%rsp,%rax)
je 0x5bf0
movq 0x4142e(%rip), %rbx     # 0x46fd8
leaq 0x281f7(%rip), %rsi     # 0x2dda8
movl $0x1c, %edx
movq %rbx, %rdi
callq 0x5300
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x5280
movsbl %al, %esi
movq 0x413fc(%rip), %rdi     # 0x46fd8
callq 0x5030
movq %rax, %rdi
callq 0x51e0
xorl %ebx, %ebx
jmp 0x5e64
leaq 0xc0(%rsp), %rdi
callq 0x51f0
leaq 0xd0(%rsp), %rdi
leaq 0x258(%rsp), %rsi
callq 0x5080
leaq 0xd8(%rsp), %rsi
leaq 0x60(%rsp), %rdi
callq 0x53e0
leaq 0x248(%rsp), %rdi
callq 0x5070
movq 0x60(%rsp), %rax
leaq 0xb8(%rsp), %rdx
movq %rax, (%rdx)
addq 0x68(%rsp), %rax
leaq 0x90(%rsp), %rcx
movq %rax, (%rcx)
leaq 0x20(%rsp), %rdi
leaq 0x450(%rsp), %rsi
xorl %r8d, %r8d
callq 0x1fdc4
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
leaq 0x50(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x28148(%rip), %rsi     # 0x2ddc5
leaq 0x28143(%rip), %rdx     # 0x2ddc7
leaq 0x40(%rsp), %rdi
callq 0xf950
movq (%rsp), %rax
movq 0x8(%rsp), %rcx
movq %rax, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
testq %rax, %rax
je 0x5ca9
lock
incl (%rax)
leaq 0x416c0(%rip), %rsi     # 0x47370
leaq 0x90(%rsp), %rbx
leaq 0x40(%rsp), %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0xde8a
leaq 0x748(%rsp), %rax
movq %rbx, 0x80(%rsp)
movq %rax, 0x88(%rsp)
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
movq %rax, 0x30(%rsp)
movq %rcx, 0x38(%rsp)
testq %rax, %rax
je 0x5cfb
lock
incl (%rax)
leaq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x19f0(%rsp), %rdx
leaq 0x80(%rsp), %rcx
xorl %r8d, %r8d
callq 0x2c40e
movl %eax, %ebx
leaq 0x30(%rsp), %rdi
callq 0x17fe0
leaq 0xa0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5d4a
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x52b0
leaq 0x10(%rsp), %rdi
callq 0x17fe0
testb %bl, %bl
je 0x5db5
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
callq 0xdf68
testb %al, %al
je 0x5db5
movq 0x41268(%rip), %rdi     # 0x46fd8
leaq 0x28051(%rip), %rsi     # 0x2ddc8
movl $0x1b, %edx
callq 0x5300
movq 0x41250(%rip), %rdi     # 0x46fd8
leaq 0x28055(%rip), %rsi     # 0x2dde4
movl $0x12, %edx
callq 0x5300
movb $0x1, %bl
movq 0x41236(%rip), %rdi     # 0x46fd8
leaq 0x28020(%rip), %rsi     # 0x2ddc9
movl $0x1a, %edx
callq 0x5300
jmp 0x5dff
movq 0x4121c(%rip), %rdi     # 0x46fd8
leaq 0x28005(%rip), %rsi     # 0x2ddc8
movl $0x1b, %edx
callq 0x5300
movq 0x41204(%rip), %rdi     # 0x46fd8
leaq 0x2801c(%rip), %rsi     # 0x2ddf7
movl $0xf, %edx
callq 0x5300
movq 0x411ec(%rip), %rdi     # 0x46fd8
leaq 0x27fd6(%rip), %rsi     # 0x2ddc9
movl $0x1a, %edx
callq 0x5300
xorl %ebx, %ebx
movq 0x40(%rsp), %rdi
cmpq %r14, %rdi
je 0x5e16
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x52b0
movq %rsp, %rdi
callq 0x17fe0
leaq 0x20(%rsp), %rdi
callq 0x17fe0
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5e43
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x52b0
movq 0x4115e(%rip), %rsi     # 0x46fa8
leaq 0xc0(%rsp), %rdi
callq 0x5230
leaq 0x140(%rsp), %rdi
callq 0x50e0
leaq 0x248(%rsp), %rdi
callq 0x5090
leaq 0x19f0(%rsp), %rdi
callq 0xe02a
leaq 0x450(%rsp), %rdi
callq 0xeabe
movl %ebx, %eax
addq $0x2c20, %rsp           # imm = 0x2C20
popq %rbx
popq %r14
popq %r15
retq
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x17fe0
leaq 0xa0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5ecd
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x52b0
jmp 0x5ecd
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x17fe0
jmp 0x5f01
movq %rax, %rbx
jmp 0x5f18
jmp 0x5ee0
movq %rax, %rbx
jmp 0x5f2a
jmp 0x5ee7
movq %rax, %rbx
jmp 0x5f45
jmp 0x5f68
movq %rax, %rbx
jmp 0x5f78
movq %rax, %rbx
jmp 0x5f85
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r14, %rdi
je 0x5f18
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x52b0
movq %rsp, %rdi
callq 0x17fe0
leaq 0x20(%rsp), %rdi
callq 0x17fe0
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5f45
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x52b0
movq 0x4105c(%rip), %rsi     # 0x46fa8
leaq 0xc0(%rsp), %rdi
callq 0x5230
leaq 0x140(%rsp), %rdi
callq 0x50e0
jmp 0x5f6b
movq %rax, %rbx
leaq 0x248(%rsp), %rdi
callq 0x5090
leaq 0x19f0(%rsp), %rdi
callq 0xe02a
leaq 0x450(%rsp), %rdi
callq 0xeabe
movq %rbx, %rdi
callq 0x5460