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/parsing/preparse-data.h" | 5 #include "src/parsing/preparse-data.h" |
6 #include "src/base/hashmap.h" | 6 #include "src/base/hashmap.h" |
7 #include "src/base/logging.h" | 7 #include "src/base/logging.h" |
8 #include "src/globals.h" | 8 #include "src/globals.h" |
9 #include "src/parsing/parser.h" | 9 #include "src/parsing/parser.h" |
10 #include "src/parsing/preparse-data-format.h" | 10 #include "src/parsing/preparse-data-format.h" |
11 | 11 |
12 namespace v8 { | 12 namespace v8 { |
13 namespace internal { | 13 namespace internal { |
14 | 14 |
15 void CompleteParserRecorder::LogFunction( | 15 void ParserLogger::LogFunction(int start, int end, int num_parameters, |
16 int start, int end, int num_parameters, int function_length, | 16 int function_length, |
17 bool has_duplicate_parameters, int literals, int properties, | 17 bool has_duplicate_parameters, int literals, |
18 LanguageMode language_mode, bool uses_super_property, bool calls_eval) { | 18 int properties, LanguageMode language_mode, |
| 19 bool uses_super_property, bool calls_eval) { |
19 function_store_.Add(start); | 20 function_store_.Add(start); |
20 function_store_.Add(end); | 21 function_store_.Add(end); |
21 function_store_.Add(num_parameters); | 22 function_store_.Add(num_parameters); |
22 function_store_.Add(function_length); | 23 function_store_.Add(function_length); |
23 function_store_.Add(literals); | 24 function_store_.Add(literals); |
24 function_store_.Add(properties); | 25 function_store_.Add(properties); |
25 function_store_.Add( | 26 function_store_.Add( |
26 FunctionEntry::EncodeFlags(language_mode, uses_super_property, calls_eval, | 27 FunctionEntry::EncodeFlags(language_mode, uses_super_property, calls_eval, |
27 has_duplicate_parameters)); | 28 has_duplicate_parameters)); |
28 } | 29 } |
29 | 30 |
30 CompleteParserRecorder::CompleteParserRecorder() { | 31 ParserLogger::ParserLogger() { |
31 preamble_[PreparseDataConstants::kMagicOffset] = | 32 preamble_[PreparseDataConstants::kMagicOffset] = |
32 PreparseDataConstants::kMagicNumber; | 33 PreparseDataConstants::kMagicNumber; |
33 preamble_[PreparseDataConstants::kVersionOffset] = | 34 preamble_[PreparseDataConstants::kVersionOffset] = |
34 PreparseDataConstants::kCurrentVersion; | 35 PreparseDataConstants::kCurrentVersion; |
35 preamble_[PreparseDataConstants::kHasErrorOffset] = false; | 36 preamble_[PreparseDataConstants::kHasErrorOffset] = false; |
36 preamble_[PreparseDataConstants::kFunctionsSizeOffset] = 0; | 37 preamble_[PreparseDataConstants::kFunctionsSizeOffset] = 0; |
37 preamble_[PreparseDataConstants::kSizeOffset] = 0; | 38 preamble_[PreparseDataConstants::kSizeOffset] = 0; |
38 DCHECK_EQ(5, PreparseDataConstants::kHeaderSize); | 39 DCHECK_EQ(5, PreparseDataConstants::kHeaderSize); |
39 #ifdef DEBUG | 40 #ifdef DEBUG |
40 prev_start_ = -1; | 41 prev_start_ = -1; |
41 #endif | 42 #endif |
42 } | 43 } |
43 | 44 |
44 | 45 void ParserLogger::LogMessage(int start_pos, int end_pos, |
45 void CompleteParserRecorder::LogMessage(int start_pos, int end_pos, | 46 MessageTemplate::Template message, |
46 MessageTemplate::Template message, | 47 const char* arg_opt, ParseErrorType error_type) { |
47 const char* arg_opt, | |
48 ParseErrorType error_type) { | |
49 if (HasError()) return; | 48 if (HasError()) return; |
50 preamble_[PreparseDataConstants::kHasErrorOffset] = true; | 49 preamble_[PreparseDataConstants::kHasErrorOffset] = true; |
51 function_store_.Reset(); | 50 function_store_.Reset(); |
52 STATIC_ASSERT(PreparseDataConstants::kMessageStartPos == 0); | 51 STATIC_ASSERT(PreparseDataConstants::kMessageStartPos == 0); |
53 function_store_.Add(start_pos); | 52 function_store_.Add(start_pos); |
54 STATIC_ASSERT(PreparseDataConstants::kMessageEndPos == 1); | 53 STATIC_ASSERT(PreparseDataConstants::kMessageEndPos == 1); |
55 function_store_.Add(end_pos); | 54 function_store_.Add(end_pos); |
56 STATIC_ASSERT(PreparseDataConstants::kMessageArgCountPos == 2); | 55 STATIC_ASSERT(PreparseDataConstants::kMessageArgCountPos == 2); |
57 function_store_.Add((arg_opt == NULL) ? 0 : 1); | 56 function_store_.Add((arg_opt == NULL) ? 0 : 1); |
58 STATIC_ASSERT(PreparseDataConstants::kParseErrorTypePos == 3); | 57 STATIC_ASSERT(PreparseDataConstants::kParseErrorTypePos == 3); |
59 function_store_.Add(error_type); | 58 function_store_.Add(error_type); |
60 STATIC_ASSERT(PreparseDataConstants::kMessageTemplatePos == 4); | 59 STATIC_ASSERT(PreparseDataConstants::kMessageTemplatePos == 4); |
61 function_store_.Add(static_cast<unsigned>(message)); | 60 function_store_.Add(static_cast<unsigned>(message)); |
62 STATIC_ASSERT(PreparseDataConstants::kMessageArgPos == 5); | 61 STATIC_ASSERT(PreparseDataConstants::kMessageArgPos == 5); |
63 if (arg_opt != NULL) WriteString(CStrVector(arg_opt)); | 62 if (arg_opt != NULL) WriteString(CStrVector(arg_opt)); |
64 } | 63 } |
65 | 64 |
66 | 65 void ParserLogger::WriteString(Vector<const char> str) { |
67 void CompleteParserRecorder::WriteString(Vector<const char> str) { | |
68 function_store_.Add(str.length()); | 66 function_store_.Add(str.length()); |
69 for (int i = 0; i < str.length(); i++) { | 67 for (int i = 0; i < str.length(); i++) { |
70 function_store_.Add(str[i]); | 68 function_store_.Add(str[i]); |
71 } | 69 } |
72 } | 70 } |
73 | 71 |
74 | 72 ScriptData* ParserLogger::GetScriptData() { |
75 ScriptData* CompleteParserRecorder::GetScriptData() { | |
76 int function_size = function_store_.size(); | 73 int function_size = function_store_.size(); |
77 int total_size = PreparseDataConstants::kHeaderSize + function_size; | 74 int total_size = PreparseDataConstants::kHeaderSize + function_size; |
78 unsigned* data = NewArray<unsigned>(total_size); | 75 unsigned* data = NewArray<unsigned>(total_size); |
79 preamble_[PreparseDataConstants::kFunctionsSizeOffset] = function_size; | 76 preamble_[PreparseDataConstants::kFunctionsSizeOffset] = function_size; |
80 MemCopy(data, preamble_, sizeof(preamble_)); | 77 MemCopy(data, preamble_, sizeof(preamble_)); |
81 if (function_size > 0) { | 78 if (function_size > 0) { |
82 function_store_.WriteTo(Vector<unsigned>( | 79 function_store_.WriteTo(Vector<unsigned>( |
83 data + PreparseDataConstants::kHeaderSize, function_size)); | 80 data + PreparseDataConstants::kHeaderSize, function_size)); |
84 } | 81 } |
85 DCHECK(IsAligned(reinterpret_cast<intptr_t>(data), kPointerAlignment)); | 82 DCHECK(IsAligned(reinterpret_cast<intptr_t>(data), kPointerAlignment)); |
86 ScriptData* result = new ScriptData(reinterpret_cast<byte*>(data), | 83 ScriptData* result = new ScriptData(reinterpret_cast<byte*>(data), |
87 total_size * sizeof(unsigned)); | 84 total_size * sizeof(unsigned)); |
88 result->AcquireDataOwnership(); | 85 result->AcquireDataOwnership(); |
89 return result; | 86 return result; |
90 } | 87 } |
91 | 88 |
92 | 89 |
93 } // namespace internal | 90 } // namespace internal |
94 } // namespace v8. | 91 } // namespace v8. |
OLD | NEW |