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
#include <stdlib.h>
#include <stdio.h>
#include "utils.h"
#include "tac_string_builder.h"
char *mcc_tac_new_temporary_string(struct mcc_tac *tac) {
size_t num_digits = (size_t) mcc_get_number_of_digits(tac -> temporary_count);
// +2 for character t and for \0
char *t = malloc(num_digits + 2);
if (t == NULL) {
return NULL;
}
sprintf(t, "t%d", tac -> temporary_count);
tac -> temporary_count++;
tac -> last_temporary = t;
return t;
}
char *mcc_tac_new_label_string(struct mcc_tac *tac) {
size_t num_digits = (size_t) mcc_get_number_of_digits(tac -> label_count);
// +2 for character t and for \0
char *t = malloc(num_digits + 2);
if (t == NULL) {
return NULL;
}
sprintf(t, "L%d", tac -> label_count);
tac -> label_count++;
tac -> last_label = t;
return t;
}