source: trunk/third/perl/opcode.pl @ 10724

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