Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(295)

Side by Side Diff: runtime/vm/flags.cc

Issue 898093003: Make instruction counter in simulators 64-bit (issue 22302). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/flags.h ('k') | runtime/vm/simulator_arm.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/flags.h" 5 #include "vm/flags.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/json_stream.h" 8 #include "vm/json_stream.h"
9 #include "vm/os.h" 9 #include "vm/os.h"
10 10
11 namespace dart { 11 namespace dart {
12 12
13 DEFINE_FLAG(bool, print_flags, false, "Print flags as they are being parsed."); 13 DEFINE_FLAG(bool, print_flags, false, "Print flags as they are being parsed.");
14 DEFINE_FLAG(bool, ignore_unrecognized_flags, false, 14 DEFINE_FLAG(bool, ignore_unrecognized_flags, false,
15 "Ignore unrecognized flags."); 15 "Ignore unrecognized flags.");
16 16
17 bool Flags::initialized_ = false; 17 bool Flags::initialized_ = false;
18 18
19 // List of registered flags. 19 // List of registered flags.
20 Flag** Flags::flags_ = NULL; 20 Flag** Flags::flags_ = NULL;
21 intptr_t Flags::capacity_ = 0; 21 intptr_t Flags::capacity_ = 0;
22 intptr_t Flags::num_flags_ = 0; 22 intptr_t Flags::num_flags_ = 0;
23 23
24 class Flag { 24 class Flag {
25 public: 25 public:
26 enum FlagType { 26 enum FlagType {
27 kBoolean, 27 kBoolean,
28 kInteger, 28 kInteger,
29 kUint64,
29 kString, 30 kString,
30 kFunc, 31 kFunc,
31 kNumFlagTypes 32 kNumFlagTypes
32 }; 33 };
33 34
34 Flag(const char* name, const char* comment, void* addr, FlagType type) 35 Flag(const char* name, const char* comment, void* addr, FlagType type)
35 : name_(name), comment_(comment), addr_(addr), type_(type) { 36 : name_(name), comment_(comment), addr_(addr), type_(type) {
36 } 37 }
37 Flag(const char* name, const char* comment, FlagHandler handler) 38 Flag(const char* name, const char* comment, FlagHandler handler)
38 : name_(name), comment_(comment), handler_(handler), type_(kFunc) { 39 : name_(name), comment_(comment), handler_(handler), type_(kFunc) {
39 } 40 }
40 41
41 void Print() { 42 void Print() {
42 if (IsUnrecognized()) { 43 if (IsUnrecognized()) {
43 OS::Print("%s: unrecognized\n", name_); 44 OS::Print("%s: unrecognized\n", name_);
44 return; 45 return;
45 } 46 }
46 switch (type_) { 47 switch (type_) {
47 case kBoolean: { 48 case kBoolean: {
48 OS::Print("%s: %s (%s)\n", 49 OS::Print("%s: %s (%s)\n",
49 name_, *this->bool_ptr_ ? "true" : "false", comment_); 50 name_, *this->bool_ptr_ ? "true" : "false", comment_);
50 break; 51 break;
51 } 52 }
52 case kInteger: { 53 case kInteger: {
53 OS::Print("%s: %d (%s)\n", name_, *this->int_ptr_, comment_); 54 OS::Print("%s: %d (%s)\n", name_, *this->int_ptr_, comment_);
54 break; 55 break;
55 } 56 }
57 case kUint64: {
58 OS::Print("%s: %"Pu64" (%s)\n", name_, *this->uint64_ptr_, comment_);
59 break;
60 }
56 case kString: { 61 case kString: {
57 if (*this->charp_ptr_ != NULL) { 62 if (*this->charp_ptr_ != NULL) {
58 OS::Print("%s: '%s' (%s)\n", name_, *this->charp_ptr_, comment_); 63 OS::Print("%s: '%s' (%s)\n", name_, *this->charp_ptr_, comment_);
59 } else { 64 } else {
60 OS::Print("%s: (null) (%s)\n", name_, comment_); 65 OS::Print("%s: (null) (%s)\n", name_, comment_);
61 } 66 }
62 break; 67 break;
63 } 68 }
64 case kFunc: { 69 case kFunc: {
65 OS::Print("%s: (%s)\n", name_, comment_); 70 OS::Print("%s: (%s)\n", name_, comment_);
66 break; 71 break;
67 } 72 }
68 default: 73 default:
69 UNREACHABLE(); 74 UNREACHABLE();
70 break; 75 break;
71 } 76 }
72 } 77 }
73 78
74 bool IsUnrecognized() const { 79 bool IsUnrecognized() const {
75 return (type_ == kBoolean) && (bool_ptr_ == NULL); 80 return (type_ == kBoolean) && (bool_ptr_ == NULL);
76 } 81 }
77 82
78 const char* name_; 83 const char* name_;
79 const char* comment_; 84 const char* comment_;
80 union { 85 union {
81 void* addr_; 86 void* addr_;
82 bool* bool_ptr_; 87 bool* bool_ptr_;
83 int* int_ptr_; 88 int* int_ptr_;
89 uint64_t* uint64_ptr_;
84 charp* charp_ptr_; 90 charp* charp_ptr_;
85 FlagHandler handler_; 91 FlagHandler handler_;
86 }; 92 };
87 FlagType type_; 93 FlagType type_;
88 bool changed_; 94 bool changed_;
89 }; 95 };
90 96
91 97
92 Flag* Flags::Lookup(const char* name) { 98 Flag* Flags::Lookup(const char* name) {
93 for (intptr_t i = 0; i < num_flags_; i++) { 99 for (intptr_t i = 0; i < num_flags_; i++) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 const char* comment) { 157 const char* comment) {
152 ASSERT(Lookup(name) == NULL); 158 ASSERT(Lookup(name) == NULL);
153 159
154 Flag* flag = new Flag(name, comment, addr, Flag::kInteger); 160 Flag* flag = new Flag(name, comment, addr, Flag::kInteger);
155 AddFlag(flag); 161 AddFlag(flag);
156 162
157 return default_value; 163 return default_value;
158 } 164 }
159 165
160 166
167 uint64_t Flags::Register_uint64_t(uint64_t* addr,
168 const char* name,
169 uint64_t default_value,
170 const char* comment) {
171 ASSERT(Lookup(name) == NULL);
172
173 Flag* flag = new Flag(name, comment, addr, Flag::kUint64);
174 AddFlag(flag);
175
176 return default_value;
177 }
178
179
161 const char* Flags::Register_charp(charp* addr, 180 const char* Flags::Register_charp(charp* addr,
162 const char* name, 181 const char* name,
163 const char* default_value, 182 const char* default_value,
164 const char* comment) { 183 const char* comment) {
165 ASSERT(Lookup(name) == NULL); 184 ASSERT(Lookup(name) == NULL);
166 Flag* flag = new Flag(name, comment, addr, Flag::kString); 185 Flag* flag = new Flag(name, comment, addr, Flag::kString);
167 AddFlag(flag); 186 AddFlag(flag);
168 return default_value; 187 return default_value;
169 } 188 }
170 189
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 base = 16; 233 base = 16;
215 } 234 }
216 int val = strtol(argument, &endptr, base); 235 int val = strtol(argument, &endptr, base);
217 if (endptr == argument + len) { 236 if (endptr == argument + len) {
218 *flag->int_ptr_ = val; 237 *flag->int_ptr_ = val;
219 } else { 238 } else {
220 return false; 239 return false;
221 } 240 }
222 break; 241 break;
223 } 242 }
243 case Flag::kUint64: {
244 char* endptr = NULL;
245 const intptr_t len = strlen(argument);
246 int base = 10;
247 if ((len > 2) && (argument[0] == '0') && (argument[1] == 'x')) {
248 base = 16;
249 }
250 int64_t val = strtoll(argument, &endptr, base);
251 if (endptr == argument + len) {
252 *flag->uint64_ptr_ = static_cast<uint64_t>(val);
253 } else {
254 return false;
255 }
256 break;
257 }
224 case Flag::kFunc: { 258 case Flag::kFunc: {
225 if (strcmp(argument, "true") == 0) { 259 if (strcmp(argument, "true") == 0) {
226 (flag->handler_)(true); 260 (flag->handler_)(true);
227 } else if (strcmp(argument, "false") == 0) { 261 } else if (strcmp(argument, "false") == 0) {
228 (flag->handler_)(false); 262 (flag->handler_)(false);
229 } else { 263 } else {
230 return false; 264 return false;
231 } 265 }
232 break; 266 break;
233 } 267 }
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 jsflag.AddProperty("flagType", "bool"); 432 jsflag.AddProperty("flagType", "bool");
399 jsflag.AddProperty("valueAsString", 433 jsflag.AddProperty("valueAsString",
400 (*flag->bool_ptr_ ? "true" : "false")); 434 (*flag->bool_ptr_ ? "true" : "false"));
401 break; 435 break;
402 } 436 }
403 case Flag::kInteger: { 437 case Flag::kInteger: {
404 jsflag.AddProperty("flagType", "int"); 438 jsflag.AddProperty("flagType", "int");
405 jsflag.AddPropertyF("valueAsString", "%d", *flag->int_ptr_); 439 jsflag.AddPropertyF("valueAsString", "%d", *flag->int_ptr_);
406 break; 440 break;
407 } 441 }
442 case Flag::kUint64: {
443 jsflag.AddProperty("flagType", "uint64_t");
444 jsflag.AddPropertyF("valueAsString", "%"Pu64, *flag->uint64_ptr_);
445 break;
446 }
408 case Flag::kString: { 447 case Flag::kString: {
409 jsflag.AddProperty("flagType", "string"); 448 jsflag.AddProperty("flagType", "string");
410 if (flag->charp_ptr_ != NULL) { 449 if (flag->charp_ptr_ != NULL) {
411 jsflag.AddPropertyF("valueAsString", "%s", *flag->charp_ptr_); 450 jsflag.AddPropertyF("valueAsString", "%s", *flag->charp_ptr_);
412 } else { 451 } else {
413 // valueAsString missing means NULL. 452 // valueAsString missing means NULL.
414 } 453 }
415 break; 454 break;
416 } 455 }
417 default: 456 default:
(...skipping 22 matching lines...) Expand all
440 for (intptr_t i = 0; i < num_flags_; ++i) { 479 for (intptr_t i = 0; i < num_flags_; ++i) {
441 Flag* flag = flags_[i]; 480 Flag* flag = flags_[i];
442 if (flag->changed_) { 481 if (flag->changed_) {
443 PrintFlagToJSONArray(&jsarr, flag); 482 PrintFlagToJSONArray(&jsarr, flag);
444 } 483 }
445 } 484 }
446 } 485 }
447 } 486 }
448 487
449 } // namespace dart 488 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/flags.h ('k') | runtime/vm/simulator_arm.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698