| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/compiler/wasm-compiler.h" | 5 #include "src/compiler/wasm-compiler.h" |
| 6 | 6 |
| 7 #include "src/isolate-inl.h" | 7 #include "src/isolate-inl.h" |
| 8 | 8 |
| 9 #include "src/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" |
| 10 | 10 |
| (...skipping 2054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2065 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "wasm-to-js", index, | 2065 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "wasm-to-js", index, |
| 2066 module->module->GetName(func->name_offset)); | 2066 module->module->GetName(func->name_offset)); |
| 2067 } | 2067 } |
| 2068 return code; | 2068 return code; |
| 2069 } | 2069 } |
| 2070 | 2070 |
| 2071 | 2071 |
| 2072 // Helper function to compile a single function. | 2072 // Helper function to compile a single function. |
| 2073 Handle<Code> CompileWasmFunction(wasm::ErrorThrower& thrower, Isolate* isolate, | 2073 Handle<Code> CompileWasmFunction(wasm::ErrorThrower& thrower, Isolate* isolate, |
| 2074 wasm::ModuleEnv* module_env, | 2074 wasm::ModuleEnv* module_env, |
| 2075 const wasm::WasmFunction& function, | 2075 const wasm::WasmFunction& function) { |
| 2076 int index) { | |
| 2077 if (FLAG_trace_wasm_compiler || FLAG_trace_wasm_decode_time) { | 2076 if (FLAG_trace_wasm_compiler || FLAG_trace_wasm_decode_time) { |
| 2078 // TODO(titzer): clean me up a bit. | |
| 2079 OFStream os(stdout); | 2077 OFStream os(stdout); |
| 2080 os << "Compiling WASM function #" << index << ":"; | 2078 os << "Compiling WASM function " |
| 2081 if (function.name_offset > 0) { | 2079 << wasm::WasmFunctionName(&function, module_env) << std::endl; |
| 2082 os << module_env->module->GetName(function.name_offset); | |
| 2083 } | |
| 2084 os << std::endl; | 2080 os << std::endl; |
| 2085 } | 2081 } |
| 2086 // Initialize the function environment for decoding. | 2082 // Initialize the function environment for decoding. |
| 2087 wasm::FunctionEnv env; | 2083 wasm::FunctionEnv env; |
| 2088 env.module = module_env; | 2084 env.module = module_env; |
| 2089 env.sig = function.sig; | 2085 env.sig = function.sig; |
| 2090 env.local_i32_count = function.local_i32_count; | 2086 env.local_i32_count = function.local_i32_count; |
| 2091 env.local_i64_count = function.local_i64_count; | 2087 env.local_i64_count = function.local_i64_count; |
| 2092 env.local_f32_count = function.local_f32_count; | 2088 env.local_f32_count = function.local_f32_count; |
| 2093 env.local_f64_count = function.local_f64_count; | 2089 env.local_f64_count = function.local_f64_count; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2108 module_env->module->module_start + function.code_start_offset, // -- | 2104 module_env->module->module_start + function.code_start_offset, // -- |
| 2109 module_env->module->module_start + function.code_end_offset); // -- | 2105 module_env->module->module_start + function.code_end_offset); // -- |
| 2110 | 2106 |
| 2111 if (result.failed()) { | 2107 if (result.failed()) { |
| 2112 if (FLAG_trace_wasm_compiler) { | 2108 if (FLAG_trace_wasm_compiler) { |
| 2113 OFStream os(stdout); | 2109 OFStream os(stdout); |
| 2114 os << "Compilation failed: " << result << std::endl; | 2110 os << "Compilation failed: " << result << std::endl; |
| 2115 } | 2111 } |
| 2116 // Add the function as another context for the exception | 2112 // Add the function as another context for the exception |
| 2117 ScopedVector<char> buffer(128); | 2113 ScopedVector<char> buffer(128); |
| 2118 SNPrintF(buffer, "Compiling WASM function #%d:%s failed:", index, | 2114 SNPrintF(buffer, "Compiling WASM function #%d:%s failed:", |
| 2115 function.func_index, |
| 2119 module_env->module->GetName(function.name_offset)); | 2116 module_env->module->GetName(function.name_offset)); |
| 2120 thrower.Failed(buffer.start(), result); | 2117 thrower.Failed(buffer.start(), result); |
| 2121 return Handle<Code>::null(); | 2118 return Handle<Code>::null(); |
| 2122 } | 2119 } |
| 2123 | 2120 |
| 2124 // Run the compiler pipeline to generate machine code. | 2121 // Run the compiler pipeline to generate machine code. |
| 2125 CallDescriptor* descriptor = const_cast<CallDescriptor*>( | 2122 CallDescriptor* descriptor = const_cast<CallDescriptor*>( |
| 2126 module_env->GetWasmCallDescriptor(&zone, function.sig)); | 2123 module_env->GetWasmCallDescriptor(&zone, function.sig)); |
| 2127 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION); | 2124 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION); |
| 2128 // add flags here if a meaningful name is helpful for debugging. | 2125 // add flags here if a meaningful name is helpful for debugging. |
| 2129 bool debugging = | 2126 bool debugging = |
| 2130 FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph; | 2127 FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph; |
| 2131 const char* func_name = "wasm"; | 2128 const char* func_name = "wasm"; |
| 2132 Vector<char> buffer; | 2129 Vector<char> buffer; |
| 2133 if (debugging) { | 2130 if (debugging) { |
| 2134 buffer = Vector<char>::New(128); | 2131 buffer = Vector<char>::New(128); |
| 2135 SNPrintF(buffer, "WASM_function_#%d:%s", index, | 2132 SNPrintF(buffer, "WASM_function_#%d:%s", function.func_index, |
| 2136 module_env->module->GetName(function.name_offset)); | 2133 module_env->module->GetName(function.name_offset)); |
| 2137 func_name = buffer.start(); | 2134 func_name = buffer.start(); |
| 2138 } | 2135 } |
| 2139 CompilationInfo info(func_name, isolate, &zone, flags); | 2136 CompilationInfo info(func_name, isolate, &zone, flags); |
| 2140 | 2137 |
| 2141 Handle<Code> code = | 2138 Handle<Code> code = |
| 2142 Pipeline::GenerateCodeForTesting(&info, descriptor, &graph); | 2139 Pipeline::GenerateCodeForTesting(&info, descriptor, &graph); |
| 2143 if (debugging) { | 2140 if (debugging) { |
| 2144 buffer.Dispose(); | 2141 buffer.Dispose(); |
| 2145 } | 2142 } |
| 2146 if (!code.is_null()) { | 2143 if (!code.is_null()) { |
| 2147 RecordFunctionCompilation( | 2144 RecordFunctionCompilation( |
| 2148 Logger::FUNCTION_TAG, &info, "WASM_function", index, | 2145 Logger::FUNCTION_TAG, &info, "WASM_function", function.func_index, |
| 2149 module_env->module->GetName(function.name_offset)); | 2146 module_env->module->GetName(function.name_offset)); |
| 2150 } | 2147 } |
| 2151 | 2148 |
| 2152 return code; | 2149 return code; |
| 2153 } | 2150 } |
| 2154 | 2151 |
| 2155 | 2152 |
| 2156 } // namespace compiler | 2153 } // namespace compiler |
| 2157 } // namespace internal | 2154 } // namespace internal |
| 2158 } // namespace v8 | 2155 } // namespace v8 |
| OLD | NEW |