symbols: Added new symbol format option
authorLukas Krickl <lukas@krickl.dev>
Sat, 1 Mar 2025 18:29:50 +0000 (19:29 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sat, 1 Mar 2025 18:29:50 +0000 (19:29 +0100)
man/ulas.1
src/main.c
src/ulas.c
src/ulas.h

index 4614691e4563d020a65e6859d4b4d63daf6f74d5..35e477f889b7c27851f17ad64ea535fe01802732 100644 (file)
@@ -6,7 +6,7 @@
 .SH NAME
   ulas
 .SH SYNOPSIS
-  ulas [-hvVpdA] [-o=path] [-I=path] [-l=path] [-a=initial-address] [-S=ulas|mlb] [input]
+  ulas [-hvVpdA] [-o=path] [-I=path] [-l=path] [-a=initial-address] [-S=ulas|mlb|sym] [input]
 .SH DESCRIPTION
   ulas
 
index 8acf6a11e22c2403e9a948dd36a81c85fd463c0e..6e48637a8c2909cd0d640fe81eb46eef26ee60b0 100644 (file)
@@ -69,7 +69,9 @@ void ulas_getopt(int argc, char **argv, struct ulas_config *cfg) {
         cfg->sym_fmt = ULAS_SYM_FMT_DEFAULT; 
       } else if (strcmp("mlb", optarg) == 0) {
         cfg->sym_fmt = ULAS_SYM_FMT_MLB; 
-      } else {
+      } else if (strcmp("sym", optarg) == 0) {
+        cfg->sym_fmt = ULAS_SYM_FMT_SYM;
+      }else {
         printf("Invalid symbol format: %s\n", optarg);
         exit(-1);
       }
index 6c3925396edf24198c65a0d6af22e18b207a2809..98588f36d9bcb4eb31ee5983e12f9929f9b0a9ff 100644 (file)
@@ -24,7 +24,7 @@ unsigned long defslen = 0;
 void ulas_help(void) {
   printf("%s\n", ULAS_NAME);
   printf("Usage %s [-%s] [-o=path] [-I=path] [-l=path] [-a=initial-address] "
-         "[-S=ulas|mlb] "
+         "[-S=ulas|mlb|sym] "
          "[input]\n\n",
          ULAS_NAME, ULAS_OPTS);
   ULAS_HELP("h", "display this help and exit");
@@ -440,6 +440,28 @@ int ulas_symbolout(FILE *dst, struct ulas_sym *s) {
     }
     fprintf(dst, "\n");
     break;
+  case ULAS_SYM_FMT_SYM:
+    fprintf(dst, "00:");
+    
+    switch (s->tok.type) {
+    case ULAS_INT:
+      fprintf(dst, "%x", ulas_valint(&s->tok, &rc));
+      break;
+    case ULAS_STR:
+      fprintf(dst, "%s", ulas_valstr(&s->tok, &rc));
+      break;
+    default:
+      fprintf(dst, "<Unknown type>");
+      break;
+    }
+
+    if (!s->name || s->name[0] == '\0') {
+      fprintf(dst, "<unnamed>");
+    } else {
+      fprintf(dst, " %s", s->name);
+    }
+    fprintf(dst, "\n");
+    break;
   case ULAS_SYM_FMT_MLB:
     switch (s->tok.type) {
     case ULAS_INT: {
index 43deaa73f65f477824b3027fd2697fd60849de77..9f62e74f71e4652bc1e2f2f0de33044b3ab40113 100644 (file)
@@ -142,7 +142,7 @@ struct ulas_tok;
 
 enum ulas_warm { ULAS_WARN_OVERFLOW = 1, ULAS_WARN_ALL = 0x7FFFFFFF };
 
-enum ulas_symfmt { ULAS_SYM_FMT_DEFAULT, ULAS_SYM_FMT_MLB };
+enum ulas_symfmt { ULAS_SYM_FMT_DEFAULT, ULAS_SYM_FMT_SYM, ULAS_SYM_FMT_MLB };
 
 struct ulas_config {
   // argv represents file names