-
Notifications
You must be signed in to change notification settings - Fork 9
/
SASPragmas.pl
136 lines (117 loc) · 4.24 KB
/
SASPragmas.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
### Class SASPragmas: Create a SAS/C pragmas file #############################
BEGIN {
package SASPragmas;
sub new {
my $proto = shift;
my %params = @_;
my $class = ref($proto) || $proto;
my $self = {};
$self->{SFD} = $params{'sfd'};
bless ($self, $class);
return $self;
}
sub header {
my $self = shift;
my $sfd = $self->{SFD};
my $id = $$sfd{'id'};
my $v = $id;
my $d = $id;
$v =~ s/^\$[I]d: .*? ([0-9.]+).*/$1/;
$d =~ s,^\$[I]d: .*? [0-9.]+ (\d{4})/(\d{2})/(\d{2}).*,($3.$2.$1),;
print "/* Automatically generated header (sfdc SFDC_VERSION)! Do not edit! */\n";
print "#ifndef PRAGMAS_$sfd->{BASENAME}_PRAGMAS_H\n";
print "#define PRAGMAS_$sfd->{BASENAME}_PRAGMAS_H\n";
print "\n";
print "/*\n";
print "** \$VER: $$sfd{'basename'}_pragmas.h $v $d\n";
print "**\n";
print "** Direct ROM interface (pragma) definitions.\n";
print "**\n";
print "** $$sfd{'copyright'}\n";
print "** All Rights Reserved\n";
print "*/\n";
print "\n";
print "#if defined(LATTICE) || defined(__SASC) || defined(_DCC)\n";
print "#ifndef __CLIB_PRAGMA_LIBCALL\n";
print "#define __CLIB_PRAGMA_LIBCALL\n";
print "#endif /* __CLIB_PRAGMA_LIBCALL */\n";
print "#else /* __MAXON__, __STORM__ or AZTEC_C */\n";
print "#ifndef __CLIB_PRAGMA_AMICALL\n";
print "#define __CLIB_PRAGMA_AMICALL\n";
print "#endif /* __CLIB_PRAGMA_AMICALL */\n";
print "#endif /* */\n";
print "\n";
print "#if defined(__SASC_60) || defined(__STORM__)\n";
print "#ifndef __CLIB_PRAGMA_TAGCALL\n";
print "#define __CLIB_PRAGMA_TAGCALL\n";
print "#endif /* __CLIB_PRAGMA_TAGCALL */\n";
print "#endif /* __MAXON__, __STORM__ or AZTEC_C */\n";
print "\n";
}
sub function {
my $self = shift;
my %params = @_;
my $prototype = $params{'prototype'};
my $sfd = $self->{SFD};
# Don't process private functions
if ($prototype->{private}) {
return;
}
my $regs = '';
foreach my $reg (@{$prototype->{regs}}) {
my $num;
if ($reg =~ /^d[0-7]$/) {
($num) = $reg =~ /^d(.)/;
}
elsif ($reg =~ /^a[0-9]$/) {
($num) = $reg =~ /^a(.)/;
$num += 8;
}
else {
die;
}
$regs = sprintf "%x$regs", $num;
}
$regs .= '0'; #Result in d0
$regs .= $prototype->{numregs};
if ($prototype->{type} eq 'function') {
# Always use libcall, since access to 4 is very expensive
print "#ifdef __CLIB_PRAGMA_LIBCALL\n";
print " #pragma libcall $sfd->{base} $prototype->{funcname} ";
printf "%x $regs\n", $prototype->{bias};
print "#endif /* __CLIB_PRAGMA_LIBCALL */\n";
print "#ifdef __CLIB_PRAGMA_AMICALL\n";
printf " #pragma amicall($sfd->{base}, 0x%x, $prototype->{funcname}(",
$prototype->{bias};
print join (',', @{$prototype->{regs}}) . "))\n";
print "#endif /* __CLIB_PRAGMA_AMICALL */\n";
}
elsif ($prototype->{type} eq 'varargs') {
print "#ifdef __CLIB_PRAGMA_TAGCALL\n";
print " #ifdef __CLIB_PRAGMA_LIBCALL\n";
print " #pragma tagcall $sfd->{base} $prototype->{funcname} ";
printf "%x $regs\n", $prototype->{bias};
print " #endif /* __CLIB_PRAGMA_LIBCALL */\n";
print " #ifdef __CLIB_PRAGMA_AMICALL\n";
printf " #pragma tagcall($sfd->{base}, 0x%x, $prototype->{funcname}(",
$prototype->{bias};
print join (',', @{$prototype->{regs}}) . "))\n";
print " #endif /* __CLIB_PRAGMA_AMICALL */\n";
print "#endif /* __CLIB_PRAGMA_TAGCALL */\n";
}
elsif ($prototype->{type} eq 'cfunction') {
# Do nothing
}
else {
print STDERR "$prototype->{funcname}: Unsupported function " .
"type.\n";
die;
}
}
sub footer {
my $self = shift;
my $sfd = $self->{SFD};
print "\n";
print "#endif /* PRAGMAS_$sfd->{BASENAME}_PRAGMAS_H */\n";
}
}