varaq-wasm-c/main.c

37 lines
695 B
C
Raw Permalink Normal View History

2023-02-04 14:06:00 -05:00
#include "common.h"
#include "compiler.h"
#include "tokenizer.h"
int
2023-03-04 13:20:59 -05:00
main(int argc, char** argv)
2023-02-04 14:06:00 -05:00
{
2023-03-04 13:20:59 -05:00
if (argc != 3) {
printf("usage: varaq input.vq output.wasm");
return EXIT_FAILURE;
}
2023-02-04 14:06:00 -05:00
2023-03-04 13:20:59 -05:00
char* buffer;
2023-02-04 14:06:00 -05:00
int length = 0;
2023-03-04 13:20:59 -05:00
int sp = open(argv[1], O_RDONLY);
2023-02-04 14:06:00 -05:00
2023-03-04 13:20:59 -05:00
if (sp) {
length = lseek(sp, (size_t)0, SEEK_END);
lseek(sp, (size_t)0, SEEK_SET);
buffer = malloc(length);
if (buffer) {
read(sp, buffer, length * sizeof(char));
2023-02-04 14:06:00 -05:00
}
2023-03-04 13:20:59 -05:00
close(sp);
}
2023-02-04 14:06:00 -05:00
2023-03-04 13:20:59 -05:00
initMap();
Code* prog = compile(buffer);
2023-02-04 14:06:00 -05:00
2023-03-04 13:37:34 -05:00
int tp =
open(argv[2], O_CREAT | O_WRONLY | O_TRUNC, S_IRWXU | S_IRGRP | S_IROTH);
2023-03-04 13:20:59 -05:00
write(tp, prog->cells, prog->count);
close(tp);
2023-02-04 14:06:00 -05:00
return EXIT_SUCCESS;
}