Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / bin / pl2pm
CommitLineData
920dae64
AT
1#!/import/archperf/ws/devtools/4/v8plus/bin/perl
2 eval 'exec /import/archperf/ws/devtools/4/v8plus/bin/perl -S $0 ${1+"$@"}'
3 if $running_under_some_shell;
4
5=head1 NAME
6
7pl2pm - Rough tool to translate Perl4 .pl files to Perl5 .pm modules.
8
9=head1 SYNOPSIS
10
11B<pl2pm> F<files>
12
13=head1 DESCRIPTION
14
15B<pl2pm> is a tool to aid in the conversion of Perl4-style .pl
16library files to Perl5-style library modules. Usually, your old .pl
17file will still work fine and you should only use this tool if you
18plan to update your library to use some of the newer Perl 5 features,
19such as AutoLoading.
20
21=head1 LIMITATIONS
22
23It's just a first step, but it's usually a good first step.
24
25=head1 AUTHOR
26
27Larry Wall <larry@wall.org>
28
29=cut
30
31use strict;
32use warnings;
33
34my %keyword = ();
35
36while (<DATA>) {
37 chomp;
38 $keyword{$_} = 1;
39}
40
41local $/;
42
43while (<>) {
44 my $newname = $ARGV;
45 $newname =~ s/\.pl$/.pm/ || next;
46 $newname =~ s#(.*/)?(\w+)#$1\u$2#;
47 if (-f $newname) {
48 warn "Won't overwrite existing $newname\n";
49 next;
50 }
51 my $oldpack = $2;
52 my $newpack = "\u$2";
53 my @export = ();
54
55 s/\bstd(in|out|err)\b/\U$&/g;
56 s/(sub\s+)(\w+)(\s*\{[ \t]*\n)\s*package\s+$oldpack\s*;[ \t]*\n+/${1}main'$2$3/ig;
57 if (/sub\s+\w+'/) {
58 @export = m/sub\s+\w+'(\w+)/g;
59 s/(sub\s+)main'(\w+)/$1$2/g;
60 }
61 else {
62 @export = m/sub\s+([A-Za-z]\w*)/g;
63 }
64 my @export_ok = grep($keyword{$_}, @export);
65 @export = grep(!$keyword{$_}, @export);
66
67 my %export = ();
68 @export{@export} = (1) x @export;
69
70 s/(^\s*);#/$1#/g;
71 s/(#.*)require ['"]$oldpack\.pl['"]/$1use $newpack/;
72 s/(package\s*)($oldpack)\s*;[ \t]*\n+//ig;
73 s/([\$\@%&*])'(\w+)/&xlate($1,"",$2,$newpack,$oldpack,\%export)/eg;
74 s/([\$\@%&*]?)(\w+)'(\w+)/&xlate($1,$2,$3,$newpack,$oldpack,\%export)/eg;
75 if (!/\$\[\s*\)?\s*=\s*[^0\s]/) {
76 s/^\s*(local\s*\()?\s*\$\[\s*\)?\s*=\s*0\s*;[ \t]*\n//g;
77 s/\$\[\s*\+\s*//g;
78 s/\s*\+\s*\$\[//g;
79 s/\$\[/0/g;
80 }
81 s/open\s+(\w+)/open($1)/g;
82
83 my $export_ok = '';
84 my $carp ='';
85
86
87 if (s/\bdie\b/croak/g) {
88 $carp = "use Carp;\n";
89 s/croak "([^"]*)\\n"/croak "$1"/g;
90 }
91
92 if (@export_ok) {
93 $export_ok = "\@EXPORT_OK = qw(@export_ok);\n";
94 }
95
96 if ( open(PM, ">$newname") ) {
97 print PM <<"END";
98package $newpack;
99use 5.006;
100require Exporter;
101$carp
102\@ISA = qw(Exporter);
103\@EXPORT = qw(@export);
104$export_ok
105$_
106END
107 }
108 else {
109 warn "Can't create $newname: $!\n";
110 }
111}
112
113sub xlate {
114 my ($prefix, $pack, $ident,$newpack,$oldpack,$export) = @_;
115
116 my $xlated ;
117 if ($prefix eq '' && $ident =~ /^(t|s|m|d|ing|ll|ed|ve|re)$/) {
118 $xlated = "${pack}'$ident";
119 }
120 elsif ($pack eq '' || $pack eq 'main') {
121 if ($export->{$ident}) {
122 $xlated = "$prefix$ident";
123 }
124 else {
125 $xlated = "$prefix${pack}::$ident";
126 }
127 }
128 elsif ($pack eq $oldpack) {
129 $xlated = "$prefix${newpack}::$ident";
130 }
131 else {
132 $xlated = "$prefix${pack}::$ident";
133 }
134
135 return $xlated;
136}
137__END__
138AUTOLOAD
139BEGIN
140CORE
141DESTROY
142END
143INIT
144CHECK
145abs
146accept
147alarm
148and
149atan2
150bind
151binmode
152bless
153caller
154chdir
155chmod
156chomp
157chop
158chown
159chr
160chroot
161close
162closedir
163cmp
164connect
165continue
166cos
167crypt
168dbmclose
169dbmopen
170defined
171delete
172die
173do
174dump
175each
176else
177elsif
178endgrent
179endhostent
180endnetent
181endprotoent
182endpwent
183endservent
184eof
185eq
186eval
187exec
188exists
189exit
190exp
191fcntl
192fileno
193flock
194for
195foreach
196fork
197format
198formline
199ge
200getc
201getgrent
202getgrgid
203getgrnam
204gethostbyaddr
205gethostbyname
206gethostent
207getlogin
208getnetbyaddr
209getnetbyname
210getnetent
211getpeername
212getpgrp
213getppid
214getpriority
215getprotobyname
216getprotobynumber
217getprotoent
218getpwent
219getpwnam
220getpwuid
221getservbyname
222getservbyport
223getservent
224getsockname
225getsockopt
226glob
227gmtime
228goto
229grep
230gt
231hex
232if
233index
234int
235ioctl
236join
237keys
238kill
239last
240lc
241lcfirst
242le
243length
244link
245listen
246local
247localtime
248lock
249log
250lstat
251lt
252m
253map
254mkdir
255msgctl
256msgget
257msgrcv
258msgsnd
259my
260ne
261next
262no
263not
264oct
265open
266opendir
267or
268ord
269our
270pack
271package
272pipe
273pop
274pos
275print
276printf
277prototype
278push
279q
280qq
281qr
282quotemeta
283qw
284qx
285rand
286read
287readdir
288readline
289readlink
290readpipe
291recv
292redo
293ref
294rename
295require
296reset
297return
298reverse
299rewinddir
300rindex
301rmdir
302s
303scalar
304seek
305seekdir
306select
307semctl
308semget
309semop
310send
311setgrent
312sethostent
313setnetent
314setpgrp
315setpriority
316setprotoent
317setpwent
318setservent
319setsockopt
320shift
321shmctl
322shmget
323shmread
324shmwrite
325shutdown
326sin
327sleep
328socket
329socketpair
330sort
331splice
332split
333sprintf
334sqrt
335srand
336stat
337study
338sub
339substr
340symlink
341syscall
342sysopen
343sysread
344sysseek
345system
346syswrite
347tell
348telldir
349tie
350tied
351time
352times
353tr
354truncate
355uc
356ucfirst
357umask
358undef
359unless
360unlink
361unpack
362unshift
363untie
364until
365use
366utime
367values
368vec
369wait
370waitpid
371wantarray
372warn
373while
374write
375x
376xor
377y