Beispiel #1
0
void add()
{
	match('+');
	term();
	emitLine("pop %rbx");
	emitLine("add %rbx, %rax");
}
Beispiel #2
0
void init()
{
	getChar();
    emitLine(".text");
    emitLine(".globl _start");
    emitLine("_start:");
}
Beispiel #3
0
void multiply()
{
    match('*');
    factor();
    emitLine("pop %rbx");
    emitLine("mul %rbx");
}
Beispiel #4
0
void subtract()
{
	match('-');
	term();
	emitLine("pop %rbx");
	emitLine("sub %rbx, %rax");
	emitLine("neg %rax");
}
Beispiel #5
0
void emitHead()
{
    emitComment(fileName);
    sprintf(buffer, ".class public %s", className);
    emitLine(buffer);
    emitLine(".super java/lang/Object");
    emitLineBreak();
    return;
}
Beispiel #6
0
void divide()
{
    match('/');
    factor();
    emitLine("pop %rdx");
    emitLine("mov %rax, %rbx");
    emitLine("mov %rdx, %rax");
    emitLine("xor %rdx, %rdx");
    emitLine("div %rbx");
}
Beispiel #7
0
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);
}
Beispiel #8
0
//--------------------------------------------------------------
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);
	}
}
Beispiel #9
0
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;
        }
    }
}
Beispiel #10
0
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);
}
Beispiel #11
0
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);
    }
}
Beispiel #12
0
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("}"));
}
Beispiel #14
0
 void Output::postLabel(std::string label)
 {
     emitLine(label + ":");
 }
Beispiel #15
0
void finish()
{
    emitLine("mov %rax, %rdi");
    emitLine("mov $60, %rax");
    emitLine("syscall");
}