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