blob: 30975f06e3e741ae402dcec819b5070b30a2fdde (
plain)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#include <stdio.h>
#include "gen_code.h"
#include "pc.h"
int gen_label(t)
ptree *t;
{
int tmp;
if (!(t->l && t->r))
return 0;
if (t->l) {
tmp = gen_label(t->l);
t->l->label = (!tmp ? 1 : tmp);
} else
yyerror("GEN_LABEL: left child NULL, shouldn't happen!\n");
if (t->r)
t->r->label = gen_label(t->r);
else
t->r->label = 0;
if (t->r->label == t->l->label) {
return 1 + t->l->label;
} else {
return t->r->label > t->l->label ? t->r->label : t->l->label;
}
}
void gen_expr(t)
ptree *t;
{
}
void gen_statement(t)
ptree *t;
{
char buf[100];
if (!t)
return;
switch (t->type){
case ASSIGNOP:
break;
case PCALL:
break;
case LIST:
break;
case IF:
break;
case WHILE:
break;
case FOR:
break;
default:
snprintf(buf, 100, "Unknown statement type: %d\n", t->type);
yyerror(buf);
}
}
void gen_code(t, name)
ptree *t;
char *name;
{
printf("\n.globl %s\n.type %s, @function\n%s:\n", name, name, name);
/*TODO call gen_statement on all statements in LIST t*/
/*Look at set_type for list traverseal code*/
}
|