blob: 5b6cac9c1a989b86221858065233d1e736cc6616 (
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)) {
inst_t IR = compile(line);
if (IR == 0xFFFFFFFFFFFFFFFF)
die("illegal instruction: %s", line);
fwrite(&IR, sizeof(inst_t), 1, pfd);
}
return 0;
}
|