aboutsummaryrefslogtreecommitdiff
path: root/gen_code.c
blob: 22d1e76f8ebc047866712103e603119768c2898f (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
#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_code(t, name)
ptree *t;
{
	/*Test gen_label*/
	if (t->type == ASSIGNOP){
		gen_label(t->r);
		print_tree(t->r);
	}
}