migrate substitution keywords to SVN
[reactos.git] / reactos / lib / kjs / src / make-switch.pl
1 #!/usr/local/bin/perl -w
2 #
3 # Create link and execute definitions for switch dispatch method.
4 # Copyright (c) 1998 New Generation Software (NGS) Oy
5 #
6 # Author: Markku Rossi <mtr@ngs.fi>
7 #
8
9 #
10 # This library is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU Library General Public
12 # License as published by the Free Software Foundation; either
13 # version 2 of the License, or (at your option) any later version.
14 #
15 # This library is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 # Library General Public License for more details.
19 #
20 # You should have received a copy of the GNU Library General Public
21 # License along with this library; if not, write to the Free
22 # Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23 # MA 02111-1307, USA
24 #
25 #
26 #
27 # $Source: /cygdrive/c/RCVS/CVS/ReactOS/reactos/lib/kjs/src/make-switch.pl,v $
28 # $Id$
29 #
30
31 $linenumbers = 0;
32
33 $opcount = 0;
34
35 $target = "./c1switch.h";
36 open(CFP, ">$target") || die "couldn't create `$target': $!\n";
37
38 $target = "./c2switch.h";
39 open(CFP2, ">$target") || die "couldn't create `$target': $!\n";
40
41 $target = "./eswitch.h";
42 open(EFP, ">$target") || die "couldn't create `$target': $!\n";
43
44 while (<>) {
45 if (/operand\s+([a-zA-Z_][a-zA-Z0-9_]+)\s+([\S]+)\s+\{(.*)/) {
46 $operand = $1;
47 $args = $2;
48 $flags = $3;
49
50 $f_symbol = 0;
51 if ($flags =~ /symbol/) {
52 $f_symbol = 1;
53 }
54 $f_jump = 0;
55 if ($flags =~ /jump/) {
56 $f_jump = 1;
57 }
58
59 if ($linenumbers) {
60 printf CFP ("#line %d \"%s\"\n", $. - 1, $ARGV);
61 }
62
63 #
64 # Compilation phase 1.
65 #
66 print CFP "/* operand $operand ($opcount) */\n";
67 print CFP "case $opcount:\n";
68 print CFP " SAVE_OP ($opcount);\n";
69
70 if ($operand eq "const") {
71 # Patch const offsets.
72 printf CFP " JS_BC_READ_INT32 (cp, i);\n";
73 printf CFP " i += consts_offset;\n";
74 printf CFP " SAVE_INT32 (i);\n";
75 } elsif ($f_symbol) {
76 # Link symbols.
77 printf CFP " JS_BC_READ_INT32 (cp, i);\n";
78 printf CFP " i += consts_offset;\n";
79 printf CFP " i = vm->consts[i].u.vsymbol;\n";
80 printf CFP " SAVE_INT32 (i);\n";
81 } else {
82 # Handle standard arguments.
83 if ($args =~ /0/) {
84 } elsif ($args =~ /1/) {
85 print CFP " JS_BC_READ_INT8 (cp, i);\n";
86 print CFP " SAVE_INT8 (i);\n";
87 } elsif ($args =~ /2/) {
88 print CFP " JS_BC_READ_INT16 (cp, i);\n";
89 print CFP " SAVE_INT16 (i);\n";
90 } elsif ($args =~ /4/) {
91 print CFP " JS_BC_READ_INT32 (cp, i);\n";
92 print CFP " SAVE_INT32 (i);\n";
93 } else {
94 die("$ARGV:$.: illegal argument: $args\n");
95 }
96 }
97
98 print CFP " cp += $args;\n";
99 print CFP " break;\n\n";
100 } else {
101 next;
102 }
103
104 #
105 # Compilation phase 2.
106 #
107 if ($linenumbers) {
108 printf CFP2 "#line %d \"%s\"\n", $. - 1, $ARGV;
109 }
110 print CFP2 "/* operand $operand ($opcount) */\n";
111 print CFP2 "case $opcount:\n";
112 print CFP2 " cpos++;\n";
113 if ($f_jump) {
114 print CFP2 " i = ARG_INT32 ();\n";
115 if (0) {
116 print CFP2 " printf(\"%s: delta=%d, cp=%d\\n\", \"$operand\", i, cp - code_start - 1);\n";
117 }
118 print CFP2 " i = reloc[cp - fixed_code + 4 + i] - &f->code[cpos + 1];\n";
119 if (0) {
120 print CFP2 " printf (\"%s: newdelta=%d\\n\", \"$operand\", i);\n";
121 }
122 print CFP2 " ARG_INT32 () = i;\n";
123 }
124 if ($args ne "0") {
125 print CFP2 " cp += $args;\n";
126 print CFP2 " cpos++;\n";
127 }
128 print CFP2 " break;\n\n";
129
130 #
131 # Execution.
132 #
133 if ($linenumbers) {
134 printf EFP "#line %d\"%s\"\n", $. - 1, $ARGV;
135 }
136 print EFP "/* operand $operand ($opcount) */\n";
137 print EFP "case $opcount:\n";
138 while (<>) {
139 if (/^\}/) {
140 print EFP " break;\n\n";
141 last;
142 }
143 print EFP;
144 }
145
146 $opcount++;
147 }
148 close(CFP);
149 close(CFP2);
150 close(EFP);