2 ### Class Gate: Create a generic gate file ####################################
10 my $class = ref($proto) || $proto;
12 $self->{SFD
} = $params{'sfd'};
13 $self->{PROTO
} = $params{'proto'};
14 $self->{LIBPROTO
} = $params{'libproto'};
15 bless ($self, $class);
21 my $sfd = $self->{SFD
};
24 print "/* Automatically generated header! Do not edit! */\n";
26 print "#ifndef _GATEPROTO_$$sfd{'BASENAME'}_H\n";
27 print "#define _GATEPROTO_$$sfd{'BASENAME'}_H\n";
29 elsif ($self->{LIBPROTO
}) {
30 print "/* Automatically generated header! Do not edit! */\n";
32 print "#ifndef _LIBPROTO_$$sfd{'BASENAME'}_H\n";
33 print "#define _LIBPROTO_$$sfd{'BASENAME'}_H\n";
36 print "/* Automatically generated gatestubs! Do not edit! */\n";
40 foreach my $inc (@
{$$sfd{'includes'}}) {
41 print "#include $inc\n";
44 foreach my $td (@
{$$sfd{'typedefs'}}) {
45 print "typedef $td;\n";
49 print "#define _sfdc_strarg(a) _sfdc_strarg2(a)\n";
50 print "#define _sfdc_strarg2(a) #a\n";
53 print "#ifdef __cplusplus\n";
54 print "extern \"C\" {\n";
55 print "#endif /* __cplusplus */\n";
62 my $prototype = $params{'prototype'};
63 my $sfd = $self->{SFD
};
65 if ($prototype->{type
} eq 'function') {
66 $self->function_proto (prototype => $prototype);
67 $self->function_start (prototype => $prototype);
68 for my $i (0 .. $$prototype{'numargs'} - 1 ) {
69 $self->function_arg (prototype => $prototype,
70 argtype
=> $$prototype{'argtypes'}[$i],
71 argname
=> $$prototype{'___argnames'}[$i],
72 argreg
=> $$prototype{'regs'}[$i],
75 $self->function_end (prototype => $prototype);
79 elsif ($prototype->{type
} eq 'cfunction') {
80 $self->function_proto (prototype => $prototype);
82 if (!$self->{LIBPROTO
}) {
83 print_gateproto
($sfd, $prototype);
87 if (!$self->{PROTO
} && !$self->{LIBPROTO
}) {
88 print "__asm(\".globl \" _sfdc_strarg(" .
89 "$gateprefix$prototype->{funcname}) );\n";
90 print "__asm(\".type \" _sfdc_strarg(" .
91 "$gateprefix$prototype->{funcname}) \"" .
93 print "__asm(_sfdc_strarg(".
94 "$gateprefix$prototype->{funcname}) \":\");\n";
95 print "#if defined(__mc68000__) || defined(__i386__)\n";
96 print "__asm(\"jmp $libprefix$prototype->{funcname}\");\n";
98 print "# error \"Unknown CPU\"\n";
107 my $sfd = $self->{SFD
};
110 print "#ifdef __cplusplus\n";
112 print "#endif /* __cplusplus */\n";
114 if ($self->{PROTO
}) {
116 print "#endif /* _GATEPROTO_$$sfd{'BASENAME'}_H */\n";
118 elsif ($self->{LIBPROTO
}) {
120 print "#endif /* _LIBPROTO_$$sfd{'BASENAME'}_H */\n";
130 my $prototype = $params{'prototype'};
131 my $sfd = $self->{SFD
};
133 if (!$self->{PROTO
}) {
134 if ($prototype->{type
} eq 'varargs') {
135 print_libproto
($sfd, $prototype->{real_prototype
});
138 print_libproto
($sfd, $prototype);
147 my $prototype = $params{'prototype'};
148 my $sfd = $self->{SFD
};
150 if (!$self->{LIBPROTO
}) {
151 print_gateproto
($sfd, $prototype);
154 if ($self->{PROTO
}) {
157 elsif (!$self->{LIBPROTO
}) {
160 print " return $libprefix$prototype->{funcname}(";
162 if ($libarg eq 'first' && !$prototype->{nb
}) {
164 print $prototype->{numargs
} > 0 ?
", " : "";
172 if (!$self->{PROTO
} && !$self->{LIBPROTO
}) {
174 my $argname = $params{'argname'};
175 my $argnum = $params{'argnum'};
177 print $argnum > 0 ?
", " : "";
185 if (!$self->{PROTO
} && !$self->{LIBPROTO
}) {
187 my $prototype = $params{'prototype'};
188 my $sfd = $self->{SFD
};
190 if ($libarg eq 'last' && !$prototype->{nb
}) {
191 print $prototype->{numargs
} > 0 ?
", " : "";
201 sub print_gateproto
{
203 my $prototype = shift;
205 print "$prototype->{return}\n";
206 print "$gateprefix$prototype->{funcname}(";
208 if ($libarg eq 'first' && !$prototype->{nb
}) {
209 print "$sfd->{basetype} _base";
210 print $prototype->{numargs
} > 0 ?
", " : "";
213 print join (', ', @
{$prototype->{___args
}});
215 if ($libarg eq 'last' && !$prototype->{nb
}) {
216 print $prototype->{numargs
} > 0 ?
", " : "";
217 print "$sfd->{basetype} _base";
220 if ($libarg eq 'none' && $prototype->{numargs
} == 0) {
229 my $prototype = shift;
231 print "$prototype->{return}\n";
232 print "$libprefix$prototype->{funcname}(";
234 if ($libarg eq 'first' && !$prototype->{nb
}) {
235 print "$sfd->{basetype} _base";
236 print $prototype->{numargs
} > 0 ?
", " : "";
239 print join (', ', @
{$prototype->{___args
}});
241 if ($libarg eq 'last' && !$prototype->{nb
}) {
242 print $prototype->{numargs
} > 0 ?
", " : "";
243 print "$sfd->{basetype} _base";
246 if ($libarg eq 'none' && $prototype->{numargs
} == 0) {