OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
| 28 // TODO(X64): Remove stdio.h when compiler test is removed. |
| 29 #include <stdio.h> |
28 | 30 |
29 #include "v8.h" | 31 #include "v8.h" |
30 | 32 |
31 #include "bootstrapper.h" | 33 #include "bootstrapper.h" |
32 #include "codegen-inl.h" | 34 #include "codegen-inl.h" |
33 #include "debug.h" | 35 #include "debug.h" |
34 #include "ic-inl.h" | 36 #include "ic-inl.h" |
35 #include "parser.h" | 37 #include "parser.h" |
36 #include "register-allocator-inl.h" | 38 #include "register-allocator-inl.h" |
37 #include "scopes.h" | 39 #include "scopes.h" |
38 | 40 |
39 // TEST | 41 // TODO(X64): Remove compiler.h when compiler test is removed. |
40 #include "compiler.h" | 42 #include "compiler.h" |
41 | 43 |
42 namespace v8 { | 44 namespace v8 { |
43 namespace internal { | 45 namespace internal { |
44 | 46 |
45 #define __ ACCESS_MASM(masm_) | 47 #define __ ACCESS_MASM(masm_) |
46 | 48 |
47 // ------------------------------------------------------------------------- | 49 // ------------------------------------------------------------------------- |
48 // Platform-specific DeferredCode functions. | 50 // Platform-specific DeferredCode functions. |
49 | 51 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 | 132 |
131 // Set flags appropriately for this stage of implementation. | 133 // Set flags appropriately for this stage of implementation. |
132 // TODO(X64): Make ic work, and stop disabling them. | 134 // TODO(X64): Make ic work, and stop disabling them. |
133 // These settings stick - remove them when we don't want them anymore. | 135 // These settings stick - remove them when we don't want them anymore. |
134 #ifdef DEBUG | 136 #ifdef DEBUG |
135 FLAG_print_builtin_source = true; | 137 FLAG_print_builtin_source = true; |
136 FLAG_print_builtin_ast = true; | 138 FLAG_print_builtin_ast = true; |
137 #endif | 139 #endif |
138 FLAG_use_ic = false; | 140 FLAG_use_ic = false; |
139 | 141 |
140 Handle<JSFunction> test_function = Compiler::Compile( | 142 // Read the file "test.js" from the current directory, compile, and run it. |
141 Factory::NewStringFromAscii(CStrVector( | 143 // If the file is not there, use a simple script embedded here instead. |
| 144 Handle<String> test_script; |
| 145 FILE* file = fopen("test.js", "rb"); |
| 146 if (file == NULL) { |
| 147 test_script = Factory::NewStringFromAscii(CStrVector( |
142 "// Put all code in anonymous function to avoid global scope.\n" | 148 "// Put all code in anonymous function to avoid global scope.\n" |
143 "(function(){" | 149 "(function(){" |
144 " function test_if_then_else(x, y, z){" | 150 " var x = true ? 47 : 32;" |
145 " if (x) {" | 151 " return x;" |
146 " x = y;" | 152 "})()")); |
147 " } else {" | 153 } else { |
148 " x = z;" | 154 fseek(file, 0, SEEK_END); |
149 " }" | 155 int size = ftell(file); |
150 " return x;" | 156 rewind(file); |
151 " }" | 157 |
152 "\n" | 158 char* chars = new char[size + 1]; |
153 " function test_recursion_with_base(x, y, z, w) {" | 159 chars[size] = '\0'; |
154 " if (x) {" | 160 for (int i = 0; i < size;) { |
155 " x = x;" | 161 int read = fread(&chars[i], 1, size - i, file); |
156 " } else {" | 162 i += read; |
157 " x = test_recursion_with_base(y, z, w, 0);" | 163 } |
158 " }" | 164 fclose(file); |
159 " return x;" | 165 test_script = Factory::NewStringFromAscii(CStrVector(chars)); |
160 " }" | 166 delete[] chars; |
161 "\n" | 167 } |
162 " function test_local_variables(x, y){" | 168 |
163 " var w; y = x; x = w; w = y; y = x; return w;" | 169 Handle<JSFunction> test_function = Compiler::Compile( |
164 " };" | 170 test_script, |
165 " test_local_variables(2,3);" | |
166 " function test_nesting_calls(x, y, zee){return zee;};" | |
167 " test_local_variables(" | |
168 " test_nesting_calls(test_local_variables(1,3), 42, 47)," | |
169 " test_local_variables(-25.3, 2));" | |
170 " // return test_recursion_with_base(0, 0, 0, 47);\n" | |
171 " var x_value = 42;" | |
172 " var o = { x: x_value };" | |
173 " o.x = 43;" | |
174 " o.x;" | |
175 " var x_string = 'x';" | |
176 " o[x_string] = 44;" | |
177 " o[x_string];" | |
178 " o.f = function() { return 45; };" | |
179 " o.f();" | |
180 " var f_string = 'f';" | |
181 " o[f_string]();" | |
182 " var a = [ 1, 2, 3 ];" | |
183 " var x = true ? 42 : 32;" | |
184 " return test_if_then_else(0, 46, 47);" | |
185 "})()")), | |
186 Factory::NewStringFromAscii(CStrVector("CodeGeneratorTestScript")), | 171 Factory::NewStringFromAscii(CStrVector("CodeGeneratorTestScript")), |
187 0, | 172 0, |
188 0, | 173 0, |
189 NULL, | 174 NULL, |
190 NULL); | 175 NULL); |
191 | 176 |
192 Code* code_object = test_function->code(); // Local for debugging ease. | 177 Code* code_object = test_function->code(); // Local for debugging ease. |
193 USE(code_object); | 178 USE(code_object); |
194 | 179 |
195 // Create a dummy function and context. | 180 // Create a dummy function and context. |
(...skipping 2833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3029 __ addq(rsp, Immediate(2 * kPointerSize)); // remove markers | 3014 __ addq(rsp, Immediate(2 * kPointerSize)); // remove markers |
3030 | 3015 |
3031 // Restore frame pointer and return. | 3016 // Restore frame pointer and return. |
3032 __ pop(rbp); | 3017 __ pop(rbp); |
3033 __ ret(0); | 3018 __ ret(0); |
3034 } | 3019 } |
3035 | 3020 |
3036 #undef __ | 3021 #undef __ |
3037 | 3022 |
3038 } } // namespace v8::internal | 3023 } } // namespace v8::internal |
OLD | NEW |