2 ### Class Stub: Create a generic stub file ####################################
10 my $class = ref($proto) || $proto;
12 $self->{SFD
} = $params{'sfd'};
14 bless ($self, $class);
20 my $sfd = $self->{SFD
};
24 print "/* Automatically generated stubs! Do not edit! */\n";
27 foreach my $inc (@
{$$sfd{'includes'}}) {
28 print "#include $inc\n";
31 foreach my $td (@
{$$sfd{'typedefs'}}) {
32 print "typedef $td;\n";
36 print "#ifdef __cplusplus\n";
37 print "extern \"C\" {\n";
38 print "#endif /* __cplusplus */\n";
41 if ($$sfd{'base'} ne '') {
42 print "#ifndef BASE_EXT_DECL\n";
43 print "#define BASE_EXT_DECL\n";
44 print "#define BASE_EXT_DECL0 extern $$sfd{'basetype'} " .
46 print "#endif /* !BASE_EXT_DECL */\n";
47 print "#ifndef BASE_PAR_DECL\n";
48 print "#define BASE_PAR_NAME\n";
49 print "#define BASE_PAR_DECL\n";
50 print "#define BASE_PAR_DECL0 void\n";
51 print "#endif /* !BASE_PAR_DECL */\n";
52 print "#ifndef BASE_NAME\n";
53 print "#define BASE_NAME $$sfd{'base'}\n";
54 print "#endif /* !BASE_NAME */\n";
56 print "BASE_EXT_DECL0\n";
65 my $prototype = $params{'prototype'};
66 my $sfd = $self->{SFD
};
68 # Don't process private functions
69 if ($prototype->{private
}) {
73 $self->function_proto (prototype => $prototype, decl_regular
=> $self->{NEWFILE
} );
74 $self->function_start (prototype => $prototype);
75 for my $i (0 .. $$prototype{'numargs'} - 1 ) {
76 $self->function_arg (prototype => $prototype,
77 argtype
=> $$prototype{'argtypes'}[$i],
78 argname
=> $$prototype{'___argnames'}[$i],
79 argreg
=> $$prototype{'regs'}[$i],
82 $self->function_end (prototype => $prototype);
91 my $sfd = $self->{SFD
};
94 print "#undef BASE_EXT_DECL\n";
95 print "#undef BASE_EXT_DECL0\n";
96 print "#undef BASE_PAR_NAME\n";
97 print "#undef BASE_PAR_DECL\n";
98 print "#undef BASE_PAR_DECL0\n";
99 print "#undef BASE_NAME\n";
101 print "#ifdef __cplusplus\n";
103 print "#endif /* __cplusplus */\n";
112 my $prototype = $params{'prototype'};
113 my $decl_regular = $params{'decl_regular'};
114 my $sfd = $self->{SFD
};
116 if ($prototype->{type
} eq 'varargs' && $decl_regular) {
117 my $rproto = $prototype->{real_prototype
};
119 print "__inline $$rproto{'return'} $$rproto{'funcname'}(";
120 if (!$prototype->{nb
}) {
121 if ($$rproto{'numargs'} == 0) {
122 print "BASE_PAR_DECL0";
125 print "BASE_PAR_DECL ";
128 print join (', ', @
{$$rproto{'___args'}});
134 if ($prototype->{type
} eq 'cfunction' &&
135 $prototype->{argnames
}[$#{@{$prototype->{argnames}}}] eq '...') {
137 print "/* Unsupported */\n";
140 # Declare structs in case some ==include directive is missing
141 for my $argtype (@
{$prototype->{argtypes
}}) {
144 (undef, $struct) = ( $argtype =~ /\s*(const)?\s*struct\s*(\w+).*/) and
145 printf "struct $struct;\n";
149 print "__inline $$prototype{'return'}\n";
150 print "$$prototype{'funcname'}(";
151 if (!$prototype->{nb
}) {
152 if ($$prototype{'numargs'} == 0) {
153 print "BASE_PAR_DECL0";
156 print "BASE_PAR_DECL ";
159 print join (', ', @
{$$prototype{'___args'}});
167 my $prototype = $params{'prototype'};
168 my $sfd = $self->{SFD
};
173 if ($$prototype{'type'} eq 'varargs') {
174 print " return $$prototype{'real_funcname'}(BASE_PAR_NAME ";
176 elsif ($prototype->{type
} eq 'cfunction') {
177 if (!$prototype->{nb
}) {
178 print " BASE_EXT_DECL\n";
181 my $argtypes = join (', ',@
{$$prototype{'argtypes'}});
183 if ($argtypes eq '') {
184 if ($prototype->{nb
}) {
189 if (!$prototype->{nb
}) {
190 $argtypes = "$sfd->{basetype}, $argtypes";
195 # Skip jmp instruction (is m68k ILLEGAL in MOS)
196 my $offs = $$prototype{'bias'} - 2;
198 print " $$prototype{'return'} (*_func) ($argtypes) = \n";
199 print " ($$prototype{'return'} (*) ($argtypes))\n";
200 print " *((ULONG*) (((char*) BASE_NAME) - $offs));\n";
201 print " return (*_func)(";
203 if (!$prototype->{nb
}) {
205 print ", " unless $prototype->{numargs
} == 0;
209 print STDERR
"$prototype->{funcname}: Unhandled.\n";
217 my $prototype = $params{'prototype'};
218 my $argtype = $params{'argtype'};
219 my $argname = $params{'argname'};
220 my $argreg = $params{'argreg'};
221 my $argnum = $params{'argnum'};
222 my $sfd = $self->{SFD
};
226 if ($$prototype{'type'} eq 'varargs') {
227 if ($prototype->{subtype
} eq 'printfcall') {
228 if ($argnum < $$prototype{'numargs'} - 1) {
231 elsif ($argnum == $$prototype{'numargs'} - 1) {
233 $$prototype{'argtypes'}[$$prototype{'numargs'} - 1];
235 $$prototype{'___argnames'}[$$prototype{'numargs'} - 2];
236 $argstr = "($vartype) (&$argnm + 1)";
244 if ($argnum < $$prototype{'numargs'} - 2) {
247 elsif ($argnum == $$prototype{'numargs'} - 2) {
249 $$prototype{'argtypes'}[$$prototype{'numargs'} - 1];
250 $argstr = "($vartype) &$argname";
257 elsif ($prototype->{type
} eq 'cfunction') {
261 print STDERR
"$prototype->{funcname}: Unhandled.\n";
266 print ($argnum != 0 ?
", $argstr" : $argstr);
273 my $prototype = $params{'prototype'};
274 my $sfd = $self->{SFD
};
279 if ($prototype->{type
} eq 'cfunction' &&
280 $prototype->{argnames
}[$#{@{$prototype->{argnames}}}] eq '...') {
281 print "/* Unsupported */\n";