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