blob: e4180b2e2e683776eb1400652b64d31b60fd77d8 (
plain) (
tree)
|
|
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include "asm.h"
#include "log.h"
static
void usage(int rc)
{
fprintf(stderr, "Usage: riscas <source> <program>\n");
exit(rc);
}
int main(int argc, char *argv[])
{
if (argc < 3) {
usage(EXIT_FAILURE);
}
FILE *sfd;
if ((sfd = fopen(argv[1], "r")) == NULL)
pdie("could not open source %s", argv[1]);
FILE *pfd;
if ((pfd = fopen(argv[2], "w")) == NULL)
pdie("could not open program %s", argv[2]);
char line[128];
while (fgets(line, 128, sfd)) {
uint32_t IR = compile(line);
if (IR == 0xFFFFFFFF)
die("illegal instruction: %s", line);
fwrite(&IR, sizeof(uint32_t), 1, pfd);
}
return 0;
}
|