-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathGateAROS.pl
148 lines (121 loc) · 3.99 KB
/
GateAROS.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
### Class GateAROS: Create an AROS gatestub file ##############################
BEGIN {
package GateAROS;
use vars qw(@ISA);
@ISA = qw( Gate );
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = $class->SUPER::new( @_ );
bless ($self, $class);
return $self;
}
sub header {
my $self = shift;
my $sfd = $self->{SFD};
$self->SUPER::header (@_);
print "#include <aros/libcall.h>\n";
print "\n";
}
sub function {
my $self = shift;
my %params = @_;
my $prototype = $params{'prototype'};
my $sfd = $self->{SFD};
if ($prototype->{type} eq 'cfunction') {
print "#define $gateprefix$prototype->{funcname} " .
"AROS_SLIB_ENTRY(" .
"$gateprefix$prototype->{funcname},$sfd->{Basename})\n\n";
}
$self->SUPER::function (@_);
}
sub function_start {
my $self = shift;
my %params = @_;
my $prototype = $params{'prototype'};
my $sfd = $self->{SFD};
my $nb = $prototype->{nb} || $libarg eq 'none';
# AROS macros cannot handle function pointer arguments :-(
for my $i (0 .. $prototype->{numargs} - 1) {
if ($prototype->{argtypes}[$i] =~ /\(\*\)/) {
my $typedef = $prototype->{argtypes}[$i];
my $typename = "$sfd->{Basename}_$prototype->{funcname}_fp$i";
$typedef =~ s/\(\*\)/(*_$typename)/;
print "typedef $typedef;\n";
}
}
if ($self->{PROTO}) {
printf "AROS_LD%d%s(", $prototype->{numargs}, $nb ? "I" : "";
}
else {
printf "AROS_LH%d%s(", $prototype->{numargs}, $nb ? "I" : "";
}
print "$prototype->{return}, $gateprefix$prototype->{funcname},\n";
}
sub function_arg {
my $self = shift;
my %params = @_;
my $prototype = $params{'prototype'};
my $argtype = $params{'argtype'};
my $argname = $params{'argname'};
my $argreg = $params{'argreg'};
my $argnum = $params{'argnum'};
my $sfd = $self->{SFD};
if ($argtype =~ /\(\*\)/) {
$argtype = "_$sfd->{Basename}_$prototype->{funcname}_fp$argnum";
}
if ($self->{PROTO}) {
print " AROS_LDA($argtype, $argname, " . (uc $argreg) . "),\n";
}
else {
print " AROS_LHA($argtype, $argname, " . (uc $argreg) . "),\n";
}
}
sub function_end {
my $self = shift;
my %params = @_;
my $prototype = $params{'prototype'};
my $sfd = $self->{SFD};
my $bt = "/* bt */";
my $bn = "/* bn */";
if ($prototype->{nb}) {
for my $i (0 .. $#{$prototype->{regs}}) {
if ($prototype->{regs}[$i] eq 'a6') {
$bt = $prototype->{argtypes}[$i];
$bn =$prototype->{___argnames}[$i];
last;
}
}
}
else {
$bt = $sfd->{basetype};
$bn = "_base";
}
printf " $bt, $bn, %d, $sfd->{Basename})",
$prototype->{bias} / 6;
if ($self->{PROTO}) {
print ";\n";
print "#define $gateprefix$prototype->{funcname} " .
"AROS_SLIB_ENTRY(" .
"$gateprefix$prototype->{funcname},$sfd->{Basename})\n";
}
else {
print "\n";
print "{\n";
print " AROS_LIBFUNC_INIT\n";
print " return $libprefix$prototype->{funcname}(";
if ($libarg eq 'first' && !$prototype->{nb}) {
print "_base";
print $prototype->{numargs} > 0 ? ", " : "";
}
print join (', ', @{$prototype->{___argnames}});
if ($libarg eq 'last' && !$prototype->{nb}) {
print $prototype->{numargs} > 0 ? ", " : "";
print "_base";
}
print ");\n";
print " AROS_LIBFUNC_EXIT\n";
print "}\n";
}
}
}