-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathGateMOS.pl
147 lines (122 loc) · 3.64 KB
/
GateMOS.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
### Class GateMOS: Create a MorphOS gatestub file #############################
BEGIN {
package GateMOS;
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;
$self->SUPER::header (@_);
if ($sdi eq 0) {
print "#include <emul/emulregs.h>\n\n";
print "int $gateprefix" . "UNIMPLEMENTED(void)";
}
else {
print "#include <SDI_lib.h>\n\n";
print "LIBSTUB(UNIMPLEMENTED, int)";
}
if ($self->{PROTO}) {
print ";";
}
else {
print "\n";
print "{\n";
print " // nothing\n";
print " return 0;\n";
print "}\n";
}
print "\n";
}
sub function_start {
my $self = shift;
my %params = @_;
my $prototype = $params{'prototype'};
my $sfd = $self->{SFD};
my $rettype_prefix = $prototype->{return};
my $rettype_postfix = "";
if ($prototype->{return} =~ /(.*\(\*+)(\).*)/) {
$rettype_prefix = $1;
$rettype_postfix = $2;
}
if ($sdi eq 0) {
print "$rettype_prefix ";
print "$gateprefix$prototype->{funcname}(void)$rettype_postfix";
}
else {
if ($prototype->{return} =~ /\(\*+\)/) {
print "LIBSTUB($prototype->{funcname}, void *)";
}
else {
print "LIBSTUB($prototype->{funcname}, $prototype->{return})";
}
}
if ($self->{PROTO}) {
print ";";
}
else {
print "\n";
print "{\n";
if ($sdi ne 0) {
print " __BASE_OR_IFACE = (__BASE_OR_IFACE_TYPE)REG_A6;\n";
print " return CALL_LFUNC($prototype->{funcname}";
}
}
}
sub function_arg {
my $self = shift;
if (!$self->{PROTO}) {
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 eq "va_list") {
$argtype = "long *";
}
my $argdef = $argtype . " " . $argname;
if ($argtype =~ /\(\*+\)/) {
$argdef = $argtype;
$argdef =~ s/\(\*+\)/\(\*$argname\)/g;
}
if ($sdi eq 0) {
print " $argdef = ($argtype)REG_" . (uc $argreg) . ";\n";
}
else {
print ", ($argtype)REG_" . (uc $argreg);
}
}
}
sub function_end {
my $self = shift;
if (!$self->{PROTO}) {
my %params = @_;
my $prototype = $params{'prototype'};
my $sfd = $self->{SFD};
if ($sdi eq 0) {
if ($libarg ne 'none' && !$prototype->{nb}) {
print " $sfd->{basetype} _base = ($sfd->{basetype})"."REG_A6;\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 "}\n";
}
}
}