Skip to content
Snippets Groups Projects
Commit 84e5526a authored by krf41037's avatar krf41037
Browse files

Asm_gen first try

parent f02f1c0d
No related branches found
No related tags found
No related merge requests found
......@@ -104,7 +104,7 @@ enum mcc_tac_operation {
MCC_TAC_CALL,
MCC_TAC_FUNCTION_START,
MCC_TAC_FUNCTION_END,
MCC_TAC_UNKNOWN
};
......
#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;
}
}
}
\ No newline at end of file
......@@ -408,8 +408,9 @@ struct mcc_tac *mcc_tac_build(struct mcc_ast_program *program, struct mcc_symbol
// parse all functions one after another
mcc_tac_parse_function(f, tac);
}
// mcc_tac_create_and_add_new_entry(MCC_TAC_EOF,NULL,NULL,NULL,tac);
return tac;
}
......@@ -82,6 +82,7 @@ char *tac_type(enum mcc_tac_operation type)
case MCC_TAC_PARAM_POP_FLOAT_ARR:
case MCC_TAC_PARAM_FLOAT_ARR: return "float_arr";
default: return "ERROR";
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment