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