This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
avoid literal 'undef' in $lddlflags under `Configure -Uoptimize`
[perl5.git] / opcode.pl
... / ...
CommitLineData
1#!/usr/bin/perl
2
3unlink "opcode.h";
4open(OC, ">opcode.h") || die "Can't create opcode.h: $!\n";
5select OC;
6
7# Read data.
8
9while (<DATA>) {
10 chop;
11 next unless $_;
12 next if /^#/;
13 ($key, $desc, $check, $flags, $args) = split(/\t+/, $_, 5);
14
15 warn qq[Description "$desc" duplicates $seen{$desc}\n] if $seen{$desc};
16 die qq[Opcode "$key" duplicates $seen{$key}\n] if $seen{$key};
17 $seen{$desc} = qq[description of opcode "$key"];
18 $seen{$key} = qq[opcode "$key"];
19
20 push(@ops, $key);
21 $desc{$key} = $desc;
22 $check{$key} = $check;
23 $ckname{$check}++;
24 $flags{$key} = $flags;
25 $args{$key} = $args;
26}
27
28# Emit defines.
29
30$i = 0;
31print <<"END";
32#define pp_i_preinc pp_preinc
33#define pp_i_predec pp_predec
34#define pp_i_postinc pp_postinc
35#define pp_i_postdec pp_postdec
36
37typedef enum {
38END
39for (@ops) {
40 print "\t", &tab(3,"OP_\U$_,"), "/* ", $i++, " */\n";
41}
42print "\t", &tab(3,"OP_max"), "\n";
43print "} opcode;\n";
44print "\n#define MAXO ", scalar @ops, "\n\n";
45
46# Emit op names and descriptions.
47
48print <<END;
49#ifndef DOINIT
50EXT char *PL_op_name[];
51#else
52EXT char *PL_op_name[] = {
53END
54
55for (@ops) {
56 print qq(\t"$_",\n);
57}
58
59print <<END;
60};
61#endif
62
63END
64
65print <<END;
66#ifndef DOINIT
67EXT char *PL_op_desc[];
68#else
69EXT char *PL_op_desc[] = {
70END
71
72for (@ops) {
73 print qq(\t"$desc{$_}",\n);
74}
75
76print <<END;
77};
78#endif
79
80#ifndef PERL_OBJECT
81START_EXTERN_C
82
83#undef PERL_CKDEF
84#undef PERL_PPDEF
85#define PERL_CKDEF(s) OP *s _((OP *o));
86#define PERL_PPDEF(s) OP *s _((ARGSproto));
87
88#include "pp_proto.h"
89
90END
91
92# Emit function declarations.
93
94#for (sort keys %ckname) {
95# print "OP *\t", &tab(3,$_),"_((OP* o));\n";
96#}
97#
98#print "\n";
99#
100#for (@ops) {
101# print "OP *\t", &tab(3, "pp_$_"), "_((ARGSproto));\n";
102#}
103
104# Emit ppcode switch array.
105
106print <<END;
107
108END_EXTERN_C
109#endif /* PERL_OBJECT */
110
111#ifndef DOINIT
112EXT OP * (CPERLscope(*PL_ppaddr)[])(ARGSproto);
113#else
114EXT OP * (CPERLscope(*PL_ppaddr)[])(ARGSproto) = {
115END
116
117for (@ops) {
118 print "\tpp_$_,\n";
119}
120
121print <<END;
122};
123#endif
124
125END
126
127# Emit check routines.
128
129print <<END;
130#ifndef DOINIT
131EXT OP * (CPERLscope(*PL_check)[]) _((OP *op));
132#else
133EXT OP * (CPERLscope(*PL_check)[]) _((OP *op)) = {
134END
135
136for (@ops) {
137 print "\t", &tab(3, "$check{$_},"), "/* $_ */\n";
138}
139
140print <<END;
141};
142#endif
143
144END
145
146# Emit allowed argument types.
147
148print <<END;
149#ifndef DOINIT
150EXT U32 PL_opargs[];
151#else
152EXT U32 PL_opargs[] = {
153END
154
155%argnum = (
156 S, 1, # scalar
157 L, 2, # list
158 A, 3, # array value
159 H, 4, # hash value
160 C, 5, # code value
161 F, 6, # file value
162 R, 7, # scalar reference
163);
164
165%opclass = (
166 '0', 0, # baseop
167 '1', 1, # unop
168 '2', 2, # binop
169 '|', 3, # logop
170 '?', 4, # condop
171 '@', 5, # listop
172 '/', 6, # pmop
173 '$', 7, # svop
174 '*', 8, # gvop
175 '"', 9, # pvop
176 '{', 10, # loop
177 ';', 11, # cop
178 '%', 12, # baseop_or_unop
179 '-', 13, # filestatop
180 '}', 14, # loopexop
181);
182
183for (@ops) {
184 $argsum = 0;
185 $flags = $flags{$_};
186 $argsum |= 1 if $flags =~ /m/; # needs stack mark
187 $argsum |= 2 if $flags =~ /f/; # fold constants
188 $argsum |= 4 if $flags =~ /s/; # always produces scalar
189 $argsum |= 8 if $flags =~ /t/; # needs target scalar
190 $argsum |= 16 if $flags =~ /i/; # always produces integer
191 $argsum |= 32 if $flags =~ /I/; # has corresponding int op
192 $argsum |= 64 if $flags =~ /d/; # danger, unknown side effects
193 $argsum |= 128 if $flags =~ /u/; # defaults to $_
194
195 $flags =~ /([\W\d_])/ or die qq[Opcode "$_" has no class indicator];
196 $argsum |= $opclass{$1} << 8;
197 $mul = 4096; # 2 ^ OASHIFT
198 for $arg (split(' ',$args{$_})) {
199 $argnum = ($arg =~ s/\?//) ? 8 : 0;
200 $argnum += $argnum{$arg};
201 $argsum += $argnum * $mul;
202 $mul <<= 4;
203 }
204 $argsum = sprintf("0x%08x", $argsum);
205 print "\t", &tab(3, "$argsum,"), "/* $_ */\n";
206}
207
208print <<END;
209};
210#endif
211END
212
213close OC or die "Error closing opcode.h: $!";
214
215unlink "pp_proto.h";
216unlink "pp.sym";
217open PP, '>pp_proto.h' or die "Error creating pp_proto.h: $!";
218open PPSYM, '>pp.sym' or die "Error creating pp.sym: $!";
219
220for (sort keys %ckname) {
221 print PP "PERL_CKDEF($_)\n";
222#OP *\t", &tab(3,$_),"_((OP* o));\n";
223}
224
225print PP "\n\n";
226
227for (@ops) {
228 next if /^i_(pre|post)(inc|dec)$/;
229 print PP "PERL_PPDEF(pp_$_)\n";
230 print PPSYM "pp_$_\n";
231}
232
233close PP or die "Error closing pp_proto.h: $!";
234close PPSYM or die "Error closing pp.sym: $!";
235
236###########################################################################
237sub tab {
238 local($l, $t) = @_;
239 $t .= "\t" x ($l - (length($t) + 1) / 8);
240 $t;
241}
242###########################################################################
243__END__
244
245# Nothing.
246
247null null operation ck_null 0
248stub stub ck_null 0
249scalar scalar ck_fun s% S
250
251# Pushy stuff.
252
253pushmark pushmark ck_null s0
254wantarray wantarray ck_null is0
255
256const constant item ck_svconst s$
257
258gvsv scalar variable ck_null ds*
259gv glob value ck_null ds*
260gelem glob elem ck_null d2 S S
261padsv private variable ck_null ds0
262padav private array ck_null d0
263padhv private hash ck_null d0
264padany private something ck_null d0
265
266pushre push regexp ck_null d/
267
268# References and stuff.
269
270rv2gv ref-to-glob cast ck_rvconst ds1
271rv2sv scalar deref ck_rvconst ds1
272av2arylen array length ck_null is1
273rv2cv subroutine deref ck_rvconst d1
274anoncode anonymous subroutine ck_anoncode $
275prototype subroutine prototype ck_null s% S
276refgen reference constructor ck_spair m1 L
277srefgen scalar ref constructor ck_null fs1 S
278ref reference-type operator ck_fun stu% S?
279bless bless ck_fun s@ S S?
280
281# Pushy I/O.
282
283backtick backticks ck_null t%
284# glob defaults its first arg to $_
285glob glob ck_glob t@ S? S?
286readline <HANDLE> ck_null t%
287rcatline append I/O operator ck_null t%
288
289# Bindable operators.
290
291regcmaybe regexp comp once ck_fun s1 S
292regcreset regexp reset interpolation flag ck_fun s1 S
293regcomp regexp compilation ck_null s| S
294match pattern match ck_match d/
295qr pattern quote ck_match s/
296subst substitution ck_null dis/ S
297substcont substitution cont ck_null dis|
298trans character translation ck_null is" S
299
300# Lvalue operators.
301# sassign is special-cased for op class
302
303sassign scalar assignment ck_null s0
304aassign list assignment ck_null t2 L L
305
306chop chop ck_spair mts% L
307schop scalar chop ck_null stu% S?
308chomp safe chop ck_spair mts% L
309schomp scalar safe chop ck_null stu% S?
310defined defined operator ck_rfun isu% S?
311undef undef operator ck_lfun s% S?
312study study ck_fun su% S?
313pos match position ck_lfun stu% S?
314
315preinc preincrement ck_lfun dIs1 S
316i_preinc integer preincrement ck_lfun dis1 S
317predec predecrement ck_lfun dIs1 S
318i_predec integer predecrement ck_lfun dis1 S
319postinc postincrement ck_lfun dIst1 S
320i_postinc integer postincrement ck_lfun dist1 S
321postdec postdecrement ck_lfun dIst1 S
322i_postdec integer postdecrement ck_lfun dist1 S
323
324# Ordinary operators.
325
326pow exponentiation ck_null fst2 S S
327
328multiply multiplication ck_null Ifst2 S S
329i_multiply integer multiplication ck_null ifst2 S S
330divide division ck_null Ifst2 S S
331i_divide integer division ck_null ifst2 S S
332modulo modulus ck_null Iifst2 S S
333i_modulo integer modulus ck_null ifst2 S S
334repeat repeat ck_repeat mt2 L S
335
336add addition ck_null Ifst2 S S
337i_add integer addition ck_null ifst2 S S
338subtract subtraction ck_null Ifst2 S S
339i_subtract integer subtraction ck_null ifst2 S S
340concat concatenation ck_concat fst2 S S
341stringify string ck_fun fst@ S
342
343left_shift left bitshift ck_bitop fst2 S S
344right_shift right bitshift ck_bitop fst2 S S
345
346lt numeric lt ck_null Iifs2 S S
347i_lt integer lt ck_null ifs2 S S
348gt numeric gt ck_null Iifs2 S S
349i_gt integer gt ck_null ifs2 S S
350le numeric le ck_null Iifs2 S S
351i_le integer le ck_null ifs2 S S
352ge numeric ge ck_null Iifs2 S S
353i_ge integer ge ck_null ifs2 S S
354eq numeric eq ck_null Iifs2 S S
355i_eq integer eq ck_null ifs2 S S
356ne numeric ne ck_null Iifs2 S S
357i_ne integer ne ck_null ifs2 S S
358ncmp spaceship operator ck_null Iifst2 S S
359i_ncmp integer spaceship ck_null ifst2 S S
360
361slt string lt ck_scmp ifs2 S S
362sgt string gt ck_scmp ifs2 S S
363sle string le ck_scmp ifs2 S S
364sge string ge ck_scmp ifs2 S S
365seq string eq ck_null ifs2 S S
366sne string ne ck_null ifs2 S S
367scmp string comparison ck_scmp ifst2 S S
368
369bit_and bitwise and ck_bitop fst2 S S
370bit_xor bitwise xor ck_bitop fst2 S S
371bit_or bitwise or ck_bitop fst2 S S
372
373negate negate ck_null Ifst1 S
374i_negate integer negate ck_null ifst1 S
375not not ck_null ifs1 S
376complement 1's complement ck_bitop fst1 S
377
378# High falutin' math.
379
380atan2 atan2 ck_fun fst@ S S
381sin sin ck_fun fstu% S?
382cos cos ck_fun fstu% S?
383rand rand ck_fun st% S?
384srand srand ck_fun s% S?
385exp exp ck_fun fstu% S?
386log log ck_fun fstu% S?
387sqrt sqrt ck_fun fstu% S?
388
389# Lowbrow math.
390
391int int ck_fun fstu% S?
392hex hex ck_fun fstu% S?
393oct oct ck_fun fstu% S?
394abs abs ck_fun fstu% S?
395
396# String stuff.
397
398length length ck_lengthconst istu% S?
399substr substr ck_fun st@ S S S? S?
400vec vec ck_fun ist@ S S S
401
402index index ck_index ist@ S S S?
403rindex rindex ck_index ist@ S S S?
404
405sprintf sprintf ck_fun_locale mfst@ S L
406formline formline ck_fun ms@ S L
407ord ord ck_fun ifstu% S?
408chr chr ck_fun fstu% S?
409crypt crypt ck_fun fst@ S S
410ucfirst upper case first ck_fun_locale fstu% S?
411lcfirst lower case first ck_fun_locale fstu% S?
412uc upper case ck_fun_locale fstu% S?
413lc lower case ck_fun_locale fstu% S?
414quotemeta quote metachars ck_fun fstu% S?
415
416# Arrays.
417
418rv2av array deref ck_rvconst dt1
419aelemfast known array element ck_null s* A S
420aelem array element ck_null s2 A S
421aslice array slice ck_null m@ A L
422
423# Hashes.
424
425each each ck_fun t% H
426values values ck_fun t% H
427keys keys ck_fun t% H
428delete delete ck_delete % S
429exists exists operator ck_exists is% S
430rv2hv hash deref ck_rvconst dt1
431helem hash elem ck_null s2@ H S
432hslice hash slice ck_null m@ H L
433
434# Explosives and implosives.
435
436unpack unpack ck_fun @ S S
437pack pack ck_fun mst@ S L
438split split ck_split t@ S S S
439join join ck_fun mst@ S L
440
441# List operators.
442
443list list ck_null m@ L
444lslice list slice ck_null 2 H L L
445anonlist anonymous list ck_fun ms@ L
446anonhash anonymous hash ck_fun ms@ L
447
448splice splice ck_fun m@ A S? S? L
449push push ck_fun imst@ A L
450pop pop ck_shift s% A
451shift shift ck_shift s% A
452unshift unshift ck_fun imst@ A L
453sort sort ck_sort m@ C? L
454reverse reverse ck_fun mt@ L
455
456grepstart grep ck_grep dm@ C L
457grepwhile grep iterator ck_null dt|
458
459mapstart map ck_grep dm@ C L
460mapwhile map iterator ck_null dt|
461
462# Range stuff.
463
464range flipflop ck_null ? S S
465flip range (or flip) ck_null 1 S S
466flop range (or flop) ck_null 1
467
468# Control.
469
470and logical and ck_null |
471or logical or ck_null |
472xor logical xor ck_null fs| S S
473cond_expr conditional expression ck_null d?
474andassign logical and assignment ck_null s|
475orassign logical or assignment ck_null s|
476
477method method lookup ck_null d1
478entersub subroutine entry ck_subr dmt1 L
479leavesub subroutine exit ck_null 1
480caller caller ck_fun t% S?
481warn warn ck_fun imst@ L
482die die ck_fun dimst@ L
483reset reset ck_fun is% S?
484
485lineseq line sequence ck_null @
486nextstate next statement ck_null s;
487dbstate debug next statement ck_null s;
488unstack unstack ck_null s0
489enter block entry ck_null 0
490leave block exit ck_null @
491scope block ck_null @
492enteriter foreach loop entry ck_null d{
493iter foreach loop iterator ck_null 0
494enterloop loop entry ck_null d{
495leaveloop loop exit ck_null 2
496return return ck_null dm@ L
497last last ck_null ds}
498next next ck_null ds}
499redo redo ck_null ds}
500dump dump ck_null ds}
501goto goto ck_null ds}
502exit exit ck_fun ds% S?
503
504#nswitch numeric switch ck_null d
505#cswitch character switch ck_null d
506
507# I/O.
508
509open open ck_fun ist@ F S?
510close close ck_fun is% F?
511pipe_op pipe ck_fun is@ F F
512
513fileno fileno ck_fun ist% F
514umask umask ck_fun ist% S?
515binmode binmode ck_fun s% F
516
517tie tie ck_fun idms@ R S L
518untie untie ck_fun is% R
519tied tied ck_fun s% R
520dbmopen dbmopen ck_fun is@ H S S
521dbmclose dbmclose ck_fun is% H
522
523sselect select system call ck_select t@ S S S S
524select select ck_select st@ F?
525
526getc getc ck_eof st% F?
527read read ck_fun imst@ F R S S?
528enterwrite write ck_fun dis% F?
529leavewrite write exit ck_null 1
530
531prtf printf ck_listiob ims@ F? L
532print print ck_listiob ims@ F? L
533
534sysopen sysopen ck_fun s@ F S S S?
535sysseek sysseek ck_fun s@ F S S
536sysread sysread ck_fun imst@ F R S S?
537syswrite syswrite ck_fun imst@ F S S? S?
538
539send send ck_fun imst@ F S S S?
540recv recv ck_fun imst@ F R S S
541
542eof eof ck_eof is% F?
543tell tell ck_fun st% F?
544seek seek ck_fun s@ F S S
545# truncate really behaves as if it had both "S S" and "F S"
546truncate truncate ck_trunc is@ S S
547
548fcntl fcntl ck_fun st@ F S S
549ioctl ioctl ck_fun st@ F S S
550flock flock ck_fun ist@ F S
551
552# Sockets.
553
554socket socket ck_fun is@ F S S S
555sockpair socketpair ck_fun is@ F F S S S
556
557bind bind ck_fun is@ F S
558connect connect ck_fun is@ F S
559listen listen ck_fun is@ F S
560accept accept ck_fun ist@ F F
561shutdown shutdown ck_fun ist@ F S
562
563gsockopt getsockopt ck_fun is@ F S S
564ssockopt setsockopt ck_fun is@ F S S S
565
566getsockname getsockname ck_fun is% F
567getpeername getpeername ck_fun is% F
568
569# Stat calls.
570
571lstat lstat ck_ftst u- F
572stat stat ck_ftst u- F
573ftrread -R ck_ftst isu- F
574ftrwrite -W ck_ftst isu- F
575ftrexec -X ck_ftst isu- F
576fteread -r ck_ftst isu- F
577ftewrite -w ck_ftst isu- F
578fteexec -x ck_ftst isu- F
579ftis -e ck_ftst isu- F
580fteowned -O ck_ftst isu- F
581ftrowned -o ck_ftst isu- F
582ftzero -z ck_ftst isu- F
583ftsize -s ck_ftst istu- F
584ftmtime -M ck_ftst stu- F
585ftatime -A ck_ftst stu- F
586ftctime -C ck_ftst stu- F
587ftsock -S ck_ftst isu- F
588ftchr -c ck_ftst isu- F
589ftblk -b ck_ftst isu- F
590ftfile -f ck_ftst isu- F
591ftdir -d ck_ftst isu- F
592ftpipe -p ck_ftst isu- F
593ftlink -l ck_ftst isu- F
594ftsuid -u ck_ftst isu- F
595ftsgid -g ck_ftst isu- F
596ftsvtx -k ck_ftst isu- F
597fttty -t ck_ftst is- F
598fttext -T ck_ftst isu- F
599ftbinary -B ck_ftst isu- F
600
601# File calls.
602
603chdir chdir ck_fun ist% S?
604chown chown ck_fun imst@ L
605chroot chroot ck_fun istu% S?
606unlink unlink ck_fun imstu@ L
607chmod chmod ck_fun imst@ L
608utime utime ck_fun imst@ L
609rename rename ck_fun ist@ S S
610link link ck_fun ist@ S S
611symlink symlink ck_fun ist@ S S
612readlink readlink ck_fun stu% S?
613mkdir mkdir ck_fun ist@ S S
614rmdir rmdir ck_fun istu% S?
615
616# Directory calls.
617
618open_dir opendir ck_fun is@ F S
619readdir readdir ck_fun % F
620telldir telldir ck_fun st% F
621seekdir seekdir ck_fun s@ F S
622rewinddir rewinddir ck_fun s% F
623closedir closedir ck_fun is% F
624
625# Process control.
626
627fork fork ck_null ist0
628wait wait ck_null ist0
629waitpid waitpid ck_fun ist@ S S
630system system ck_exec imst@ S? L
631exec exec ck_exec dimst@ S? L
632kill kill ck_fun dimst@ L
633getppid getppid ck_null ist0
634getpgrp getpgrp ck_fun ist% S?
635setpgrp setpgrp ck_fun ist@ S? S?
636getpriority getpriority ck_fun ist@ S S
637setpriority setpriority ck_fun ist@ S S S
638
639# Time calls.
640
641time time ck_null ist0
642tms times ck_null 0
643localtime localtime ck_fun t% S?
644gmtime gmtime ck_fun t% S?
645alarm alarm ck_fun istu% S?
646sleep sleep ck_fun ist% S?
647
648# Shared memory.
649
650shmget shmget ck_fun imst@ S S S
651shmctl shmctl ck_fun imst@ S S S
652shmread shmread ck_fun imst@ S S S S
653shmwrite shmwrite ck_fun imst@ S S S S
654
655# Message passing.
656
657msgget msgget ck_fun imst@ S S
658msgctl msgctl ck_fun imst@ S S S
659msgsnd msgsnd ck_fun imst@ S S S
660msgrcv msgrcv ck_fun imst@ S S S S S
661
662# Semaphores.
663
664semget semget ck_fun imst@ S S S
665semctl semctl ck_fun imst@ S S S S
666semop semop ck_fun imst@ S S
667
668# Eval.
669
670require require ck_require du% S?
671dofile do 'file' ck_fun d1 S
672entereval eval string ck_eval d% S
673leaveeval eval exit ck_null 1 S
674#evalonce eval constant string ck_null d1 S
675entertry eval block ck_null |
676leavetry eval block exit ck_null @
677
678# Get system info.
679
680ghbyname gethostbyname ck_fun % S
681ghbyaddr gethostbyaddr ck_fun @ S S
682ghostent gethostent ck_null 0
683gnbyname getnetbyname ck_fun % S
684gnbyaddr getnetbyaddr ck_fun @ S S
685gnetent getnetent ck_null 0
686gpbyname getprotobyname ck_fun % S
687gpbynumber getprotobynumber ck_fun @ S
688gprotoent getprotoent ck_null 0
689gsbyname getservbyname ck_fun @ S S
690gsbyport getservbyport ck_fun @ S S
691gservent getservent ck_null 0
692shostent sethostent ck_fun is% S
693snetent setnetent ck_fun is% S
694sprotoent setprotoent ck_fun is% S
695sservent setservent ck_fun is% S
696ehostent endhostent ck_null is0
697enetent endnetent ck_null is0
698eprotoent endprotoent ck_null is0
699eservent endservent ck_null is0
700gpwnam getpwnam ck_fun % S
701gpwuid getpwuid ck_fun % S
702gpwent getpwent ck_null 0
703spwent setpwent ck_null is0
704epwent endpwent ck_null is0
705ggrnam getgrnam ck_fun % S
706ggrgid getgrgid ck_fun % S
707ggrent getgrent ck_null 0
708sgrent setgrent ck_null is0
709egrent endgrent ck_null is0
710getlogin getlogin ck_null st0
711
712# Miscellaneous.
713
714syscall syscall ck_fun imst@ S L
715
716# For multi-threading
717lock lock ck_rfun s% S
718threadsv per-thread variable ck_null ds0