summaryrefslogtreecommitdiffstats
path: root/src/emu/riscas.c
blob: 7a4af47bb4ade1066195372693e09b1dd96384eb (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, 4, 1, pfd);
	}

	return 0;
}