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> | 8 #include <fenv.h> |
9 #endif | 9 #endif |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 } | 121 } |
122 | 122 |
123 if (FLAG_trace_codegen || print_source || print_ast) { | 123 if (FLAG_trace_codegen || print_source || print_ast) { |
124 PrintF("[generating %s code for %s function: ", kind, ftype); | 124 PrintF("[generating %s code for %s function: ", kind, ftype); |
125 if (info->IsStub()) { | 125 if (info->IsStub()) { |
126 const char* name = | 126 const char* name = |
127 CodeStub::MajorName(info->code_stub()->MajorKey(), true); | 127 CodeStub::MajorName(info->code_stub()->MajorKey(), true); |
128 PrintF("%s", name == NULL ? "<unknown>" : name); | 128 PrintF("%s", name == NULL ? "<unknown>" : name); |
129 } else { | 129 } else { |
130 AllowDeferredHandleDereference allow_deference_for_trace; | 130 AllowDeferredHandleDereference allow_deference_for_trace; |
131 PrintF("%s", info->function()->debug_name()->ToCString().get()); | 131 PrintF("%s", info->literal()->debug_name()->ToCString().get()); |
132 } | 132 } |
133 PrintF("]\n"); | 133 PrintF("]\n"); |
134 } | 134 } |
135 | 135 |
136 #ifdef DEBUG | 136 #ifdef DEBUG |
137 if (info->parse_info() && print_source) { | 137 if (info->parse_info() && print_source) { |
138 PrintF("--- Source from AST ---\n%s\n", | 138 PrintF("--- Source from AST ---\n%s\n", |
139 PrettyPrinter(info->isolate(), info->zone()) | 139 PrettyPrinter(info->isolate(), info->zone()) |
140 .PrintProgram(info->function())); | 140 .PrintProgram(info->literal())); |
141 } | 141 } |
142 | 142 |
143 if (info->parse_info() && print_ast) { | 143 if (info->parse_info() && print_ast) { |
144 PrintF("--- AST ---\n%s\n", AstPrinter(info->isolate(), info->zone()) | 144 PrintF("--- AST ---\n%s\n", AstPrinter(info->isolate(), info->zone()) |
145 .PrintProgram(info->function())); | 145 .PrintProgram(info->literal())); |
146 } | 146 } |
147 #endif // DEBUG | 147 #endif // DEBUG |
148 } | 148 } |
149 | 149 |
150 | 150 |
151 Handle<Code> CodeGenerator::MakeCodeEpilogue(MacroAssembler* masm, | 151 Handle<Code> CodeGenerator::MakeCodeEpilogue(MacroAssembler* masm, |
152 Code::Flags flags, | 152 Code::Flags flags, |
153 CompilationInfo* info) { | 153 CompilationInfo* info) { |
154 Isolate* isolate = info->isolate(); | 154 Isolate* isolate = info->isolate(); |
155 | 155 |
(...skipping 24 matching lines...) Expand all Loading... |
180 : (FLAG_print_code || | 180 : (FLAG_print_code || |
181 (info->IsStub() && FLAG_print_code_stubs) || | 181 (info->IsStub() && FLAG_print_code_stubs) || |
182 (info->IsOptimizing() && FLAG_print_opt_code)); | 182 (info->IsOptimizing() && FLAG_print_opt_code)); |
183 if (print_code) { | 183 if (print_code) { |
184 const char* debug_name; | 184 const char* debug_name; |
185 base::SmartArrayPointer<char> debug_name_holder; | 185 base::SmartArrayPointer<char> debug_name_holder; |
186 if (info->IsStub()) { | 186 if (info->IsStub()) { |
187 CodeStub::Major major_key = info->code_stub()->MajorKey(); | 187 CodeStub::Major major_key = info->code_stub()->MajorKey(); |
188 debug_name = CodeStub::MajorName(major_key, false); | 188 debug_name = CodeStub::MajorName(major_key, false); |
189 } else { | 189 } else { |
190 debug_name_holder = | 190 debug_name_holder = info->literal()->debug_name()->ToCString(); |
191 info->parse_info()->function()->debug_name()->ToCString(); | |
192 debug_name = debug_name_holder.get(); | 191 debug_name = debug_name_holder.get(); |
193 } | 192 } |
194 | 193 |
195 CodeTracer::Scope tracing_scope(info->isolate()->GetCodeTracer()); | 194 CodeTracer::Scope tracing_scope(info->isolate()->GetCodeTracer()); |
196 OFStream os(tracing_scope.file()); | 195 OFStream os(tracing_scope.file()); |
197 | 196 |
198 // Print the source code if available. | 197 // Print the source code if available. |
199 FunctionLiteral* function = nullptr; | |
200 bool print_source = | 198 bool print_source = |
201 info->parse_info() && (code->kind() == Code::OPTIMIZED_FUNCTION || | 199 info->parse_info() && (code->kind() == Code::OPTIMIZED_FUNCTION || |
202 code->kind() == Code::FUNCTION); | 200 code->kind() == Code::FUNCTION); |
203 if (print_source) { | 201 if (print_source) { |
204 function = info->function(); | 202 FunctionLiteral* literal = info->literal(); |
205 Handle<Script> script = info->script(); | 203 Handle<Script> script = info->script(); |
206 if (!script->IsUndefined() && !script->source()->IsUndefined()) { | 204 if (!script->IsUndefined() && !script->source()->IsUndefined()) { |
207 os << "--- Raw source ---\n"; | 205 os << "--- Raw source ---\n"; |
208 StringCharacterStream stream(String::cast(script->source()), | 206 StringCharacterStream stream(String::cast(script->source()), |
209 function->start_position()); | 207 literal->start_position()); |
210 // fun->end_position() points to the last character in the stream. We | 208 // fun->end_position() points to the last character in the stream. We |
211 // need to compensate by adding one to calculate the length. | 209 // need to compensate by adding one to calculate the length. |
212 int source_len = | 210 int source_len = |
213 function->end_position() - function->start_position() + 1; | 211 literal->end_position() - literal->start_position() + 1; |
214 for (int i = 0; i < source_len; i++) { | 212 for (int i = 0; i < source_len; i++) { |
215 if (stream.HasMore()) { | 213 if (stream.HasMore()) { |
216 os << AsReversiblyEscapedUC16(stream.GetNext()); | 214 os << AsReversiblyEscapedUC16(stream.GetNext()); |
217 } | 215 } |
218 } | 216 } |
219 os << "\n\n"; | 217 os << "\n\n"; |
220 } | 218 } |
221 } | 219 } |
222 if (info->IsOptimizing()) { | 220 if (info->IsOptimizing()) { |
223 if (FLAG_print_unopt_code && info->parse_info()) { | 221 if (FLAG_print_unopt_code && info->parse_info()) { |
224 os << "--- Unoptimized code ---\n"; | 222 os << "--- Unoptimized code ---\n"; |
225 info->closure()->shared()->code()->Disassemble(debug_name, os); | 223 info->closure()->shared()->code()->Disassemble(debug_name, os); |
226 } | 224 } |
227 os << "--- Optimized code ---\n" | 225 os << "--- Optimized code ---\n" |
228 << "optimization_id = " << info->optimization_id() << "\n"; | 226 << "optimization_id = " << info->optimization_id() << "\n"; |
229 } else { | 227 } else { |
230 os << "--- Code ---\n"; | 228 os << "--- Code ---\n"; |
231 } | 229 } |
232 if (print_source) { | 230 if (print_source) { |
233 os << "source_position = " << function->start_position() << "\n"; | 231 FunctionLiteral* literal = info->literal(); |
| 232 os << "source_position = " << literal->start_position() << "\n"; |
234 } | 233 } |
235 code->Disassemble(debug_name, os); | 234 code->Disassemble(debug_name, os); |
236 os << "--- End code ---\n"; | 235 os << "--- End code ---\n"; |
237 } | 236 } |
238 #endif // ENABLE_DISASSEMBLER | 237 #endif // ENABLE_DISASSEMBLER |
239 } | 238 } |
240 | 239 |
241 } // namespace internal | 240 } // namespace internal |
242 } // namespace v8 | 241 } // namespace v8 |
OLD | NEW |