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