translate: some 64bit math stuff, arg-reuse tailcall
[ia32rtools.git] / tools / asmproc.c
index 678f58f..6f1e3d5 100644 (file)
@@ -193,7 +193,7 @@ int main(int argc, char *argv[])
                        }
                }
 
-               if (IS_OR3(word, "call", "jmp", "public")) {
+               if (IS_OR2(word, "call", "jmp")) {
                        ssym.name = word2;
                        sym = bsearch(&ssym, symlist, symlist_cnt,
                                sizeof(symlist[0]), cmp_sym);
@@ -206,6 +206,16 @@ int main(int argc, char *argv[])
                        }
                }
 
+               if (IS(word, "public")) {
+                       ssym.name = word2;
+                       sym = bsearch(&ssym, symlist, symlist_cnt,
+                               sizeof(symlist[0]), cmp_sym);
+                       if (sym != NULL) {
+                               fprintf(fout, "\t\tpublic %s%s", sym_use(sym), p);
+                               continue;
+                       }
+               }
+
                p = sskip(p);
                if (*p == 0 || *p == ';')
                        goto pass; // need at least 3 words
@@ -229,9 +239,11 @@ int main(int argc, char *argv[])
                }
 
                // dd offset <sym>
-               if (IS(word, "dd") && IS(word2, "offset")) {
+               if (IS(word, "dd")
+                       && (IS(word2, "offset") || strstr(p, "offset")))
+               {
                        fprintf(fout, "\t\tdd");
-                       strcpy(word, word3);
+                       p = next_word(word, sizeof(word), line);
                        goto offset_loop;
                }
 
@@ -242,9 +254,12 @@ int main(int argc, char *argv[])
                p = next_word(word4, sizeof(word4), p);
 
                // <name> dd offset <sym>
-               if (IS(word2, "dd") && IS(word3, "offset")) {
+               if (IS(word2, "dd")
+                       && (IS(word3, "offset") || strstr(p, "offset")))
+               {
                        fprintf(fout, "%s\tdd", word);
-                       strcpy(word, word4);
+                       p = next_word(word, sizeof(word), line);
+                       p = next_word(word, sizeof(word), p);
                        goto offset_loop;
                }
 
@@ -294,6 +309,19 @@ pass:
 
 offset_loop:
                while (1) {
+                       p2 = next_word(word, sizeof(word), p);
+                       if (word[0] == 0 || word[0] == ';') {
+                               break;
+                       }
+                       if (!IS(word, "offset")) {
+                               // pass through
+                               p2 = strstr(p, "offset");
+                               if (p2 == NULL)
+                                       break;
+                               fwrite(p, 1, p2 - p, fout);
+                               p2 = next_word(word, sizeof(word), p2);
+                       }
+                       p = next_word(word, sizeof(word), p2);
                        p2 = strchr(word, ',');
                        if (p2)
                                *p2 = 0;
@@ -304,16 +332,6 @@ offset_loop:
                        fprintf(fout, " offset %s%s",
                                (sym != NULL && sym->callsites) ? sym_use(sym) : word,
                                p2 ? "," : "");
-
-                       p2 = next_word(word, sizeof(word), p);
-                       if (word[0] == 0 || word[0] == ';') {
-                               break;
-                       }
-                       if (!IS(word, "offset")) {
-                               printf("could not handle offset array\n");
-                               break;
-                       }
-                       p = next_word(word, sizeof(word), p2);
                }
                fprintf(fout, "%s", p);
                continue;