// File: Eronana[P]strawberry/src/ast_codegen.cpp
// Function: AST_BinaryOperationExpression::codeGen(Symbol*)
DEF_AST_METHOD(BinaryOperationExpression,AST_CODEGEN)
{
    auto optype=GET_LITERAL(optr).type;
    int label;
    if(optype==TOKEN_LOGIC_AND)
    {
        label=nextLabel();
        PRINTF("dup\n");
        PRINTF("istrue\n");
        PRINTF("jmp label_%d\n",label);
        PRINTF("pop\n");
    }
    else if(optype==TOKEN_LOGIC_OR)
    {
        label=nextLabel();
        PRINTF("dup\n");
        PRINTF("isfalse\n");
        PRINTF("jmp label_%d\n",label);
        PRINTF("pop\n");
    }
    bool isIdentifier=is_identifier(expr);
    if(isIdentifier)loadVariant(symbol,expr);
    else CODEGEN(expr);
    switch(optype)
    {
        case TOKEN_MUL:
            PRINTF("mul\n");
            break;
        case TOKEN_DIV:
            PRINTF("div\n");
            break;
        case TOKEN_MOD:
            PRINTF("mod\n");
            break;
        case TOKEN_ADD:
            PRINTF("add\n");
            break;
        case TOKEN_SUB:
            PRINTF("sub\n");
            break;
        case TOKEN_BITWISE_AND:
            PRINTF("band\n");
            break;
        case TOKEN_BITWISE_XOR:
            PRINTF("xor\n");
            break;
        case TOKEN_BITWISE_OR:
            PRINTF("bor\n");
            break;
        case TOKEN_LEFT_SHIFT:
            PRINTF("shl\n");
            break;
        case TOKEN_RIGHT_SHIFT:
            PRINTF("shr\n");
            break;
        case TOKEN_LESS:
            PRINTF("less\n");
            break;
        case TOKEN_GREATER:
            PRINTF("gt\n");
            break;
        case TOKEN_LESS_EQUAL:
            PRINTF("le\n");
            break;
        case TOKEN_GREATER_EQUAL:
            PRINTF("ge\n");
            break;
        case TOKEN_EQUAL:
            PRINTF("eq\n");
            break;
        case TOKEN_INEQUAL:
            PRINTF("ieq\n");
            break;
        case TOKEN_LOGIC_AND:
        case TOKEN_LOGIC_OR:
            PRINTF("label_%d:\n",label);
            break;
        default:
            break;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x28(%rbp)
addq $0x10, %rdi
callq 0xabd0
movl 0x8(%rax), %eax
movl %eax, -0x14(%rbp)
cmpl $0x17, -0x14(%rbp)
jne 0x536bd
callq 0x1a000
movl %eax, -0x18(%rbp)
movl 0x375f1(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x375e8(%rip)     # 0x8ac10
leaq 0x372b9(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x61ad(%rip), %rsi      # 0x597e6
movb $0x0, %al
callq 0x74c0
movl 0x375ca(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x375c1(%rip)     # 0x8ac10
leaq 0x37292(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x620d(%rip), %rsi      # 0x5986d
movb $0x0, %al
callq 0x74c0
movl 0x375a3(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x3759a(%rip)     # 0x8ac10
leaq 0x3726b(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
movl -0x18(%rbp), %edx
leaq 0x61eb(%rip), %rsi      # 0x59875
movb $0x0, %al
callq 0x74c0
movl 0x37579(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x37570(%rip)     # 0x8ac10
leaq 0x37241(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x6126(%rip), %rsi      # 0x597d7
movb $0x0, %al
callq 0x74c0
jmp 0x53770
cmpl $0x14, -0x14(%rbp)
jne 0x5376e
callq 0x1a000
movl %eax, -0x18(%rbp)
movl 0x3753b(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x37532(%rip)     # 0x8ac10
leaq 0x37203(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x60f7(%rip), %rsi      # 0x597e6
movb $0x0, %al
callq 0x74c0
movl 0x37514(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x3750b(%rip)     # 0x8ac10
leaq 0x371dc(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x616d(%rip), %rsi      # 0x59883
movb $0x0, %al
callq 0x74c0
movl 0x374ed(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x374e4(%rip)     # 0x8ac10
leaq 0x371b5(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
movl -0x18(%rbp), %edx
leaq 0x6135(%rip), %rsi      # 0x59875
movb $0x0, %al
callq 0x74c0
movl 0x374c3(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x374ba(%rip)     # 0x8ac10
leaq 0x3718b(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x6070(%rip), %rsi      # 0x597d7
movb $0x0, %al
callq 0x74c0
jmp 0x53770
movq -0x28(%rbp), %rdi
addq $0x8, %rdi
callq 0x52300
andb $0x1, %al
movb %al, -0x19(%rbp)
testb $0x1, -0x19(%rbp)
je 0x5379b
movq -0x28(%rbp), %rsi
movq -0x10(%rbp), %rdi
addq $0x8, %rsi
callq 0x554c0
jmp 0x537b5
movq -0x28(%rbp), %rdi
addq $0x8, %rdi
callq 0x8f60
movq %rax, %rdi
movq -0x10(%rbp), %rsi
movq (%rdi), %rax
callq *0x18(%rax)
movl -0x14(%rbp), %eax
addl $-0x4, %eax
movl %eax, %ecx
movq %rcx, -0x30(%rbp)
subl $0x24, %eax
ja 0x53ac4
movq -0x30(%rbp), %rax
leaq 0x5e6b(%rip), %rcx      # 0x59640
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x3742c(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x37423(%rip)     # 0x8ac10
leaq 0x370f4(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x608e(%rip), %rsi      # 0x5988c
movb $0x0, %al
callq 0x74c0
jmp 0x53ac6
movl 0x37400(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x373f7(%rip)     # 0x8ac10
leaq 0x370c8(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x6067(%rip), %rsi      # 0x59891
movb $0x0, %al
callq 0x74c0
jmp 0x53ac6
movl 0x373d4(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x373cb(%rip)     # 0x8ac10
leaq 0x3709c(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x6040(%rip), %rsi      # 0x59896
movb $0x0, %al
callq 0x74c0
jmp 0x53ac6
movl 0x373a8(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x3739f(%rip)     # 0x8ac10
leaq 0x37070(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x6019(%rip), %rsi      # 0x5989b
movb $0x0, %al
callq 0x74c0
jmp 0x53ac6
movl 0x3737c(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x37373(%rip)     # 0x8ac10
leaq 0x37044(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x5ff2(%rip), %rsi      # 0x598a0
movb $0x0, %al
callq 0x74c0
jmp 0x53ac6
movl 0x37350(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x37347(%rip)     # 0x8ac10
leaq 0x37018(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x5fcb(%rip), %rsi      # 0x598a5
movb $0x0, %al
callq 0x74c0
jmp 0x53ac6
movl 0x37324(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x3731b(%rip)     # 0x8ac10
leaq 0x36fec(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x5fa5(%rip), %rsi      # 0x598ab
movb $0x0, %al
callq 0x74c0
jmp 0x53ac6
movl 0x372f8(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x372ef(%rip)     # 0x8ac10
leaq 0x36fc0(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x5f7e(%rip), %rsi      # 0x598b0
movb $0x0, %al
callq 0x74c0
jmp 0x53ac6
movl 0x372cc(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x372c3(%rip)     # 0x8ac10
leaq 0x36f94(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x5f57(%rip), %rsi      # 0x598b5
movb $0x0, %al
callq 0x74c0
jmp 0x53ac6
movl 0x372a0(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x37297(%rip)     # 0x8ac10
leaq 0x36f68(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x5f30(%rip), %rsi      # 0x598ba
movb $0x0, %al
callq 0x74c0
jmp 0x53ac6
movl 0x37274(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x3726b(%rip)     # 0x8ac10
leaq 0x36f3c(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x5f09(%rip), %rsi      # 0x598bf
movb $0x0, %al
callq 0x74c0
jmp 0x53ac6
movl 0x37248(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x3723f(%rip)     # 0x8ac10
leaq 0x36f10(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x5ee3(%rip), %rsi      # 0x598c5
movb $0x0, %al
callq 0x74c0
jmp 0x53ac6
movl 0x3721c(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x37213(%rip)     # 0x8ac10
leaq 0x36ee4(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x5ebb(%rip), %rsi      # 0x598c9
movb $0x0, %al
callq 0x74c0
jmp 0x53ac6
movl 0x371f0(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x371e7(%rip)     # 0x8ac10
leaq 0x36eb8(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x5e93(%rip), %rsi      # 0x598cd
movb $0x0, %al
callq 0x74c0
jmp 0x53ac6
movl 0x371c4(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x371bb(%rip)     # 0x8ac10
leaq 0x36e8c(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x5e6c(%rip), %rsi      # 0x598d2
movb $0x0, %al
callq 0x74c0
jmp 0x53ac6
movl 0x3719b(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x37192(%rip)     # 0x8ac10
leaq 0x36e63(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x5e42(%rip), %rsi      # 0x598d1
movb $0x0, %al
callq 0x74c0
jmp 0x53ac6
movl 0x37172(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x37169(%rip)     # 0x8ac10
leaq 0x36e3a(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
movl -0x18(%rbp), %edx
leaq 0x5e1b(%rip), %rsi      # 0x598d6
movb $0x0, %al
callq 0x74c0
jmp 0x53ac6
jmp 0x53ac6
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)