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