mips/masm/main.c
2024-09-11 12:06:09 -04:00

57 lines
921 B
C

#include <unistd.h>
#include <merror.h>
#include <string.h>
#include "asm.h"
void help(void) {
printf("usage: masm [options] source.asm\n\n");
printf("options:\n");
printf("\t-h\t\tprints this help message\n");
printf("\t-o output\tselect a output file destination\n");
}
int main(int argc, char **argv) {
struct assembler_arguments args = {
.in_file = NULL,
.out_file = NULL,
};
int c;
while ((c = getopt(argc, argv, "ho:")) != 1) {
switch(c) {
case 'h':
help();
return M_SUCCESS;
case 'o':
args.out_file = optarg;
break;
case '?':
return M_ERROR;
default:
goto next;
}
}
next:
if (optind < argc - 1) {
ERROR("too many source files passed");
return M_ERROR;
}
if (optind >= argc) {
ERROR("no source files passed");
return M_ERROR;
}
args.in_file = argv[optind];
if (args.out_file == NULL) {
args.out_file = "out.o";
}
return assemble_file(args);
}