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

Side by Side Diff: src/utils.h

Issue 18842: Experimental: periodic merge of the bleeding_edge branch to the... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/toiger/
Patch Set: Created 11 years, 11 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 | « src/usage-analyzer.cc ('k') | src/utils.cc » ('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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 217
218 // Our version of fflush. 218 // Our version of fflush.
219 void Flush(); 219 void Flush();
220 220
221 221
222 // Read a line of characters after printing the prompt to stdout. The resulting 222 // Read a line of characters after printing the prompt to stdout. The resulting
223 // char* needs to be disposed off with DeleteArray by the caller. 223 // char* needs to be disposed off with DeleteArray by the caller.
224 char* ReadLine(const char* prompt); 224 char* ReadLine(const char* prompt);
225 225
226 226
227 // Read and return the raw chars in a file. the size of the buffer is returned 227 // Read and return the raw bytes in a file. the size of the buffer is returned
228 // in size. 228 // in size.
229 // The returned buffer is not 0-terminated. It must be freed by the caller. 229 // The returned buffer must be freed by the caller.
230 char* ReadChars(const char* filename, int* size, bool verbose = true); 230 byte* ReadBytes(const char* filename, int* size, bool verbose = true);
231 231
232 232
233 // Write size chars from str to the file given by filename. 233 // Write size chars from str to the file given by filename.
234 // The file is overwritten. Returns the number of chars written. 234 // The file is overwritten. Returns the number of chars written.
235 int WriteChars(const char* filename, 235 int WriteChars(const char* filename,
236 const char* str, 236 const char* str,
237 int size, 237 int size,
238 bool verbose = true); 238 bool verbose = true);
239 239
240 240
241 // Write size bytes to the file given by filename.
242 // The file is overwritten. Returns the number of bytes written.
243 int WriteBytes(const char* filename,
244 const byte* bytes,
245 int size,
246 bool verbose = true);
247
248
241 // Write the C code 249 // Write the C code
242 // const char* <varname> = "<str>"; 250 // const char* <varname> = "<str>";
243 // const int <varname>_len = <len>; 251 // const int <varname>_len = <len>;
244 // to the file given by filename. Only the first len chars are written. 252 // to the file given by filename. Only the first len chars are written.
245 int WriteAsCFile(const char* filename, const char* varname, 253 int WriteAsCFile(const char* filename, const char* varname,
246 const char* str, int size, bool verbose = true); 254 const char* str, int size, bool verbose = true);
247 255
248 256
249 // ---------------------------------------------------------------------------- 257 // ----------------------------------------------------------------------------
250 // Miscellaneous 258 // Miscellaneous
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 template <typename T> 422 template <typename T>
415 inline Vector< Handle<Object> > HandleVector(v8::internal::Handle<T>* elms, 423 inline Vector< Handle<Object> > HandleVector(v8::internal::Handle<T>* elms,
416 int length) { 424 int length) {
417 return Vector< Handle<Object> >( 425 return Vector< Handle<Object> >(
418 reinterpret_cast<v8::internal::Handle<Object>*>(elms), length); 426 reinterpret_cast<v8::internal::Handle<Object>*>(elms), length);
419 } 427 }
420 428
421 429
422 // Simple support to read a file into a 0-terminated C-string. 430 // Simple support to read a file into a 0-terminated C-string.
423 // The returned buffer must be freed by the caller. 431 // The returned buffer must be freed by the caller.
424 // On return, *exits tells whether the file exisited. 432 // On return, *exits tells whether the file existed.
425 Vector<const char> ReadFile(const char* filename, 433 Vector<const char> ReadFile(const char* filename,
426 bool* exists, 434 bool* exists,
427 bool verbose = true); 435 bool verbose = true);
428 436
429 437
430 // Simple wrapper that allows an ExternalString to refer to a 438 // Simple wrapper that allows an ExternalString to refer to a
431 // Vector<const char>. Doesn't assume ownership of the data. 439 // Vector<const char>. Doesn't assume ownership of the data.
432 class AsciiStringAdapter: public v8::String::ExternalAsciiStringResource { 440 class AsciiStringAdapter: public v8::String::ExternalAsciiStringResource {
433 public: 441 public:
434 explicit AsciiStringAdapter(Vector<const char> data) : data_(data) {} 442 explicit AsciiStringAdapter(Vector<const char> data) : data_(data) {}
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 src += kStepSize; 528 src += kStepSize;
521 } 529 }
522 } 530 }
523 #endif 531 #endif
524 while (dest < limit) { 532 while (dest < limit) {
525 *dest++ = static_cast<sinkchar>(*src++); 533 *dest++ = static_cast<sinkchar>(*src++);
526 } 534 }
527 } 535 }
528 536
529 537
530 static inline int Load16(const byte* ptr) {
531 #ifdef CAN_READ_UNALIGNED
532 return *reinterpret_cast<const uint16_t*>(ptr);
533 #else
534 uint32_t word;
535 word = ptr[1];
536 word |= ptr[0] << 8;
537 return word;
538 #endif
539 }
540
541
542 static inline int Load32(const byte* ptr) {
543 #ifdef CAN_READ_UNALIGNED
544 return *reinterpret_cast<const uint32_t*>(ptr);
545 #else
546 uint32_t word;
547 word = ptr[3];
548 word |= ptr[2] << 8;
549 word |= ptr[1] << 16;
550 word |= ptr[0] << 24;
551 return word;
552 #endif
553 }
554
555
556 static inline void Store16(byte* ptr, uint16_t value) {
557 #ifdef CAN_READ_UNALIGNED
558 *reinterpret_cast<uint16_t*>(ptr) = value;
559 #else
560 // Cast to avoid warning C4244 when compiling with Microsoft Visual C++.
561 ptr[1] = static_cast<byte>(value);
562 ptr[0] = value >> 8;
563 #endif
564 }
565
566
567 static inline void Store32(byte* ptr, uint32_t value) {
568 #ifdef CAN_READ_UNALIGNED
569 *reinterpret_cast<uint32_t*>(ptr) = value;
570 #else
571 ptr[3] = value;
572 ptr[2] = value >> 8;
573 ptr[1] = value >> 16;
574 ptr[0] = value >> 24;
575 #endif
576 }
577
578
579 } } // namespace v8::internal 538 } } // namespace v8::internal
580 539
581 #endif // V8_UTILS_H_ 540 #endif // V8_UTILS_H_
OLDNEW
« no previous file with comments | « src/usage-analyzer.cc ('k') | src/utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698