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" |
11 #include "vm/os.h" | 11 #include "vm/os.h" |
12 #include "vm/zone.h" | 12 #include "vm/zone.h" |
13 | 13 |
14 namespace dart { | 14 namespace dart { |
15 | 15 |
| 16 DEFINE_FLAG(bool, code_comments, false, |
| 17 "Include comments into code and disassembly"); |
| 18 |
| 19 |
16 static uword NewContents(intptr_t capacity) { | 20 static uword NewContents(intptr_t capacity) { |
17 Zone* zone = Isolate::Current()->current_zone(); | 21 Zone* zone = Isolate::Current()->current_zone(); |
18 uword result = zone->AllocUnsafe(capacity); | 22 uword result = zone->AllocUnsafe(capacity); |
19 #if defined(DEBUG) | 23 #if defined(DEBUG) |
20 // Initialize the buffer with kBreakPointInstruction to force a break | 24 // Initialize the buffer with kBreakPointInstruction to force a break |
21 // point if we ever execute an uninitialized part of the code buffer. | 25 // point if we ever execute an uninitialized part of the code buffer. |
22 Assembler::InitializeMemoryWithBreakpoints(result, capacity); | 26 Assembler::InitializeMemoryWithBreakpoints(result, capacity); |
23 #endif | 27 #endif |
24 return result; | 28 return result; |
25 } | 29 } |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 182 |
179 | 183 |
180 void Assembler::Unreachable(const char* message) { | 184 void Assembler::Unreachable(const char* message) { |
181 const char* format = "Unreachable: %s"; | 185 const char* format = "Unreachable: %s"; |
182 const intptr_t len = OS::SNPrint(NULL, 0, format, message); | 186 const intptr_t len = OS::SNPrint(NULL, 0, format, message); |
183 char* buffer = reinterpret_cast<char*>(malloc(len + 1)); | 187 char* buffer = reinterpret_cast<char*>(malloc(len + 1)); |
184 OS::SNPrint(buffer, len + 1, format, message); | 188 OS::SNPrint(buffer, len + 1, format, message); |
185 Stop(buffer); | 189 Stop(buffer); |
186 } | 190 } |
187 | 191 |
| 192 |
| 193 void Assembler::Comment(const char* format, ...) { |
| 194 if (FLAG_code_comments) { |
| 195 char buffer[1024]; |
| 196 |
| 197 va_list args; |
| 198 va_start(args, format); |
| 199 OS::VSNPrint(buffer, sizeof(buffer), format, args); |
| 200 va_end(args); |
| 201 |
| 202 comments_.Add(new CodeComment(buffer_.GetPosition(), |
| 203 String::Handle(String::New(buffer)))); |
| 204 } |
| 205 } |
| 206 |
| 207 |
| 208 const Code::Comments& Assembler::GetCodeComments() const { |
| 209 Code::Comments& comments = Code::Comments::New(comments_.length()); |
| 210 |
| 211 for (intptr_t i = 0; i < comments_.length(); i++) { |
| 212 comments.SetPCOffsetAt(i, comments_[i]->pc_offset()); |
| 213 comments.SetCommentAt(i, comments_[i]->comment()); |
| 214 } |
| 215 |
| 216 return comments; |
| 217 } |
| 218 |
188 } // namespace dart | 219 } // namespace dart |
OLD | NEW |