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

Side by Side Diff: preparser/preparser-process.cc

Issue 5862002: Version 3.0.2. (Closed)
Patch Set: Created 10 years 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
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 *ok = false; 120 *ok = false;
121 return 0; 121 return 0;
122 } 122 }
123 n = (n << 8) + static_cast<uint32_t>(c); 123 n = (n << 8) + static_cast<uint32_t>(c);
124 } 124 }
125 return n; 125 return n;
126 } 126 }
127 127
128 128
129 bool ReadBuffer(FILE* source, void* buffer, size_t length) { 129 bool ReadBuffer(FILE* source, void* buffer, size_t length) {
130 size_t actually_read = fread(buffer, 1, length, source); 130 size_t actually_read = fread(buffer, 1, length, stdin);
131 return (actually_read == length); 131 return (actually_read == length);
132 } 132 }
133 133
134 134
135 bool WriteBuffer(FILE* dest, const void* buffer, size_t length) { 135 bool WriteBuffer(FILE* dest, const void* buffer, size_t length) {
136 size_t actually_written = fwrite(buffer, 1, length, dest); 136 size_t actually_written = fwrite(buffer, 1, length, dest);
137 return (actually_written == length); 137 return (actually_written == length);
138 } 138 }
139 139
140 140
141 template <typename T> 141 template <typename T>
142 class ScopedPointer { 142 class ScopedPointer {
143 public: 143 public:
144 explicit ScopedPointer(T* pointer) : pointer_(pointer) {} 144 explicit ScopedPointer(T* pointer) : pointer_(pointer) {}
145 ~ScopedPointer() { delete[] pointer_; } 145 ~ScopedPointer() { delete[] pointer_; }
146 T& operator[](int index) { return pointer_[index]; } 146 T& operator[](int index) { return pointer_[index]; }
147 T* operator*() { return pointer_ ;} 147 T* operator*() { return pointer_ ;}
148 private: 148 private:
149 T* pointer_; 149 T* pointer_;
150 }; 150 };
151 151
152 152
153 // Preparse input and output result on stdout. 153 // Preparse stdin and output result on stdout.
154 int PreParseIO(FILE* input) { 154 int PreParseIO() {
155 fprintf(stderr, "LOG: Enter parsing loop\n"); 155 fprintf(stderr, "LOG: Enter parsing loop\n");
156 bool ok = true; 156 bool ok = true;
157 uint32_t length = ReadUInt32(input, &ok); 157 uint32_t length = ReadUInt32(stdin, &ok);
158 fprintf(stderr, "LOG: Input length: %d\n", length);
159 if (!ok) return kErrorReading; 158 if (!ok) return kErrorReading;
160 ScopedPointer<uint8_t> buffer(new uint8_t[length]); 159 ScopedPointer<uint8_t> buffer(new uint8_t[length]);
161 160
162 if (!ReadBuffer(input, *buffer, length)) { 161 if (!ReadBuffer(stdin, *buffer, length)) {
163 return kErrorReading; 162 return kErrorReading;
164 } 163 }
165 UTF8InputStream input_buffer(*buffer, static_cast<size_t>(length)); 164 UTF8InputStream input_buffer(*buffer, static_cast<size_t>(length));
166 165
167 v8::PreParserData data = 166 v8::PreParserData data =
168 v8::Preparse(&input_buffer, 64 * 1024 * sizeof(void*)); // NOLINT 167 v8::Preparse(&input_buffer, 64 * sizeof(void*)); // NOLINT
169 if (data.stack_overflow()) { 168 if (data.stack_overflow()) {
170 fprintf(stderr, "LOG: Stack overflow\n");
171 fflush(stderr);
172 // Report stack overflow error/no-preparser-data. 169 // Report stack overflow error/no-preparser-data.
173 WriteUInt32(stdout, 0, &ok); 170 WriteUInt32(stdout, 0, &ok);
174 if (!ok) return kErrorWriting; 171 if (!ok) return kErrorWriting;
175 return 0; 172 return 0;
176 } 173 }
177 174
178 uint32_t size = data.size(); 175 uint32_t size = data.size();
179 fprintf(stderr, "LOG: Success, data size: %u\n", size);
180 fflush(stderr);
181 WriteUInt32(stdout, size, &ok); 176 WriteUInt32(stdout, size, &ok);
182 if (!ok) return kErrorWriting; 177 if (!ok) return kErrorWriting;
183 if (!WriteBuffer(stdout, data.data(), size)) { 178 if (!WriteBuffer(stdout, data.data(), size)) {
184 return kErrorWriting; 179 return kErrorWriting;
185 } 180 }
186 return 0; 181 return 0;
187 } 182 }
188 183
189 } } // namespace v8::internal 184 } } // namespace v8::internal
190 185
191 186
192 int main(int argc, char* argv[]) { 187 int main(int argc, char* argv[]) {
193 FILE* input = stdin;
194 if (argc > 1) {
195 char* arg = argv[1];
196 input = fopen(arg, "rb");
197 if (input == NULL) return EXIT_FAILURE;
198 }
199 int status = 0; 188 int status = 0;
200 do { 189 do {
201 status = v8::internal::PreParseIO(input); 190 status = v8::internal::PreParseIO();
202 } while (status == 0); 191 } while (status == 0);
203 fprintf(stderr, "EXIT: Failure %d\n", status); 192 fprintf(stderr, "EXIT: Failure %d\n", status);
204 fflush(stderr);
205 return EXIT_FAILURE; 193 return EXIT_FAILURE;
206 } 194 }
OLDNEW
« ChangeLog ('K') | « include/v8-profiler.h ('k') | samples/shell.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698