// File: vssense[P]Compiler/src/front-end/translator.cpp
// Function: TranslateExpression(Node*, _IO_FILE*)
void TranslateExpression(Node* node, FILE* file)
{
    assert(node);
    assert(file);

    switch (node->type)
    {
        case MATH_TYPE :
        {
            if (NeededBracket(node))
            {
                fprintf(file, "(");
            }
            
            TranslateExpression(node->left, file);
            fprintf(file, " %s ", STRING_MATH_OP[node->value.op]);
            TranslateExpression(node->right, file);

            if (NeededBracket(node)) 
            {
                fprintf(file, ")");
            }
            break;
        }
        case NUMB_TYPE :
        {   
            IntToDrevniyRus(file, node->value.number);   
            break;
        }
        case CALL_TYPE :
        {
            if (!TranslateStdCall(node, file))
            {
                fprintf(file, "%s(", node->left->value.name);
                TranslateParams(node->right, file);
                fprintf(file, ")");
            }
            break;
        }
        case ID_TYPE :
        {
            fprintf(file, "%s", node->value.name);
            break;
        }
        default :
        {
            fprintf(file, "can't interpret this construction");
            // printf("I'm here, but I shouldn't, line = %d\n", __LINE__);
            break;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x6679
jmp 0x6698
leaq 0xa77(%rip), %rdi       # 0x70f7
leaq 0x1c1d(%rip), %rsi      # 0x82a4
movl $0xf9, %edx
leaq 0x1ede(%rip), %rcx      # 0x8571
callq 0x2090
cmpq $0x0, -0x10(%rbp)
je 0x66a1
jmp 0x66c0
leaq 0x119b(%rip), %rdi      # 0x7843
leaq 0x1bf5(%rip), %rsi      # 0x82a4
movl $0xfa, %edx
leaq 0x1eb6(%rip), %rcx      # 0x8571
callq 0x2090
movq -0x8(%rbp), %rax
movl (%rax), %eax
addl $-0x4, %eax
movl %eax, %ecx
movq %rcx, -0x18(%rbp)
subl $0xb, %eax
ja 0x67ff
movq -0x18(%rbp), %rax
leaq 0x1b91(%rip), %rcx      # 0x8274
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rdi
callq 0x6bb0
testb $0x1, %al
jne 0x66fb
jmp 0x670d
movq -0x10(%rbp), %rdi
leaq 0x1e1e(%rip), %rsi      # 0x8524
movb $0x0, %al
callq 0x2140
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x6660
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movslq 0x8(%rax), %rcx
leaq 0x49cf(%rip), %rax      # 0xb100
movq (%rax,%rcx,8), %rdx
leaq 0x1d49(%rip), %rsi      # 0x8485
movb $0x0, %al
callq 0x2140
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x6660
movq -0x8(%rbp), %rdi
callq 0x6bb0
testb $0x1, %al
jne 0x6763
jmp 0x6775
movq -0x10(%rbp), %rdi
leaq 0x15fe(%rip), %rsi      # 0x7d6c
movb $0x0, %al
callq 0x2140
jmp 0x6811
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x8(%rax), %esi
callq 0x6c20
jmp 0x6811
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x69f0
testb $0x1, %al
jne 0x67e1
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rdx
leaq 0x1bfa(%rip), %rsi      # 0x83b1
movb $0x0, %al
callq 0x2140
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x6af0
movq -0x10(%rbp), %rdi
leaq 0x1592(%rip), %rsi      # 0x7d6c
movb $0x0, %al
callq 0x2140
jmp 0x6811
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0x1be7(%rip), %rsi      # 0x83dd
movb $0x0, %al
callq 0x2140
jmp 0x6811
movq -0x10(%rbp), %rdi
leaq 0x1c54(%rip), %rsi      # 0x845e
movb $0x0, %al
callq 0x2140
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)