Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#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;
}
}
}