summaryrefslogtreecommitdiff
path: root/masm/main.c
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2024-09-10 18:23:46 -0400
committerFreya Murphy <freya@freyacat.org>2024-09-10 18:23:46 -0400
commit92a7e5853c6caeec09122c05ddbc19ae1498a0d8 (patch)
treed14a6a1c091df35c06ffb735ce3f6c72b1f37b42 /masm/main.c
parentrelocation table hell (diff)
downloadmips-92a7e5853c6caeec09122c05ddbc19ae1498a0d8.tar.gz
mips-92a7e5853c6caeec09122c05ddbc19ae1498a0d8.tar.bz2
mips-92a7e5853c6caeec09122c05ddbc19ae1498a0d8.zip
joe
Diffstat (limited to 'masm/main.c')
-rw-r--r--masm/main.c64
1 files changed, 61 insertions, 3 deletions
diff --git a/masm/main.c b/masm/main.c
index 957b34c..be156d8 100644
--- a/masm/main.c
+++ b/masm/main.c
@@ -1,9 +1,67 @@
+#include <unistd.h>
+#include <merror.h>
+#include <string.h>
+
#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) {
- if (argc != 2)
- return 0;
+ 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_mips32(argv[1]);
+ return assemble_file(args);
}