diff --git a/fdpp/parsers/thunks.m4 b/fdpp/parsers/thunks.m4 deleted file mode 100644 index 882305e2..00000000 --- a/fdpp/parsers/thunks.m4 +++ /dev/null @@ -1,50 +0,0 @@ -# thunk template generator for fdpp - -# foru - upcounting loop. -m4_define(foru, [m4_cond(m4_eval($3>=$2), 1, [m4_for([$1],[$2],[$3],,[$4])])]) - -m4_define(G_S0, [foru(i, 1, $1, [aat[]i a[]i; \ -m4_if($1, i,, [ ])])]) -m4_define(G_S1, [foru(i, 1, $1, [aat[]m4_eval($1-i+1) a[]m4_eval($1-i+1); \ -m4_if($1, i,, [ ])])]) -m4_define(G_I0, [foru(i, 1, $1, [_a[]i[]m4_if($1, i,, [, ])])]) -m4_define(G_I1, [foru(i, 1, $1, [_a[]m4_eval($1-i+1)[]m4_if($1, i,, [, ])])]) -m4_define(G_M, [m4_cond($3, 1, _P_)$1[]m4_cond($2, 1, _v)]) -m4_define(G_A, [m4_if($1, 0, [NULL, 0], [(UBYTE *)&_args, sizeof(_args)])]) -m4_define(THUNK, -[[#]define _THUNK[]G_M($1,$2,$3)(n, m4_cond($2, 0, [r, s, ])f, foru(i, 1, $1, - [t[]i, q[]i, at[]i, aat[]i, c[]i, l[]i, ])z) \ -m4_if($2, 1, void, r) f(m4_if($1, 0, void, [foru(i, 1, $1, -[t[]i a[]i q[]i[]m4_if($1, i,, [, ])])])) \ -{ \ - const uint32_t _flags = z; \ -m4_cond($2, 0, [dnl - uint32_t _ret; \ -])dnl -foru(i, 1, $1, [dnl - _CNV(c[]i, t[]i, at[]i, l[]i, i); \ -])dnl -m4_if($1, 0,, [dnl - struct { \ - G_S$3($1)dnl - } PACKED _args = { G_I$3($1) }; \ -])dnl -m4_if($2, 0, [dnl - _ret = ], [dnl - ])__CALL(n, G_A($1), _flags); \ -m4_cond(m4_eval($3==0&&$1>0), 1, [dnl - __CSTK(sizeof(_args)); \ -])dnl -foru(i, 1, $1, [dnl - _UCNV(c[]i, l[]i, i); \ -])dnl -m4_cond($2, 0, [dnl - return s(r, _ret); \ -])dnl -}dnl -]) - -# now enable output. Should do it last to not get newlines from -# defines or comments. -m4_define([_m4_divert(STDOUT)], 1) -m4_divert_push([STDOUT])dnl diff --git a/fdpp/subprojects/thunk_gen b/fdpp/subprojects/thunk_gen deleted file mode 120000 index 112baaac..00000000 --- a/fdpp/subprojects/thunk_gen +++ /dev/null @@ -1 +0,0 @@ -../thunk_gen \ No newline at end of file diff --git a/fdpp/thunk_gen/makefile b/fdpp/thunk_gen/makefile deleted file mode 100644 index e1be34ba..00000000 --- a/fdpp/thunk_gen/makefile +++ /dev/null @@ -1,27 +0,0 @@ --include config.mak -srcdir ?= $(CURDIR) -include $(srcdir)/../clang.mak - -thunk_gen: lex.yy.o thunk_gen.tab.o - $(CC_FOR_BUILD) -g -o $@ $^ - -lex.yy.o: lex.yy.c thunk_gen.tab.h - -%.o: %.c - $(CC_FOR_BUILD) $(CLCFLAGS) -I $(srcdir) -Wno-unused-function -o $@ $< - -# not sure why GNU make does not set BISON -BISON ?= bison -need = 4.3 -ifneq ($(filter $(need),$(firstword $(sort $(MAKE_VERSION) $(need)))),) -thunk_gen.tab.c thunk_gen.tab.h &: $(srcdir)/thunk_gen.y -else -%.tab.c %.tab.h : $(srcdir)/%.y -endif - $(BISON) -d $^ - -lex.yy.c: $(srcdir)/thunk_gen.l - $(LEX) $^ - -clean: - $(RM) *.tab.* lex.yy.c *.o thunk_gen diff --git a/fdpp/thunk_gen/meson.build b/fdpp/thunk_gen/meson.build deleted file mode 100644 index 046d75f7..00000000 --- a/fdpp/thunk_gen/meson.build +++ /dev/null @@ -1,16 +0,0 @@ -project('thunk_gen', 'c', version: '0.1') - -flex = find_program('flex', required: true) -bison = find_program('bison', required: true) - -lgen = generator(flex, - output : '@PLAINNAME@.yy.c', - arguments : ['-o', '@OUTPUT@', '@INPUT@']) -lfiles = lgen.process('thunk_gen.l') - -pgen = generator(bison, - output : ['@BASENAME@.tab.c', '@BASENAME@.tab.h'], - arguments : ['@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@']) -pfiles = pgen.process('thunk_gen.y') - -TG = executable('thunk_gen', lfiles, pfiles, native: true) diff --git a/fdpp/thunk_gen/thunk_gen.l b/fdpp/thunk_gen/thunk_gen.l deleted file mode 100644 index 81f6bdcf..00000000 --- a/fdpp/thunk_gen/thunk_gen.l +++ /dev/null @@ -1,80 +0,0 @@ -%option noyywrap - -%{ -/* - * function prototype parser - lexer - * Author: Stas Sergeev - * - */ - -#include - -#define YY_DECL int yylex() - -#include "thunk_gen.tab.h" - -%} - -%% - -[0-9]+ { - yylval.NUM = atoi(yytext); - return NUM; - } -"(" { return LB; } -")" { return RB; } -";" { return SEMIC; } -"," { return COMMA; } -"\n" { return NEWLINE; } -"ASMCFUNC" { return ASMCFUNC; } -"ASMPASCAL" { return ASMPASCAL; } -"ASMFUNC" { } -"INITTEXT" { return INITTEXT; } -"SEGM" { return SEGM; } -"FAR" { return FAR; } -"far" { return FAR; } -"*" { return ASTER; } -"[" { return LBR; } -"]" { return RBR; } -"VOID" { return VOID; } -"void" { return VOID; } -"WORD" { return WORD; } -"COUNT" { return WORD; } -"BOOL" { return WORD; } -"char" { return CHAR; } -"short" { return WORD; } -"UCOUNT" { return UWORD; } -"UWORD" { return UWORD; } -"BYTE" { return BYTE; } -"UBYTE" { return UBYTE; } -"unsigned char" { return UBYTE; } -"unsigned short" { return UWORD; } -"int" { return DWORD; } -"unsigned" { return UDWORD; } -"unsigned int" { return UDWORD; } -"long" { return DWORD; } -"unsigned long" { return UDWORD; } -"size_t" { return UDWORD; } -"ssize_t" { return DWORD; } -"uint32_t" { return UDWORD; } -"ULONG" { return UDWORD; } -"ULONG32" { return UDWORD; } -"DWORD" { return DWORD; } -"UDWORD" { return UDWORD; } -"float" { return FLOAT; } -"double" { return DOUBLE; } -"long double" { return LDOUBLE; } -"struct" { return STRUCT; } -"union" { return UNION; } -"const" { return CONST; } -"NORETURN" { return NORETURN; } -"_V_FW" { return V_FW; } -"_V_BW" { return V_BW; } -"/*".*"*/" { /* comments */ } -[\t ]+ { /* skip spaces */ } -[_A-Za-z][_A-Za-z0-9]* { - yylval.STRING = strdup(yytext); - return STRING; - } - -%% diff --git a/fdpp/thunk_gen/thunk_gen.y b/fdpp/thunk_gen/thunk_gen.y deleted file mode 100644 index 3b32d415..00000000 --- a/fdpp/thunk_gen/thunk_gen.y +++ /dev/null @@ -1,637 +0,0 @@ -%{ -/* - * function prototype parser - * Author: Stas Sergeev - * - */ -#include -#include -#include -#include -#include - -#define YYDEBUG 1 - -static void yyerror(const char* s); -int yylex(void); - -static int thunk_type; -static int ptr_size; -static int align; - -static int arg_num; -static int arg_offs; -static int arg_size; -static int al_arg_size; -static int arr_sz; -static int is_ptr; -static int is_arr; -static int is_rptr; -static int is_far; -static int is_rfar; -static int is_ffar; -static int is_cbk; -static int is_void; -static int is_rvoid; -static int is_const; -static int is_pas; -static int is_init; -static int is_noret; -static int ref_inc; -static int ref_mult; -static int rlen; -static char abuf[1024]; -static char atype[256]; -static char atype2[256]; -static char atype3[256]; -static char rtbuf[256]; -/* conversion types for flat pointers */ -enum { CVTYPE_OTHER, CVTYPE_VOID, CVTYPE_CHAR, CVTYPE_ARR, CVTYPE_CHAR_ARR }; -static int cvtype; - - -static void beg_arg(void) -{ - is_far = 0; - is_ptr = 0; - is_arr = 0; - is_cbk = 0; - is_void = 0; - is_const = 0; - cvtype = CVTYPE_OTHER; - arr_sz = 0; - atype[0] = 0; - atype2[0] = 0; - atype3[0] = 0; - arg_size = 0; - ref_inc = 0; - ref_mult = 0; -} - -static void init_line(void) -{ - is_init = 0; - is_pas = 0; - is_rvoid = 0; - is_rptr = 0; - is_rfar = 0; - is_ffar = 0; - is_noret = 0; - rlen = 0; - beg_arg(); -} - -static void do_start_arg(int anum) -{ - if (thunk_type == 1 || thunk_type == 2) - strcat(abuf, "_"); - if (is_ptr) { - if (is_far) { - switch (anum) { - case 0: - strcat(abuf, "_ARG_PTR_FAR("); - break; - case 1: - strcat(abuf, "_ARG_PTR_FAR_A("); - break; - case 2: - strcat(abuf, "_CNV_PTR_FAR, _L_NONE"); - break; - } - } else { - switch (anum) { - case 0: - strcat(abuf, "_ARG_PTR("); - break; - case 1: - strcat(abuf, "_ARG_PTR_A("); - break; - case 2: - /* flat pointers need conversion to far */ - switch (cvtype) { - case CVTYPE_VOID: - if (ref_inc) - sprintf(abuf + strlen(abuf), "_CNV_PTR_%sVOID, _L_REF(%i, %i)", - is_const ? "C" : "", arg_num + 1 + ref_inc, ref_mult); - else - sprintf(abuf + strlen(abuf), "_CNV_PTR_%sPVOID, _L_NONE", - is_const ? "C" : ""); - break; - case CVTYPE_CHAR: - if (is_const) - strcat(abuf, "_CNV_PTR_CCHAR, _L_NONE"); - else - strcat(abuf, "_CNV_PTR_CHAR, _L_UNIMP"); - break; - case CVTYPE_CHAR_ARR: - if (is_const) { - if (arr_sz == -1) // main() template - strcat(abuf, "_CNV_PTR_CCHAR_ARR, _L_UNIMP"); // FIXME! - else - sprintf(abuf + strlen(abuf), "_CNV_PTR_CCHAR_ARR, " - "_L_IMM(%i, %i)", arg_num + 1, arr_sz); - } else - strcat(abuf, "_CNV_PTR_CHAR_ARR, _L_UNIMP"); - break; - case CVTYPE_ARR: - sprintf(abuf + strlen(abuf), "_CNV_PTR_ARR, _L_IMM(%i, %i)", - arg_num + 1, arr_sz); - break; - case CVTYPE_OTHER: - sprintf(abuf + strlen(abuf), "_CNV_%sPTR, _L_SZ(%i)", - is_const ? "C" : "", arg_num + 1); - break; - } - break; - } - } - } else if (is_cbk) { - switch (anum) { - case 0: - strcat(abuf, "_ARG_CBK("); - break; - case 1: - strcat(abuf, "_ARG_CBK_A("); - break; - case 2: - strcat(abuf, "_CNV_CBK, _L_NONE"); - break; - } - } else if (is_arr) { - switch (anum) { - case 0: - strcat(abuf, "_ARG_ARR("); - break; - case 1: - strcat(abuf, "_ARG_ARR_A("); - break; - case 2: - switch (cvtype) { - case CVTYPE_CHAR_ARR: - if (is_const) { - if (arr_sz == -1) - strcat(abuf, "_CNV_CCHAR_ARR, _L_UNIMP"); // FIXME! - else - sprintf(abuf + strlen(abuf), "_CNV_CCHAR_ARR, " - "_L_IMM(%i, %i)", arg_num + 1, arr_sz); - } else - sprintf(abuf + strlen(abuf), "_CNV_CHAR_ARR, " - "_L_IMM(%i, %i)", arg_num + 1, arr_sz); - break; - case CVTYPE_ARR: - sprintf(abuf + strlen(abuf), "_CNV_ARR, _L_IMM(%i, %i)", - arg_num + 1, arr_sz); - break; - case CVTYPE_OTHER: - sprintf(abuf + strlen(abuf), "_CNV_%sPTR, _L_SZ(%i)", - is_const ? "C" : "", arg_num + 1); - break; - } - } - } else { - switch (anum) { - case 0: - strcat(abuf, "_ARG("); - break; - case 1: - strcat(abuf, "_ARG_A("); - break; - case 2: - strcat(abuf, "_CNV_SIMPLE, _L_NONE"); - break; - } - } -} - -static void fin_arg(int last) -{ - int real_arg_size; - if (!atype[0]) - return; - if (!is_ptr && is_void) - return; - do_start_arg(0); - switch (thunk_type) { - case 0: - sprintf(abuf + strlen(abuf), "%i, %s%s%s, _SP)", arg_offs, - is_const ? "const " : "", atype, is_arr ? " *" : ""); - break; - case 1: - case 2: - if (is_const) - strcat(abuf, "const "); - sprintf(abuf + strlen(abuf), "%s)", atype); - strcat(abuf, ", "); - if (is_arr) { - if (arr_sz != -1) - sprintf(abuf + strlen(abuf), "[%i], ", arr_sz); - else - strcat(abuf, "[], "); - } else - strcat(abuf, ", "); - do_start_arg(1); - if (is_const) - strcat(abuf, "const "); - sprintf(abuf + strlen(abuf), "%s)", atype2[0] ? atype2 : atype); - strcat(abuf, ", "); - do_start_arg(1); - if (is_const) - strcat(abuf, "const "); - if (is_ptr) - sprintf(abuf + strlen(abuf), "%s)", atype2[0] ? atype2 : atype); - else - sprintf(abuf + strlen(abuf), "%s)", atype3[0] ? - atype3 : (atype2[0] ? atype2 : atype)); - strcat(abuf, ", "); - do_start_arg(2); - break; - } - if (is_ptr) { - real_arg_size = ptr_size; - if (is_far) - real_arg_size *= 2; - } else { - if (arg_size <= 0) { - if (arg_size == 0 && arg_num) - yyerror("parse error, void argument?"); - if (arg_size == -1 && !last) - yyerror("unknown argument size"); - return; - } - real_arg_size = al_arg_size; - } - assert(real_arg_size > 0); - arg_offs += real_arg_size; - arg_num++; -} - -static void add_flg(char *buf, const char *flg, int num) -{ - if (!num) { - strcpy(buf, flg); - } else { - strcat(buf, " | "); - strcat(buf, flg); - } -} - -static const char *get_flags(void) -{ - static char buf[32]; - int flg = 0; - - if (is_ffar) - add_flg(buf, "_TFLG_FAR", flg++); - if (is_noret) - add_flg(buf, "_TFLG_NORET", flg++); - if (is_init) - add_flg(buf, "_TFLG_INIT", flg++); - if (!flg) - add_flg(buf, "_TFLG_NONE", flg++); - return buf; -} - -#define AL(x) (((x) + (align - 1)) & ~(align - 1)) -static const char *al_s_type(void) { return (align == 2 ? "WORD" : "DWORD"); } -static const char *al_u_type(void) { return (align == 2 ? "UWORD" : "UDWORD"); } -#define ATYPE3(s) \ - if (al_arg_size > arg_size) \ - strcat(atype3, al_##s##_type()) - -%} - -%token LB RB SEMIC COMMA ASTER NEWLINE STRING NUM -%token ASMCFUNC ASMPASCAL FAR SEGM INITTEXT -%token VOID WORD UWORD CHAR BYTE UBYTE DWORD UDWORD DOUBLE LDOUBLE FLOAT -%token STRUCT UNION -%token LBR RBR -%token CONST -%token NORETURN V_FW V_BW - -%define api.value.type union -%type num lnum NUM -%type fname sname tname STRING - -%% - -input: input line NEWLINE - | -; - -line: lnum rdecls fname lb args rb attrs SEMIC - { - const char *rt, *rv; - - if (is_rptr) { - rt = "_RET_PTR"; - rv = "_ARG_RPTR"; - rlen = ptr_size; - if (is_rfar) { - rlen *= 2; - rt = "_RET_PTR_FAR"; - rv = "_ARG_RPTR_FAR"; - } - } else { - rt = "_RET"; - rv = "_ARG_R"; - } - switch (thunk_type) { - case 0: - if (!is_rvoid) { - if (abuf[0]) - printf("\tcase %i:\n\t\t_DISPATCH(%i, %s(%s), %s, %s, %s);\n\t\tbreak;\n", - $1, rlen, rv, rtbuf, rt, $3, abuf); - else - printf("\tcase %i:\n\t\t_DISPATCH(%i, %s(%s), %s, %s);\n\t\tbreak;\n", - $1, rlen, rv, rtbuf, rt, $3); - } else { - if (abuf[0]) - printf("\tcase %i:\n\t\t_DISPATCH_v(%s, %s);\n\t\tbreak;\n", - $1, $3, abuf); - else - printf("\tcase %i:\n\t\t_DISPATCH_v(%s);\n\t\tbreak;\n", - $1, $3); - } - break; - case 1: - /* for m4 */ - printf("THUNK(%i, %i, %i)\n", - arg_num, is_rvoid && !is_rptr, is_pas); - break; - case 2: - /* for cpp */ - if (!is_rvoid || is_rptr) - printf("_THUNK%s%i(%i, %s(%s), %s, %s", - is_pas ? "_P_" : "", - arg_num, - $1, - is_rptr ? (is_rfar ? "__ARG_PTR_FAR" : - "__ARG_PTR") : "__ARG", - rtbuf, - is_rptr ? (is_rfar ? "__RET_PTR_FAR" : - "__RET_PTR") : "__RET", - $3); - else - printf("_THUNK%s%i_v(%i, %s", - is_pas ? "_P_" : "", - arg_num, - $1, $3); - if (arg_num) - printf(", %s", abuf); - printf(", %s)\n", get_flags()); - break; - } - } -; - -lb: LB { arg_offs = 0; arg_num = 0; beg_arg(); } -; -rb: RB { fin_arg(1); } -; - -lnum: num { init_line(); } -; -num: NUM -; -fname: STRING -; -sname: STRING -; -tname: STRING -; -cname: STRING -; - -rquals: FAR ASTER { is_rfar = 1; is_rptr = 1; } - | ASTER { is_rptr = 1; } -; - -quals: FAR quals { is_far = 1; } - | ASTER quals { is_ptr = 1; } - | arr - | -; - -arr: LBR num RBR { cvtype == CVTYPE_CHAR ? cvtype = CVTYPE_CHAR_ARR : CVTYPE_ARR; is_arr = 1; arr_sz = $2; } - | LBR RBR { cvtype == CVTYPE_CHAR ? cvtype = CVTYPE_CHAR_ARR : CVTYPE_ARR; is_arr = 1; arr_sz = -1; } -; - -fatr: ASMCFUNC - | ASMPASCAL { is_pas = 1; } - | INITTEXT { is_init = 1; } - | NORETURN { is_noret = 1; } - | FAR { is_ffar = 1; } - | SEGM LB STRING RB -; - -fatrs: fatr fatrs - | fatr -; - -attr: NORETURN { is_noret = 1; } -; - -attrs: attr attrs - | -; - -rq_fa: rquals fatrs - | rquals - | fatrs - | -; - -rtype: VOID { rlen = 0; - strcpy(rtbuf, "void"); - is_rvoid = 1; - } - | WORD { rlen = 2; - strcpy(rtbuf, "WORD"); - } - | UWORD { rlen = 2; - strcpy(rtbuf, "UWORD"); - } - | DWORD { rlen = 4; - strcpy(rtbuf, "DWORD"); - } - | UDWORD { rlen = 4; - strcpy(rtbuf, "UDWORD"); - } - | FLOAT { rlen = 4; - strcpy(rtbuf, "float"); - } - | DOUBLE { rlen = 8; - strcpy(rtbuf, "double"); - } - | LDOUBLE { rlen = 12; - strcpy(rtbuf, "long double"); - } - | BYTE { rlen = 1; - strcpy(rtbuf, "BYTE"); - } - | CHAR { rlen = 1; - strcpy(rtbuf, "char"); - } - | UBYTE { rlen = 1; - strcpy(rtbuf, "UBYTE"); - } -; - -vref: - V_FW LB NUM RB - { - ref_inc = 1; - ref_mult = $3; - } - | V_BW LB NUM RB - { - ref_inc = -1; - ref_mult = $3; - } -; - -atype: - VOID vref { - arg_size = 0; - cvtype = CVTYPE_VOID; - strcat(atype, "VOID"); - al_arg_size = AL(arg_size); - is_void = 1; - } - | VOID { - arg_size = 0; - cvtype = CVTYPE_VOID; - strcat(atype, "VOID"); - al_arg_size = AL(arg_size); - is_void = 1; - } - | CHAR { - arg_size = 1; - cvtype = CVTYPE_CHAR; - strcat(atype, "char"); - al_arg_size = AL(arg_size); - ATYPE3(s); - } - | WORD { - arg_size = 2; - strcat(atype, "WORD"); - al_arg_size = AL(arg_size); - ATYPE3(s); - } - | UWORD { - arg_size = 2; - strcat(atype, "UWORD"); - al_arg_size = AL(arg_size); - ATYPE3(u); - } - | DWORD { - arg_size = 4; - strcat(atype, "DWORD"); - al_arg_size = AL(arg_size); - } - | UDWORD { - arg_size = 4; - strcat(atype, "UDWORD"); - al_arg_size = AL(arg_size); - } - | FLOAT { - arg_size = 4; - strcat(atype, "float"); - al_arg_size = AL(arg_size); - } - | DOUBLE { - arg_size = 8; - strcat(atype, "double"); - al_arg_size = AL(arg_size); - } - | LDOUBLE { - arg_size = 12; - strcat(atype, "long double"); - al_arg_size = AL(arg_size); - } - | BYTE { - arg_size = 1; - strcat(atype, "BYTE"); - al_arg_size = AL(arg_size); - ATYPE3(s); - } - | UBYTE { - arg_size = 1; - strcat(atype, "UBYTE"); - al_arg_size = AL(arg_size); - ATYPE3(u); - } - | VOID LB ASTER cname RB LB VOID RB { - arg_size = 4; - is_cbk = 1; - strcat(atype, "VOID"); - al_arg_size = AL(arg_size); - } - | STRUCT sname { - arg_size = -1; - sprintf(atype + strlen(atype), "struct %s", $2); - } - | UNION sname { - arg_size = -1; - sprintf(atype + strlen(atype), "union %s", $2); - } - | tname { - arg_size = -1; - sprintf(atype + strlen(atype), "%s", $1); - } -; - -rdecls: rtype rq_fa { abuf[0] = 0; } -; - -adecls: atype quals - | CONST atype quals { is_const = 1; } -; - -argsep: COMMA { fin_arg(0); strcat(abuf, ", "); beg_arg(); } - -args: args argsep arg - | arg -; - -arg: adecls STRING arr - | adecls STRING - | adecls -; - -%% - -int main(int argc, char *argv[]) -{ - const char *optstr = "dp:a:"; - int c; - yydebug = 0; - - while ((c = getopt(argc, argv, optstr)) != -1) { - switch (c) { - case 'a': - align = atoi(optarg); - break; - case 'p': - ptr_size = atoi(optarg); - break; - case 'd': - yydebug = 1; - break; - case '?': - fprintf(stderr, "unknown option %c\n", c); - return EXIT_FAILURE; - } - } - if (optind < argc) - thunk_type = atoi(argv[optind++]); - - yyparse(); - return 0; -} - -static void yyerror(const char* s) -{ - fprintf(stderr, "Parse error: %s\n", s); - exit(1); -}