• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "src/parsing/preparse-data.h"
6 #include "src/base/hashmap.h"
7 #include "src/base/logging.h"
8 #include "src/globals.h"
9 #include "src/objects-inl.h"
10 #include "src/parsing/parser.h"
11 #include "src/parsing/preparse-data-format.h"
12 
13 namespace v8 {
14 namespace internal {
15 
LogFunction(int start,int end,int num_parameters,int function_length,bool has_duplicate_parameters,int properties,LanguageMode language_mode,bool uses_super_property,bool calls_eval,int num_inner_functions)16 void ParserLogger::LogFunction(int start, int end, int num_parameters,
17                                int function_length,
18                                bool has_duplicate_parameters, int properties,
19                                LanguageMode language_mode,
20                                bool uses_super_property, bool calls_eval,
21                                int num_inner_functions) {
22   function_store_.Add(start);
23   function_store_.Add(end);
24   function_store_.Add(num_parameters);
25   function_store_.Add(function_length);
26   function_store_.Add(properties);
27   function_store_.Add(
28       FunctionEntry::EncodeFlags(language_mode, uses_super_property, calls_eval,
29                                  has_duplicate_parameters));
30   function_store_.Add(num_inner_functions);
31 }
32 
ParserLogger()33 ParserLogger::ParserLogger() {
34   preamble_[PreparseDataConstants::kMagicOffset] =
35       PreparseDataConstants::kMagicNumber;
36   preamble_[PreparseDataConstants::kVersionOffset] =
37       PreparseDataConstants::kCurrentVersion;
38   preamble_[PreparseDataConstants::kFunctionsSizeOffset] = 0;
39   preamble_[PreparseDataConstants::kSizeOffset] = 0;
40   DCHECK_EQ(4, PreparseDataConstants::kHeaderSize);
41 #ifdef DEBUG
42   prev_start_ = -1;
43 #endif
44 }
45 
GetScriptData()46 ScriptData* ParserLogger::GetScriptData() {
47   int function_size = function_store_.size();
48   int total_size = PreparseDataConstants::kHeaderSize + function_size;
49   unsigned* data = NewArray<unsigned>(total_size);
50   preamble_[PreparseDataConstants::kFunctionsSizeOffset] = function_size;
51   MemCopy(data, preamble_, sizeof(preamble_));
52   if (function_size > 0) {
53     function_store_.WriteTo(Vector<unsigned>(
54         data + PreparseDataConstants::kHeaderSize, function_size));
55   }
56   DCHECK(IsAligned(reinterpret_cast<intptr_t>(data), kPointerAlignment));
57   ScriptData* result = new ScriptData(reinterpret_cast<byte*>(data),
58                                       total_size * sizeof(unsigned));
59   result->AcquireDataOwnership();
60   return result;
61 }
62 
63 
64 }  // namespace internal
65 }  // namespace v8.
66