-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassembler.c
More file actions
58 lines (55 loc) · 2.02 KB
/
assembler.c
File metadata and controls
58 lines (55 loc) · 2.02 KB
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
#include "misc/definitions.h"
#include "misc/utils.h"
#include "passes/pre_assembler.h"
#include "passes/first_pass.h"
/**
* main wrapper function that parses the user inputs and executes the runs
* @param argc
* @param argv
*/
void mainRunner(int argc, char **argv) {
int errors = 0;
int inputFileCounter = 1;
char line[MAX_LENGTH];
char *outPutFileName = malloc(sizeof(char));
macroTable *table = malloc(sizeof(macroTable));
FILE *outP;
FILE *inp;
checkMalloc(outPutFileName);
checkMalloc(table);
printf("Received %d files, starting assembler process.\n\n", argc-1);
while (inputFileCounter < argc) { /* iterate over files from argv .as */
errors = 0;
lineNum = 1;
memset(line, '0', 4);
if ((inp = inputFileInit(argv, inp, &inputFileCounter)) == NULL) {
printError("file not found, skipping to next");
continue;
} else outP = outputFileInit(outP, outPutFileName, argv[inputFileCounter - 1]);
while (!(strstr(line, "NULL"))) {
stringCopy(line, iterator(line, inp, &errors));
if (strstr(line, "NULL")) break;
preAssembler(line, &errors, inp, outP, table); /* macro handler */
}
free(table);
table = malloc(sizeof(macroTable));
printf("===>>>>>> Pre assembler finished: Errors: %d\n", errors);
if (errors == 0) {
fclose(inp);
lineNum = 1;
firstPass(line, outP, &errors, outPutFileName);
} else {
fclose(inp);
remove(outPutFileName);
printError("due to errors not continuing with flow on current file, continue with next file");
}
printf("===>>>>>> Finished file: %s <<<<<<===\n", outPutFileName);
printf("======================================================================\n\n");
}
free(table);
printf("Finished processing - %d file(s) that were received.\n", argc-1);
}
int main(int argc, char **argv) {
mainRunner(argc, argv);
return 0;
}