Fix unnecessary re-linking
[p5sagit/p5-mst-13.2.git] / opcode.pl
CommitLineData
79072805 1#!/usr/bin/perl
2
36477c24 3unlink "opcode.h";
79072805 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 /^#/;
c07a80fd 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
79072805 20 push(@ops, $key);
c07a80fd 21 $desc{$key} = $desc;
79072805 22 $check{$key} = $check;
23 $ckname{$check}++;
24 $flags{$key} = $flags;
25 $args{$key} = $args;
26}
27
28# Emit defines.
29
30$i = 0;
748a9306 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
79072805 39for (@ops) {
40 print "\t", &tab(3,"OP_\U$_,"), "/* ", $i++, " */\n";
41}
85e6fe83 42print "\t", &tab(3,"OP_max"), "\n";
79072805 43print "} opcode;\n";
44print "\n#define MAXO ", scalar @ops, "\n\n";
45
c07a80fd 46# Emit op names and descriptions.
79072805 47
48print <<END;
49#ifndef DOINIT
a0d0e21e 50EXT char *op_name[];
79072805 51#else
a0d0e21e 52EXT char *op_name[] = {
79072805 53END
54
55for (@ops) {
c07a80fd 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);
79072805 74}
75
76print <<END;
77};
78#endif
79
80END
81
82# Emit function declarations.
83
84for (sort keys %ckname) {
a0d0e21e 85 print "OP *\t", &tab(3,$_),"_((OP* op));\n";
79072805 86}
87
88print "\n";
89
90for (@ops) {
a0d0e21e 91 print "OP *\t", &tab(3, "pp_\L$_"), "_((void));\n";
79072805 92}
93
94# Emit ppcode switch array.
95
96print <<END;
97
98#ifndef DOINIT
a0d0e21e 99EXT OP * (*ppaddr[])();
79072805 100#else
a0d0e21e 101EXT OP * (*ppaddr[])() = {
79072805 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
c6ecf61f 118EXT OP * (*check[]) _((OP *op));
79072805 119#else
c6ecf61f 120EXT OP * (*check[]) _((OP *op)) = {
79072805 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
a0d0e21e 139EXT U32 opargs[] = {
79072805 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
a0d0e21e 162 $argsum |= 128 if $flags =~ /u/; # defaults to $_
79072805 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
93a17b20 191stub stub ck_null 0
192scalar scalar ck_fun s S
79072805 193
194# Pushy stuff.
195
196pushmark pushmark ck_null s
197wantarray wantarray ck_null is
198
8990e307 199const constant item ck_svconst s
79072805 200
201gvsv scalar variable ck_null ds
202gv glob value ck_null ds
c07a80fd 203gelem glob elem ck_null d S S
748a9306 204padsv private variable ck_null ds
205padav private array ck_null d
206padhv private hash ck_null d
207padany private something ck_null d
79072805 208
209pushre push regexp ck_null 0
210
211# References and stuff.
212
213rv2gv ref-to-glob cast ck_rvconst ds
a0d0e21e 214rv2sv scalar deref ck_rvconst ds
79072805 215av2arylen array length ck_null is
a0d0e21e 216rv2cv subroutine deref ck_rvconst d
5f05dabc 217anoncode anonymous subroutine ck_anoncode 0
c07a80fd 218prototype subroutine prototype ck_null s S
a0d0e21e 219refgen reference constructor ck_spair m L
220srefgen scalar ref constructor ck_null fs S
221ref reference-type operator ck_fun stu S?
463ee0b2 222bless bless ck_fun s S S?
79072805 223
224# Pushy I/O.
225
226backtick backticks ck_null t
0a753a76 227# glob defaults its first arg to $_
228glob glob ck_glob t S? S?
79072805 229readline <HANDLE> ck_null t
230rcatline append I/O operator ck_null t
231
232# Bindable operators.
233
463ee0b2 234regcmaybe regexp comp once ck_fun s S
79072805 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
a0d0e21e 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?
79072805 251undef undef operator ck_lfun s S?
c07a80fd 252study study ck_fun su S?
a0d0e21e 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
79072805 263
264# Ordinary operators.
265
a0d0e21e 266pow exponentiation ck_null fst S S
79072805 267
85e6fe83 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
79072805 274repeat repeat ck_repeat mt L S
275
276add addition ck_null Ifst S S
85e6fe83 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
79072805 280concat concatenation ck_concat fst S S
a0d0e21e 281stringify string ck_fun fst S
79072805 282
55497cff 283left_shift left bitshift ck_bitop fst S S
284right_shift right bitshift ck_bitop fst S S
79072805 285
85e6fe83 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
a0d0e21e 298ncmp spaceship operator ck_null Iifst S S
85e6fe83 299i_ncmp integer spaceship ck_null ifst S S
79072805 300
bbce6d69 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
36477c24 305seq string eq ck_null ifs S S
306sne string ne ck_null ifs S S
bbce6d69 307scmp string comparison ck_scmp ifst S S
79072805 308
55497cff 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
79072805 312
85e6fe83 313negate negate ck_null Ifst S
314i_negate integer negate ck_null ifst S
79072805 315not not ck_null ifs S
55497cff 316complement 1's complement ck_bitop fst S
79072805 317
318# High falutin' math.
319
320atan2 atan2 ck_fun fst S S
a0d0e21e 321sin sin ck_fun fstu S?
322cos cos ck_fun fstu S?
79072805 323rand rand ck_fun st S?
324srand srand ck_fun s S?
a0d0e21e 325exp exp ck_fun fstu S?
326log log ck_fun fstu S?
327sqrt sqrt ck_fun fstu S?
79072805 328
a0d0e21e 329int int ck_fun fstu S?
330hex hex ck_fun istu S?
331oct oct ck_fun istu S?
332abs abs ck_fun fstu S?
79072805 333
334# String stuff.
335
a0d0e21e 336length length ck_lengthconst istu S?
79072805 337substr substr ck_fun st S S S?
338vec vec ck_fun ist S S S
339
340index index ck_index ist S S S?
341rindex rindex ck_index ist S S S?
342
bbce6d69 343sprintf sprintf ck_fun_locale mst S L
344formline formline ck_fun ms S L
a0d0e21e 345ord ord ck_fun ifstu S?
346chr chr ck_fun fstu S?
79072805 347crypt crypt ck_fun fst S S
bbce6d69 348ucfirst upper case first ck_fun_locale fstu S?
349lcfirst lower case first ck_fun_locale fstu S?
350uc upper case ck_fun_locale fstu S?
351lc lower case ck_fun_locale fstu S?
55497cff 352quotemeta quote metachars ck_fun fstu S?
79072805 353
354# Arrays.
355
356rv2av array deref ck_rvconst dt
357aelemfast known array element ck_null s A S
8990e307 358aelem array element ck_null s A S
79072805 359aslice array slice ck_null m A L
360
aa689395 361# Hashes.
79072805 362
363each each ck_fun t H
364values values ck_fun t H
365keys keys ck_fun t H
5f05dabc 366delete delete ck_delete 0 S
367exists exists operator ck_exists is S
aa689395 368rv2hv hash deref ck_rvconst dt
369helem hash elem ck_null s H S
370hslice hash slice ck_null m H L
79072805 371
372# Explosives and implosives.
373
374unpack unpack ck_fun 0 S S
375pack pack ck_fun mst S L
376split split ck_split t S S S
377join join ck_fun mst S L
378
379# List operators.
380
381list list ck_null m L
382lslice list slice ck_null 0 H L L
a0d0e21e 383anonlist anonymous list ck_fun ms L
384anonhash anonymous hash ck_fun ms L
79072805 385
a0d0e21e 386splice splice ck_fun m A S? S? L
79072805 387push push ck_fun imst A L
388pop pop ck_shift s A
389shift shift ck_shift s A
390unshift unshift ck_fun imst A L
391sort sort ck_sort m C? L
392reverse reverse ck_fun mt L
393
394grepstart grep ck_grep dm C L
395grepwhile grep iterator ck_null dt
396
a0d0e21e 397mapstart map ck_grep dm C L
398mapwhile map iterator ck_null dt
399
79072805 400# Range stuff.
401
402range flipflop ck_null 0 S S
403flip range (or flip) ck_null 0 S S
404flop range (or flop) ck_null 0
405
406# Control.
407
408and logical and ck_null 0
409or logical or ck_null 0
a0d0e21e 410xor logical xor ck_null fs S S
4633a7c4 411cond_expr conditional expression ck_null d
79072805 412andassign logical and assignment ck_null s
413orassign logical or assignment ck_null s
414
463ee0b2 415method method lookup ck_null d
a0d0e21e 416entersub subroutine entry ck_subr dmt L
417leavesub subroutine exit ck_null 0
79072805 418caller caller ck_fun t S?
419warn warn ck_fun imst L
420die die ck_fun dimst L
421reset reset ck_fun is S?
422
423lineseq line sequence ck_null 0
93a17b20 424nextstate next statement ck_null s
425dbstate debug next statement ck_null s
79072805 426unstack unstack ck_null s
427enter block entry ck_null 0
428leave block exit ck_null 0
463ee0b2 429scope block ck_null 0
79072805 430enteriter foreach loop entry ck_null d
431iter foreach loop iterator ck_null 0
432enterloop loop entry ck_null d
a0d0e21e 433leaveloop loop exit ck_null 0
748a9306 434return return ck_null dm L
79072805 435last last ck_null ds
436next next ck_null ds
437redo redo ck_null ds
438dump dump ck_null ds
439goto goto ck_null ds
440exit exit ck_fun ds S?
441
a0d0e21e 442#nswitch numeric switch ck_null d
443#cswitch character switch ck_null d
79072805 444
445# I/O.
446
447open open ck_fun ist F S?
448close close ck_fun is F?
449pipe_op pipe ck_fun is F F
450
451fileno fileno ck_fun ist F
452umask umask ck_fun ist S?
453binmode binmode ck_fun s F
454
463ee0b2 455tie tie ck_fun idms R S L
456untie untie ck_fun is R
a5f75d66 457tied tied ck_fun s R
463ee0b2 458dbmopen dbmopen ck_fun is H S S
79072805 459dbmclose dbmclose ck_fun is H
460
461sselect select system call ck_select t S S S S
462select select ck_select st F?
463
464getc getc ck_eof st F?
465read read ck_fun imst F R S S?
466enterwrite write ck_fun dis F?
467leavewrite write exit ck_null 0
468
463ee0b2 469prtf printf ck_listiob ims F? L
79072805 470print print ck_listiob ims F? L
471
a5f75d66 472sysopen sysopen ck_fun s F S S S?
96e4d5b1 473systell systell ck_fun st F?
137443ea 474sysseek sysseek ck_fun s F S S
79072805 475sysread sysread ck_fun imst F R S S?
476syswrite syswrite ck_fun imst F S S S?
477
478send send ck_fun imst F S S S?
479recv recv ck_fun imst F R S S
480
481eof eof ck_eof is F?
482tell tell ck_fun st F?
483seek seek ck_fun s F S S
9b01e405 484# truncate really behaves as if it had both "S S" and "F S"
485truncate truncate ck_trunc is S S
79072805 486
487fcntl fcntl ck_fun st F S S
488ioctl ioctl ck_fun st F S S
489flock flock ck_fun ist F S
490
491# Sockets.
492
493socket socket ck_fun is F S S S
494sockpair socketpair ck_fun is F F S S S
495
496bind bind ck_fun is F S
497connect connect ck_fun is F S
498listen listen ck_fun is F S
499accept accept ck_fun ist F F
500shutdown shutdown ck_fun ist F S
501
502gsockopt getsockopt ck_fun is F S S
503ssockopt setsockopt ck_fun is F S S S
504
505getsockname getsockname ck_fun is F
506getpeername getpeername ck_fun is F
507
508# Stat calls.
509
a0d0e21e 510lstat lstat ck_ftst u F
511stat stat ck_ftst u F
512ftrread -R ck_ftst isu F
513ftrwrite -W ck_ftst isu F
514ftrexec -X ck_ftst isu F
515fteread -r ck_ftst isu F
516ftewrite -w ck_ftst isu F
517fteexec -x ck_ftst isu F
518ftis -e ck_ftst isu F
519fteowned -O ck_ftst isu F
520ftrowned -o ck_ftst isu F
521ftzero -z ck_ftst isu F
522ftsize -s ck_ftst istu F
523ftmtime -M ck_ftst stu F
524ftatime -A ck_ftst stu F
525ftctime -C ck_ftst stu F
526ftsock -S ck_ftst isu F
527ftchr -c ck_ftst isu F
528ftblk -b ck_ftst isu F
529ftfile -f ck_ftst isu F
530ftdir -d ck_ftst isu F
531ftpipe -p ck_ftst isu F
532ftlink -l ck_ftst isu F
533ftsuid -u ck_ftst isu F
534ftsgid -g ck_ftst isu F
535ftsvtx -k ck_ftst isu F
79072805 536fttty -t ck_ftst is F
a0d0e21e 537fttext -T ck_ftst isu F
538ftbinary -B ck_ftst isu F
79072805 539
540# File calls.
541
542chdir chdir ck_fun ist S?
543chown chown ck_fun imst L
a0d0e21e 544chroot chroot ck_fun istu S?
545unlink unlink ck_fun imstu L
79072805 546chmod chmod ck_fun imst L
547utime utime ck_fun imst L
548rename rename ck_fun ist S S
549link link ck_fun ist S S
550symlink symlink ck_fun ist S S
a0d0e21e 551readlink readlink ck_fun stu S?
79072805 552mkdir mkdir ck_fun ist S S
a0d0e21e 553rmdir rmdir ck_fun istu S?
79072805 554
555# Directory calls.
556
557open_dir opendir ck_fun is F S
558readdir readdir ck_fun 0 F
559telldir telldir ck_fun st F
560seekdir seekdir ck_fun s F S
561rewinddir rewinddir ck_fun s F
562closedir closedir ck_fun is F
563
564# Process control.
565
566fork fork ck_null ist
567wait wait ck_null ist
568waitpid waitpid ck_fun ist S S
569system system ck_exec imst S? L
570exec exec ck_exec dimst S? L
571kill kill ck_fun dimst L
572getppid getppid ck_null ist
573getpgrp getpgrp ck_fun ist S?
a0d0e21e 574setpgrp setpgrp ck_fun ist S? S?
79072805 575getpriority getpriority ck_fun ist S S
576setpriority setpriority ck_fun ist S S S
577
578# Time calls.
579
580time time ck_null ist
581tms times ck_null 0
582localtime localtime ck_fun t S?
583gmtime gmtime ck_fun t S?
a0d0e21e 584alarm alarm ck_fun istu S?
79072805 585sleep sleep ck_fun ist S?
586
587# Shared memory.
588
589shmget shmget ck_fun imst S S S
590shmctl shmctl ck_fun imst S S S
591shmread shmread ck_fun imst S S S S
16d20bd9 592shmwrite shmwrite ck_fun imst S S S S
79072805 593
594# Message passing.
595
596msgget msgget ck_fun imst S S
597msgctl msgctl ck_fun imst S S S
598msgsnd msgsnd ck_fun imst S S S
599msgrcv msgrcv ck_fun imst S S S S S
600
601# Semaphores.
602
603semget semget ck_fun imst S S S
604semctl semctl ck_fun imst S S S S
ecfc5424 605semop semop ck_fun imst S S
79072805 606
607# Eval.
608
a0d0e21e 609require require ck_require du S?
79072805 610dofile do 'file' ck_fun d S
611entereval eval string ck_eval d S
612leaveeval eval exit ck_null 0 S
a0d0e21e 613#evalonce eval constant string ck_null d S
79072805 614entertry eval block ck_null 0
615leavetry eval block exit ck_null 0
616
617# Get system info.
618
619ghbyname gethostbyname ck_fun 0 S
620ghbyaddr gethostbyaddr ck_fun 0 S S
621ghostent gethostent ck_null 0
622gnbyname getnetbyname ck_fun 0 S
623gnbyaddr getnetbyaddr ck_fun 0 S S
624gnetent getnetent ck_null 0
625gpbyname getprotobyname ck_fun 0 S
626gpbynumber getprotobynumber ck_fun 0 S
627gprotoent getprotoent ck_null 0
628gsbyname getservbyname ck_fun 0 S S
629gsbyport getservbyport ck_fun 0 S S
630gservent getservent ck_null 0
93a17b20 631shostent sethostent ck_fun is S
632snetent setnetent ck_fun is S
633sprotoent setprotoent ck_fun is S
634sservent setservent ck_fun is S
635ehostent endhostent ck_null is
636enetent endnetent ck_null is
637eprotoent endprotoent ck_null is
638eservent endservent ck_null is
79072805 639gpwnam getpwnam ck_fun 0 S
640gpwuid getpwuid ck_fun 0 S
641gpwent getpwent ck_null 0
a0d0e21e 642spwent setpwent ck_null is
643epwent endpwent ck_null is
79072805 644ggrnam getgrnam ck_fun 0 S
645ggrgid getgrgid ck_fun 0 S
646ggrent getgrent ck_null 0
a0d0e21e 647sgrent setgrent ck_null is
648egrent endgrent ck_null is
79072805 649getlogin getlogin ck_null st
650
651# Miscellaneous.
652
a0d0e21e 653syscall syscall ck_fun imst S L