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