2021-01-04 15:00:48 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "threads.h"
|
|
|
|
#include "parser.h"
|
|
|
|
#include "compiler.h"
|
|
|
|
#include "io.h"
|
|
|
|
#include "os.h"
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
if(argc < 2) {
|
|
|
|
eprintf("Usage: %s {input file(s)}\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
FILELIST* files = getfiles(argv[1]);
|
|
|
|
FILELIST* curr = files->next;
|
|
|
|
|
|
|
|
COMPILEUNIT* head = (COMPILEUNIT*)malloc(sizeof(COMPILEUNIT));
|
|
|
|
|
|
|
|
head->file = files;
|
|
|
|
head->parser = mkparser(tokenize(files->fullname), files->name);
|
|
|
|
|
|
|
|
COMPILEUNIT* currunit = head;
|
|
|
|
while(curr != NULL) {
|
|
|
|
COMPILEUNIT* newunit = (COMPILEUNIT*)malloc(sizeof(COMPILEUNIT));
|
|
|
|
newunit->file = curr;
|
|
|
|
newunit->parser = mkparser(tokenize(curr->fullname), curr->name);
|
|
|
|
currunit->next = newunit;
|
|
|
|
currunit = newunit;
|
|
|
|
curr = curr->next;
|
|
|
|
}
|
|
|
|
currunit->next = NULL;
|
|
|
|
|
|
|
|
actonunits(head, parseunit);
|
|
|
|
|
|
|
|
CLASS* headclass = head->parsed;
|
|
|
|
CLASS* currclass = headclass;
|
|
|
|
currunit = head->next;
|
|
|
|
while(currunit != NULL) {
|
|
|
|
currclass->next = currunit->parsed;
|
|
|
|
currclass = currunit->parsed;
|
|
|
|
currunit = currunit->next;
|
|
|
|
}
|
|
|
|
currclass->next = NULL;
|
|
|
|
COMPILER* compiler = mkcompiler(headclass);
|
|
|
|
|
|
|
|
currunit = head;
|
|
|
|
while(currunit != NULL) {
|
|
|
|
currunit->compiler = compiler;
|
|
|
|
currunit = currunit->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
actonunits(head, compileunit);
|
|
|
|
|
|
|
|
actonunits(head, vmtranslateunit);
|
|
|
|
|
|
|
|
currunit = head;
|
2021-01-04 15:12:32 -05:00
|
|
|
FILE* output = fopen("out.asm", "w");
|
2021-01-04 15:00:48 -05:00
|
|
|
while(currunit != NULL) {
|
|
|
|
if(output == NULL) {
|
|
|
|
eprintf("%s", strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
printstrlist(currunit->asmlns, output);
|
|
|
|
COMPILEUNIT* next = currunit->next;
|
|
|
|
freeunit(currunit);
|
|
|
|
currunit = next;
|
|
|
|
}
|
2021-01-04 15:12:32 -05:00
|
|
|
fclose(output);
|
2021-01-04 15:00:48 -05:00
|
|
|
|
|
|
|
freecompiler(compiler);
|
|
|
|
freetree(headclass);
|
|
|
|
freefilelist(files);
|
|
|
|
return 0;
|
|
|
|
}
|