varaq-wasm-c/main.c

38 lines
723 B
C
Raw Normal View History

2023-02-04 14:06:00 -05:00
#include "common.h"
#include "compiler.h"
#include "tokenizer.h"
int
main (int argc, char **argv)
{
if (argc != 3)
{
printf ("usage: varaq input.vq output.wasm");
return EXIT_FAILURE;
}
char *buffer;
int length = 0;
int sp = open (argv[1], O_RDONLY);
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));
}
close (sp);
}
Code *prog = compile (buffer);
int tp = open (argv[2], O_CREAT | O_WRONLY, S_IRWXU | S_IRGRP | S_IROTH);
write (tp, prog->cells, prog->count);
close (tp);
return EXIT_SUCCESS;
}