OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/assembler.h" | 5 #include "vm/assembler.h" |
6 | 6 |
7 #include "platform/utils.h" | 7 #include "platform/utils.h" |
8 #include "vm/cpu.h" | 8 #include "vm/cpu.h" |
9 #include "vm/heap.h" | 9 #include "vm/heap.h" |
10 #include "vm/memory_region.h" | 10 #include "vm/memory_region.h" |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 void Assembler::Unreachable(const char* message) { | 203 void Assembler::Unreachable(const char* message) { |
204 const char* format = "Unreachable: %s"; | 204 const char* format = "Unreachable: %s"; |
205 const intptr_t len = OS::SNPrint(NULL, 0, format, message); | 205 const intptr_t len = OS::SNPrint(NULL, 0, format, message); |
206 char* buffer = reinterpret_cast<char*>(malloc(len + 1)); | 206 char* buffer = reinterpret_cast<char*>(malloc(len + 1)); |
207 OS::SNPrint(buffer, len + 1, format, message); | 207 OS::SNPrint(buffer, len + 1, format, message); |
208 Stop(buffer); | 208 Stop(buffer); |
209 } | 209 } |
210 | 210 |
211 | 211 |
212 void Assembler::Comment(const char* format, ...) { | 212 void Assembler::Comment(const char* format, ...) { |
213 if (FLAG_code_comments || FLAG_disassemble || FLAG_disassemble_optimized) { | 213 if (EmittingComments()) { |
214 char buffer[1024]; | 214 char buffer[1024]; |
215 | 215 |
216 va_list args; | 216 va_list args; |
217 va_start(args, format); | 217 va_start(args, format); |
218 OS::VSNPrint(buffer, sizeof(buffer), format, args); | 218 OS::VSNPrint(buffer, sizeof(buffer), format, args); |
219 va_end(args); | 219 va_end(args); |
220 | 220 |
221 comments_.Add(new CodeComment(buffer_.GetPosition(), | 221 comments_.Add(new CodeComment(buffer_.GetPosition(), |
222 String::ZoneHandle(String::New(buffer, | 222 String::ZoneHandle(String::New(buffer, |
223 Heap::kOld)))); | 223 Heap::kOld)))); |
224 } | 224 } |
225 } | 225 } |
226 | 226 |
227 | 227 |
| 228 bool Assembler::EmittingComments() { |
| 229 return FLAG_code_comments || FLAG_disassemble || FLAG_disassemble_optimized; |
| 230 } |
| 231 |
| 232 |
228 const Code::Comments& Assembler::GetCodeComments() const { | 233 const Code::Comments& Assembler::GetCodeComments() const { |
229 Code::Comments& comments = Code::Comments::New(comments_.length()); | 234 Code::Comments& comments = Code::Comments::New(comments_.length()); |
230 | 235 |
231 for (intptr_t i = 0; i < comments_.length(); i++) { | 236 for (intptr_t i = 0; i < comments_.length(); i++) { |
232 comments.SetPCOffsetAt(i, comments_[i]->pc_offset()); | 237 comments.SetPCOffsetAt(i, comments_[i]->pc_offset()); |
233 comments.SetCommentAt(i, comments_[i]->comment()); | 238 comments.SetCommentAt(i, comments_[i]->comment()); |
234 } | 239 } |
235 | 240 |
236 return comments; | 241 return comments; |
237 } | 242 } |
238 | 243 |
239 } // namespace dart | 244 } // namespace dart |
OLD | NEW |