#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include "project.h"

/* Ye olde main function. */
int main(int argc, char** argv)
{
	if (strcmp(strchr(argv[0], 0) - 3, "asm") == 0) {
		if (argc != 4) die(
		"Usage: asm source image map\n"
		"source       preprocessed assembly source code\n"
		"image        memory image to be written\n"
		"map          map to be written\n");
		asm_assemble(argv[1], argv[2], argv[3]);
	} else if (strcmp(strchr(argv[0], 0) - 2, "vm") == 0) {
		if (argc != 3) die(
		"Usage: vm image map\n"
		"image        memory image to execute\n"
		"map          map to be utilized\n");
		vm_simulate(argv[1], argv[2]);
	} else {
		die("Invalid invocation '%s'; use asm or vm\n", argv[0]);
	}
}

/* Prints an error message and terminates the program. */
void die(const char* format, ...)
{
	va_list ap;
	va_start(ap, format);
	vfprintf(stderr, format, ap);
	va_end(ap);
	exit(EXIT_FAILURE);
}

