Skip to content
Snippets Groups Projects
assembly_gen.c 1.46 KiB
Newer Older
krf41037's avatar
krf41037 committed
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>

#include "mcc/tac.h"
#include "mcc/tac_print.h"
#include "mcc/symbol_table.h"



char *mcc_asm_gen(FILE *out, struct mcc_tac *tac)
{

    for(int i = 0; i < tac->tac_entries->size; i++)
    {
        struct mcc_tac_entry *entry = tac->tac_entries->arr[i];
        char *arg1 = entry->arg1;
        
        switch (entry->tac_op)
        {
        case MCC_TAC_FUNCTION_START:
            fprintf(out, "\t.globl %s\n", arg1);
			fprintf(out, "\t.type %s, @function\n", arg1);
			fprintf(out, "%s:\n", arg1);
			fprintf(out, "\tpushl\t%%ebp\n");
			fprintf(out, "\tmovl\t%%esp, %%ebp\n");
            break;
        
        case MCC_TAC_CALL:
            fprintf(out, "\tcall\t%s\n", arg1);
            break;
        case MCC_TAC_NOT:
            fprintf(out, "\tnegl\t%%eax\n");
        case MCC_TAC_PLUS_INT:
            fprintf(out, "\taddl\t%d(%%ebp), %%eax\n", offset );
            break;
        case MCC_TAC_MINUS_INT_BIN:
            fprintf(out, "\tsubl\t%d(%%ebp), %%eax\n",offset);
		    break;
        case MCC_TAC_MUL_INT:
            fprintf(out, "\timull\t%d(%%ebp), %%eax\n",offset);
        case MCC_TAC_PLUS_FLOAT:
            break;
        case MCC_TAC_BOOL_LITERAL:
            break;
        case MCC_TAC_INT_LITERAL:
            break;
        case MCC_TAC_STRING_LITERAL:
            break;
        case MCC_TAC_FLOAT_LITERAL:
            break;
        default:
            break;
        }
    }



}