| 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 21 matching lines...) Expand all Loading... |
| 32 #include "objects.h" | 32 #include "objects.h" |
| 33 #include "objects-inl.h" | 33 #include "objects-inl.h" |
| 34 #include "spaces-inl.h" | 34 #include "spaces-inl.h" |
| 35 #include "isolate.h" | 35 #include "isolate.h" |
| 36 #include "lexer.h" | 36 #include "lexer.h" |
| 37 #include "even-more-experimental-scanner.h" | 37 #include "even-more-experimental-scanner.h" |
| 38 | 38 |
| 39 namespace v8 { | 39 namespace v8 { |
| 40 namespace internal { | 40 namespace internal { |
| 41 | 41 |
| 42 namespace { | |
| 43 | 42 |
| 44 // Will go away. | 43 const byte* ReadFile(const char* name, Isolate* isolate, |
| 45 const byte* ReadFile(const char* name, Isolate* isolate, int* size) { | 44 int* size, int repeat) { |
| 46 FILE* file = fopen(name, "rb"); | 45 FILE* file = fopen(name, "rb"); |
| 47 *size = 0; | 46 *size = 0; |
| 48 if (file == NULL) return NULL; | 47 if (file == NULL) return NULL; |
| 49 | 48 |
| 50 fseek(file, 0, SEEK_END); | 49 fseek(file, 0, SEEK_END); |
| 51 *size = ftell(file); | 50 int file_size = ftell(file); |
| 52 rewind(file); | 51 rewind(file); |
| 53 | 52 |
| 53 *size = file_size * repeat; |
| 54 |
| 54 byte* chars = new byte[*size + 1]; | 55 byte* chars = new byte[*size + 1]; |
| 55 chars[*size] = 0; | 56 for (int i = 0; i < file_size;) { |
| 56 for (int i = 0; i < *size;) { | 57 int read = static_cast<int>(fread(&chars[i], 1, file_size - i, file)); |
| 57 int read = static_cast<int>(fread(&chars[i], 1, *size - i, file)); | |
| 58 i += read; | 58 i += read; |
| 59 } | 59 } |
| 60 fclose(file); | 60 fclose(file); |
| 61 |
| 62 for (int i = file_size; i < *size; i++) { |
| 63 chars[i] = chars[i - file_size]; |
| 64 } |
| 65 chars[*size] = 0; |
| 66 |
| 61 return chars; | 67 return chars; |
| 62 } | 68 } |
| 63 | 69 |
| 64 } | |
| 65 | 70 |
| 66 ExperimentalScanner::ExperimentalScanner(const char* fname, | 71 ExperimentalScanner::ExperimentalScanner(const char* fname, |
| 67 bool read_all_at_once, | 72 bool read_all_at_once, |
| 68 Isolate* isolate) | 73 Isolate* isolate, |
| 74 int repeat) |
| 69 : current_(0), | 75 : current_(0), |
| 70 fetched_(0), | 76 fetched_(0), |
| 71 read_all_at_once_(read_all_at_once), | 77 read_all_at_once_(read_all_at_once), |
| 72 already_pushed_(false), | 78 already_pushed_(false), |
| 73 source_(0), | 79 source_(0), |
| 74 length_(0) { | 80 length_(0) { |
| 81 CHECK(repeat == 1 || read_all_at_once); |
| 75 file_ = fopen(fname, "rb"); | 82 file_ = fopen(fname, "rb"); |
| 76 // python generated version | 83 // python generated version |
| 77 scanner_ = new EvenMoreExperimentalScanner(this, isolate->unicode_cache()); | 84 scanner_ = new EvenMoreExperimentalScanner(this, isolate->unicode_cache()); |
| 78 // re2c version | 85 // re2c version |
| 79 // scanner_ = new PushScanner(this, isolate->unicode_cache()); | 86 // scanner_ = new PushScanner(this, isolate->unicode_cache()); |
| 80 if (read_all_at_once_) { | 87 if (read_all_at_once_) { |
| 81 source_ = ReadFile(fname, isolate, &length_); | 88 source_ = ReadFile(fname, isolate, &length_, repeat); |
| 82 token_.resize(1500); | 89 token_.resize(length_); |
| 83 } else { | 90 } else { |
| 84 token_.resize(BUFFER_SIZE); | 91 token_.resize(BUFFER_SIZE); |
| 85 } | 92 } |
| 86 } | 93 } |
| 87 | 94 |
| 88 | 95 |
| 89 ExperimentalScanner::~ExperimentalScanner() { | 96 ExperimentalScanner::~ExperimentalScanner() { |
| 90 fclose(file_); | 97 fclose(file_); |
| 91 delete[] source_; | 98 delete[] source_; |
| 92 } | 99 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 if (fetched_ >= token_.size()) { | 140 if (fetched_ >= token_.size()) { |
| 134 token_.resize(token_.size() * 2); | 141 token_.resize(token_.size() * 2); |
| 135 } | 142 } |
| 136 token_[fetched_].value = token; | 143 token_[fetched_].value = token; |
| 137 token_[fetched_].beg = beg; | 144 token_[fetched_].beg = beg; |
| 138 token_[fetched_].end = end; | 145 token_[fetched_].end = end; |
| 139 fetched_++; | 146 fetched_++; |
| 140 } | 147 } |
| 141 | 148 |
| 142 } } // namespace v8::internal | 149 } } // namespace v8::internal |
| OLD | NEW |