-
Notifications
You must be signed in to change notification settings - Fork 0
/
decl.c
76 lines (62 loc) · 2 KB
/
decl.c
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
#include <stdio.h>
#include <stdlib.h>
#include "smalltools.h"
#include "decl.h"
#include "scope.h"
decl* decl_create(char *name, type *type, expr *value, stmt *code, decl *next) {
decl* rval = malloc(sizeof(decl));
rval->name = name;
rval->type = type;
rval->value = value;
rval->code = code;
rval->next = next;
rval->symbol = NULL;
rval->rbpoffset = 0;
return rval;
}
int decl_print_dot(decl *d, int* global_counter) {
int local_counter = (*global_counter)++;
int typer = -1;
int valuer = -1;
int coder = -1;
int nextr = -1;
printf("struct%d [label=\"{DECL|{", local_counter);
int first = 0;
if (d->name != NULL) {
print_with_bar_unless_first(&first, "nme = ");
printf("%s", d->name);
}
if (d->type != NULL) print_with_bar_unless_first(&first, "<f0> type");
if (d->value != NULL) print_with_bar_unless_first(&first, "<f1> value");
if (d->code != NULL) print_with_bar_unless_first(&first, "<f2> code");
if (d->next != NULL) print_with_bar_unless_first(&first, "<f3> next");
if (d->symbol != NULL && d->symbol->kind == SYMBOL_LOCAL && d->symbol->which >= 0) {
print_with_bar_unless_first(&first, " stk ");
printf("(%d)", d->symbol->which);
}
printf("}}\"];\n");
//rec calls
if (d->type != NULL) {
typer = type_print_dot(d->type, global_counter);
printf("struct%d:f0 -> struct%d;\n", local_counter, typer);
}
if (d->value != NULL) {
valuer = expr_print_dot(d->value, global_counter);
printf("struct%d:f1 -> struct%d;\n", local_counter, valuer);
}
if (d->code != NULL) {
coder = stmt_print_dot(d->code, global_counter);
printf("struct%d:f2 -> struct%d;\n", local_counter, coder);
}
if (d->next != NULL) {
nextr = decl_print_dot(d->next, global_counter);
printf("struct%d:f3 -> struct%d;\n", local_counter, nextr);
}
return local_counter;
}
void print_dot(decl* program_root) {
int global_counter = 0;
printf("digraph{\nnode [shape=record];\n");
decl_print_dot(program_root, &global_counter);
printf("}\n");
}