#!/bin/sh
+# export decorated symbols using undecorated ones from .asm
+# $1 - .def
+# $2 - .in_c
outf=$3
-grep '@' $1 | awk '{print $1}' > ${outf}_explist
+grep '@' $1 | grep -v '\<DATA\>' | awk '{print $1}' > ${outf}_explist
echo ".text" > $outf
echo ".align 4" >> $outf
cat ${outf}_explist | while read i; do
- sym=`echo $i | awk -F@ '{print $1}'`
+ s0=`echo $i | cut -c 1`
+ if [ "$s0" = "@" ]; then
+ sym=`echo $i | awk -F@ '{print $2}'`
+ pre=""
+ else
+ sym=`echo $i | awk -F@ '{print $1}'`
+ pre="_"
+ fi
if grep -q "$sym" $2; then
continue
fi
- echo ".globl _$i" >> $outf
- echo "_$i:" >> $outf
+ echo ".globl $pre$i" >> $outf
+ echo "$pre$i:" >> $outf
echo " jmp $sym" >> $outf
echo >> $outf
done
pp->is_fastcall ? "__fastcall" :
(pp->is_stdcall ? "__stdcall" : "__cdecl"));
if (ret64)
- fprintf(f, " ret64");
+ fprintf(f, " ret64");
+ if (!pp->is_fastcall && pp->argc_reg != 0)
+ fprintf(f, " +reg");
+
+ if (pp->is_stdcall && !pp->is_fastcall && pp->argc_reg != 0
+ && !IS_START(sym, "sub_") && !IS_START(sym, "f_"))
+ {
+ // alias for possible .def export
+ char sym2[256];
+
+ snprintf(sym2, sizeof(sym2), "_%s@%d",
+ sym, pp->argc * 4);
+ fprintf(f, "\n.global %s # for .def\n", sym2);
+ fprintf(f, "%s:", sym2);
+ }
fprintf(f, "\n.global %s\n", sym);
fprintf(f, "%s:\n", sym);
my_assert_not(fout, NULL);
fprintf(fout, ".text\n\n");
- fprintf(fout, "# to asm\n\n");
+ fprintf(fout, "# C -> asm\n\n");
while (fgets(line, sizeof(line), fsyms_to))
{
out_toasm_x86(fout, sym_noat, pp);
}
- fprintf(fout, "# from asm\n\n");
+ fprintf(fout, "# asm -> C\n\n");
while (fgets(line, sizeof(line), fsyms_from))
{
{
const struct parsed_proto *pp;
FILE *fout, *fhdr;
- char basename[256];
+ char basename[256] = { 0, };
char line[256];
char fmt[256];
char word[256];
for (arg = 1; arg < argc; arg++) {
if (IS(argv[arg], "-n"))
noname = 1;
+ else if (IS(argv[arg], "-b") && arg < argc - 1)
+ snprintf(basename, sizeof(basename), "%s", argv[++arg]);
else
break;
}
if (argc != arg + 2) {
- printf("usage:\n%s [-n] <.h> <.def>\n", argv[0]);
+ printf("usage:\n%s [-n] [-b <basename>] <.h> <.def>\n", argv[0]);
return 1;
}
fout = fopen(argv[arg++], "w");
my_assert_not(fout, NULL);
- p = strrchr(hdrfn, '.');
- my_assert_not(p, NULL);
- p2 = strrchr(hdrfn, '/');
- if (p2++ == NULL)
- p2 = hdrfn;
- l = p - p2;
- my_assert((unsigned int)l < 256, 1);
- memcpy(basename, p2, l);
- basename[l] = 0;
+ if (basename[0] == 0) {
+ p = strrchr(hdrfn, '.');
+ my_assert_not(p, NULL);
+ p2 = strrchr(hdrfn, '/');
+ if (p2++ == NULL)
+ p2 = hdrfn;
+ l = p - p2;
+ my_assert((unsigned int)l < 256, 1);
+ memcpy(basename, p2, l);
+ basename[l] = 0;
+ }
snprintf(fmt, sizeof(fmt), "%s_%%d", basename);
if (pp == NULL)
return 1;
- fprintf(fout, " %s", word);
+ fputc(' ', fout);
+ fputc(pp->is_fastcall ? '@' : ' ', fout);
+ fprintf(fout, "%s", word);
if (pp->is_stdcall)
- fprintf(fout, "@%-2d", pp->argc_stack * 4);
+ fprintf(fout, "@%-2d", pp->argc * 4);
else
fprintf(fout, " ");
fprintf(fout, " @%d", ord);