-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecond_pass.c
63 lines (52 loc) · 1.53 KB
/
second_pass.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
#include "second_pass.h"
/* Perform second pass on file */
bool second_pass(FILE *file) {
pass_over_file(file);
if (!populate_symbols()) {
print_error(UNKNOWN_LINE);
return false;
}
return true;
}
bool pass_over_file(FILE *file) {
char line[MAX_LINE_LENGTH];
int current_line = 1;
bool success;
/* Read whole file and process relevant lines */
while (fgets(line, MAX_LINE_LENGTH, file) != NULL) {
g_error = NO_ERRORS;
if (should_process_line(line, current_line)) {
success = process_line_again(line, current_line);
if (!success) {
print_error(current_line);
}
}
current_line++;
}
}
/* Second pass processing of line */
bool process_line_again(char *line, int current_line) {
char label[MAX_LABEL_LENGTH] = "\0";
directive directive_type;
line = trim(line);
/* Validate line integrity */
if (!valid_start(line)) {
return false;
}
/* Ignore labels */
if (check_for_label(line, label)) {
line = next_field(line);
}
if (check_for_directive(line, &directive_type)) {
return handle_directive_again(line, directive_type);
}
return true;
}
/* We only care of entry labels. If found, add entry atribute to relevant symbol */
bool handle_directive_again(char *line, directive directive_type) {
if (directive_type != DIRECTIVE_ENTRY) {
return true;
}
line = next_field(line);
return add_attribute_to_symbol(line, ATTRIBUTE_ENTRY);
}