void add() { match('+'); term(); emitLine("pop %rbx"); emitLine("add %rbx, %rax"); }
void init() { getChar(); emitLine(".text"); emitLine(".globl _start"); emitLine("_start:"); }
void multiply() { match('*'); factor(); emitLine("pop %rbx"); emitLine("mul %rbx"); }
void subtract() { match('-'); term(); emitLine("pop %rbx"); emitLine("sub %rbx, %rax"); emitLine("neg %rax"); }
void emitHead() { emitComment(fileName); sprintf(buffer, ".class public %s", className); emitLine(buffer); emitLine(".super java/lang/Object"); emitLineBreak(); return; }
void divide() { match('/'); factor(); emitLine("pop %rdx"); emitLine("mov %rax, %rbx"); emitLine("mov %rdx, %rax"); emitLine("xor %rdx, %rdx"); emitLine("div %rbx"); }
void assignment() { char* name = getName(); char string[80]; match('='); expression(); snprintf(string, 80, ".comm %s,4,4", name); emitLine(string); snprintf(string, 80, "lea %s(%%rip), %%rbx", name); emitLine(string); emitLine("mov %rax, (%rbx)"); free(name); }
//-------------------------------------------------------------- void AnimationLinesFF::onNewPacket(DevicePacket* pDevicePacket, string deviceId, float x, float y) { accumulateVolume(pDevicePacket->m_volume, deviceId); m_lastPacketColor = pDevicePacket->m_color; if (pDevicePacket->m_volume >= m_volValuesMeanTh) { emitLine(deviceId); } }
void expression() { if(isaddop(look)) emitLine("xor %rax, %rax"); else term(); while(isaddop(look)) { emitLine("push %rax"); switch(look) { case '+': add(); break; case '-': subtract(); break; default: expected("addop"); break; } } }
void identify() { char* name = getName(); char string[80]; if(look == '(') { match('('); match(')'); snprintf(string, 80, "jmp %s", name); } else { snprintf(string, 80, "mov %s(%%rip), %%rax", name); } emitLine(string); free(name); }
void factor() { if(look == '(') { match('('); expression(); match(')'); } else if(isalpha(look)) { identify(); } else { char string[80]; snprintf(string, 80, "mov $%s, %%rax", getNum()); emitLine(string); } }
void term() { factor(); while(ismulop(look)) { emitLine("push %rax"); switch(look) { case '*': multiply(); break; case '/': divide(); break; default: expected("mulop"); break; } } }
void CodeGenerator::generateCode(std::ostream *os_) { os = os_; emitLine(std::string("#include \"node.h\"")); emitLine(std::string("#include \"stltree.h\"")); emitLine(std::string("")); emitLine(std::string("void stltree_create(stltree *t) {")); indent(); ast->root->codeGen(*this); emitLine(std::string("t->root = n") + ast->root->id() + std::string(";")); deindent(); emitLine(std::string("}")); }
void Output::postLabel(std::string label) { emitLine(label + ":"); }
void finish() { emitLine("mov %rax, %rdi"); emitLine("mov $60, %rax"); emitLine("syscall"); }