06a729b3a0a63361b7e6402f89b9884d4a399ad9
[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_null         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
175 pushre          push regexp             ck_null         0
176
177 # References and stuff.
178
179 rv2gv           ref-to-glob cast        ck_rvconst      ds      
180 sv2len          scalar value length     ck_null         ist     
181 rv2sv           ref-to-scalar cast      ck_rvconst      ds      
182 av2arylen       array length            ck_null         is      
183 rv2cv           subroutine reference    ck_rvconst      d
184 refgen          backslash reference     ck_null         fst     L
185 ref             reference-type operator ck_fun          st      S?
186 bless           bless                   ck_fun          s       S S?
187
188 # Pushy I/O.
189
190 backtick        backticks               ck_null         t       
191 glob            glob                    ck_glob         t       
192 readline        <HANDLE>                ck_null         t       
193 rcatline        append I/O operator     ck_null         t       
194
195 # Bindable operators.
196
197 regcmaybe       regexp comp once        ck_fun          s       S
198 regcomp         regexp compilation      ck_null         s       S
199 match           pattern match           ck_match        d
200 subst           substitution            ck_null         dis     S
201 substcont       substitution cont       ck_null         dis     
202 trans           character translation   ck_null         is      S
203
204 # Lvalue operators.
205
206 sassign         scalar assignment       ck_null         s
207 aassign         list assignment         ck_null         t       L L
208
209 schop           scalar chop             ck_null         t
210 chop            chop                    ck_chop         mt      L
211 defined         defined operator        ck_lfun         is      S?
212 undef           undef operator          ck_lfun         s       S?
213 study           study                   ck_fun          st      S?
214
215 preinc          preincrement            ck_lfun         s       S
216 predec          predecrement            ck_lfun         s       S
217 postinc         postincrement           ck_lfun         st      S
218 postdec         postdecrement           ck_lfun         st      S
219
220 # Ordinary operators.
221
222 pow             exponentiation          ck_null         fst     S S
223
224 multiply        multiplication          ck_null         fst     S S
225 divide          division                ck_null         fst     S S
226 modulo          modulus                 ck_null         ifst    S S
227 repeat          repeat                  ck_repeat       mt      L S
228
229 add             addition                ck_null         Ifst    S S
230 intadd          integer addition        ck_null         ifst    S S
231 subtract        subtraction             ck_null         fst     S S
232 concat          concatenation           ck_concat       fst     S S
233
234 left_shift      left bitshift           ck_null         ifst    S S
235 right_shift     right bitshift          ck_null         ifst    S S
236
237 lt              numeric lt              ck_null         ifs     S S
238 gt              numeric gt              ck_null         ifs     S S
239 le              numeric le              ck_null         ifs     S S
240 ge              numeric ge              ck_null         ifs     S S
241 eq              numeric eq              ck_null         ifs     S S
242 ne              numeric ne              ck_null         ifs     S S
243 ncmp            spaceship               ck_null         ifst    S S
244
245 slt             string lt               ck_null         ifs     S S
246 sgt             string gt               ck_null         ifs     S S
247 sle             string le               ck_null         ifs     S S
248 sge             string ge               ck_null         ifs     S S
249 seq             string eq               ck_null         ifs     S S
250 sne             string ne               ck_null         ifs     S S
251 scmp            string comparison       ck_null         ifst    S S
252
253 bit_and         bit and                 ck_null         fst     S S
254 xor             xor                     ck_null         fst     S S
255 bit_or          bit or                  ck_null         fst     S S
256
257 negate          negate                  ck_null         fst     S
258 not             not                     ck_null         ifs     S
259 complement      1's complement          ck_null         fst     S
260
261 # High falutin' math.
262
263 atan2           atan2                   ck_fun          fst     S S
264 sin             sin                     ck_fun          fst     S?
265 cos             cos                     ck_fun          fst     S?
266 rand            rand                    ck_fun          st      S?
267 srand           srand                   ck_fun          s       S?
268 exp             exp                     ck_fun          fst     S?
269 log             log                     ck_fun          fst     S?
270 sqrt            sqrt                    ck_fun          fst     S?
271
272 int             int                     ck_fun          fst     S?
273 hex             hex                     ck_fun          ist     S?
274 oct             oct                     ck_fun          ist     S?
275 abs             abs                     ck_fun          fst     S?
276
277 # String stuff.
278
279 length          length                  ck_lengthconst  ist     S
280 substr          substr                  ck_fun          st      S S S?
281 vec             vec                     ck_fun          ist     S S S
282
283 index           index                   ck_index        ist     S S S?
284 rindex          rindex                  ck_index        ist     S S S?
285
286 sprintf         sprintf                 ck_fun          mst     S L
287 formline        formline                ck_formline     ms      S L
288 ord             ord                     ck_fun          ifst    S?
289 chr             chr                     ck_fun          fst     S?
290 crypt           crypt                   ck_fun          fst     S S
291 ucfirst         upper case first        ck_fun          ft      S
292 lcfirst         lower case first        ck_fun          ft      S
293 uc              upper case              ck_fun          ft      S
294 lc              lower case              ck_fun          ft      S
295
296 # Arrays.
297
298 rv2av           array deref             ck_rvconst      dt      
299 aelemfast       known array element     ck_null         s       A S
300 aelem           array element           ck_aelem        s       A S
301 aslice          array slice             ck_null         m       A L
302
303 # Associative arrays.
304
305 each            each                    ck_fun          t       H
306 values          values                  ck_fun          t       H
307 keys            keys                    ck_fun          t       H
308 delete          delete                  ck_null         s       H S
309 rv2hv           associative array deref ck_rvconst      dt      
310 helem           associative array elem  ck_null         s       H S
311 hslice          associative array slice ck_null         m       H L
312
313 # Explosives and implosives.
314
315 unpack          unpack                  ck_fun          0       S S
316 pack            pack                    ck_fun          mst     S L
317 split           split                   ck_split        t       S S S
318 join            join                    ck_fun          mst     S L
319
320 # List operators.
321
322 list            list                    ck_null         m       L
323 lslice          list slice              ck_null         0       H L L
324 anonlist        anonymous list          ck_null         m       L
325 anonhash        anonymous hash          ck_null         m       L
326
327 splice          splice                  ck_fun          m       A S S? L
328 push            push                    ck_fun          imst    A L
329 pop             pop                     ck_shift        s       A
330 shift           shift                   ck_shift        s       A
331 unshift         unshift                 ck_fun          imst    A L
332 sort            sort                    ck_sort         m       C? L
333 reverse         reverse                 ck_fun          mt      L
334
335 grepstart       grep                    ck_grep         dm      C L
336 grepwhile       grep iterator           ck_null         dt      
337
338 # Range stuff.
339
340 range           flipflop                ck_null         0       S S
341 flip            range (or flip)         ck_null         0       S S
342 flop            range (or flop)         ck_null         0
343
344 # Control.
345
346 and             logical and             ck_null         0       
347 or              logical or              ck_null         0       
348 cond_expr       conditional expression  ck_null         0       
349 andassign       logical and assignment  ck_null         s       
350 orassign        logical or assignment   ck_null         s       
351
352 method          method lookup           ck_null         d
353 entersubr       subroutine entry        ck_subr         dm      L
354 leavesubr       subroutine exit         ck_null         0       
355 caller          caller                  ck_fun          t       S?
356 warn            warn                    ck_fun          imst    L
357 die             die                     ck_fun          dimst   L
358 reset           reset                   ck_fun          is      S?
359
360 lineseq         line sequence           ck_null         0       
361 nextstate       next statement          ck_null         s       
362 dbstate         debug next statement    ck_null         s       
363 unstack         unstack                 ck_null         s
364 enter           block entry             ck_null         0       
365 leave           block exit              ck_null         0       
366 scope           block                   ck_null         0       
367 enteriter       foreach loop entry      ck_null         d       
368 iter            foreach loop iterator   ck_null         0       
369 enterloop       loop entry              ck_null         d       
370 leaveloop       loop exit               ck_null         s       
371 return          return                  ck_fun          dm      L
372 last            last                    ck_null         ds      
373 next            next                    ck_null         ds      
374 redo            redo                    ck_null         ds      
375 dump            dump                    ck_null         ds      
376 goto            goto                    ck_null         ds      
377 exit            exit                    ck_fun          ds      S?
378
379 nswitch         numeric switch          ck_null         d       
380 cswitch         character switch        ck_null         d       
381
382 # I/O.
383
384 open            open                    ck_fun          ist     F S?
385 close           close                   ck_fun          is      F?
386 pipe_op         pipe                    ck_fun          is      F F
387
388 fileno          fileno                  ck_fun          ist     F
389 umask           umask                   ck_fun          ist     S?
390 binmode         binmode                 ck_fun          s       F
391
392 tie             tie                     ck_fun          idms    R S L
393 untie           untie                   ck_fun          is      R
394 dbmopen         dbmopen                 ck_fun          is      H S S
395 dbmclose        dbmclose                ck_fun          is      H
396
397 sselect         select system call      ck_select       t       S S S S
398 select          select                  ck_select       st      F?
399
400 getc            getc                    ck_eof          st      F?
401 read            read                    ck_fun          imst    F R S S?
402 enterwrite      write                   ck_fun          dis     F?
403 leavewrite      write exit              ck_null         0       
404
405 prtf            printf                  ck_listiob      ims     F? L
406 print           print                   ck_listiob      ims     F? L
407
408 sysread         sysread                 ck_fun          imst    F R S S?
409 syswrite        syswrite                ck_fun          imst    F S S S?
410
411 send            send                    ck_fun          imst    F S S S?
412 recv            recv                    ck_fun          imst    F R S S
413
414 eof             eof                     ck_eof          is      F?
415 tell            tell                    ck_fun          st      F?
416 seek            seek                    ck_fun          s       F S S
417 truncate        truncate                ck_trunc        is      S S
418
419 fcntl           fcntl                   ck_fun          st      F S S
420 ioctl           ioctl                   ck_fun          st      F S S
421 flock           flock                   ck_fun          ist     F S
422
423 # Sockets.
424
425 socket          socket                  ck_fun          is      F S S S
426 sockpair        socketpair              ck_fun          is      F F S S S
427
428 bind            bind                    ck_fun          is      F S
429 connect         connect                 ck_fun          is      F S
430 listen          listen                  ck_fun          is      F S
431 accept          accept                  ck_fun          ist     F F
432 shutdown        shutdown                ck_fun          ist     F S
433
434 gsockopt        getsockopt              ck_fun          is      F S S
435 ssockopt        setsockopt              ck_fun          is      F S S S
436
437 getsockname     getsockname             ck_fun          is      F
438 getpeername     getpeername             ck_fun          is      F
439
440 # Stat calls.
441
442 lstat           lstat                   ck_ftst         0       F
443 stat            stat                    ck_ftst         0       F
444 ftrread         -R                      ck_ftst         is      F
445 ftrwrite        -W                      ck_ftst         is      F
446 ftrexec         -X                      ck_ftst         is      F
447 fteread         -r                      ck_ftst         is      F
448 ftewrite        -w                      ck_ftst         is      F
449 fteexec         -x                      ck_ftst         is      F
450 ftis            -e                      ck_ftst         is      F
451 fteowned        -O                      ck_ftst         is      F
452 ftrowned        -o                      ck_ftst         is      F
453 ftzero          -z                      ck_ftst         is      F
454 ftsize          -s                      ck_ftst         ist     F
455 ftmtime         -M                      ck_ftst         st      F
456 ftatime         -A                      ck_ftst         st      F
457 ftctime         -C                      ck_ftst         st      F
458 ftsock          -S                      ck_ftst         is      F
459 ftchr           -c                      ck_ftst         is      F
460 ftblk           -b                      ck_ftst         is      F
461 ftfile          -f                      ck_ftst         is      F
462 ftdir           -d                      ck_ftst         is      F
463 ftpipe          -p                      ck_ftst         is      F
464 ftlink          -l                      ck_ftst         is      F
465 ftsuid          -u                      ck_ftst         is      F
466 ftsgid          -g                      ck_ftst         is      F
467 ftsvtx          -k                      ck_ftst         is      F
468 fttty           -t                      ck_ftst         is      F
469 fttext          -T                      ck_ftst         is      F
470 ftbinary        -B                      ck_ftst         is      F
471
472 # File calls.
473
474 chdir           chdir                   ck_fun          ist     S?
475 chown           chown                   ck_fun          imst    L
476 chroot          chroot                  ck_fun          ist     S?
477 unlink          unlink                  ck_fun          imst    L
478 chmod           chmod                   ck_fun          imst    L
479 utime           utime                   ck_fun          imst    L
480 rename          rename                  ck_fun          ist     S S
481 link            link                    ck_fun          ist     S S
482 symlink         symlink                 ck_fun          ist     S S
483 readlink        readlink                ck_fun          st      S?
484 mkdir           mkdir                   ck_fun          ist     S S
485 rmdir           rmdir                   ck_fun          ist     S?
486
487 # Directory calls.
488
489 open_dir        opendir                 ck_fun          is      F S
490 readdir         readdir                 ck_fun          0       F
491 telldir         telldir                 ck_fun          st      F
492 seekdir         seekdir                 ck_fun          s       F S
493 rewinddir       rewinddir               ck_fun          s       F
494 closedir        closedir                ck_fun          is      F
495
496 # Process control.
497
498 fork            fork                    ck_null         ist     
499 wait            wait                    ck_null         ist     
500 waitpid         waitpid                 ck_fun          ist     S S
501 system          system                  ck_exec         imst    S? L
502 exec            exec                    ck_exec         dimst   S? L
503 kill            kill                    ck_fun          dimst   L
504 getppid         getppid                 ck_null         ist     
505 getpgrp         getpgrp                 ck_fun          ist     S?
506 setpgrp         setpgrp                 ck_fun          ist     S S
507 getpriority     getpriority             ck_fun          ist     S S
508 setpriority     setpriority             ck_fun          ist     S S S
509
510 # Time calls.
511
512 time            time                    ck_null         ist     
513 tms             times                   ck_null         0       
514 localtime       localtime               ck_fun          t       S?
515 gmtime          gmtime                  ck_fun          t       S?
516 alarm           alarm                   ck_fun          ist     S?
517 sleep           sleep                   ck_fun          ist     S?
518
519 # Shared memory.
520
521 shmget          shmget                  ck_fun          imst    S S S
522 shmctl          shmctl                  ck_fun          imst    S S S
523 shmread         shmread                 ck_fun          imst    S S S S
524 shmwrite        shmwrite                ck_fun          ist     S S S S
525
526 # Message passing.
527
528 msgget          msgget                  ck_fun          imst    S S
529 msgctl          msgctl                  ck_fun          imst    S S S
530 msgsnd          msgsnd                  ck_fun          imst    S S S
531 msgrcv          msgrcv                  ck_fun          imst    S S S S S
532
533 # Semaphores.
534
535 semget          semget                  ck_fun          imst    S S S
536 semctl          semctl                  ck_fun          imst    S S S S
537 semop           semop                   ck_fun          imst    S S S
538
539 # Eval.
540
541 require         require                 ck_fun          d       S
542 dofile          do 'file'               ck_fun          d       S
543 entereval       eval string             ck_eval         d       S
544 leaveeval       eval exit               ck_null         0       S
545 evalonce        eval constant string    ck_null         d       S
546 entertry        eval block              ck_null         0       
547 leavetry        eval block exit         ck_null         0       
548
549 # Get system info.
550
551 ghbyname        gethostbyname           ck_fun          0       S
552 ghbyaddr        gethostbyaddr           ck_fun          0       S S
553 ghostent        gethostent              ck_null         0       
554 gnbyname        getnetbyname            ck_fun          0       S
555 gnbyaddr        getnetbyaddr            ck_fun          0       S S
556 gnetent         getnetent               ck_null         0       
557 gpbyname        getprotobyname          ck_fun          0       S
558 gpbynumber      getprotobynumber        ck_fun          0       S
559 gprotoent       getprotoent             ck_null         0       
560 gsbyname        getservbyname           ck_fun          0       S S
561 gsbyport        getservbyport           ck_fun          0       S S
562 gservent        getservent              ck_null         0       
563 shostent        sethostent              ck_fun          is      S
564 snetent         setnetent               ck_fun          is      S
565 sprotoent       setprotoent             ck_fun          is      S
566 sservent        setservent              ck_fun          is      S
567 ehostent        endhostent              ck_null         is      
568 enetent         endnetent               ck_null         is      
569 eprotoent       endprotoent             ck_null         is      
570 eservent        endservent              ck_null         is      
571 gpwnam          getpwnam                ck_fun          0       S
572 gpwuid          getpwuid                ck_fun          0       S
573 gpwent          getpwent                ck_null         0       
574 spwent          setpwent                ck_null         ist     
575 epwent          endpwent                ck_null         ist     
576 ggrnam          getgrnam                ck_fun          0       S
577 ggrgid          getgrgid                ck_fun          0       S
578 ggrent          getgrent                ck_null         0       
579 sgrent          setgrent                ck_null         ist     
580 egrent          endgrent                ck_null         ist     
581 getlogin        getlogin                ck_null         st      
582
583 # Miscellaneous.
584
585 syscall         syscall                 ck_fun          ist     S L