| OLD | NEW |
| 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 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 UnicodeCache* unicode_cache_; | 162 UnicodeCache* unicode_cache_; |
| 163 const byte* source_; | 163 const byte* source_; |
| 164 BufferedUtf16CharacterStream* stream_; | 164 BufferedUtf16CharacterStream* stream_; |
| 165 }; | 165 }; |
| 166 | 166 |
| 167 | 167 |
| 168 struct TokenWithLocation { | 168 struct TokenWithLocation { |
| 169 Token::Value value; | 169 Token::Value value; |
| 170 size_t beg; | 170 size_t beg; |
| 171 size_t end; | 171 size_t end; |
| 172 std::string ascii_literal; |
| 173 std::wstring utf16_literal; |
| 172 TokenWithLocation() : value(Token::ILLEGAL), beg(0), end(0) { } | 174 TokenWithLocation() : value(Token::ILLEGAL), beg(0), end(0) { } |
| 173 TokenWithLocation(Token::Value value, size_t beg, size_t end) : | 175 TokenWithLocation(Token::Value value, size_t beg, size_t end) : |
| 174 value(value), beg(beg), end(end) { } | 176 value(value), beg(beg), end(end) { } |
| 175 bool operator==(const TokenWithLocation& other) { | 177 bool operator==(const TokenWithLocation& other) { |
| 176 return value == other.value && beg == other.beg && end == other.end; | 178 return value == other.value && beg == other.beg && end == other.end && |
| 179 ascii_literal == other.ascii_literal && |
| 180 utf16_literal == other.utf16_literal; |
| 177 } | 181 } |
| 178 bool operator!=(const TokenWithLocation& other) { | 182 bool operator!=(const TokenWithLocation& other) { |
| 179 return !(*this == other); | 183 return !(*this == other); |
| 180 } | 184 } |
| 181 void Print(const char* prefix) const { | 185 void Print(const char* prefix) const { |
| 182 printf("%s %11s at (%d, %d)\n", | 186 printf("%s %11s at (%d, %d)", |
| 183 prefix, Token::Name(value), | 187 prefix, Token::Name(value), |
| 184 static_cast<int>(beg), static_cast<int>(end)); | 188 static_cast<int>(beg), static_cast<int>(end)); |
| 189 if (ascii_literal.size() > 0) { |
| 190 for (size_t i = 0; i < ascii_literal.size(); i++) { |
| 191 printf(" %02x", static_cast<int>(ascii_literal[i])); |
| 192 } |
| 193 } |
| 194 if (utf16_literal.size() > 0) { |
| 195 for (size_t i = 0; i < utf16_literal.size(); i++) { |
| 196 printf(" %04x", static_cast<int>(utf16_literal[i])); |
| 197 } |
| 198 } |
| 199 printf("\n"); |
| 185 } | 200 } |
| 186 }; | 201 }; |
| 187 | 202 |
| 188 | 203 |
| 204 bool HasLiteral(Token::Value token) { |
| 205 return token == Token::IDENTIFIER || |
| 206 token == Token::STRING || |
| 207 token == Token::NUMBER; |
| 208 } |
| 209 |
| 210 |
| 211 std::string ToStdString(const Vector<const char>& literal) { |
| 212 return std::string(literal.start(), literal.length()); |
| 213 } |
| 214 |
| 215 |
| 216 std::wstring ToStdWString(const Vector<const uint16_t>& literal) { |
| 217 return std::wstring(reinterpret_cast<const wchar_t*>(literal.start()), |
| 218 literal.length()); |
| 219 } |
| 220 |
| 221 |
| 222 template<typename Scanner> |
| 223 TokenWithLocation GetTokenWithLocation(Scanner *scanner, Token::Value token) { |
| 224 int beg = scanner->location().beg_pos; |
| 225 int end = scanner->location().end_pos; |
| 226 TokenWithLocation result(token, beg, end); |
| 227 if (HasLiteral(token)) { |
| 228 if (scanner->is_literal_ascii()) { |
| 229 result.ascii_literal = ToStdString(scanner->literal_ascii_string()); |
| 230 } else { |
| 231 result.utf16_literal = ToStdWString(scanner->literal_utf16_string()); |
| 232 } |
| 233 } |
| 234 return result; |
| 235 } |
| 236 |
| 237 |
| 189 TimeDelta RunBaselineScanner(const char* fname, | 238 TimeDelta RunBaselineScanner(const char* fname, |
| 190 Isolate* isolate, | 239 Isolate* isolate, |
| 191 Encoding encoding, | 240 Encoding encoding, |
| 192 bool dump_tokens, | 241 bool dump_tokens, |
| 193 std::vector<TokenWithLocation>* tokens, | 242 std::vector<TokenWithLocation>* tokens, |
| 194 int repeat, | 243 int repeat, |
| 195 HarmonySettings harmony_settings) { | 244 HarmonySettings harmony_settings) { |
| 196 ElapsedTimer timer; | 245 ElapsedTimer timer; |
| 197 BaselineScanner scanner( | 246 BaselineScanner scanner( |
| 198 fname, isolate, encoding, &timer, repeat, harmony_settings); | 247 fname, isolate, encoding, &timer, repeat, harmony_settings); |
| 199 Token::Value token; | 248 Token::Value token; |
| 200 int beg, end; | |
| 201 do { | 249 do { |
| 202 token = scanner.scanner_->Next(); | 250 token = scanner.scanner_->Next(); |
| 203 beg = scanner.scanner_->location().beg_pos; | |
| 204 end = scanner.scanner_->location().end_pos; | |
| 205 if (dump_tokens) { | 251 if (dump_tokens) { |
| 206 tokens->push_back(TokenWithLocation(token, beg, end)); | 252 tokens->push_back(GetTokenWithLocation(scanner.scanner_, token)); |
| 207 } | 253 } |
| 208 } while (token != Token::EOS); | 254 } while (token != Token::EOS); |
| 209 return timer.Elapsed(); | 255 return timer.Elapsed(); |
| 210 } | 256 } |
| 211 | 257 |
| 212 | 258 |
| 213 template<typename Char> | 259 template<typename Char> |
| 214 TimeDelta RunExperimentalScanner(Handle<String> source, | 260 TimeDelta RunExperimentalScanner(Handle<String> source, |
| 215 Isolate* isolate, | 261 Isolate* isolate, |
| 216 Encoding encoding, | 262 Encoding encoding, |
| 217 bool dump_tokens, | 263 bool dump_tokens, |
| 218 std::vector<TokenWithLocation>* tokens, | 264 std::vector<TokenWithLocation>* tokens, |
| 219 int repeat, | 265 int repeat, |
| 220 HarmonySettings harmony_settings) { | 266 HarmonySettings harmony_settings) { |
| 221 ElapsedTimer timer; | 267 ElapsedTimer timer; |
| 222 timer.Start(); | 268 timer.Start(); |
| 223 ExperimentalScanner<Char> scanner(source, isolate); | 269 ExperimentalScanner<Char> scanner(source, isolate); |
| 224 scanner.SetHarmonyNumericLiterals(harmony_settings.numeric_literals); | 270 scanner.SetHarmonyNumericLiterals(harmony_settings.numeric_literals); |
| 225 scanner.SetHarmonyModules(harmony_settings.modules); | 271 scanner.SetHarmonyModules(harmony_settings.modules); |
| 226 scanner.SetHarmonyScoping(harmony_settings.scoping); | 272 scanner.SetHarmonyScoping(harmony_settings.scoping); |
| 227 | 273 |
| 228 Token::Value token; | 274 Token::Value token; |
| 229 int beg, end; | |
| 230 do { | 275 do { |
| 231 token = scanner.Next(); | 276 token = scanner.Next(); |
| 232 beg = scanner.location().beg_pos; | |
| 233 end = scanner.location().end_pos; | |
| 234 if (dump_tokens) { | 277 if (dump_tokens) { |
| 235 tokens->push_back(TokenWithLocation(token, beg, end)); | 278 tokens->push_back(GetTokenWithLocation(&scanner, token)); |
| 236 } | 279 } |
| 237 } while (token != Token::EOS); | 280 } while (token != Token::EOS); |
| 238 return timer.Elapsed(); | 281 return timer.Elapsed(); |
| 239 } | 282 } |
| 240 | 283 |
| 241 | 284 |
| 242 void PrintTokens(const char* name, | 285 void PrintTokens(const char* name, |
| 243 const std::vector<TokenWithLocation>& tokens) { | 286 const std::vector<TokenWithLocation>& tokens) { |
| 244 printf("No of tokens: %d\n", | 287 printf("No of tokens: %d\n", |
| 245 static_cast<int>(tokens.size())); | 288 static_cast<int>(tokens.size())); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 if (run_experimental) { | 468 if (run_experimental) { |
| 426 if (benchmark.empty()) benchmark = "Experimental"; | 469 if (benchmark.empty()) benchmark = "Experimental"; |
| 427 printf("%s(RunTime): %.f ms\n", benchmark.c_str(), | 470 printf("%s(RunTime): %.f ms\n", benchmark.c_str(), |
| 428 experimental_total); | 471 experimental_total); |
| 429 } | 472 } |
| 430 } | 473 } |
| 431 } | 474 } |
| 432 v8::V8::Dispose(); | 475 v8::V8::Dispose(); |
| 433 return 0; | 476 return 0; |
| 434 } | 477 } |
| OLD | NEW |