migrate substitution keywords to SVN
[reactos.git] / reactos / lib / kjs / src / make-jumps.pl
1 #!/usr/local/bin/perl -w
2 #
3 # Create link and execute definitions for jumps2 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 # $Id$
28 #
29
30 $linenumbers = 0;
31 $opcount = 0;
32
33 $target = "c1jumps.h";
34 open(CFP, ">$target") || die "couldn't create `$target': $!\n";
35
36 $target = "c2jumps.h";
37 open(CFP2, ">$target") || die "couldn't create `$target': $!\n";
38
39 $target = "./ejumps.h";
40 open(EFP, ">$target") || die "couldn't create `$target': $!\n";
41
42 while (<>) {
43 if (/operand\s+([a-zA-Z_][a-zA-Z0-9_]*)\s+([\S]+)\s+\{(.*)/) {
44 $operand = $1;
45 $args = $2;
46 $flags = $3;
47
48 $f_symbol = 0;
49 if ($flags =~ /symbol/) {
50 $f_symbol = 1;
51 }
52 $f_jump = 0;
53 if ($flags =~ /jump/) {
54 $f_jump = 1;
55 }
56
57 if ($linenumbers) {
58 printf CFP ("#line %d \"%s\"\n", $. - 1, $ARGV);
59 }
60 #
61 # Compilation phase 1.
62 #
63 print CFP "/* operand $operand ($opcount) */\n";
64 print CFP "case $opcount:\n";
65 print CFP " SAVE_OP (&&op_$operand);\n";
66
67 if ($operand eq "const") {
68 # Patch const offsets.
69 printf CFP " JS_BC_READ_INT32 (cp, i);\n";
70 printf CFP " i += consts_offset;\n";
71 printf CFP " SAVE_INT32 (i);\n";
72 } elsif ($f_symbol) {
73 # Link symbols.
74 printf CFP " JS_BC_READ_INT32 (cp, i);\n";
75 printf CFP " i += consts_offset;\n";
76 printf CFP " i = vm->consts[i].u.vsymbol;\n";
77 printf CFP " SAVE_INT32 (i);\n";
78 } else {
79 # Handle standard arguments.
80 if ($args =~ /0/) {
81 } elsif ($args =~ /1/) {
82 print CFP " JS_BC_READ_INT8 (cp, i);\n";
83 print CFP " SAVE_INT8 (i);\n";
84 } elsif ($args =~ /2/) {
85 print CFP " JS_BC_READ_INT16 (cp, i);\n";
86 print CFP " SAVE_INT16 (i);\n";
87 } elsif ($args =~ /4/) {
88 print CFP " JS_BC_READ_INT32 (cp, i);\n";
89 print CFP " SAVE_INT32 (i);\n";
90 } else {
91 die("$ARGV:$.: illegal argument: $args\n");
92 }
93 }
94
95 print CFP " cp += $args;\n";
96 print CFP " break;\n\n";
97 } else {
98 next;
99 }
100
101 #
102 # Compilation phase 2.
103 #
104 if ($linenumbers) {
105 printf CFP2 "#line %d \"%s\"\n", $. - 1, $ARGV;
106 }
107 print CFP2 "/* operand $operand ($opcount) */\n";
108 print CFP2 "case $opcount:\n";
109 print CFP2 " cpos++;\n";
110 if ($f_jump){
111 print CFP2 " i = ARG_INT32 ();\n";
112 if (0) {
113 print CFP2 " printf(\"%s: delta=%d, cp=%d\\n\", \"$operand\", i, cp - code_start - 1);\n";
114 }
115 print CFP2 " i = reloc[cp - code_start + 4 + i] - &f->code[cpos + 1];\n";
116 if (0) {
117 print CFP2 " printf (\"%s: newdelta=%d\\n\", \"$operand\", i);\n";
118 }
119 print CFP2 " ARG_INT32 () = i;\n";
120 }
121 if ($args ne "0") {
122 print CFP2 " cp += $args;\n";
123 print CFP2 " cpos++;\n";
124 }
125 print CFP2 " break;\n\n";
126
127
128 #
129 # Execution.
130 #
131 if ($linenumbers) {
132 printf EFP "#line %d \"%s\"\n", $. - 1, $ARGV;
133 }
134 print EFP "/* operand $operand ($opcount) */\n";
135 print EFP "op_$operand:\n";
136 print EFP " OPERAND ($opcount);\n";
137
138 if (0) {
139 print EFP "printf (\"$operand\\n\");\n";
140 }
141
142 while (<>) {
143 if (/^\}/) {
144 print EFP " NEXT ();\n";
145 print EFP "\n";
146 last;
147 }
148 print EFP;
149 }
150
151 $opcount++;
152 }
153 close(CFP);
154 close(CFP2);
155 close(EFP);