-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtime.c
50 lines (45 loc) · 1.19 KB
/
runtime.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
#include "header.h"
int assembler_first_go(Control *ctrl) {
char line[MAX_SRC_LINE];
char label[MAX_SRC_LINE] = "";
string pt;
while (get_line(ctrl, line)) {
ctrl->line++;
pt = line;
/*Ignore comments and blank lines*/
if (*line == COMMENT || *line == '\n')
continue;
/*Get label*/
strcpy(label, line);
if (find_label(ctrl, label)) {
pt += strlen(label) + 1;
} else {
strcpy(label, "");
}
pt += trim(pt);
if (!strlen(pt)) {
add_error(ctrl, "Syntax error: can not add label to an empty line.\n");
continue;
}
/*Data and Strings*/
/*printf("label?: %d\t #%s\n", strlen(label) != 0, pt);*/
/* printf("file: %s%s, line %d: %s\n", ctrl->filename, IN_EXT, ctrl->line,
line);*/
}
return OK;
}
void cleanup(Control *ctrl) {
/*
Description: Cleanup run-time enviornment: free allocated memory, close files.
Input: Control object.
Output: void.
*/
if (ctrl->fp)
if (fclose(ctrl->fp) == EOF)
PANIC("Error closing files, assembler crashed!")
free_list(&ctrl->errors_array);
free_list(&ctrl->instruction_array);
free_list(&ctrl->data_array);
free_list(&ctrl->symbol_table);
return;
}