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

Side by Side Diff: src/lexer/lexer-shell.cc

Issue 187633003: Experimental parser: make lexer shell do something again (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 9 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include <assert.h>
29 #include <fcntl.h> 28 #include <fcntl.h>
30 #include <string.h> 29 #include <string.h>
31 #include <stdio.h> 30 #include <stdio.h>
32 #include <stdlib.h> 31 #include <stdlib.h>
33 #include <string> 32 #include <string>
34 #include <vector> 33 #include <vector>
35 #include "v8.h" 34 #include "v8.h"
36 35
37 #include "api.h" 36 #include "api.h"
38 #include "ast.h" 37 #include "ast.h"
39 #include "char-predicates-inl.h" 38 #include "char-predicates-inl.h"
40 #include "messages.h" 39 #include "messages.h"
41 #include "platform.h" 40 #include "platform.h"
42 #include "runtime.h" 41 #include "runtime.h"
43 #include "scanner-character-streams.h" 42 #include "scanner-character-streams.h"
44 #include "scopeinfo.h" 43 #include "scopeinfo.h"
45 #include "string-stream.h" 44 #include "string-stream.h"
46 #include "scanner.h" 45 #include "scanner.h"
47 #include "lexer/lexer.h" 46 #include "lexer/lexer.h"
48 47
49 using namespace v8::internal; 48 using namespace v8::internal;
50 49
51 byte* ReadFile(const char* name, const byte** end, int repeat, 50 static byte* ReadFile(const char* name, const byte** end, int repeat,
52 bool convert_to_utf16) { 51 bool convert_to_utf16) {
53 FILE* file = fopen(name, "rb"); 52 FILE* file = fopen(name, "rb");
54 if (file == NULL) return NULL; 53 if (file == NULL) return NULL;
55 54
56 fseek(file, 0, SEEK_END); 55 fseek(file, 0, SEEK_END);
57 int file_size = ftell(file); 56 int file_size = ftell(file);
58 rewind(file); 57 rewind(file);
59 58
60 int size = file_size * repeat; 59 int size = file_size * repeat;
61 60
62 byte* chars = new byte[size]; 61 byte* chars = new byte[size];
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 LATIN1, 95 LATIN1,
97 UTF8, 96 UTF8,
98 UTF16, 97 UTF16,
99 UTF8TO16 // Read as UTF8, convert to UTF16 before giving it to the lexers. 98 UTF8TO16 // Read as UTF8, convert to UTF16 before giving it to the lexers.
100 }; 99 };
101 100
102 101
103 struct LexerShellSettings { 102 struct LexerShellSettings {
104 Encoding encoding; 103 Encoding encoding;
105 bool print_tokens; 104 bool print_tokens;
106 bool run_baseline;
107 bool run_experimental;
108 bool check_tokens;
109 bool dump_tokens;
110 bool break_after_illegal; 105 bool break_after_illegal;
111 bool eos_test; 106 bool eos_test;
112 int repeat; 107 int repeat;
113 bool harmony_numeric_literals; 108 bool harmony_numeric_literals;
114 bool harmony_modules; 109 bool harmony_modules;
115 bool harmony_scoping; 110 bool harmony_scoping;
116 LexerShellSettings() 111 LexerShellSettings()
117 : encoding(LATIN1), 112 : encoding(LATIN1),
118 print_tokens(false), 113 print_tokens(false),
119 run_baseline(true),
120 run_experimental(true),
121 check_tokens(true),
122 dump_tokens(false),
123 break_after_illegal(false), 114 break_after_illegal(false),
124 eos_test(false), 115 eos_test(false),
125 repeat(1), 116 repeat(1),
126 harmony_numeric_literals(false), 117 harmony_numeric_literals(false),
127 harmony_modules(false), 118 harmony_modules(false),
128 harmony_scoping(false) {} 119 harmony_scoping(false) {}
129 }; 120 };
130 121
131 class BaselineScanner {
132 public:
133 BaselineScanner(const byte* source,
134 const byte* source_end,
135 Isolate* isolate,
136 ElapsedTimer* timer,
137 const LexerShellSettings& settings)
138 : source_(source), stream_(NULL) {
139 scanner_ = new Scanner(isolate->unicode_cache());
140 scanner_->SetHarmonyNumericLiterals(settings.harmony_numeric_literals);
141 scanner_->SetHarmonyModules(settings.harmony_modules);
142 scanner_->SetHarmonyScoping(settings.harmony_scoping);
143 switch (settings.encoding) {
144 case UTF8:
145 case UTF8TO16:
146 stream_ = new Utf8ToUtf16CharacterStream(source_, source_end - source_);
147 break;
148 case UTF16: {
149 Handle<String> result = isolate->factory()->NewStringFromTwoByte(
150 Vector<const uint16_t>(
151 reinterpret_cast<const uint16_t*>(source_),
152 (source_end - source_) / 2));
153 stream_ =
154 new GenericStringUtf16CharacterStream(result, 0, result->length());
155 break;
156 }
157 case LATIN1: {
158 Handle<String> result = isolate->factory()->NewStringFromOneByte(
159 Vector<const uint8_t>(source_, source_end - source_));
160 stream_ =
161 new GenericStringUtf16CharacterStream(result, 0, result->length());
162 break;
163 }
164 }
165 timer->Start();
166 scanner_->Initialize(stream_);
167 }
168
169 ~BaselineScanner() {
170 delete scanner_;
171 delete stream_;
172 delete unicode_cache_;
173 }
174
175 Scanner* scanner_;
176
177 private:
178 UnicodeCache* unicode_cache_;
179 const byte* source_;
180 Utf16CharacterStream* stream_;
181 };
182
183 122
184 struct TokenWithLocation { 123 struct TokenWithLocation {
185 Token::Value value; 124 Token::Value value;
186 size_t beg; 125 size_t beg;
187 size_t end; 126 size_t end;
188 std::vector<int> literal; 127 std::vector<int> literal;
189 bool is_ascii; 128 bool is_ascii;
190 // The location of the latest octal position when the token was seen. 129 // The location of the latest octal position when the token was seen.
191 int octal_beg; 130 int octal_beg;
192 int octal_end; 131 int octal_end;
(...skipping 19 matching lines...) Expand all
212 for (size_t i = 0; i < literal.size(); i++) { 151 for (size_t i = 0; i < literal.size(); i++) {
213 printf(is_ascii ? " %02x" : " %04x", literal[i]); 152 printf(is_ascii ? " %02x" : " %04x", literal[i]);
214 } 153 }
215 printf(" (is ascii: %d)", is_ascii); 154 printf(" (is ascii: %d)", is_ascii);
216 } 155 }
217 printf(" (last octal start: %d)\n", octal_beg); 156 printf(" (last octal start: %d)\n", octal_beg);
218 } 157 }
219 }; 158 };
220 159
221 160
222 bool HasLiteral(Token::Value token) { 161 static bool HasLiteral(Token::Value token) {
223 return token == Token::IDENTIFIER || 162 return token == Token::IDENTIFIER ||
224 token == Token::STRING || 163 token == Token::STRING ||
225 token == Token::NUMBER; 164 token == Token::NUMBER;
226 } 165 }
227 166
228 167
229 template<typename Char> 168 template<typename Char>
230 std::vector<int> ToStdVector(const Vector<Char>& literal) { 169 static std::vector<int> ToStdVector(const Vector<Char>& literal) {
231 std::vector<int> result; 170 std::vector<int> result;
232 for (int i = 0; i < literal.length(); i++) { 171 for (int i = 0; i < literal.length(); i++) {
233 result.push_back(literal[i]); 172 result.push_back(literal[i]);
234 } 173 }
235 return result; 174 return result;
236 } 175 }
237 176
238 177
239 template<typename Scanner> 178 template<typename Scanner>
240 TokenWithLocation GetTokenWithLocation(Scanner *scanner, Token::Value token) { 179 static TokenWithLocation GetTokenWithLocation(
180 Scanner *scanner, Token::Value token) {
241 int beg = scanner->location().beg_pos; 181 int beg = scanner->location().beg_pos;
242 int end = scanner->location().end_pos; 182 int end = scanner->location().end_pos;
243 TokenWithLocation result(token, beg, end, scanner->octal_position().beg_pos); 183 TokenWithLocation result(token, beg, end, scanner->octal_position().beg_pos);
244 if (HasLiteral(token)) { 184 if (HasLiteral(token)) {
245 result.is_ascii = scanner->is_literal_ascii(); 185 result.is_ascii = scanner->is_literal_ascii();
246 if (scanner->is_literal_ascii()) { 186 if (scanner->is_literal_ascii()) {
247 result.literal = ToStdVector(scanner->literal_ascii_string()); 187 result.literal = ToStdVector(scanner->literal_ascii_string());
248 } else { 188 } else {
249 result.literal = ToStdVector(scanner->literal_utf16_string()); 189 result.literal = ToStdVector(scanner->literal_utf16_string());
250 } 190 }
251 } 191 }
252 return result; 192 return result;
253 } 193 }
254 194
255 195
256 TimeDelta RunBaselineScanner(const byte* source, 196 static TimeDelta RunLexer(const byte* source,
257 const byte* source_end, 197 const byte* source_end,
258 Isolate* isolate, 198 Isolate* isolate,
259 std::vector<TokenWithLocation>* tokens, 199 std::vector<TokenWithLocation>* tokens,
260 const LexerShellSettings& settings) { 200 const LexerShellSettings& settings) {
201 SmartPointer<Utf16CharacterStream> stream;
202 switch (settings.encoding) {
203 case UTF8:
204 case UTF8TO16:
205 stream.Reset(new Utf8ToUtf16CharacterStream(source, source_end - source));
206 break;
207 case UTF16: {
208 Handle<String> result = isolate->factory()->NewStringFromTwoByte(
209 Vector<const uint16_t>(
210 reinterpret_cast<const uint16_t*>(source),
211 (source_end - source) / 2));
212 stream.Reset(
213 new GenericStringUtf16CharacterStream(result, 0, result->length()));
214 break;
215 }
216 case LATIN1: {
217 Handle<String> result = isolate->factory()->NewStringFromOneByte(
218 Vector<const uint8_t>(source, source_end - source));
219 stream.Reset(
220 new GenericStringUtf16CharacterStream(result, 0, result->length()));
221 break;
222 }
223 }
224 Scanner scanner(isolate->unicode_cache());
225 scanner.SetHarmonyNumericLiterals(settings.harmony_numeric_literals);
226 scanner.SetHarmonyModules(settings.harmony_modules);
227 scanner.SetHarmonyScoping(settings.harmony_scoping);
261 ElapsedTimer timer; 228 ElapsedTimer timer;
262 BaselineScanner scanner(source, 229 timer.Start();
263 source_end, 230 scanner.Initialize(stream.get());
264 isolate,
265 &timer,
266 settings);
267 Token::Value token; 231 Token::Value token;
268 do { 232 do {
269 token = scanner.scanner_->Next(); 233 token = scanner.Next();
270 if (settings.dump_tokens) { 234 if (settings.print_tokens) {
271 tokens->push_back(GetTokenWithLocation(scanner.scanner_, token)); 235 tokens->push_back(GetTokenWithLocation(&scanner, token));
272 } else if (HasLiteral(token)) { 236 } else if (HasLiteral(token)) {
273 if (scanner.scanner_->is_literal_ascii()) { 237 if (scanner.is_literal_ascii()) {
274 scanner.scanner_->literal_ascii_string(); 238 scanner.literal_ascii_string();
275 } else { 239 } else {
276 scanner.scanner_->literal_utf16_string(); 240 scanner.literal_utf16_string();
277 } 241 }
278 } 242 }
279 } while (token != Token::EOS); 243 } while (token != Token::EOS);
280 return timer.Elapsed(); 244 return timer.Elapsed();
281 } 245 }
282 246
283 247
284 void PrintTokens(const char* name, 248 static TimeDelta ProcessFile(
285 const std::vector<TokenWithLocation>& tokens) {
286 printf("No of tokens: %d\n",
287 static_cast<int>(tokens.size()));
288 printf("%s:\n", name);
289 for (size_t i = 0; i < tokens.size(); ++i) {
290 tokens[i].Print("=>");
291 }
292 }
293
294
295 std::pair<TimeDelta, TimeDelta> ProcessFile(
296 const char* fname, 249 const char* fname,
297 Isolate* isolate, 250 Isolate* isolate,
298 const LexerShellSettings& settings, 251 const LexerShellSettings& settings,
299 int truncate_by, 252 int truncate_by,
300 bool* can_truncate) { 253 bool* can_truncate) {
301 const bool print_tokens = settings.print_tokens; 254 if (settings.print_tokens) {
302 const bool run_baseline = settings.run_baseline;
303 const bool run_experimental = settings.run_experimental;
304 if (print_tokens) {
305 printf("Processing file %s, truncating by %d bytes\n", fname, truncate_by); 255 printf("Processing file %s, truncating by %d bytes\n", fname, truncate_by);
306 } 256 }
307 HandleScope handle_scope(isolate); 257 HandleScope handle_scope(isolate);
308 std::vector<TokenWithLocation> baseline_tokens, experimental_tokens; 258 std::vector<TokenWithLocation> tokens;
309 TimeDelta baseline_time, experimental_time; 259 TimeDelta time;
310 if (settings.run_baseline) { 260 {
311 const byte* buffer_end = 0; 261 const byte* buffer_end = 0;
312 const byte* buffer = ReadFile(fname, &buffer_end, settings.repeat, false); 262 const byte* buffer = ReadFile(fname, &buffer_end, settings.repeat, false);
313 if (truncate_by > buffer_end - buffer) { 263 if (truncate_by > buffer_end - buffer) {
314 *can_truncate = false; 264 *can_truncate = false;
315 } else { 265 } else {
316 buffer_end -= truncate_by; 266 buffer_end -= truncate_by;
317 baseline_time = RunBaselineScanner( 267 time = RunLexer(buffer, buffer_end, isolate, &tokens, settings);
318 buffer, buffer_end, isolate, &baseline_tokens, settings);
319 } 268 }
320 delete[] buffer; 269 delete[] buffer;
321 } 270 }
322 if (print_tokens && !run_experimental) { 271 if (settings.print_tokens) {
323 PrintTokens("Baseline", baseline_tokens); 272 printf("No of tokens:\t%d\n", static_cast<int>(tokens.size()));
324 } 273 for (size_t i = 0; i < tokens.size(); ++i) {
325 if (print_tokens && !run_baseline) { 274 tokens[i].Print("=>");
326 PrintTokens("Experimental", experimental_tokens); 275 if (tokens[i].value == Token::ILLEGAL) {
327 }
328 if ((print_tokens || settings.check_tokens) &&
329 run_baseline && run_experimental) {
330 if (print_tokens) {
331 printf("No of tokens in Baseline: %d\n",
332 static_cast<int>(baseline_tokens.size()));
333 printf("No of tokens in Experimental: %d\n",
334 static_cast<int>(experimental_tokens.size()));
335 printf("Baseline and Experimental:\n");
336 }
337 for (size_t i = 0; i < experimental_tokens.size(); ++i) {
338 if (print_tokens) experimental_tokens[i].Print("=>");
339 if (baseline_tokens[i].value == Token::ILLEGAL) {
340 if (experimental_tokens[i].value != Token::ILLEGAL ||
341 experimental_tokens[i].beg != baseline_tokens[i].beg) {
342 printf("MISMATCH:\n");
343 baseline_tokens[i].Print("Expected: ");
344 experimental_tokens[i].Print("Actual: ");
345 exit(1);
346 }
347 if (settings.break_after_illegal) 276 if (settings.break_after_illegal)
348 break; 277 break;
349 continue;
350 }
351 if (experimental_tokens[i] != baseline_tokens[i]) {
352 printf("MISMATCH:\n");
353 baseline_tokens[i].Print("Expected: ");
354 experimental_tokens[i].Print("Actual: ");
355 exit(1);
356 } 278 }
357 } 279 }
358 } 280 }
359 return std::make_pair(baseline_time, experimental_time); 281 return time;
360 } 282 }
361 283
362 284
363 int main(int argc, char* argv[]) { 285 int main(int argc, char* argv[]) {
364 return 0;
365 v8::V8::InitializeICU(); 286 v8::V8::InitializeICU();
366 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); 287 v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
367 std::vector<std::string> fnames; 288 std::vector<std::string> fnames;
368 std::string benchmark;
369 LexerShellSettings settings; 289 LexerShellSettings settings;
370 for (int i = 0; i < argc; ++i) { 290 for (int i = 0; i < argc; ++i) {
371 if (strcmp(argv[i], "--latin1") == 0) { 291 if (strcmp(argv[i], "--latin1") == 0) {
372 settings.encoding = LATIN1; 292 settings.encoding = LATIN1;
373 } else if (strcmp(argv[i], "--utf8") == 0) { 293 } else if (strcmp(argv[i], "--utf8") == 0) {
374 settings.encoding = UTF8; 294 settings.encoding = UTF8;
375 } else if (strcmp(argv[i], "--utf16") == 0) { 295 } else if (strcmp(argv[i], "--utf16") == 0) {
376 settings.encoding = UTF16; 296 settings.encoding = UTF16;
377 } else if (strcmp(argv[i], "--utf8to16") == 0) { 297 } else if (strcmp(argv[i], "--utf8to16") == 0) {
378 settings.encoding = UTF8TO16; 298 settings.encoding = UTF8TO16;
379 } else if (strcmp(argv[i], "--print-tokens") == 0) { 299 } else if (strcmp(argv[i], "--print-tokens") == 0) {
380 settings.print_tokens = true; 300 settings.print_tokens = true;
381 } else if (strcmp(argv[i], "--no-baseline") == 0) { 301 } else if (strcmp(argv[i], "--no-baseline") == 0) {
302 // Ignore.
382 } else if (strcmp(argv[i], "--no-experimental") == 0) { 303 } else if (strcmp(argv[i], "--no-experimental") == 0) {
304 // Ignore.
383 } else if (strcmp(argv[i], "--no-check") == 0) { 305 } else if (strcmp(argv[i], "--no-check") == 0) {
384 settings.check_tokens = false; 306 // Ignore.
385 } else if (strcmp(argv[i], "--break-after-illegal") == 0) { 307 } else if (strcmp(argv[i], "--break-after-illegal") == 0) {
386 settings.break_after_illegal = true; 308 settings.break_after_illegal = true;
387 } else if (strcmp(argv[i], "--use-harmony") == 0) { 309 } else if (strcmp(argv[i], "--use-harmony") == 0) {
388 settings.harmony_numeric_literals = true; 310 settings.harmony_numeric_literals = true;
389 settings.harmony_modules = true; 311 settings.harmony_modules = true;
390 settings.harmony_scoping = true; 312 settings.harmony_scoping = true;
391 } else if (strncmp(argv[i], "--benchmark=", 12) == 0) { 313 } else if (strncmp(argv[i], "--benchmark=", 12) == 0) {
392 benchmark = std::string(argv[i]).substr(12); 314 // Ignore.
393 } else if (strncmp(argv[i], "--repeat=", 9) == 0) { 315 } else if (strncmp(argv[i], "--repeat=", 9) == 0) {
394 std::string repeat_str = std::string(argv[i]).substr(9); 316 std::string repeat_str = std::string(argv[i]).substr(9);
395 settings.repeat = atoi(repeat_str.c_str()); 317 settings.repeat = atoi(repeat_str.c_str());
396 } else if (strcmp(argv[i], "--eos-test") == 0) { 318 } else if (strcmp(argv[i], "--eos-test") == 0) {
397 settings.eos_test = true; 319 settings.eos_test = true;
398 } else if (i > 0 && argv[i][0] != '-') { 320 } else if (i > 0 && argv[i][0] != '-') {
399 fnames.push_back(std::string(argv[i])); 321 fnames.push_back(std::string(argv[i]));
400 } 322 }
401 } 323 }
402 settings.check_tokens =
403 settings.check_tokens &&
404 settings.run_baseline &&
405 settings.run_experimental;
406 settings.dump_tokens = settings.check_tokens || settings.print_tokens;
407 v8::Isolate* isolate = v8::Isolate::GetCurrent();
408 { 324 {
325 v8::Isolate* isolate = v8::Isolate::GetCurrent();
409 v8::HandleScope handle_scope(isolate); 326 v8::HandleScope handle_scope(isolate);
410 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); 327 v8::Local<v8::Context> context = v8::Context::New(isolate);
411 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global); 328 CHECK(!context.IsEmpty());
412 ASSERT(!context.IsEmpty()); 329 v8::Context::Scope scope(context);
413 { 330 Isolate* internal_isolate = Isolate::Current();
414 v8::Context::Scope scope(context); 331 double total_time = 0;
415 Isolate* internal_isolate = Isolate::Current(); 332 for (size_t i = 0; i < fnames.size(); i++) {
416 double baseline_total = 0, experimental_total = 0; 333 std::pair<TimeDelta, TimeDelta> times;
417 for (size_t i = 0; i < fnames.size(); i++) { 334 bool can_truncate = settings.eos_test;
418 std::pair<TimeDelta, TimeDelta> times; 335 int truncate_by = 0;
419 bool can_truncate = settings.eos_test; 336 do {
420 int truncate_by = 0; 337 TimeDelta t = ProcessFile(fnames[i].c_str(),
421 do { 338 internal_isolate,
422 times = ProcessFile(fnames[i].c_str(), 339 settings,
423 internal_isolate, 340 truncate_by,
424 settings, 341 &can_truncate);
425 truncate_by, 342 total_time += t.InMillisecondsF();
426 &can_truncate); 343 ++truncate_by;
427 baseline_total += times.first.InMillisecondsF(); 344 } while (can_truncate);
428 experimental_total += times.second.InMillisecondsF();
429 ++truncate_by;
430 } while (can_truncate);
431 }
432 if (settings.run_baseline) {
433 printf("Baseline%s(RunTime): %.f ms\n", benchmark.c_str(),
434 baseline_total);
435 }
436 if (settings.run_experimental) {
437 if (benchmark.empty()) benchmark = "Experimental";
438 printf("%s(RunTime): %.f ms\n", benchmark.c_str(),
439 experimental_total);
440 }
441 } 345 }
346 printf("RunTime: %.f ms\n", total_time);
442 } 347 }
443 v8::V8::Dispose(); 348 v8::V8::Dispose();
444 return 0; 349 return 0;
445 } 350 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698