get rid of some duplication
[ia32rtools.git] / tools / asmproc.c
index c016fd5..956ffa2 100644 (file)
@@ -1,9 +1,18 @@
+/*
+ * ia32rtools
+ * (C) notaz, 2013,2014
+ *
+ * This work is licensed under the terms of 3-clause BSD license.
+ * See COPYING file in the top-level directory.
+ */
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
 #include "my_assert.h"
 #include "my_str.h"
+#include "common.h"
 
 struct sl_item {
        char *name;
@@ -101,7 +110,6 @@ const char *sym_use(const struct sl_item *sym, int is_rm)
        return buf;
 }
 
-#define IS(w, y) !strcasecmp(w, y)
 #define IS_OR2(w, x, y) (IS(w, x) || IS(w, y))
 #define IS_OR3(w, x, y, z) (IS(w, x) || IS(w, y) || IS(w, z))
 
@@ -227,9 +235,7 @@ int main(int argc, char *argv[])
                p = next_word(word3, sizeof(word3), p);
 
                // push offset <sym>
-               // jcc short <sym>
-               if ( (IS(word, "push") && IS(word2, "offset"))
-                 || (word[0] == 'j' && IS(word2, "short") && !IS(word3, "exit")) ) {
+               if (IS(word, "push") && IS(word2, "offset")) {
                        ssym.name = word3;
                        sym = bsearch(&ssym, symlist, symlist_cnt,
                                sizeof(symlist[0]), cmp_sym);
@@ -240,6 +246,22 @@ int main(int argc, char *argv[])
                        }
                }
 
+               // jcc short <sym>
+               if (word[0] == 'j' && IS(word2, "short") && !IS(word3, "exit")) {
+                       ssym.name = word3;
+                       sym = bsearch(&ssym, symlist, symlist_cnt,
+                               sizeof(symlist[0]), cmp_sym);
+                       if (sym != NULL) {
+                               fprintf(fout, "\t\t%s ", word);
+                               // for conditional "call", don't print 'short'
+                               if (IS(word3, func))
+                                       fprintf(fout, "short ");
+                               fprintf(fout, "%s%s",
+                                 sym_use(sym, sym->callsites || IS(word3, func)), p);
+                               continue;
+                       }
+               }
+
                // dd offset <sym>
                if (IS(word, "dd")
                        && (IS(word2, "offset") || strstr(p, "offset")))