This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix small nits
[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 Perl_pp_i_preinc Perl_pp_preinc
33#define Perl_pp_i_predec Perl_pp_predec
34#define Perl_pp_i_postinc Perl_pp_postinc
35#define Perl_pp_i_postdec Perl_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 (pTHX_ OP *o);
86#define PERL_PPDEF(s) OP *s (pTHX);
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,$_),"(pTHX_ OP* o);\n";
96#}
97#
98#print "\n";
99#
100#for (@ops) {
101# print "OP *\t", &tab(3, "pp_$_"), "(pTHX);\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)[])(pTHX);
113#else
114EXT OP * (CPERLscope(*PL_ppaddr)[])(pTHX) = {
115END
116
117for (@ops) {
118 print "\tPerl_pp_$_,\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)[]) (pTHX_ OP *op);
132#else
133EXT OP * (CPERLscope(*PL_check)[]) (pTHX_ OP *op) = {
134END
135
136for (@ops) {
137 print "\t", &tab(3, "Perl_$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_or_svop
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(Perl_$_)\n";
222 print PPSYM "Perl_$_\n";
223#OP *\t", &tab(3,$_),"(OP* o);\n";
224}
225
226print PP "\n\n";
227
228for (@ops) {
229 next if /^i_(pre|post)(inc|dec)$/;
230 print PP "PERL_PPDEF(Perl_pp_$_)\n";
231 print PPSYM "Perl_pp_$_\n";
232}
233
234close PP or die "Error closing pp_proto.h: $!";
235close PPSYM or die "Error closing pp.sym: $!";
236
237###########################################################################
238sub tab {
239 local($l, $t) = @_;
240 $t .= "\t" x ($l - (length($t) + 1) / 8);
241 $t;
242}
243###########################################################################
244__END__
245
246# Nothing.
247
248null null operation ck_null 0
249stub stub ck_null 0
250scalar scalar ck_fun s% S
251
252# Pushy stuff.
253
254pushmark pushmark ck_null s0
255wantarray wantarray ck_null is0
256
257const constant item ck_svconst s$
258
259gvsv scalar variable ck_null ds*
260gv glob value ck_null ds*
261gelem glob elem ck_null d2 S S
262padsv private variable ck_null ds0
263padav private array ck_null d0
264padhv private hash ck_null d0
265padany private something ck_null d0
266
267pushre push regexp ck_null d/
268
269# References and stuff.
270
271rv2gv ref-to-glob cast ck_rvconst ds1
272rv2sv scalar deref ck_rvconst ds1
273av2arylen array length ck_null is1
274rv2cv subroutine deref ck_rvconst d1
275anoncode anonymous subroutine ck_anoncode $
276prototype subroutine prototype ck_null s% S
277refgen reference constructor ck_spair m1 L
278srefgen scalar ref constructor ck_null fs1 S
279ref reference-type operator ck_fun stu% S?
280bless bless ck_fun s@ S S?
281
282# Pushy I/O.
283
284backtick backticks ck_null t%
285# glob defaults its first arg to $_
286glob glob ck_glob t@ S? S?
287readline <HANDLE> ck_null t%
288rcatline append I/O operator ck_null t%
289
290# Bindable operators.
291
292regcmaybe regexp comp once ck_fun s1 S
293regcreset regexp reset interpolation flag ck_fun s1 S
294regcomp regexp compilation ck_null s| S
295match pattern match ck_match d/
296qr pattern quote ck_match s/
297subst substitution ck_null dis/ S
298substcont substitution cont ck_null dis|
299trans character translation ck_null is" S
300
301# Lvalue operators.
302# sassign is special-cased for op class
303
304sassign scalar assignment ck_null s0
305aassign list assignment ck_null t2 L L
306
307chop chop ck_spair mts% L
308schop scalar chop ck_null stu% S?
309chomp safe chop ck_spair mts% L
310schomp scalar safe chop ck_null stu% S?
311defined defined operator ck_defined isu% S?
312undef undef operator ck_lfun s% S?
313study study ck_fun su% S?
314pos match position ck_lfun stu% S?
315
316preinc preincrement ck_lfun dIs1 S
317i_preinc integer preincrement ck_lfun dis1 S
318predec predecrement ck_lfun dIs1 S
319i_predec integer predecrement ck_lfun dis1 S
320postinc postincrement ck_lfun dIst1 S
321i_postinc integer postincrement ck_lfun dist1 S
322postdec postdecrement ck_lfun dIst1 S
323i_postdec integer postdecrement ck_lfun dist1 S
324
325# Ordinary operators.
326
327pow exponentiation ck_null fst2 S S
328
329multiply multiplication ck_null Ifst2 S S
330i_multiply integer multiplication ck_null ifst2 S S
331divide division ck_null Ifst2 S S
332i_divide integer division ck_null ifst2 S S
333modulo modulus ck_null Iifst2 S S
334i_modulo integer modulus ck_null ifst2 S S
335repeat repeat ck_repeat mt2 L S
336
337add addition ck_null Ifst2 S S
338i_add integer addition ck_null ifst2 S S
339subtract subtraction ck_null Ifst2 S S
340i_subtract integer subtraction ck_null ifst2 S S
341concat concatenation ck_concat fst2 S S
342stringify string ck_fun fst@ S
343
344left_shift left bitshift ck_bitop fst2 S S
345right_shift right bitshift ck_bitop fst2 S S
346
347lt numeric lt ck_null Iifs2 S S
348i_lt integer lt ck_null ifs2 S S
349gt numeric gt ck_null Iifs2 S S
350i_gt integer gt ck_null ifs2 S S
351le numeric le ck_null Iifs2 S S
352i_le integer le ck_null ifs2 S S
353ge numeric ge ck_null Iifs2 S S
354i_ge integer ge ck_null ifs2 S S
355eq numeric eq ck_null Iifs2 S S
356i_eq integer eq ck_null ifs2 S S
357ne numeric ne ck_null Iifs2 S S
358i_ne integer ne ck_null ifs2 S S
359ncmp spaceship operator ck_null Iifst2 S S
360i_ncmp integer spaceship ck_null ifst2 S S
361
362slt string lt ck_scmp ifs2 S S
363sgt string gt ck_scmp ifs2 S S
364sle string le ck_scmp ifs2 S S
365sge string ge ck_scmp ifs2 S S
366seq string eq ck_null ifs2 S S
367sne string ne ck_null ifs2 S S
368scmp string comparison ck_scmp ifst2 S S
369
370bit_and bitwise and ck_bitop fst2 S S
371bit_xor bitwise xor ck_bitop fst2 S S
372bit_or bitwise or ck_bitop fst2 S S
373
374negate negate ck_null Ifst1 S
375i_negate integer negate ck_null ifst1 S
376not not ck_null ifs1 S
377complement 1's complement ck_bitop fst1 S
378
379# High falutin' math.
380
381atan2 atan2 ck_fun fst@ S S
382sin sin ck_fun fstu% S?
383cos cos ck_fun fstu% S?
384rand rand ck_fun st% S?
385srand srand ck_fun s% S?
386exp exp ck_fun fstu% S?
387log log ck_fun fstu% S?
388sqrt sqrt ck_fun fstu% S?
389
390# Lowbrow math.
391
392int int ck_fun fstu% S?
393hex hex ck_fun fstu% S?
394oct oct ck_fun fstu% S?
395abs abs ck_fun fstu% S?
396
397# String stuff.
398
399length length ck_lengthconst istu% S?
400substr substr ck_fun st@ S S S? S?
401vec vec ck_fun ist@ S S S
402
403index index ck_index ist@ S S S?
404rindex rindex ck_index ist@ S S S?
405
406sprintf sprintf ck_fun_locale mfst@ S L
407formline formline ck_fun ms@ S L
408ord ord ck_fun ifstu% S?
409chr chr ck_fun fstu% S?
410crypt crypt ck_fun fst@ S S
411ucfirst upper case first ck_fun_locale fstu% S?
412lcfirst lower case first ck_fun_locale fstu% S?
413uc upper case ck_fun_locale fstu% S?
414lc lower case ck_fun_locale fstu% S?
415quotemeta quote metachars ck_fun fstu% S?
416
417# Arrays.
418
419rv2av array deref ck_rvconst dt1
420aelemfast known array element ck_null s* A S
421aelem array element ck_null s2 A S
422aslice array slice ck_null m@ A L
423
424# Hashes.
425
426each each ck_fun t% H
427values values ck_fun t% H
428keys keys ck_fun t% H
429delete delete ck_delete % S
430exists exists operator ck_exists is% S
431rv2hv hash deref ck_rvconst dt1
432helem hash elem ck_null s2@ H S
433hslice hash slice ck_null m@ H L
434
435# Explosives and implosives.
436
437unpack unpack ck_fun @ S S
438pack pack ck_fun mst@ S L
439split split ck_split t@ S S S
440join join ck_fun mst@ S L
441
442# List operators.
443
444list list ck_null m@ L
445lslice list slice ck_null 2 H L L
446anonlist anonymous list ck_fun ms@ L
447anonhash anonymous hash ck_fun ms@ L
448
449splice splice ck_fun m@ A S? S? L
450push push ck_fun imst@ A L
451pop pop ck_shift s% A
452shift shift ck_shift s% A
453unshift unshift ck_fun imst@ A L
454sort sort ck_sort m@ C? L
455reverse reverse ck_fun mt@ L
456
457grepstart grep ck_grep dm@ C L
458grepwhile grep iterator ck_null dt|
459
460mapstart map ck_grep dm@ C L
461mapwhile map iterator ck_null dt|
462
463# Range stuff.
464
465range flipflop ck_null ? S S
466flip range (or flip) ck_null 1 S S
467flop range (or flop) ck_null 1
468
469# Control.
470
471and logical and ck_null |
472or logical or ck_null |
473xor logical xor ck_null fs| S S
474cond_expr conditional expression ck_null d?
475andassign logical and assignment ck_null s|
476orassign logical or assignment ck_null s|
477
478method method lookup ck_null d1
479entersub subroutine entry ck_subr dmt1 L
480leavesub subroutine exit ck_null 1
481caller caller ck_fun t% S?
482warn warn ck_fun imst@ L
483die die ck_fun dimst@ L
484reset reset ck_fun is% S?
485
486lineseq line sequence ck_null @
487nextstate next statement ck_null s;
488dbstate debug next statement ck_null s;
489unstack iteration finalizer ck_null s0
490enter block entry ck_null 0
491leave block exit ck_null @
492scope block ck_null @
493enteriter foreach loop entry ck_null d{
494iter foreach loop iterator ck_null 0
495enterloop loop entry ck_null d{
496leaveloop loop exit ck_null 2
497return return ck_null dm@ L
498last last ck_null ds}
499next next ck_null ds}
500redo redo ck_null ds}
501dump dump ck_null ds}
502goto goto ck_null ds}
503exit exit ck_fun ds% S?
504
505#nswitch numeric switch ck_null d
506#cswitch character switch ck_null d
507
508# I/O.
509
510open open ck_fun ist@ F S?
511close close ck_fun is% F?
512pipe_op pipe ck_fun is@ F F
513
514fileno fileno ck_fun ist% F
515umask umask ck_fun ist% S?
516binmode binmode ck_fun s% F
517
518tie tie ck_fun idms@ R S L
519untie untie ck_fun is% R
520tied tied ck_fun s% R
521dbmopen dbmopen ck_fun is@ H S S
522dbmclose dbmclose ck_fun is% H
523
524sselect select system call ck_select t@ S S S S
525select select ck_select st@ F?
526
527getc getc ck_eof st% F?
528read read ck_fun imst@ F R S S?
529enterwrite write ck_fun dis% F?
530leavewrite write exit ck_null 1
531
532prtf printf ck_listiob ims@ F? L
533print print ck_listiob ims@ F? L
534
535sysopen sysopen ck_fun s@ F S S S?
536sysseek sysseek ck_fun s@ F S S
537sysread sysread ck_fun imst@ F R S S?
538syswrite syswrite ck_fun imst@ F S S? S?
539
540send send ck_fun imst@ F S S S?
541recv recv ck_fun imst@ F R S S
542
543eof eof ck_eof is% F?
544tell tell ck_fun st% F?
545seek seek ck_fun s@ F S S
546# truncate really behaves as if it had both "S S" and "F S"
547truncate truncate ck_trunc is@ S S
548
549fcntl fcntl ck_fun st@ F S S
550ioctl ioctl ck_fun st@ F S S
551flock flock ck_fun ist@ F S
552
553# Sockets.
554
555socket socket ck_fun is@ F S S S
556sockpair socketpair ck_fun is@ F F S S S
557
558bind bind ck_fun is@ F S
559connect connect ck_fun is@ F S
560listen listen ck_fun is@ F S
561accept accept ck_fun ist@ F F
562shutdown shutdown ck_fun ist@ F S
563
564gsockopt getsockopt ck_fun is@ F S S
565ssockopt setsockopt ck_fun is@ F S S S
566
567getsockname getsockname ck_fun is% F
568getpeername getpeername ck_fun is% F
569
570# Stat calls.
571
572lstat lstat ck_ftst u- F
573stat stat ck_ftst u- F
574ftrread -R ck_ftst isu- F
575ftrwrite -W ck_ftst isu- F
576ftrexec -X ck_ftst isu- F
577fteread -r ck_ftst isu- F
578ftewrite -w ck_ftst isu- F
579fteexec -x ck_ftst isu- F
580ftis -e ck_ftst isu- F
581fteowned -O ck_ftst isu- F
582ftrowned -o ck_ftst isu- F
583ftzero -z ck_ftst isu- F
584ftsize -s ck_ftst istu- F
585ftmtime -M ck_ftst stu- F
586ftatime -A ck_ftst stu- F
587ftctime -C ck_ftst stu- F
588ftsock -S ck_ftst isu- F
589ftchr -c ck_ftst isu- F
590ftblk -b ck_ftst isu- F
591ftfile -f ck_ftst isu- F
592ftdir -d ck_ftst isu- F
593ftpipe -p ck_ftst isu- F
594ftlink -l ck_ftst isu- F
595ftsuid -u ck_ftst isu- F
596ftsgid -g ck_ftst isu- F
597ftsvtx -k ck_ftst isu- F
598fttty -t ck_ftst is- F
599fttext -T ck_ftst isu- F
600ftbinary -B ck_ftst isu- F
601
602# File calls.
603
604chdir chdir ck_fun ist% S?
605chown chown ck_fun imst@ L
606chroot chroot ck_fun istu% S?
607unlink unlink ck_fun imstu@ L
608chmod chmod ck_fun imst@ L
609utime utime ck_fun imst@ L
610rename rename ck_fun ist@ S S
611link link ck_fun ist@ S S
612symlink symlink ck_fun ist@ S S
613readlink readlink ck_fun stu% S?
614mkdir mkdir ck_fun ist@ S S
615rmdir rmdir ck_fun istu% S?
616
617# Directory calls.
618
619open_dir opendir ck_fun is@ F S
620readdir readdir ck_fun % F
621telldir telldir ck_fun st% F
622seekdir seekdir ck_fun s@ F S
623rewinddir rewinddir ck_fun s% F
624closedir closedir ck_fun is% F
625
626# Process control.
627
628fork fork ck_null ist0
629wait wait ck_null ist0
630waitpid waitpid ck_fun ist@ S S
631system system ck_exec imst@ S? L
632exec exec ck_exec dimst@ S? L
633kill kill ck_fun dimst@ L
634getppid getppid ck_null ist0
635getpgrp getpgrp ck_fun ist% S?
636setpgrp setpgrp ck_fun ist@ S? S?
637getpriority getpriority ck_fun ist@ S S
638setpriority setpriority ck_fun ist@ S S S
639
640# Time calls.
641
642time time ck_null ist0
643tms times ck_null 0
644localtime localtime ck_fun t% S?
645gmtime gmtime ck_fun t% S?
646alarm alarm ck_fun istu% S?
647sleep sleep ck_fun ist% S?
648
649# Shared memory.
650
651shmget shmget ck_fun imst@ S S S
652shmctl shmctl ck_fun imst@ S S S
653shmread shmread ck_fun imst@ S S S S
654shmwrite shmwrite ck_fun imst@ S S S S
655
656# Message passing.
657
658msgget msgget ck_fun imst@ S S
659msgctl msgctl ck_fun imst@ S S S
660msgsnd msgsnd ck_fun imst@ S S S
661msgrcv msgrcv ck_fun imst@ S S S S S
662
663# Semaphores.
664
665semget semget ck_fun imst@ S S S
666semctl semctl ck_fun imst@ S S S S
667semop semop ck_fun imst@ S S
668
669# Eval.
670
671require require ck_require du% S?
672dofile do 'file' ck_fun d1 S
673entereval eval string ck_eval d% S
674leaveeval eval exit ck_null 1 S
675#evalonce eval constant string ck_null d1 S
676entertry eval block ck_null |
677leavetry eval block exit ck_null @
678
679# Get system info.
680
681ghbyname gethostbyname ck_fun % S
682ghbyaddr gethostbyaddr ck_fun @ S S
683ghostent gethostent ck_null 0
684gnbyname getnetbyname ck_fun % S
685gnbyaddr getnetbyaddr ck_fun @ S S
686gnetent getnetent ck_null 0
687gpbyname getprotobyname ck_fun % S
688gpbynumber getprotobynumber ck_fun @ S
689gprotoent getprotoent ck_null 0
690gsbyname getservbyname ck_fun @ S S
691gsbyport getservbyport ck_fun @ S S
692gservent getservent ck_null 0
693shostent sethostent ck_fun is% S
694snetent setnetent ck_fun is% S
695sprotoent setprotoent ck_fun is% S
696sservent setservent ck_fun is% S
697ehostent endhostent ck_null is0
698enetent endnetent ck_null is0
699eprotoent endprotoent ck_null is0
700eservent endservent ck_null is0
701gpwnam getpwnam ck_fun % S
702gpwuid getpwuid ck_fun % S
703gpwent getpwent ck_null 0
704spwent setpwent ck_null is0
705epwent endpwent ck_null is0
706ggrnam getgrnam ck_fun % S
707ggrgid getgrgid ck_fun % S
708ggrent getgrent ck_null 0
709sgrent setgrent ck_null is0
710egrent endgrent ck_null is0
711getlogin getlogin ck_null st0
712
713# Miscellaneous.
714
715syscall syscall ck_fun imst@ S L
716
717# For multi-threading
718lock lock ck_rfun s% S
719threadsv per-thread variable ck_null ds0