#include #include #include #include "asm.h" #include "mips.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-i isa\t\tselect a ISA to assemble to (mips32)\n"); printf("\t-o output\tselect a output file destination\n"); } int main(int argc, char **argv) { struct assembler_arguments args = { .isa = ISA_MIPS32, .in_file = NULL, .out_file = NULL, }; int c; while ((c = getopt(argc, argv, "ho:i:")) != 1) { switch(c) { case 'h': help(); return M_SUCCESS; case 'o': args.out_file = optarg; break; case 'i': if (strcmp(optarg, "mips32") == 0) { args.isa = ISA_MIPS32; } else { ERROR("invalid isa '%s'", optarg); return M_ERROR; } 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); }