| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/codegen.h" | 5 #include "src/codegen.h" |
| 6 | 6 |
| 7 #if defined(V8_OS_AIX) | 7 #if defined(V8_OS_AIX) |
| 8 #include <fenv.h> // NOLINT(build/c++11) | 8 #include <fenv.h> // NOLINT(build/c++11) |
| 9 #endif | 9 #endif |
| 10 #include "src/ast/prettyprinter.h" | 10 #include "src/ast/prettyprinter.h" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 (info->IsOptimizing() && FLAG_print_opt_code)); | 154 (info->IsOptimizing() && FLAG_print_opt_code)); |
| 155 if (print_code) { | 155 if (print_code) { |
| 156 base::SmartArrayPointer<char> debug_name = info->GetDebugName(); | 156 base::SmartArrayPointer<char> debug_name = info->GetDebugName(); |
| 157 CodeTracer::Scope tracing_scope(info->isolate()->GetCodeTracer()); | 157 CodeTracer::Scope tracing_scope(info->isolate()->GetCodeTracer()); |
| 158 OFStream os(tracing_scope.file()); | 158 OFStream os(tracing_scope.file()); |
| 159 | 159 |
| 160 // Print the source code if available. | 160 // Print the source code if available. |
| 161 bool print_source = | 161 bool print_source = |
| 162 info->parse_info() && (code->kind() == Code::OPTIMIZED_FUNCTION || | 162 info->parse_info() && (code->kind() == Code::OPTIMIZED_FUNCTION || |
| 163 code->kind() == Code::FUNCTION); | 163 code->kind() == Code::FUNCTION); |
| 164 // TODO(mstarzinger): Switch this over to use SharedFunctionInfo instead of | |
| 165 // the FunctionLiteral, once we have a SharedFunctionInfo for live edit. | |
| 166 print_source = print_source && info->literal() != nullptr; | |
| 167 if (print_source) { | 164 if (print_source) { |
| 168 FunctionLiteral* literal = info->literal(); | 165 Handle<SharedFunctionInfo> shared = info->shared_info(); |
| 169 Handle<Script> script = info->script(); | 166 Handle<Script> script = info->script(); |
| 170 if (!script->IsUndefined() && !script->source()->IsUndefined()) { | 167 if (!script->IsUndefined() && !script->source()->IsUndefined()) { |
| 171 os << "--- Raw source ---\n"; | 168 os << "--- Raw source ---\n"; |
| 172 StringCharacterStream stream(String::cast(script->source()), | 169 StringCharacterStream stream(String::cast(script->source()), |
| 173 literal->start_position()); | 170 shared->start_position()); |
| 174 // fun->end_position() points to the last character in the stream. We | 171 // fun->end_position() points to the last character in the stream. We |
| 175 // need to compensate by adding one to calculate the length. | 172 // need to compensate by adding one to calculate the length. |
| 176 int source_len = | 173 int source_len = shared->end_position() - shared->start_position() + 1; |
| 177 literal->end_position() - literal->start_position() + 1; | |
| 178 for (int i = 0; i < source_len; i++) { | 174 for (int i = 0; i < source_len; i++) { |
| 179 if (stream.HasMore()) { | 175 if (stream.HasMore()) { |
| 180 os << AsReversiblyEscapedUC16(stream.GetNext()); | 176 os << AsReversiblyEscapedUC16(stream.GetNext()); |
| 181 } | 177 } |
| 182 } | 178 } |
| 183 os << "\n\n"; | 179 os << "\n\n"; |
| 184 } | 180 } |
| 185 } | 181 } |
| 186 if (info->IsOptimizing()) { | 182 if (info->IsOptimizing()) { |
| 187 if (FLAG_print_unopt_code && info->parse_info()) { | 183 if (FLAG_print_unopt_code && info->parse_info()) { |
| 188 os << "--- Unoptimized code ---\n"; | 184 os << "--- Unoptimized code ---\n"; |
| 189 info->closure()->shared()->code()->Disassemble(debug_name.get(), os); | 185 info->closure()->shared()->code()->Disassemble(debug_name.get(), os); |
| 190 } | 186 } |
| 191 os << "--- Optimized code ---\n" | 187 os << "--- Optimized code ---\n" |
| 192 << "optimization_id = " << info->optimization_id() << "\n"; | 188 << "optimization_id = " << info->optimization_id() << "\n"; |
| 193 } else { | 189 } else { |
| 194 os << "--- Code ---\n"; | 190 os << "--- Code ---\n"; |
| 195 } | 191 } |
| 196 if (print_source) { | 192 if (print_source) { |
| 197 FunctionLiteral* literal = info->literal(); | 193 Handle<SharedFunctionInfo> shared = info->shared_info(); |
| 198 os << "source_position = " << literal->start_position() << "\n"; | 194 os << "source_position = " << shared->start_position() << "\n"; |
| 199 } | 195 } |
| 200 code->Disassemble(debug_name.get(), os); | 196 code->Disassemble(debug_name.get(), os); |
| 201 os << "--- End code ---\n"; | 197 os << "--- End code ---\n"; |
| 202 } | 198 } |
| 203 #endif // ENABLE_DISASSEMBLER | 199 #endif // ENABLE_DISASSEMBLER |
| 204 } | 200 } |
| 205 | 201 |
| 206 } // namespace internal | 202 } // namespace internal |
| 207 } // namespace v8 | 203 } // namespace v8 |
| OLD | NEW |