-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
71 lines (58 loc) · 1.76 KB
/
main.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
#include <stdio.h>
#include <stdlib.h>
#include "structs.h"
#include "utilities.h"
#include "prototypes.h"
int ic;
int dc;
int err;
/* declare and initialize global structures and vars */
wordMeta word1 = {0};
wordPtr word_list = &word1;
wordPtr head_word;
labelPtr symbols_table;
boolean entry_existence, extern_existence, was_error;
wordMeta dataword1 = {0};
wordPtr data_word_list = &dataword1;
wordPtr head_data_word;
const char *commands[] = {
"mov", "cmp", "add", "sub", "lea", "clr", "not", "inc", "dec", "jmp", "bne",
"jsr", "red", "prn", "rts", "stop"
};
const char *directives[] = {
".data", ".string", ".entry", ".extern"
};
/* resets the following vars */
void reset_global_vars()
{
symbols_table = NULL;
entry_existence = FALSE;
extern_existence = FALSE;
was_error = FALSE;
}
/* receives arguments, first is the program and then multiple assembly files (without file extension)
* and handles flow of program */
int main(int argc, char *argv[]){
int i;
char *input_filename;
FILE *fp;
for(i = 1; i < argc; i++)
{
input_filename = create_file_name(argv[i], FILE_INPUT); /* Appending .as to filename */
fp = fopen(input_filename, "r");
if(fp != NULL) { /* If file exists */
printf("---------- Started %s assembling process ----------\n\n", input_filename);
reset_global_vars();
first_pass(fp);
if (!was_error) { /* proceed to second pass */
rewind(fp);
second_run(fp, argv[i]);
}
printf("\n\n---------- Finished %s assembling process ----------\n\n", input_filename);
}
else write_error(CANNOT_OPEN_FILE);
free(input_filename);
fclose(fp);
}
return 0;
}