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