blob: 5b6cac9c1a989b86221858065233d1e736cc6616 (
plain) (
blame)
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
|
#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;
}
|