-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
43 lines (32 loc) · 864 Bytes
/
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
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include "nyan.h"
#include "util.h"
int main(int argc, char** argv) {
setlocale(LC_ALL, ""); // set the locale to the user's default locale
if (argc < 3) {
printf("Usage: nyan <filename> <output>\n");
return EXIT_FAILURE;
}
char* filename = argv[1];
char* output = argv[2];
Assembly* assem = malloc(sizeof(Assembly));
struct nyan_s nyan = parse_nyan(filename);
compile_nyan(nyan, assem);
FILE* f = fopen("nyan.s", "w");
printf("%s", assem->data);
fprintf(f, "%s", assem->data);
fclose(f);
char* cmd = "nasm -f elf64 nyan.s -o nyan.o && ld nyan.o -o %s";
char* cmd2 = malloc(sizeof(char) * 1024);
sprintf(cmd2, cmd, output);
system(cmd2);
// clean up
free(cmd2);
free(assem);
// delete temp files
remove("nyan.s");
remove("nyan.o");
return EXIT_SUCCESS;
}