From: notaz Date: Sat, 18 Jan 2014 19:48:35 +0000 (+0200) Subject: .def tool, generate .lib and tramp on demand X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f906263984019d6804c760d7ca6f8c162c5b78d;p=ia32rtools.git .def tool, generate .lib and tramp on demand --- diff --git a/run_imp.sh b/run_imp.sh index fd049d0..7c10376 100755 --- a/run_imp.sh +++ b/run_imp.sh @@ -2,8 +2,8 @@ grep 'extrn ' StarCraft.asm | awk '{print $2}' | awk -F: '{print $1}' > implist -echo ".data" > tramp.s -echo ".align 4" >> tramp.s +echo ".data" > $1 +echo ".align 4" >> $1 cat implist | while read i; do rm -f tmpsym @@ -30,8 +30,8 @@ cat implist | while read i; do exit 1 fi - echo ".globl $i" >> tramp.s - echo "$i:" >> tramp.s - echo " .long $sym" >> tramp.s - echo >> tramp.s + echo ".globl $i" >> $1 + echo "$i:" >> $1 + echo " .long $sym" >> $1 + echo >> $1 done diff --git a/tools/Makefile b/tools/Makefile index 4d61132..d7ed711 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -3,7 +3,7 @@ ifndef DEBUG CFLAGS += -O2 endif -T = asmproc cmpmrg_text mkbridge translate cvt_data +T = asmproc cmpmrg_text mkbridge translate cvt_data mkdef_ord all: $(T) @@ -13,4 +13,6 @@ clean: translate: translate.o mkbridge: mkbridge.o cvt_data: cvt_data.o -mkbridge.o translate.o cvt_data.o: protoparse.h my_assert.h my_str.h +mkdef_ord: mkdef_ord.o +mkbridge.o translate.o cvt_data.o mkdef_ord.o: \ + protoparse.h my_assert.h my_str.h diff --git a/tools/mkdef_ord.c b/tools/mkdef_ord.c new file mode 100644 index 0000000..4f6b50b --- /dev/null +++ b/tools/mkdef_ord.c @@ -0,0 +1,90 @@ +#include +#include +#include + +#include "my_assert.h" +#include "my_str.h" + +#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) +#define IS(w, y) !strcmp(w, y) +#define IS_START(w, y) !strncmp(w, y, strlen(y)) + +#include "protoparse.h" + +int main(int argc, char *argv[]) +{ + const struct parsed_proto *pp; + FILE *fout, *fhdr; + char basename[256]; + char line[256]; + char fmt[256]; + char word[256]; + char *p; + int arg = 1; + int ret, ord; + int l; + + if (argc != 3) { + printf("usage:\n%s <.h> <.def>\n", argv[0]); + return 1; + } + + hdrfn = argv[arg++]; + fhdr = fopen(hdrfn, "r"); + my_assert_not(fhdr, NULL); + + fout = fopen(argv[arg++], "w"); + my_assert_not(fout, NULL); + + p = strrchr(hdrfn, '.'); + my_assert_not(p, NULL); + l = p - hdrfn; + my_assert(l < 256, 1); + memcpy(basename, hdrfn, l); + basename[l] = 0; + + snprintf(fmt, sizeof(fmt), "%s_%%d", basename); + + fprintf(fout, "LIBRARY %s\n", basename); + fprintf(fout, "EXPORTS\n"); + + while (fgets(line, sizeof(line), fhdr)) + { + p = sskip(line); + if (*p == 0) + continue; + + if (IS(p, "//")) + continue; + + ret = 0; + while (p != NULL && *p != 0) { + p = next_word(word, sizeof(word), p); + ret = sscanf(word, fmt, &ord); + if (ret == 1) + break; + } + if (ret != 1) { + printf("scan for '%s' failed for '%s'\n", fmt, line); + return 1; + } + + snprintf(word, sizeof(word), fmt, ord); + pp = proto_parse(fhdr, word, 0); + if (pp == NULL) + return 1; + + fprintf(fout, " %s", word); + if (pp->is_stdcall) + fprintf(fout, "@%-2d", pp->argc_stack * 4); + else + fprintf(fout, " "); + fprintf(fout, " @%d\n", ord); + } + + fclose(fhdr); + fclose(fout); + return 0; +} + +// vim:ts=2:shiftwidth=2:expandtab diff --git a/tools/protoparse.h b/tools/protoparse.h index c585306..3981588 100644 --- a/tools/protoparse.h +++ b/tools/protoparse.h @@ -610,8 +610,10 @@ static int b_pp_c_handler(char *proto, const char *fname) static void build_pp_cache(FILE *fhdr) { + long pos; int ret; + pos = ftell(fhdr); rewind(fhdr); ret = do_protostrs(fhdr, hdrfn); @@ -619,6 +621,7 @@ static void build_pp_cache(FILE *fhdr) exit(1); qsort(pp_cache, pp_cache_size, sizeof(pp_cache[0]), pp_name_cmp); + fseek(fhdr, pos, SEEK_SET); } static const struct parsed_proto *proto_parse(FILE *fhdr, const char *sym,