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