2 Copyright © 2015, The AROS Development Team. All rights reserved.
5 The code for creating a thunk file for the functions present in the module
10 #include "functionhead.h"
13 static void writethunkfunc(FILE *out
, struct config
*cfg
, struct functionhead
*funclist
)
15 struct functionarg
*arglistit
;
19 is_void
= (strcasecmp(funclist
->type
, "void") == 0);
22 "THUNK_PROTO%d(%s, %s, %s %s",
24 funclist
->type
, funclist
->internalname
,
25 cfg
->libbasetypeptrextern
, cfg
->libbase
);
26 for (arglistit
= funclist
->arguments
;
28 arglistit
= arglistit
->next
31 type
= getargtype(arglistit
);
32 name
= getargname(arglistit
);
33 assert(name
!= NULL
&& type
!= NULL
);
34 fprintf(out
, ", %s %s", type
, name
);
38 fprintf(out
, ");\n\n");
41 "AROS_LH%d(%s, %s,\n",
42 funclist
->argcount
, funclist
->type
, funclist
->internalname
45 for (arglistit
= funclist
->arguments
;
47 arglistit
= arglistit
->next
50 type
= getargtype(arglistit
);
51 name
= getargname(arglistit
);
52 assert(name
!= NULL
&& type
!= NULL
);
55 " AROS_LHA(%s, %s, %s),\n",
56 type
, name
, arglistit
->reg
65 " AROS_LIBFUNC_INIT\n\n",
66 cfg
->libbasetypeptrextern
, cfg
->libbase
, funclist
->lvo
, cfg
->basename
69 fprintf(out
, "THUNK_CALL%d(%s, %s, %s",
71 is_void
? "" : "return ",
72 funclist
->internalname
,
75 for (arglistit
= funclist
->arguments
;
77 arglistit
= arglistit
->next
80 name
= getargname(arglistit
);
82 fprintf(out
, ", %s", name
);
85 fprintf(out
, ");\n\n");
87 " AROS_LIBFUNC_EXIT\n"
92 void writethunk(struct config
*cfg
)
94 struct functionhead
*funclistit
;
97 struct functionarg
*arglistit
;
102 for(funclistit
= cfg
->funclist
; funclistit
!= NULL
; funclistit
= funclistit
->next
)
104 argmask
|= (1ULL << funclistit
->argcount
);
107 snprintf(line
, 255, "%s/%s_thunk.c", cfg
->gendir
, cfg
->modulename
);
108 out
= fopen(line
, "w");
116 for (i
= 0; i
< 64; i
++) {
117 if (argmask
& (1ULL << i
)) {
121 "#define THUNK_PROTO%d(type, name, arg_base", i
);
122 for (j
= 0; j
< i
; j
++) {
123 fprintf(out
, ", arg_%d", j
);
125 fprintf(out
, ")\\\n\ttype name(");
126 for (j
= 0; j
< i
; j
++) {
127 fprintf(out
, "arg_%d, ", j
);
129 fprintf(out
, "arg_base)\n");
132 "#define THUNK_CALL%d(retcode, name, arg_base", i
);
133 for (j
= 0; j
< i
; j
++) {
134 fprintf(out
, ", arg_%d", j
);
136 fprintf(out
, ")\\\n\tretcode name(");
137 for (j
= 0; j
< i
; j
++) {
138 fprintf(out
, "arg_%d, ", j
);
140 fprintf(out
, "arg_base)\n");
144 for(funclistit
= cfg
->funclist
; funclistit
!= NULL
; funclistit
= funclistit
->next
)
146 writethunkfunc(out
, cfg
, funclistit
);