| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/ast-value-factory.h" |
| 5 #include "src/base/logging.h" | 6 #include "src/base/logging.h" |
| 6 #include "src/compiler.h" | 7 #include "src/compiler.h" |
| 7 #include "src/globals.h" | 8 #include "src/globals.h" |
| 8 #include "src/hashmap.h" | 9 #include "src/hashmap.h" |
| 9 #include "src/preparse-data.h" | 10 #include "src/preparse-data.h" |
| 10 #include "src/preparse-data-format.h" | 11 #include "src/preparse-data-format.h" |
| 11 | 12 |
| 12 namespace v8 { | 13 namespace v8 { |
| 13 namespace internal { | 14 namespace internal { |
| 14 | 15 |
| 15 | 16 |
| 16 CompleteParserRecorder::CompleteParserRecorder() | 17 CompleteParserRecorder::CompleteParserRecorder() |
| 17 : function_store_(0) { | 18 : function_store_(0), next_function_calls_eval_(false) { |
| 18 preamble_[PreparseDataConstants::kMagicOffset] = | 19 preamble_[PreparseDataConstants::kMagicOffset] = |
| 19 PreparseDataConstants::kMagicNumber; | 20 PreparseDataConstants::kMagicNumber; |
| 20 preamble_[PreparseDataConstants::kVersionOffset] = | 21 preamble_[PreparseDataConstants::kVersionOffset] = |
| 21 PreparseDataConstants::kCurrentVersion; | 22 PreparseDataConstants::kCurrentVersion; |
| 22 preamble_[PreparseDataConstants::kHasErrorOffset] = false; | 23 preamble_[PreparseDataConstants::kHasErrorOffset] = false; |
| 23 preamble_[PreparseDataConstants::kFunctionsSizeOffset] = 0; | 24 preamble_[PreparseDataConstants::kFunctionsSizeOffset] = 0; |
| 24 preamble_[PreparseDataConstants::kSizeOffset] = 0; | 25 preamble_[PreparseDataConstants::kSizeOffset] = 0; |
| 25 DCHECK_EQ(5, PreparseDataConstants::kHeaderSize); | 26 DCHECK_EQ(5, PreparseDataConstants::kHeaderSize); |
| 26 #ifdef DEBUG | 27 #ifdef DEBUG |
| 27 prev_start_ = -1; | 28 prev_start_ = -1; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 52 | 53 |
| 53 | 54 |
| 54 void CompleteParserRecorder::WriteString(Vector<const char> str) { | 55 void CompleteParserRecorder::WriteString(Vector<const char> str) { |
| 55 function_store_.Add(str.length()); | 56 function_store_.Add(str.length()); |
| 56 for (int i = 0; i < str.length(); i++) { | 57 for (int i = 0; i < str.length(); i++) { |
| 57 function_store_.Add(str[i]); | 58 function_store_.Add(str[i]); |
| 58 } | 59 } |
| 59 } | 60 } |
| 60 | 61 |
| 61 | 62 |
| 63 void CompleteParserRecorder::WriteString(const AstRawString* str) { |
| 64 const bool is_one_byte = str->is_one_byte(); |
| 65 function_store_.Add(is_one_byte); |
| 66 int byte_length = str->length(); |
| 67 if (!is_one_byte) { |
| 68 byte_length *= 2; |
| 69 } |
| 70 function_store_.Add(byte_length); |
| 71 DCHECK(byte_length > 0); |
| 72 const int word_length = |
| 73 1 + (((byte_length * sizeof(unsigned char)) - 1) / sizeof(unsigned)); |
| 74 Vector<unsigned char> dest = |
| 75 Vector<unsigned char>::cast(function_store_.AddBlock(word_length, 0)); |
| 76 MemCopy(dest.start(), str->raw_data(), byte_length); |
| 77 } |
| 78 |
| 79 |
| 62 ScriptData* CompleteParserRecorder::GetScriptData() { | 80 ScriptData* CompleteParserRecorder::GetScriptData() { |
| 63 int function_size = function_store_.size(); | 81 int function_size = function_store_.size(); |
| 64 int total_size = PreparseDataConstants::kHeaderSize + function_size; | 82 int total_size = PreparseDataConstants::kHeaderSize + function_size; |
| 65 unsigned* data = NewArray<unsigned>(total_size); | 83 unsigned* data = NewArray<unsigned>(total_size); |
| 66 preamble_[PreparseDataConstants::kFunctionsSizeOffset] = function_size; | 84 preamble_[PreparseDataConstants::kFunctionsSizeOffset] = function_size; |
| 67 MemCopy(data, preamble_, sizeof(preamble_)); | 85 MemCopy(data, preamble_, sizeof(preamble_)); |
| 68 if (function_size > 0) { | 86 if (function_size > 0) { |
| 69 function_store_.WriteTo(Vector<unsigned>( | 87 function_store_.WriteTo(Vector<unsigned>( |
| 70 data + PreparseDataConstants::kHeaderSize, function_size)); | 88 data + PreparseDataConstants::kHeaderSize, function_size)); |
| 71 } | 89 } |
| 72 DCHECK(IsAligned(reinterpret_cast<intptr_t>(data), kPointerAlignment)); | 90 DCHECK(IsAligned(reinterpret_cast<intptr_t>(data), kPointerAlignment)); |
| 73 ScriptData* result = new ScriptData(reinterpret_cast<byte*>(data), | 91 ScriptData* result = new ScriptData(reinterpret_cast<byte*>(data), |
| 74 total_size * sizeof(unsigned)); | 92 total_size * sizeof(unsigned)); |
| 75 result->AcquireDataOwnership(); | 93 result->AcquireDataOwnership(); |
| 76 return result; | 94 return result; |
| 77 } | 95 } |
| 78 | 96 |
| 79 | 97 |
| 80 } } // namespace v8::internal. | 98 } } // namespace v8::internal. |
| OLD | NEW |